Fixing erros due to processing

This commit is contained in:
Rafael Vargas
2022-07-24 14:25:44 -03:00
parent 56456bf2ed
commit b904c75caa
16 changed files with 179 additions and 305 deletions

View File

@@ -1,10 +1,11 @@
import asyncio
from typing import List
from Config.Configs import Configs
from yt_dlp import YoutubeDL
from yt_dlp import YoutubeDL, DownloadError
from concurrent.futures import ThreadPoolExecutor
from Music.Song import Song
from Utils.Utils import Utils, run_async
from Config.Exceptions import DownloadingError
class Downloader:
@@ -40,16 +41,20 @@ class Downloader:
self.__playlist_keys = ['entries']
def finish_one_song(self, song: Song) -> Song:
if song.identifier is None:
return None
try:
if song.identifier is None:
return None
if Utils.is_url(song.identifier):
song_info = self.__download_url(song.identifier)
else:
song_info = self.__download_title(song.identifier)
if Utils.is_url(song.identifier):
song_info = self.__download_url(song.identifier)
else:
song_info = self.__download_title(song.identifier)
song.finish_down(song_info)
return song
song.finish_down(song_info)
return song
# Convert yt_dlp error to my own error
except DownloadError:
raise DownloadingError()
async def preload(self, songs: List[Song]) -> None:
for song in songs:
@@ -81,8 +86,11 @@ class Downloader:
else: # Failed to extract the songs
print(f'DEVELOPER NOTE -> Failed to Extract URL {url}')
return []
# Convert the yt_dlp download error to own error
except DownloadError:
raise DownloadingError()
except Exception as e:
print(f'DEVELOPER NOTE -> Error Extracting Music: {e}')
print(f'DEVELOPER NOTE -> Error Extracting Music: {e}, {type(e)}')
raise e
else:
return []