Added some more dependencies, getting data needed.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -32,6 +32,24 @@ def gen_batched_tracks(
|
||||
pos += batch_size
|
||||
|
||||
|
||||
async def track_mapper(track: plexapi.audio.Track) -> dict:
|
||||
return {
|
||||
"id": track.ratingKey,
|
||||
"track_num": track.index,
|
||||
"title": track.title,
|
||||
"artist": track.artist().title,
|
||||
"album_num": track.parentIndex,
|
||||
"album": track.parentTitle,
|
||||
"album_artist": track.grandparentTitle,
|
||||
"duration": track.duration,
|
||||
"rating": track.userRating,
|
||||
"comments": track.summary,
|
||||
"added": track.addedAt,
|
||||
"play_count": track.viewCount,
|
||||
"played": track.lastViewedAt,
|
||||
}
|
||||
|
||||
|
||||
async def gen_tracks(
|
||||
*,
|
||||
batch_size: int = 100,
|
||||
@@ -42,7 +60,12 @@ async def gen_tracks(
|
||||
Keyword Args:
|
||||
batch_size: determines how many Tracks are pulled from the Server at a time.
|
||||
"""
|
||||
track_obs = rx.AsyncRx.from_iterable(gen_batched_tracks(batch_size=batch_size))
|
||||
track_obs = track_obs.flat_map(rx.AsyncRx.from_iterable)
|
||||
async for track in track_obs.to_async_iterable():
|
||||
source = rx.AsyncRx.from_iterable(gen_batched_tracks(batch_size=batch_size))
|
||||
track_rx = rx.pipe(
|
||||
source,
|
||||
rx.flat_map(rx.AsyncRx.from_iterable),
|
||||
rx.map_async(track_mapper),
|
||||
)
|
||||
track_obs = rx.AsyncIteratorObserver(track_rx)
|
||||
async for track in track_obs:
|
||||
yield track
|
||||
|
||||
Reference in New Issue
Block a user