mirror of
https://github.com/alexta69/metube.git
synced 2025-04-03 20:27:36 +03:00
Merge pull request #335 from ArabCoders/master
Expose done/queue list as JSON endpoint
This commit is contained in:
commit
03d6edea5c
3 changed files with 21 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -46,3 +46,4 @@ Thumbs.db
|
|||
|
||||
|
||||
__pycache__
|
||||
.venv
|
||||
|
|
11
app/main.py
11
app/main.py
|
@ -132,6 +132,17 @@ async def delete(request):
|
|||
status = await (dqueue.cancel(ids) if where == 'queue' else dqueue.clear(ids))
|
||||
return web.Response(text=serializer.encode(status))
|
||||
|
||||
@routes.get(config.URL_PREFIX + 'history')
|
||||
async def history(request):
|
||||
history = { 'done': [], 'queue': []}
|
||||
|
||||
for _ ,v in dqueue.queue.saved_items():
|
||||
history['queue'].append(v)
|
||||
for _ ,v in dqueue.done.saved_items():
|
||||
history['done'].append(v)
|
||||
|
||||
return web.Response(text=serializer.encode(history))
|
||||
|
||||
@sio.event
|
||||
async def connect(sid, environ):
|
||||
await sio.emit('all', serializer.encode(dqueue.get()), to=sid)
|
||||
|
|
15
app/ytdl.py
15
app/ytdl.py
|
@ -157,17 +157,17 @@ class PersistentQueue:
|
|||
pass
|
||||
self.path = path
|
||||
self.dict = OrderedDict()
|
||||
|
||||
|
||||
def load(self):
|
||||
for k, v in self.saved_items():
|
||||
self.dict[k] = Download(None, None, None, None, None, None, {}, v)
|
||||
|
||||
def exists(self, key):
|
||||
return key in self.dict
|
||||
|
||||
|
||||
def get(self, key):
|
||||
return self.dict[key]
|
||||
|
||||
|
||||
def items(self):
|
||||
return self.dict.items()
|
||||
|
||||
|
@ -180,7 +180,7 @@ class PersistentQueue:
|
|||
self.dict[key] = value
|
||||
with shelve.open(self.path, 'w') as shelf:
|
||||
shelf[key] = value.info
|
||||
|
||||
|
||||
def delete(self, key):
|
||||
del self.dict[key]
|
||||
with shelve.open(self.path, 'w') as shelf:
|
||||
|
@ -189,7 +189,7 @@ class PersistentQueue:
|
|||
def next(self):
|
||||
k, v = next(iter(self.dict.items()))
|
||||
return k, v
|
||||
|
||||
|
||||
def empty(self):
|
||||
return not bool(self.dict)
|
||||
|
||||
|
@ -201,7 +201,7 @@ class DownloadQueue:
|
|||
self.queue = PersistentQueue(self.config.STATE_DIR + '/queue')
|
||||
self.done = PersistentQueue(self.config.STATE_DIR + '/completed')
|
||||
self.done.load()
|
||||
|
||||
|
||||
async def __import_queue(self):
|
||||
for k, v in self.queue.saved_items():
|
||||
await self.add(v.url, v.quality, v.format, v.folder, v.custom_name_prefix)
|
||||
|
@ -243,6 +243,9 @@ class DownloadQueue:
|
|||
return dldirectory, None
|
||||
|
||||
async def __add_entry(self, entry, quality, format, folder, custom_name_prefix, already):
|
||||
if not entry:
|
||||
return {'status': 'error', 'msg': "Invalid/empty data was given."}
|
||||
|
||||
etype = entry.get('_type') or 'video'
|
||||
if etype == 'playlist':
|
||||
entries = entry['entries']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue