From 4095efb6a1eee94de3822b55160bf1d6c682af06 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 22 Nov 2022 11:37:41 +0100 Subject: [PATCH] refactored using the song and src object instead of dict --- src/music_kraken/audio_source/sources/musify.py | 10 ++++++---- src/music_kraken/audio_source/sources/source.py | 7 +++++-- src/music_kraken/audio_source/sources/youtube.py | 13 ++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/music_kraken/audio_source/sources/musify.py b/src/music_kraken/audio_source/sources/musify.py index 57dd395..ffa9e84 100644 --- a/src/music_kraken/audio_source/sources/musify.py +++ b/src/music_kraken/audio_source/sources/musify.py @@ -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) """ diff --git a/src/music_kraken/audio_source/sources/source.py b/src/music_kraken/audio_source/sources/source.py index a6429a7..f2f0c65 100644 --- a/src/music_kraken/audio_source/sources/source.py +++ b/src/music_kraken/audio_source/sources/source.py @@ -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']}") diff --git a/src/music_kraken/audio_source/sources/youtube.py b/src/music_kraken/audio_source/sources/youtube.py index 2c35b10..e462a4d 100644 --- a/src/music_kraken/audio_source/sources/youtube.py +++ b/src/music_kraken/audio_source/sources/youtube.py @@ -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]: