refactor
This commit is contained in:
@@ -39,6 +39,7 @@ musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeI
|
||||
|
||||
# define the most important values and function for import in the __init__ file
|
||||
Song = database.Song
|
||||
Artist = database.Artist
|
||||
MetadataSearch = metadata.MetadataSearch
|
||||
MetadataDownload = metadata.MetadataDownload
|
||||
|
||||
|
@@ -39,9 +39,10 @@ class Download:
|
||||
@classmethod
|
||||
def fetch_sources(cls, songs: List[song_object], skip_existing_files: bool = False):
|
||||
for song in songs:
|
||||
if os.path.exists(song.target.file) and skip_existing_files:
|
||||
logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.")
|
||||
continue
|
||||
if song.target.is_set():
|
||||
if os.path.exists(song.target.file) and skip_existing_files:
|
||||
logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.")
|
||||
continue
|
||||
|
||||
sucess = False
|
||||
for src in AUDIO_SOURCES:
|
||||
|
@@ -8,7 +8,7 @@ from . import (
|
||||
)
|
||||
|
||||
Song = song.Song
|
||||
Artist = artist.Artist
|
||||
Artist = song.Artist
|
||||
Source = source.Source
|
||||
Target = target.Target
|
||||
Metadata = metadata.Metadata
|
||||
|
@@ -13,7 +13,7 @@ from .song import (
|
||||
|
||||
def get_song_from_response(response: dict) -> Song:
|
||||
# artists
|
||||
artists = [Artist(a) for a in response['artists']]
|
||||
artists = [Artist(id_=a['id'], name=a['name']) for a in response['artists']]
|
||||
|
||||
# metadata
|
||||
metadata = Metadata()
|
||||
|
@@ -6,6 +6,19 @@ from .source import Source
|
||||
from .target import Target
|
||||
|
||||
|
||||
class Artist:
|
||||
def __init__(self, id_: str = None, name: str = None) -> None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
|
||||
def __eq__(self, __o: object) -> bool:
|
||||
if type(__o) != type(self):
|
||||
return False
|
||||
return self.id == __o.id
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
class Lyrics:
|
||||
def __init__(self, text: str, language: str) -> None:
|
||||
|
@@ -25,6 +25,9 @@ class Target:
|
||||
if self._path is None:
|
||||
return None
|
||||
return os.path.join(MUSIC_DIR, self._path)
|
||||
|
||||
def is_set(self) -> bool:
|
||||
return not (self._file is None or self._path is None)
|
||||
|
||||
file = property(fget=get_file, fset=set_file)
|
||||
path = property(fget=get_path, fset=set_path)
|
||||
|
Reference in New Issue
Block a user