refactored using the song and src object instead of dict
This commit is contained in:
parent
a021b289c0
commit
4095efb6a1
@ -7,6 +7,8 @@ from ...utils.shared import *
|
||||
from ...utils import phonetic_compares
|
||||
|
||||
from .source import AudioSource
|
||||
from ...database import song as song_objects
|
||||
|
||||
|
||||
TRIES = 5
|
||||
TIMEOUT = 10
|
||||
@ -156,11 +158,11 @@ class Musify(AudioSource):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def fetch_audio(cls, url: str, row: dict):
|
||||
super().fetch_audio(url, row)
|
||||
def fetch_audio(cls, song: song_objects.Song, src: song_objects.Source):
|
||||
super().fetch_audio(song, src)
|
||||
|
||||
file_ = row['file']
|
||||
return cls.download_from_musify(file_, url)
|
||||
file_ = song['file']
|
||||
return cls.download_from_musify(file_, src.url)
|
||||
|
||||
|
||||
"""
|
||||
|
@ -1,6 +1,9 @@
|
||||
from ...utils.shared import *
|
||||
from typing import Tuple
|
||||
|
||||
from ...database import song as song_objects
|
||||
|
||||
|
||||
logger = URL_DOWNLOAD_LOGGER
|
||||
|
||||
"""
|
||||
@ -16,5 +19,5 @@ class AudioSource:
|
||||
logger.info(f"try getting source {row['title']} from {cls.__name__}")
|
||||
|
||||
@classmethod
|
||||
def fetch_audio(cls, url: str,row: dict):
|
||||
logger.info(f"downloading audio from {row['url']} from {cls.__name__} to {row['file']}")
|
||||
def fetch_audio(cls, song: song_objects.Song, src: song_objects.Sourcet):
|
||||
logger.info(f"downloading audio from {src.url} from {cls.__name__} to {song['file']}")
|
||||
|
@ -7,6 +7,9 @@ from ...utils.shared import *
|
||||
from ...utils import phonetic_compares
|
||||
from .source import AudioSource
|
||||
|
||||
from ...database import song as song_objects
|
||||
|
||||
|
||||
logger = YOUTUBE_LOGGER
|
||||
|
||||
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
|
||||
@ -59,10 +62,10 @@ class Youtube(AudioSource):
|
||||
return final_result['url']
|
||||
|
||||
@classmethod
|
||||
def fetch_audio(cls, url: str, row: dict, trie: int=0):
|
||||
super().fetch_audio(url, row)
|
||||
def fetch_audio(cls, song: song_objects.Song, src: song_objects.Source, trie: int=0):
|
||||
super().fetch_audio(song, src)
|
||||
|
||||
file_ = row['file']
|
||||
file_ = song['file']
|
||||
options = {
|
||||
'format': 'bestaudio/best',
|
||||
'keepvideo': False,
|
||||
@ -71,14 +74,14 @@ class Youtube(AudioSource):
|
||||
|
||||
try:
|
||||
with youtube_dl.YoutubeDL(options) as ydl:
|
||||
ydl.download([url])
|
||||
ydl.download([src.url])
|
||||
except youtube_dl.utils.DownloadError:
|
||||
logger.warning(f"youtube blocked downloading. ({trie}-{MAX_TRIES})")
|
||||
if trie >= MAX_TRIES:
|
||||
logger.warning("too many tries, returning")
|
||||
logger.warning(f"retrying in {WAIT_BETWEEN_BLOCK} seconds again")
|
||||
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]:
|
||||
|
Loading…
Reference in New Issue
Block a user