Skip to content

Commit

Permalink
Skip download retries if files exist with mp3, wav, m4a, or webm exte…
Browse files Browse the repository at this point in the history
…nsions
  • Loading branch information
AliOsm committed Jul 13, 2024
1 parent 275301c commit a2a5c5c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tafrigh/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ def _initialize_youtube_dl_without_archive(self) -> None:
self.youtube_dl_without_archive = yt_dlp.YoutubeDL(self._config(False))

def _should_retry(self, url_data: dict[str, Any]) -> bool:
def file_exists(file_name: str) -> bool:
extensions = ['mp3', 'wav', 'm4a', 'webm']
return any(os.path.exists(os.path.join(self.output_dir, f"{file_name}.{ext}")) for ext in extensions)

if '_type' in url_data and url_data['_type'] == 'playlist':
for entry in url_data['entries']:
if entry and not os.path.exists(os.path.join(self.output_dir, f"{entry['id']}.mp3")):
if entry and not file_exists(entry['id']):
return True
else:
if not os.path.exists(os.path.join(self.output_dir, f"{url_data['id']}.mp3")):
if not file_exists(url_data['id']):
return True

return False
Expand Down

0 comments on commit a2a5c5c

Please sign in to comment.