refactored using the song and src object instead of dict

This commit is contained in:
Lars Noack 2022-11-22 11:37:41 +01:00
parent a021b289c0
commit 4095efb6a1
3 changed files with 19 additions and 11 deletions

View File

@ -7,6 +7,8 @@ from ...utils.shared import *
from ...utils import phonetic_compares from ...utils import phonetic_compares
from .source import AudioSource from .source import AudioSource
from ...database import song as song_objects
TRIES = 5 TRIES = 5
TIMEOUT = 10 TIMEOUT = 10
@ -156,11 +158,11 @@ class Musify(AudioSource):
return True return True
@classmethod @classmethod
def fetch_audio(cls, url: str, row: dict): def fetch_audio(cls, song: song_objects.Song, src: song_objects.Source):
super().fetch_audio(url, row) super().fetch_audio(song, src)
file_ = row['file'] file_ = song['file']
return cls.download_from_musify(file_, url) return cls.download_from_musify(file_, src.url)
""" """

View File

@ -1,6 +1,9 @@
from ...utils.shared import * from ...utils.shared import *
from typing import Tuple from typing import Tuple
from ...database import song as song_objects
logger = URL_DOWNLOAD_LOGGER logger = URL_DOWNLOAD_LOGGER
""" """
@ -16,5 +19,5 @@ class AudioSource:
logger.info(f"try getting source {row['title']} from {cls.__name__}") logger.info(f"try getting source {row['title']} from {cls.__name__}")
@classmethod @classmethod
def fetch_audio(cls, url: str,row: dict): def fetch_audio(cls, song: song_objects.Song, src: song_objects.Sourcet):
logger.info(f"downloading audio from {row['url']} from {cls.__name__} to {row['file']}") logger.info(f"downloading audio from {src.url} from {cls.__name__} to {song['file']}")

View File

@ -7,6 +7,9 @@ from ...utils.shared import *
from ...utils import phonetic_compares from ...utils import phonetic_compares
from .source import AudioSource from .source import AudioSource
from ...database import song as song_objects
logger = YOUTUBE_LOGGER logger = YOUTUBE_LOGGER
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'} YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
@ -59,10 +62,10 @@ class Youtube(AudioSource):
return final_result['url'] return final_result['url']
@classmethod @classmethod
def fetch_audio(cls, url: str, row: dict, trie: int=0): def fetch_audio(cls, song: song_objects.Song, src: song_objects.Source, trie: int=0):
super().fetch_audio(url, row) super().fetch_audio(song, src)
file_ = row['file'] file_ = song['file']
options = { options = {
'format': 'bestaudio/best', 'format': 'bestaudio/best',
'keepvideo': False, 'keepvideo': False,
@ -71,14 +74,14 @@ class Youtube(AudioSource):
try: try:
with youtube_dl.YoutubeDL(options) as ydl: with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([url]) ydl.download([src.url])
except youtube_dl.utils.DownloadError: except youtube_dl.utils.DownloadError:
logger.warning(f"youtube blocked downloading. ({trie}-{MAX_TRIES})") logger.warning(f"youtube blocked downloading. ({trie}-{MAX_TRIES})")
if trie >= MAX_TRIES: if trie >= MAX_TRIES:
logger.warning("too many tries, returning") logger.warning("too many tries, returning")
logger.warning(f"retrying in {WAIT_BETWEEN_BLOCK} seconds again") logger.warning(f"retrying in {WAIT_BETWEEN_BLOCK} seconds again")
time.sleep(WAIT_BETWEEN_BLOCK) time.sleep(WAIT_BETWEEN_BLOCK)
return cls.fetch_audio(url, row, trie=trie + 1) return cls.fetch_audio(song, src, trie=trie + 1)
""" """
def get_youtube_from_isrc(isrc: str) -> List[dict]: def get_youtube_from_isrc(isrc: str) -> List[dict]: