diff --git a/notes.md b/notes.md index cbdb291..a344a3d 100644 --- a/notes.md +++ b/notes.md @@ -29,7 +29,7 @@ - metadata - search - fetch -- something with target +- target - audio_source - fetch_source - fetch_audio diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 0070e50..9e81ec3 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -1,11 +1,10 @@ from .utils.shared import * -from .metadata.download import MetadataDownloader -from .metadata import download +from .metadata.fetch import MetadataDownloader +from .metadata import fetch from .metadata import search as s -from . import download_links -from . import url_to_path -from . import download_ +from .audio_source import fetch_source, fetch_audio +from .target import set_target # NEEDS REFACTORING from .lyrics.lyrics import fetch_lyrics @@ -91,15 +90,15 @@ def cli(start_at: int = 0, only_lyrics: bool = False): if start_at <= 1 and not only_lyrics: logging.info("creating Paths") - url_to_path.UrlPath(genre=genre) + set_target.UrlPath(genre=genre) if start_at <= 2 and not only_lyrics: logging.info("Fetching Download Links") - download_links.Download() + fetch_source.Download() if start_at <= 3 and not only_lyrics: logging.info("starting to download the mp3's") - download_.Download() + fetch_audio.Download() if start_at <= 4: logging.info("starting to fetch the lyrics") diff --git a/src/music_kraken/audio_source/__init__.py b/src/music_kraken/audio_source/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/music_kraken/download_.py b/src/music_kraken/audio_source/fetch_audio.py similarity index 94% rename from src/music_kraken/download_.py rename to src/music_kraken/audio_source/fetch_audio.py index b569961..337860d 100644 --- a/src/music_kraken/download_.py +++ b/src/music_kraken/audio_source/fetch_audio.py @@ -4,8 +4,14 @@ import os.path from mutagen.easyid3 import EasyID3 from pydub import AudioSegment -from .utils.shared import * -from .scraping import musify, youtube_music +from ..utils.shared import * +from .sources import ( + youtube, + musify, + local_files +) + +logger = DOWNLOAD_LOGGER """ https://en.wikipedia.org/wiki/ID3 @@ -17,8 +23,6 @@ print("\n".join(EasyID3.valid_keys.keys())) print(EasyID3.valid_keys.keys()) """ -logger = DOWNLOAD_LOGGER - class Download: def __init__(self): @@ -36,7 +40,7 @@ class Download: if src == 'musify': download_success = musify.download(row) elif src == 'youtube': - download_success = youtube_music.download(row) + download_success = youtube.download(row) if download_success == -1: logger.warning(f"couldn't download {row['url']} from {row['src']}") diff --git a/src/music_kraken/download_links.py b/src/music_kraken/audio_source/fetch_source.py similarity index 87% rename from src/music_kraken/download_links.py rename to src/music_kraken/audio_source/fetch_source.py index be9286e..5c57bee 100644 --- a/src/music_kraken/download_links.py +++ b/src/music_kraken/audio_source/fetch_source.py @@ -1,7 +1,9 @@ -import requests - -from .utils.shared import * -from .scraping import musify, youtube_music, file_system +from ..utils.shared import * +from .sources import ( + youtube, + musify, + local_files +) logger = URL_DOWNLOAD_LOGGER @@ -28,7 +30,7 @@ class Download: """ # check YouTube - youtube_url = youtube_music.get_youtube_url(row) + youtube_url = youtube.get_youtube_url(row) if youtube_url is not None: self.add_url(youtube_url, 'youtube', id_) continue @@ -47,7 +49,8 @@ class Download: logger.warning(f"Didn't find any sources for {row['title']}") - def add_url(self, url: str, src: str, id_: str): + @staticmethod + def add_url(url: str, src: str, id_: str): database.set_download_data(id_, url, src) diff --git a/src/music_kraken/audio_source/sources/__init__.py b/src/music_kraken/audio_source/sources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/music_kraken/scraping/file_system.py b/src/music_kraken/audio_source/sources/local_files.py similarity index 96% rename from src/music_kraken/scraping/file_system.py rename to src/music_kraken/audio_source/sources/local_files.py index 72e919f..358d413 100644 --- a/src/music_kraken/scraping/file_system.py +++ b/src/music_kraken/audio_source/sources/local_files.py @@ -1,7 +1,7 @@ import os -from ..utils.shared import * -from ..utils import phonetic_compares +from ...utils.shared import * +from ...utils import phonetic_compares def is_valid(a1, a2, t1, t2) -> bool: diff --git a/src/music_kraken/scraping/musify.py b/src/music_kraken/audio_source/sources/musify.py similarity index 98% rename from src/music_kraken/scraping/musify.py rename to src/music_kraken/audio_source/sources/musify.py index a0dba25..3d424a2 100644 --- a/src/music_kraken/scraping/musify.py +++ b/src/music_kraken/audio_source/sources/musify.py @@ -4,8 +4,8 @@ import time import requests import bs4 -from ..utils.shared import * -from ..utils import phonetic_compares +from ...utils.shared import * +from ...utils import phonetic_compares TRIES = 5 TIMEOUT = 10 diff --git a/src/music_kraken/scraping/youtube_music.py b/src/music_kraken/audio_source/sources/youtube.py similarity index 98% rename from src/music_kraken/scraping/youtube_music.py rename to src/music_kraken/audio_source/sources/youtube.py index d97430a..51d03c5 100644 --- a/src/music_kraken/scraping/youtube_music.py +++ b/src/music_kraken/audio_source/sources/youtube.py @@ -4,7 +4,7 @@ import youtube_dl import logging import time -from ..utils import phonetic_compares +from ...utils import phonetic_compares YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'} YOUTUBE_URL_KEY = 'webpage_url' diff --git a/src/music_kraken/lyrics/lyrics.py b/src/music_kraken/lyrics/lyrics.py index 5d58036..1344e4f 100644 --- a/src/music_kraken/lyrics/lyrics.py +++ b/src/music_kraken/lyrics/lyrics.py @@ -1,8 +1,6 @@ import mutagen from mutagen.id3 import ID3, USLT - -from ..metadata import database as db from ..utils.shared import * from . import genius diff --git a/src/music_kraken/metadata/download.py b/src/music_kraken/metadata/fetch.py similarity index 100% rename from src/music_kraken/metadata/download.py rename to src/music_kraken/metadata/fetch.py diff --git a/src/music_kraken/metadata/object_handeling.py b/src/music_kraken/metadata/object_handeling.py deleted file mode 100644 index 7922603..0000000 --- a/src/music_kraken/metadata/object_handeling.py +++ /dev/null @@ -1,24 +0,0 @@ -from datetime import date - - -def get_elem_from_obj(current_object, keys: list, after_process=lambda x: x, return_if_none=None): - current_object = current_object - for key in keys: - if key in current_object or (type(key) == int and key < len(current_object)): - current_object = current_object[key] - else: - return return_if_none - return after_process(current_object) - - -def parse_music_brainz_date(mb_date: str) -> date: - year = 1 - month = 1 - day = 1 - - first_release_date = mb_date - if first_release_date.count("-") == 2: - year, month, day = [int(i) for i in first_release_date.split("-")] - elif first_release_date.count("-") == 0 and first_release_date.isdigit(): - year = int(first_release_date) - return date(year, month, day) diff --git a/src/music_kraken/target/__init__.py b/src/music_kraken/target/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/music_kraken/url_to_path.py b/src/music_kraken/target/set_target.py similarity index 98% rename from src/music_kraken/url_to_path.py rename to src/music_kraken/target/set_target.py index 09f8aea..4ea77c2 100644 --- a/src/music_kraken/url_to_path.py +++ b/src/music_kraken/target/set_target.py @@ -1,7 +1,7 @@ import os.path import logging -from .utils.shared import * +from ..utils.shared import * logger = PATH_LOGGER diff --git a/src/music_kraken/metadata/database.py b/src/music_kraken/utils/database.py similarity index 100% rename from src/music_kraken/metadata/database.py rename to src/music_kraken/utils/database.py diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 6c6f190..55ed317 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -3,7 +3,7 @@ import logging import tempfile import os -from ..metadata.database import Database +from .database import Database TEMP_FOLDER = "music-downloader" LOG_FILE = "download_logs.log"