Add singleton playlist manager
Currently implemented is queing, dequening, and automatic title fetch using metadatafetch.
This commit is contained in:
parent
f58217d0cb
commit
bc54eb3f6b
@ -1,7 +1,9 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
from . import playlistmanage
|
||||||
|
|
||||||
async def entry():
|
async def entry():
|
||||||
await asyncio.wait([
|
await asyncio.wait([
|
||||||
|
playlistmanage.metadatafetch_loop(),
|
||||||
])
|
])
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
34
grzegorz/playlistmanage.py
Normal file
34
grzegorz/playlistmanage.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
from . import metadatafetch
|
||||||
|
from . import nyasync
|
||||||
|
|
||||||
|
metadatafetch_queue = nyasync.Queue()
|
||||||
|
async def metadatafetch_loop():
|
||||||
|
async for item in metadatafetch_queue:
|
||||||
|
title = await metadatafetch.title(item.url)
|
||||||
|
item.title = title
|
||||||
|
metadatafetch_queue.task_done()
|
||||||
|
|
||||||
|
class PlaylistItem:
|
||||||
|
def __init__(self, url):
|
||||||
|
self.url = url
|
||||||
|
self.title = None
|
||||||
|
|
||||||
|
class Playlist:
|
||||||
|
def __init__(self):
|
||||||
|
self.playlist = []
|
||||||
|
self.nonempty = nyasync.Condition(lambda: self.playlist)
|
||||||
|
self.change = nyasync.Event()
|
||||||
|
|
||||||
|
def queue(self, url):
|
||||||
|
item = PlaylistItem(url)
|
||||||
|
self.playlist.append(item)
|
||||||
|
metadatafetch_queue.put_nowait(item)
|
||||||
|
self.nonempty.notify()
|
||||||
|
self.change.notify()
|
||||||
|
|
||||||
|
async def dequeue(self) -> PlaylistItem:
|
||||||
|
await self.nonempty
|
||||||
|
self.change.notify()
|
||||||
|
return self.playlist.pop(0)
|
Loading…
Reference in New Issue
Block a user