gotta fix fucking imports

This commit is contained in:
Lars Noack
2022-11-22 14:25:01 +01:00
parent ef362dd2a4
commit f45afcb2ce
9 changed files with 38 additions and 31 deletions

View File

@@ -10,6 +10,7 @@ from .sources import (
musify,
local_files
)
from ..database import song as song_objects
logger = DOWNLOAD_LOGGER
@@ -33,11 +34,8 @@ print(EasyID3.valid_keys.keys())
class Download:
def __init__(self):
for song in database.get_tracks_to_download():
song['artist'] = [i['name'] for i in song['artists']]
song['file'] = os.path.join(MUSIC_DIR, song['file'])
song['path'] = os.path.join(MUSIC_DIR, song['path'])
if self.path_stuff(song['path'], song['file']):
if self.path_stuff(song.target):
self.write_metadata(song, song['file'])
continue
@@ -93,12 +91,12 @@ class Download:
audiofile.save(file_path, v1=2)
@staticmethod
def path_stuff(path: str, file_: str):
def path_stuff(target: song_objects.Target):
# returns true if it shouldn't be downloaded
if os.path.exists(file_):
logger.info(f"'{file_}' does already exist, thus not downloading.")
if os.path.exists(target.file):
logger.info(f"'{target.file}' does already exist, thus not downloading.")
return True
os.makedirs(path, exist_ok=True)
os.makedirs(target.path, exist_ok=True)
return False

View File

@@ -6,6 +6,8 @@ from .sources import (
local_files
)
from .. import database
logger = URL_DOWNLOAD_LOGGER
# maps the classes to get data from to the source name

View File

@@ -26,11 +26,11 @@ session.proxies = proxies
class Musify(AudioSource):
@classmethod
def fetch_source(cls, row: dict) -> str | None:
super().fetch_source(row)
def fetch_source(cls, song: dict) -> str | None:
super().fetch_source(song)
title = row.title
artists = row.get_artist_names()
title = song.title
artists = song.get_artist_names()
# trying to get a download link via the autocomplete api
for artist in artists:
@@ -73,9 +73,9 @@ class Musify(AudioSource):
return None
if r.status_code == 200:
autocomplete = r.json()
for row in autocomplete:
if artist in row['label'] and "/track" in row['url']:
return cls.get_download_link(row['url'])
for song in autocomplete:
if artist in song['label'] and "/track" in song['url']:
return cls.get_download_link(song['url'])
return None

View File

@@ -19,5 +19,5 @@ class AudioSource:
logger.info(f"try getting source {row['title']} from {cls.__name__}")
@classmethod
def fetch_audio(cls, song: song_objects.Song, src: song_objects.Sourcet):
def fetch_audio(cls, song: song_objects.Song, src: song_objects.Source):
logger.info(f"downloading {song}: {cls.__name__} {src.url} -> {song.target.file}")