worked on metal archives

This commit is contained in:
Hellow2 2023-03-02 16:23:02 +01:00
parent 4c041ef7ff
commit 3fba46428d
8 changed files with 54 additions and 36 deletions

View File

@ -1,7 +1,4 @@
from music_kraken.objects import (
Song,
)
from music_kraken import objects
from music_kraken.pages import (
@ -66,4 +63,13 @@ print_artist(artist)
"""
results = EncyclopaediaMetallum.search_by_query("#a only smile")
print(results)
artist = results[0]
print(artist)
artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist)
for release in artist.main_album_collection:
print(release)
print(release.song_collection)

View File

@ -37,9 +37,6 @@ gc.set_threshold(allocs, gen1, gen2)
logging.getLogger("musicbrainzngs").setLevel(logging.WARNING)
musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader")
# define the most important values and function for import in the __init__ file
cache = database.cache
Database = database.Database
def get_options_from_query(query: str) -> List[objects.MusicObject]:
options = []

View File

@ -1,7 +1,4 @@
from . import (
temp_database,
old_database
)
from . import database
from .. import objects
MusicObject = objects.MusicObject
@ -19,4 +16,4 @@ Artist = objects.Artist
FormattedText = objects.FormattedText
Database = database.Database
cache = temp_database.TempDatabase()
# cache = temp_database.TempDatabase()

View File

@ -13,4 +13,4 @@ class TempDatabase(Database):
super().__init__(db_type=DatabaseType.SQLITE, db_name=TEMP_DATABASE_PATH)
temp_database = TempDatabase()
# temp_database = TempDatabase()

View File

@ -64,6 +64,15 @@ class Collection:
if type(element) is not self.element_type and self.element_type is not None:
raise TypeError(f"{type(element)} is not the set type {self.element_type}")
for source_url in element.source_url_map:
if source_url in self._by_url:
return
for attr in self.map_attributes:
value = element.__getattribute__(attr)
if value in self._by_attribute[attr]:
return
self._data.append(element)
self.map_element(element)
@ -72,7 +81,7 @@ class Collection:
yield element
def __str__(self) -> str:
return "\n".join([f"{str(j).zfill(2)}: {i}" for j, i in enumerate(self._data)])
return "\n".join([f"{str(j).zfill(2)}: {i.__repr__()}" for j, i in enumerate(self._data)])
def __len__(self) -> int:
return len(self._data)

View File

@ -14,7 +14,7 @@ class DatabaseObject:
https://docs.python.org/3/library/uuid.html
"""
_id = str(uuid.uuid4())
LOGGER.info(f"id for {self.__name__} isn't set. Setting to {_id}")
LOGGER.info(f"id for {type(self).__name__} isn't set. Setting to {_id}")
# The id can only be None, if the object is dynamic (self.dynamic = True)
self.id: Optional[str] = _id

View File

@ -58,7 +58,6 @@ class Source(DatabaseObject, MetadataAttribute):
def __init__(self, page_enum, url: str, id_: str = None, type_enum=None) -> None:
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
self.type_enum = type_enum
self.page_enum = page_enum

View File

@ -8,7 +8,7 @@ from ..utils.shared import (
)
from .abstract import Page
from ..database import (
from ..objects import (
MusicObject,
Artist,
Source,
@ -16,7 +16,8 @@ from ..database import (
Song,
Album,
ID3Timestamp,
FormattedText
FormattedText,
Label
)
from ..utils import (
string_processing
@ -237,7 +238,7 @@ class EncyclopaediaMetallum(Page):
pass
album_obj: Album = artist.main_albums.get_object_with_source(album_url) or artist.main_albums.get_object_with_attribute("title", album_name)
album_obj: Album = artist.main_album_collection.get_object_with_source(album_url) or artist.main_album_collection.get_object_with_attribute("title", album_name)
if album_obj is not None:
album_obj.add_source(Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url))
@ -247,7 +248,7 @@ class EncyclopaediaMetallum(Page):
album_obj.date = date_obj
continue
artist.main_albums.append(Album(
artist.main_album_collection.append(Album(
id_=album_id,
title=album_name,
album_type=album_type,
@ -258,7 +259,7 @@ class EncyclopaediaMetallum(Page):
))
if not flat:
for album in artist.main_albums:
for album in artist.main_album_collection:
cls.fetch_album_details(album, flat=flat)
return artist
@ -288,6 +289,7 @@ class EncyclopaediaMetallum(Page):
merchandice_source = soup.find("div", {"id": "band_links_Official_merchandise"})
label_source = soup.find("div", {"id": "band_links_Labels"})
if artist_source is not None:
for tr in artist_source.find_all("td"):
a = tr.find("a")
url = a.get("href")
@ -355,12 +357,15 @@ class EncyclopaediaMetallum(Page):
label_url = None
if label_anchor is not None:
label_url = label_anchor.get("href")
print(label_url)
artist.label_collection.append( Label(
name=label_name,
source_list=[
Source(cls.SOURCE_TYPE, label_url)
]
))
for album in artist.main_albums:
if album.label is not None:
continue
album.label = label_name
continue
"""
years active: 2012-present
@ -464,7 +469,7 @@ class EncyclopaediaMetallum(Page):
minutes, seconds = duration_stamp.split(":")
length = (int(minutes) * 60 + int(seconds))*1000 # in milliseconds
track: Song = album.tracklist.get_object_with_source(track_id) or album.tracklist.get_object_with_attribute("title", title)
track: Song = album.song_collection.get_object_with_source(track_id) or album.song_collection.get_object_with_attribute("title", title)
if track is not None:
track.add_source(Source(cls.SOURCE_TYPE, track_id))
@ -484,7 +489,7 @@ class EncyclopaediaMetallum(Page):
]
)
album.tracklist.append(track)
album.song_collection.append(track)
return album
@ -494,4 +499,9 @@ class EncyclopaediaMetallum(Page):
if len(source_list) == 0:
return song
"""
TODO
lyrics
"""
return song