From b17d039fb6e5bc8f431e730df6c835d5bddea7f8 Mon Sep 17 00:00:00 2001 From: Hellow Date: Tue, 24 Jan 2023 00:16:10 +0100 Subject: [PATCH] asddasd --- src/create_custom_objects.py | 161 +++++++++++++++++ src/goof.py | 162 +----------------- src/music_kraken/database/__init__.py | 2 + src/music_kraken/pages/__init__.py | 3 + src/music_kraken/pages/abstract.py | 40 +++++ .../pages/encyclopaedia_metallum.py | 18 ++ 6 files changed, 227 insertions(+), 159 deletions(-) create mode 100644 src/create_custom_objects.py create mode 100644 src/music_kraken/pages/__init__.py create mode 100644 src/music_kraken/pages/encyclopaedia_metallum.py diff --git a/src/create_custom_objects.py b/src/create_custom_objects.py new file mode 100644 index 0000000..35fa00f --- /dev/null +++ b/src/create_custom_objects.py @@ -0,0 +1,161 @@ +import music_kraken +from music_kraken import ( + Song, + Lyrics, + Target, + Source, + Album, + Artist, + ID3Timestamp, + SourcePages, + SourceTypes +) + +from music_kraken.tagging import ( + AudioMetadata, + write_metadata, + write_many_metadata +) + +import music_kraken.database.new_database as db + +import pycountry + + +def div(msg: str = ""): + print("-" * 50 + msg + "-" * 50) + + +cache = music_kraken.database.new_database.Database("test.db") +cache.reset() + + +main_artist = Artist( + name="I'm in a coffin", + sources=[ + Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727") + ] +) + +artist_ref = main_artist.reference + +split_artist = Artist( + name="split" +) + +feature_artist = Artist( + name="Ghost" +) + +album_input = Album( + title="One Final Action", + date=ID3Timestamp(year=1986, month=3, day=1), + language=pycountry.languages.get(alpha_2="en"), + label="cum productions", + sources=[ + Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614") + ] +) +album_input.artists = [ + main_artist, + split_artist +] + +song_input = Song( + genre="HS Core", + title="Vein Deep in the Solution", + length=666, + isrc="US-S1Z-99-00001", + tracksort=2, + target=Target(file="song.mp3", path="~/Music"), + lyrics=[ + Lyrics(text="these are some depressive lyrics", language="en"), + Lyrics(text="test", language="en") + ], + sources=[ + Source(SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"), + Source(SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/") + ], + album=album_input, + main_artist_list=[main_artist], + feature_artist_list=[feature_artist], +) + +other_song = Song( + title="this is just another song", + main_artist_list=[feature_artist], + feature_artist_list=[main_artist] +) + +print(song_input) + +additional_song = Song( + title="A fcking Song", + album=album_input +) + +song_ref = song_input.reference +print(song_ref) + +lyrics = Lyrics(text="these are some Lyrics that don't belong to any Song", language="en") + +cache.push([album_input, song_input, lyrics, additional_song, other_song]) + +# getting song by song ref +div() +song_output_list = cache.pull_songs(song_ref=song_ref) +print(len(song_output_list), song_output_list, song_output_list[0].album, sep=" | ") +song = song_output_list[0] +print("tracksort", song_output_list[0].tracksort, sep=": ") +print("ID3", dict(song.metadata)) +print(str(song_output_list[0].metadata)) +print("--src--") +for source in song.sources: + print(source) + +print("album", song.album.sources) + +# try writing metadata +write_metadata(song) + +exit() + +# getting song by album ref +div() +song_output_list = cache.pull_songs(album_ref=album_input.reference) +print(len(song_output_list), song_output_list) +for song in song_output_list: + print(song, song.album) + +# getting album +div("album") +album_output_list = cache.pull_albums(album_ref=album_input.reference) +album_output = album_output_list[0] +print(album_output) +print(f"--tracklist-{len(album_output)}--") +for track in album_output.tracklist: + print(track.tracksort, track) +print("--artist--") +for artist in album_output.artists: + print(artist) + +# getting album by song +div() +album_output_list = cache.pull_albums(song_ref=song_ref) +print(album_output_list) +print("len of album ->", len(album_output_list[0]), album_output_list[0], sep=" | ") + +# get artist +div("artist") +artist_output = cache.pull_artists(artist_ref=artist_ref)[0] +print(artist_output) + +print("---static---") +print("albums", artist_output.main_albums) +print("main_s", artist_output.main_songs) +print("feat_s", artist_output.feature_songs) + +print("---dynamic---") +print("discography", artist_output.discography) +print("songs", artist_output.songs, artist_output.songs.tracklist) +print("features", artist_output.features, artist_output.features.tracklist) diff --git a/src/goof.py b/src/goof.py index 35fa00f..33d740e 100644 --- a/src/goof.py +++ b/src/goof.py @@ -1,161 +1,5 @@ -import music_kraken -from music_kraken import ( - Song, - Lyrics, - Target, - Source, - Album, - Artist, - ID3Timestamp, - SourcePages, - SourceTypes +from music_kraken.pages import ( + EncyclopaediaMetallum ) -from music_kraken.tagging import ( - AudioMetadata, - write_metadata, - write_many_metadata -) - -import music_kraken.database.new_database as db - -import pycountry - - -def div(msg: str = ""): - print("-" * 50 + msg + "-" * 50) - - -cache = music_kraken.database.new_database.Database("test.db") -cache.reset() - - -main_artist = Artist( - name="I'm in a coffin", - sources=[ - Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727") - ] -) - -artist_ref = main_artist.reference - -split_artist = Artist( - name="split" -) - -feature_artist = Artist( - name="Ghost" -) - -album_input = Album( - title="One Final Action", - date=ID3Timestamp(year=1986, month=3, day=1), - language=pycountry.languages.get(alpha_2="en"), - label="cum productions", - sources=[ - Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614") - ] -) -album_input.artists = [ - main_artist, - split_artist -] - -song_input = Song( - genre="HS Core", - title="Vein Deep in the Solution", - length=666, - isrc="US-S1Z-99-00001", - tracksort=2, - target=Target(file="song.mp3", path="~/Music"), - lyrics=[ - Lyrics(text="these are some depressive lyrics", language="en"), - Lyrics(text="test", language="en") - ], - sources=[ - Source(SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"), - Source(SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/") - ], - album=album_input, - main_artist_list=[main_artist], - feature_artist_list=[feature_artist], -) - -other_song = Song( - title="this is just another song", - main_artist_list=[feature_artist], - feature_artist_list=[main_artist] -) - -print(song_input) - -additional_song = Song( - title="A fcking Song", - album=album_input -) - -song_ref = song_input.reference -print(song_ref) - -lyrics = Lyrics(text="these are some Lyrics that don't belong to any Song", language="en") - -cache.push([album_input, song_input, lyrics, additional_song, other_song]) - -# getting song by song ref -div() -song_output_list = cache.pull_songs(song_ref=song_ref) -print(len(song_output_list), song_output_list, song_output_list[0].album, sep=" | ") -song = song_output_list[0] -print("tracksort", song_output_list[0].tracksort, sep=": ") -print("ID3", dict(song.metadata)) -print(str(song_output_list[0].metadata)) -print("--src--") -for source in song.sources: - print(source) - -print("album", song.album.sources) - -# try writing metadata -write_metadata(song) - -exit() - -# getting song by album ref -div() -song_output_list = cache.pull_songs(album_ref=album_input.reference) -print(len(song_output_list), song_output_list) -for song in song_output_list: - print(song, song.album) - -# getting album -div("album") -album_output_list = cache.pull_albums(album_ref=album_input.reference) -album_output = album_output_list[0] -print(album_output) -print(f"--tracklist-{len(album_output)}--") -for track in album_output.tracklist: - print(track.tracksort, track) -print("--artist--") -for artist in album_output.artists: - print(artist) - -# getting album by song -div() -album_output_list = cache.pull_albums(song_ref=song_ref) -print(album_output_list) -print("len of album ->", len(album_output_list[0]), album_output_list[0], sep=" | ") - -# get artist -div("artist") -artist_output = cache.pull_artists(artist_ref=artist_ref)[0] -print(artist_output) - -print("---static---") -print("albums", artist_output.main_albums) -print("main_s", artist_output.main_songs) -print("feat_s", artist_output.feature_songs) - -print("---dynamic---") -print("discography", artist_output.discography) -print("songs", artist_output.songs, artist_output.songs.tracklist) -print("features", artist_output.features, artist_output.features.tracklist) +EncyclopaediaMetallum.search_by_query("Ghost Bath") diff --git a/src/music_kraken/database/__init__.py b/src/music_kraken/database/__init__.py index ad93dcd..067bb79 100644 --- a/src/music_kraken/database/__init__.py +++ b/src/music_kraken/database/__init__.py @@ -3,6 +3,8 @@ from . import ( objects ) +MusicObject = objects.MusicObject + ID3Timestamp = objects.ID3Timestamp SourceTypes = objects.SourceTypes SourcePages = objects.SourcePages diff --git a/src/music_kraken/pages/__init__.py b/src/music_kraken/pages/__init__.py new file mode 100644 index 0000000..406ec88 --- /dev/null +++ b/src/music_kraken/pages/__init__.py @@ -0,0 +1,3 @@ +from .encyclopaedia_metallum import EncyclopaediaMetallum + +EncyclopaediaMetallum = EncyclopaediaMetallum diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 3d129e1..b875661 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -20,6 +20,46 @@ class Page: functionality for every other class fetching something """ + class Query: + def __init__(self, query: str): + self.query = query + self.is_raw = False + + self.artist = None + self.album = None + self.song = None + + self.parse_query(query=query) + + def __str__(self): + if self.is_raw: + return self.query + return f"{self.artist}; {self.album}; {self.song}" + + def parse_query(self, query: str): + if not '#' in query: + self.is_raw = True + return + + query = query.strip() + parameters = query.split('#') + parameters.remove('') + + for parameter in parameters: + splitted = parameter.split(" ") + type_ = splitted[0] + input_ = " ".join(splitted[1:]).strip() + + if type_ == "a": + self.artist = input_ + continue + if type_ == "r": + self.album = input_ + continue + if type_ == "t": + self.song = type_ + continue + @classmethod def search_by_query(cls, query: str) -> List[MusicObject]: """ diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py new file mode 100644 index 0000000..f3aaac7 --- /dev/null +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -0,0 +1,18 @@ +from typing import List + +from .abstract import Page +from ..database import MusicObject + + +class EncyclopaediaMetallum(Page): + @classmethod + def search_by_query(cls, query: str) -> List[MusicObject]: + query_obj = cls.Query(query) + + if query_obj.is_raw: + return cls.simple_search(query_obj) + print(query_obj) + + @classmethod + def simple_search(cls, query: Page.Query): + pass