This commit is contained in:
ArabCoders 2023-11-28 17:29:45 +03:00
parent f0d4f14b1f
commit 825a42b497
2 changed files with 72 additions and 42 deletions

View file

@ -38,12 +38,34 @@ class DataStore:
default_ytdl_opts=self.config.ytdl_options, default_ytdl_opts=self.config.ytdl_options,
) )
def exists(self, key: str) -> bool: def exists(self, key: str = None, url: str = None) -> bool:
return key in self.dict if not key and not url:
raise KeyError('key or url must be provided')
def get(self, key: str) -> Download: if key and key in self.dict:
return True
if url:
for key in self.dict:
if self.dict[key].info.url == url:
return True
return False
def get(self, key: str, url: str = None) -> Download:
if not key and not url:
raise KeyError('key or url must be provided')
if key and key in self.dict:
return self.dict[key] return self.dict[key]
if url:
for key in self.dict:
if self.dict[key].info.url == url:
return self.dict[key]
raise KeyError('key or url not found')
def items(self) -> list[tuple[str, Download]]: def items(self) -> list[tuple[str, Download]]:
return self.dict.items() return self.dict.items()

View file

@ -93,8 +93,16 @@ class DownloadQueue:
return {'status': 'error', 'msg': ', '.join(res['msg'] for res in results if res['status'] == 'error' and 'msg' in res)} return {'status': 'error', 'msg': ', '.join(res['msg'] for res in results if res['status'] == 'error' and 'msg' in res)}
return {'status': 'ok'} return {'status': 'ok'}
elif etype == 'video' or etype.startswith('url') and 'id' in entry and 'title' in entry: elif (etype == 'video' or etype.startswith('url')) and 'id' in entry and 'title' in entry:
if not self.queue.exists(entry['id']):
if self.done.exists(key=entry['id'], url=entry.get('webpage_url') or entry['url']):
item = self.done.get(key=entry['id'], url=entry.get(
'webpage_url') or entry['url'])
self.done.clear([item.info._id])
if self.queue.exists(key=entry['id'], url=entry.get('webpage_url') or entry['url']):
return {'status': 'error', 'msg': 'Link already queued for downloading.'}
dl = ItemDTO( dl = ItemDTO(
id=entry['id'], id=entry['id'],
title=entry['title'], title=entry['title'],