Skip to content

Commit

Permalink
Merge pull request #335 from ArabCoders/master
Browse files Browse the repository at this point in the history
Expose done/queue list as JSON endpoint
  • Loading branch information
alexta69 authored Nov 3, 2023
2 parents 0985f97 + 72b7447 commit 03d6ede
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Thumbs.db


__pycache__
.venv
11 changes: 11 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions app/ytdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ def __init__(self, path):
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()

Expand All @@ -180,7 +180,7 @@ def put(self, value):
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:
Expand All @@ -189,7 +189,7 @@ def delete(self, key):
def next(self):
k, v = next(iter(self.dict.items()))
return k, v

def empty(self):
return not bool(self.dict)

Expand All @@ -201,7 +201,7 @@ def __init__(self, config, notifier):
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)
Expand Down Expand Up @@ -243,6 +243,9 @@ def __calc_download_path(self, quality, format, folder):
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']
Expand Down

0 comments on commit 03d6ede

Please sign in to comment.