diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..682d0c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.mp3 diff --git a/dsbm/Black Hate/Children of Failure/Alone and Cold.mp3 b/dsbm/Black Hate/Children of Failure/Alone and Cold.mp3 new file mode 100644 index 0000000..86715e1 Binary files /dev/null and b/dsbm/Black Hate/Children of Failure/Alone and Cold.mp3 differ diff --git a/dsbm/Demons & Wizards/Demons & Wizards/My Last Sunrise.mp3 b/dsbm/Demons & Wizards/Demons & Wizards/My Last Sunrise.mp3 new file mode 100644 index 0000000..6d3625f Binary files /dev/null and b/dsbm/Demons & Wizards/Demons & Wizards/My Last Sunrise.mp3 differ diff --git a/dsbm/Fornicatus/Children of Failure/Years of Angst.mp3 b/dsbm/Fornicatus/Children of Failure/Years of Angst.mp3 new file mode 100644 index 0000000..abc36ca Binary files /dev/null and b/dsbm/Fornicatus/Children of Failure/Years of Angst.mp3 differ diff --git a/dsbm/Happy Days/A World of Pain/Dens Nettop Begonia.mp3 b/dsbm/Happy Days/A World of Pain/Dens Nettop Begonia.mp3 new file mode 100644 index 0000000..ee2426c Binary files /dev/null and b/dsbm/Happy Days/A World of Pain/Dens Nettop Begonia.mp3 differ diff --git a/dsbm/Happy Days/A World of Pain/Introduksjon og Døende.mp3 b/dsbm/Happy Days/A World of Pain/Introduksjon og Døende.mp3 new file mode 100644 index 0000000..4fd9c78 Binary files /dev/null and b/dsbm/Happy Days/A World of Pain/Introduksjon og Døende.mp3 differ diff --git a/dsbm/Happy Days/A World of Pain/Lidende.mp3 b/dsbm/Happy Days/A World of Pain/Lidende.mp3 new file mode 100644 index 0000000..cd48bcb Binary files /dev/null and b/dsbm/Happy Days/A World of Pain/Lidende.mp3 differ diff --git a/dsbm/Happy Days/A World of Pain/Welcome (To a World of Pain).mp3 b/dsbm/Happy Days/A World of Pain/Welcome (To a World of Pain).mp3 new file mode 100644 index 0000000..06b9bae Binary files /dev/null and b/dsbm/Happy Days/A World of Pain/Welcome (To a World of Pain).mp3 differ diff --git a/dsbm/Happy Days/Alone and Cold/Alone and Cold.mp3 b/dsbm/Happy Days/Alone and Cold/Alone and Cold.mp3 new file mode 100644 index 0000000..ed000fe Binary files /dev/null and b/dsbm/Happy Days/Alone and Cold/Alone and Cold.mp3 differ diff --git a/dsbm/Happy Days/Alone and Cold/End All Happiness.mp3 b/dsbm/Happy Days/Alone and Cold/End All Happiness.mp3 new file mode 100644 index 0000000..4e4826c Binary files /dev/null and b/dsbm/Happy Days/Alone and Cold/End All Happiness.mp3 differ diff --git a/dsbm/Happy Days/Children of Failure/Dying Alone Done.mp3 b/dsbm/Happy Days/Children of Failure/Dying Alone Done.mp3 new file mode 100644 index 0000000..abad780 Binary files /dev/null and b/dsbm/Happy Days/Children of Failure/Dying Alone Done.mp3 differ diff --git a/dsbm/Happy Days/Defeated by Life/Defeated by Life.mp3 b/dsbm/Happy Days/Defeated by Life/Defeated by Life.mp3 new file mode 100644 index 0000000..218527e Binary files /dev/null and b/dsbm/Happy Days/Defeated by Life/Defeated by Life.mp3 differ diff --git a/dsbm/Happy Days/Defeated by Life/Emotionally Torn From Within.mp3 b/dsbm/Happy Days/Defeated by Life/Emotionally Torn From Within.mp3 new file mode 100644 index 0000000..6836625 Binary files /dev/null and b/dsbm/Happy Days/Defeated by Life/Emotionally Torn From Within.mp3 differ diff --git a/dsbm/Happy Days/Defeated by Life/Hurt, Destroyed and Torn... There's Nothing Left.mp3 b/dsbm/Happy Days/Defeated by Life/Hurt, Destroyed and Torn... There's Nothing Left.mp3 new file mode 100644 index 0000000..8d594cb Binary files /dev/null and b/dsbm/Happy Days/Defeated by Life/Hurt, Destroyed and Torn... There's Nothing Left.mp3 differ diff --git a/dsbm/Happy Days/Defeated by Life/The Painful Truth.mp3 b/dsbm/Happy Days/Defeated by Life/The Painful Truth.mp3 new file mode 100644 index 0000000..30e8c41 Binary files /dev/null and b/dsbm/Happy Days/Defeated by Life/The Painful Truth.mp3 differ diff --git a/dsbm/Happy Days/Defeated by Life/Trnový Labyrint.mp3 b/dsbm/Happy Days/Defeated by Life/Trnový Labyrint.mp3 new file mode 100644 index 0000000..7eafde1 Binary files /dev/null and b/dsbm/Happy Days/Defeated by Life/Trnový Labyrint.mp3 differ diff --git a/dsbm/Happy Days/Drowning in Negativity/En Annen Dag... En Annen Død....mp3 b/dsbm/Happy Days/Drowning in Negativity/En Annen Dag... En Annen Død....mp3 new file mode 100644 index 0000000..6c0c8eb Binary files /dev/null and b/dsbm/Happy Days/Drowning in Negativity/En Annen Dag... En Annen Død....mp3 differ diff --git a/dsbm/Happy Days/Drowning in Negativity/Jeg Er Ikke Noe....mp3 b/dsbm/Happy Days/Drowning in Negativity/Jeg Er Ikke Noe....mp3 new file mode 100644 index 0000000..79c4e7c Binary files /dev/null and b/dsbm/Happy Days/Drowning in Negativity/Jeg Er Ikke Noe....mp3 differ diff --git a/dsbm/Happy Days/Drowning in Negativity/Nedslåttheten.mp3 b/dsbm/Happy Days/Drowning in Negativity/Nedslåttheten.mp3 new file mode 100644 index 0000000..b16b746 Binary files /dev/null and b/dsbm/Happy Days/Drowning in Negativity/Nedslåttheten.mp3 differ diff --git a/dsbm/Happy Days/Drowning in Negativity/Tiggeren For Nei Barmhjertighet.mp3 b/dsbm/Happy Days/Drowning in Negativity/Tiggeren For Nei Barmhjertighet.mp3 new file mode 100644 index 0000000..85a2fce Binary files /dev/null and b/dsbm/Happy Days/Drowning in Negativity/Tiggeren For Nei Barmhjertighet.mp3 differ diff --git a/dsbm/Happy Days/Happiness Stops Here.../My Brutus.mp3 b/dsbm/Happy Days/Happiness Stops Here.../My Brutus.mp3 new file mode 100644 index 0000000..099092b Binary files /dev/null and b/dsbm/Happy Days/Happiness Stops Here.../My Brutus.mp3 differ diff --git a/dsbm/Happy Days/Happiness Stops Here.../Sovnlose Netter I Mitt Isolatrom.mp3 b/dsbm/Happy Days/Happiness Stops Here.../Sovnlose Netter I Mitt Isolatrom.mp3 new file mode 100644 index 0000000..d502ba7 Binary files /dev/null and b/dsbm/Happy Days/Happiness Stops Here.../Sovnlose Netter I Mitt Isolatrom.mp3 differ diff --git a/dsbm/Happy Days/Happiness Stops Here.../What It Feels to Be Unloved.mp3 b/dsbm/Happy Days/Happiness Stops Here.../What It Feels to Be Unloved.mp3 new file mode 100644 index 0000000..c97dbdb Binary files /dev/null and b/dsbm/Happy Days/Happiness Stops Here.../What It Feels to Be Unloved.mp3 differ diff --git a/dsbm/Happy Days/Melancholic Memories/Drowning in Razorblades.mp3 b/dsbm/Happy Days/Melancholic Memories/Drowning in Razorblades.mp3 new file mode 100644 index 0000000..654d8d5 Binary files /dev/null and b/dsbm/Happy Days/Melancholic Memories/Drowning in Razorblades.mp3 differ diff --git a/dsbm/Happy Days/Melancholic Memories/Neglect....mp3 b/dsbm/Happy Days/Melancholic Memories/Neglect....mp3 new file mode 100644 index 0000000..8ca1a5c Binary files /dev/null and b/dsbm/Happy Days/Melancholic Memories/Neglect....mp3 differ diff --git a/dsbm/Happy Days/Melancholic Memories/Slowly and Painfully.mp3 b/dsbm/Happy Days/Melancholic Memories/Slowly and Painfully.mp3 new file mode 100644 index 0000000..498a22b Binary files /dev/null and b/dsbm/Happy Days/Melancholic Memories/Slowly and Painfully.mp3 differ diff --git a/dsbm/Thy Light/Suici.De.pression/...and I Finally Reach My End.mp3 b/dsbm/Thy Light/Suici.De.pression/...and I Finally Reach My End.mp3 new file mode 100644 index 0000000..deca87b Binary files /dev/null and b/dsbm/Thy Light/Suici.De.pression/...and I Finally Reach My End.mp3 differ diff --git a/dsbm/Thy Light/Suici.De.pression/A Crawling Worm in a World of Lies.mp3 b/dsbm/Thy Light/Suici.De.pression/A Crawling Worm in a World of Lies.mp3 new file mode 100644 index 0000000..5713128 Binary files /dev/null and b/dsbm/Thy Light/Suici.De.pression/A Crawling Worm in a World of Lies.mp3 differ diff --git a/dsbm/Thy Light/Suici.De.pression/I Am the Bitter Taste of Gall.mp3 b/dsbm/Thy Light/Suici.De.pression/I Am the Bitter Taste of Gall.mp3 new file mode 100644 index 0000000..446f9d3 Binary files /dev/null and b/dsbm/Thy Light/Suici.De.pression/I Am the Bitter Taste of Gall.mp3 differ diff --git a/dsbm/Thy Light/Suici.De.pression/In My Last Mourning....mp3 b/dsbm/Thy Light/Suici.De.pression/In My Last Mourning....mp3 new file mode 100644 index 0000000..97ca50a Binary files /dev/null and b/dsbm/Thy Light/Suici.De.pression/In My Last Mourning....mp3 differ diff --git a/dsbm/Thy Light/Suici.De.pression/Suici.De.pression (Introduction to My End).mp3 b/dsbm/Thy Light/Suici.De.pression/Suici.De.pression (Introduction to My End).mp3 new file mode 100644 index 0000000..06e9244 Binary files /dev/null and b/dsbm/Thy Light/Suici.De.pression/Suici.De.pression (Introduction to My End).mp3 differ diff --git a/src/__pycache__/download.cpython-310.pyc b/src/__pycache__/download.cpython-310.pyc new file mode 100644 index 0000000..0977aa9 Binary files /dev/null and b/src/__pycache__/download.cpython-310.pyc differ diff --git a/src/__pycache__/download_links.cpython-310.pyc b/src/__pycache__/download_links.cpython-310.pyc index 278b4ea..f26a41c 100644 Binary files a/src/__pycache__/download_links.cpython-310.pyc and b/src/__pycache__/download_links.cpython-310.pyc differ diff --git a/src/__pycache__/metadata.cpython-310.pyc b/src/__pycache__/metadata.cpython-310.pyc index fee3728..d6dc62a 100644 Binary files a/src/__pycache__/metadata.cpython-310.pyc and b/src/__pycache__/metadata.cpython-310.pyc differ diff --git a/src/__pycache__/url_to_path.cpython-310.pyc b/src/__pycache__/url_to_path.cpython-310.pyc new file mode 100644 index 0000000..b608493 Binary files /dev/null and b/src/__pycache__/url_to_path.cpython-310.pyc differ diff --git a/src/download.py b/src/download.py index efa566a..bbdc03a 100644 --- a/src/download.py +++ b/src/download.py @@ -1,9 +1,77 @@ import requests import os.path import pandas as pd +from mutagen.easyid3 import EasyID3 +import json import logging +""" +https://en.wikipedia.org/wiki/ID3 +https://mutagen.readthedocs.io/en/latest/user/id3.html + +>>> from mutagen.easyid3 import EasyID3 +>>> print(EasyID3.valid_keys.keys()) +dict_keys( + [ + 'album', + 'bpm', + 'compilation', + 'composer', + 'copyright', + 'encodedby', + 'lyricist', + 'length', + 'media', + 'mood', + 'grouping', + 'title', + 'version', + 'artist', + 'albumartist', + 'conductor', + 'arranger', + 'discnumber', + 'organization', + 'tracknumber', + 'author', + 'albumartistsort', + 'albumsort', + 'composersort', + 'artistsort', + 'titlesort', + 'isrc', + 'discsubtitle', + 'language', + 'genre', + 'date', + 'originaldate', + 'performer:*', + 'musicbrainz_trackid', + 'website', + 'replaygain_*_gain', + 'replaygain_*_peak', + 'musicbrainz_artistid', + 'musicbrainz_albumid', + 'musicbrainz_albumartistid', + 'musicbrainz_trmid', + 'musicip_puid', + 'musicip_fingerprint', + 'musicbrainz_albumstatus', + 'musicbrainz_albumtype', + 'releasecountry', + 'musicbrainz_discid', + 'asin', + 'performer', + 'barcode', + 'catalognumber', + 'musicbrainz_releasetrackid', + 'musicbrainz_releasegroupid', + 'musicbrainz_workid', + 'acoustid_fingerprint', + 'acoustid_id' + ]) +""" class Download: def __init__(self, session: requests.Session = requests.Session(), file: str = ".cache3.csv", temp: str = "temp"): @@ -18,14 +86,17 @@ class Download: self.dataframe = pd.read_csv(os.path.join(self.temp, self.file), index_col=0) for idx, row in self.dataframe.iterrows(): + row['artist'] = json.loads(row['artist'].replace("'", '"')) self.download(row['path'], row['file'], row['url']) + self.write_metadata(row, row['file']) def download(self, path, file, url): if os.path.exists(file): + logging.info(f"'{file}' does already exist, thus not downloading.") return os.makedirs(path, exist_ok=True) - logging.info(f"downloading: {url}") + logging.info(f"downloading: '{url}'") r = self.session.get(url) if r.status_code != 200: if r.status_code == 404: @@ -36,99 +107,22 @@ class Download: mp3_file.write(r.content) logging.info("finished") - -""" -class Track: - def __init__(self, url: str, release: Release, track_name: str, track_artists: list = None, - session: requests.Session = requests.Session()): - self.session = session - self.url = url - - parsed_url = urllib.parse.urlparse(url) - path = os.path.normpath(parsed_url.path) - split_path = path.split(os.sep) - - url_type = split_path[1] - if url_type != "track": - raise Exception(f'"{url}" is supposed to link a track.') - name = split_path[2] - name = name.split("-") - - self.id = name[-1] - self.name = "-".join(name[:-1]) - - self.track_artists = track_artists - self.release = release - self.pretty_track = track_name - self.mp3_url = self.get_mp3_url() - - def __str__(self): - - def fetch(self): - return - - def get_mp3_url(self): - # https://musify.club/track/dl/17254894/ghost-bath-convince-me-to-bleed.mp3 - return f"https://musify.club/track/dl/{self.id}/{self.name}.mp3" - - def add_album_art(self, path): - - - img = self.release.raw_artwork - - audio = EasyMP3(path, ID3=ID3) - - try: - audio.add_tags() - except _util.error: - pass - - audio.tags.add( - APIC( - encoding=3, # UTF-8 - mime='image/png', - type=3, # 3 is for album art - desc='Cover', - data=img.read() # Reads and adds album art - ) - ) - audio.save() - - def download(self): - download_path = os.path.join(self.release.path, self.name + ".mp3") - # download only when the file doesn't exist yet - if not os.path.exists(download_path): - logging.info(f"downloading: {self.mp3_url}") - r = requests.get(self.mp3_url, proxies=proxy) - if r.status_code != 200: - if r.status_code == 404: - logging.warning(f"{self.mp3_url} was not found") - return -1 - raise ConnectionError(f"\"{self.mp3_url}\" returned {r.status_code}: {r.text}") - with open(download_path, "wb") as mp3_file: - mp3_file.write(r.content) - logging.info("finished") - - audiofile = EasyID3(download_path) - if self.track_artists is not None: - audiofile["artist"] = self.track_artists - else: - audiofile["artist"] = self.release.pretty_release - audiofile["albumartist"] = self.release.artist.pretty_name - audiofile["date"] = self.release.year - - if self.release.genre is not None: - audiofile["genre"] = self.release.genre - - audiofile["title"] = self.pretty_track - audiofile["album"] = self.release.pretty_release + def write_metadata(self, row, file): + audiofile = EasyID3(file) + + audiofile["artist"] = row['artist'] + audiofile["albumartist"] = row['album_artist'] + audiofile["date"] = str(row['year']) + audiofile["genre"] = row['genre'] + audiofile["title"] = row['title'] + audiofile["album"] = row['album'] + audiofile["tracknumber"] = str(row['track']) audiofile.save() - # self.add_album_art(download_path) -""" if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) proxies = { 'http': 'socks5h://127.0.0.1:9150', 'https': 'socks5h://127.0.0.1:9150' diff --git a/src/main.py b/src/main.py index 8d8b334..2275244 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,14 @@ import metadata import download_links import url_to_path +import download import logging +import requests TEMP = "temp" STEP_ONE_CACHE = ".cache1.csv" STEP_TWO_CACHE = ".cache2.csv" +STEP_THREE_CACHE = ".cache3.csv" logging.basicConfig(level=logging.INFO) @@ -34,16 +37,25 @@ def search_for_metadata(query: str): def cli(): + session = requests.Session() + session.proxies = { + 'http': 'socks5h://127.0.0.1:9150', + 'https': 'socks5h://127.0.0.1:9150' + } + search = search_for_metadata(query=input("initial query: ")) logging.info("Starting Downloading of metadata") search.download(file=STEP_ONE_CACHE) logging.info("Fetching Download Links") - download_links.Download(file=STEP_TWO_CACHE, metadata_csv=STEP_ONE_CACHE, temp=TEMP) + download_links.Download(file=STEP_TWO_CACHE, metadata_csv=STEP_ONE_CACHE, temp=TEMP, session=session) logging.info("creating Paths") url_to_path.UrlPath("dsbm") + logging.info("starting to download the mp3's") + download.Download(session=session, file=STEP_THREE_CACHE, temp=TEMP) + if __name__ == "__main__": cli() diff --git a/src/metadata.py b/src/metadata.py index 5dcf62f..6882770 100644 --- a/src/metadata.py +++ b/src/metadata.py @@ -1,4 +1,5 @@ import os.path +from select import select import musicbrainzngs import pandas as pd @@ -82,17 +83,8 @@ class Search: def download_track(self, mb_id, is_various_artist: bool = None, track: int = None, total_tracks: int = None): """ - Title - Artist - Album: - Album artist - Composer - Genre - Track number <> of <> - Disc number <> of <> - Year - BPM - Comment + album + bpm Album Art """ @@ -100,7 +92,8 @@ class Search: aliases, tags, user-tags, ratings, user-ratings, area-rels, artist-rels, label-rels, place-rels, event-rels, recording-rels, release-rels, release-group-rels, series-rels, url-rels, work-rels, instrument-rels """ - result = musicbrainzngs.get_recording_by_id(mb_id, includes=["artists", "releases"]) + result = musicbrainzngs.get_recording_by_id(mb_id, includes=["artists", "releases", "recording-rels"]) + print(result) recording_data = result['recording'] release_data = recording_data['release-list'][0] @@ -109,7 +102,7 @@ class Search: artist_ids = [artist_['artist']['id'] for artist_ in recording_data['artist-credit']] def get_additional_release_info(mb_id_): - r = musicbrainzngs.get_release_by_id(mb_id_, includes=["artists", "recordings"]) + r = musicbrainzngs.get_release_by_id(mb_id_, includes=["artists", "recordings", "recording-rels"]) is_various_artist_ = len(r['release']['artist-credit']) > 1 tracklist = r['release']['medium-list'][0]['track-list'] track_count_ = len(tracklist) @@ -322,10 +315,10 @@ def interactive_demo(): if __name__ == "__main__": - interactive_demo() + # interactive_demo() # automated_demo() - # search = Search(query="psychonaut 4") + search = Search(query="psychonaut 4") # search.download_release("27f00fb8-983c-4d5c-950f-51418aac55dc") # for track_ in search.download_artist("c0c720b5-012f-4204-a472-981403f37b12"): # print(track_) - # search.download_track("83a30323-aee1-401a-b767-b3c1bdd026c0") + search.download_track("83a30323-aee1-401a-b767-b3c1bdd026c0") diff --git a/temp/.cache1.csv b/temp/.cache1.csv new file mode 100644 index 0000000..38c5464 --- /dev/null +++ b/temp/.cache1.csv @@ -0,0 +1,2 @@ +,id,title,artist,album_artist,album,year,track,total_tracks +0,39e9dee2-6b09-4aa5-bb5b-d04fa43578db,Black Smoke Curling From the Lips of War,['Cradle of Filth'],Cradle of Filth,Existence Is Futile,2021,6,12 diff --git a/temp/.cache2.csv b/temp/.cache2.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/temp/.cache2.csv @@ -0,0 +1 @@ +"" diff --git a/temp/.cache3.csv b/temp/.cache3.csv new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/temp/.cache3.csv @@ -0,0 +1 @@ +""