diff --git a/.vscode/settings.json b/.vscode/settings.json index ace0f19..2108a96 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,6 +24,7 @@ "encyclopaedia", "ENDC", "Gitea", + "isrc", "levenshtein", "metallum", "musify", diff --git a/music_kraken/objects/parents.py b/music_kraken/objects/parents.py index 725e2c9..3ef6ab3 100644 --- a/music_kraken/objects/parents.py +++ b/music_kraken/objects/parents.py @@ -301,6 +301,33 @@ class OuterProxy: return r + @property + def root_collections(self) -> List[Collection]: + if len(self.UPWARDS_COLLECTION_STRING_ATTRIBUTES) == 0: + return [self] + + r = [] + for collection_string_attribute in self.UPWARDS_COLLECTION_STRING_ATTRIBUTES: + r.extend(self.__getattribute__(collection_string_attribute)) + + return r + + def _compile(self, **kwargs): + pass + + def compile(self, from_root=False, **kwargs): + # compile from the root + if not from_root: + for c in self.root_collections: + c.compile(from_root=True, **kwargs) + return + + self._compile(**kwargs) + + for c_attribute in self.DOWNWARDS_COLLECTION_STRING_ATTRIBUTES: + for c in self.__getattribute__(c_attribute): + c.compile(from_root=True, **kwargs) + TITEL = "id" @property def title_string(self) -> str: diff --git a/music_kraken/objects/song.py b/music_kraken/objects/song.py index beccb2d..8b5953b 100644 --- a/music_kraken/objects/song.py +++ b/music_kraken/objects/song.py @@ -376,6 +376,25 @@ class Album(Base): r += f" with {len(self.song_collection)} songs" return r + def _compile(self): + self.analyze_implied_album_type() + self.update_tracksort() + + def analyze_implied_album_type(self): + # if the song collection has only one song, it is reasonable to assume that it is a single + if len(self.song_collection) == 1: + self.album_type = AlbumType.SINGLE + return + + # if the album already has an album type, we don't need to do anything + if self.album_type is not AlbumType.OTHER: + return + + # for information on EP's I looked at https://www.reddit.com/r/WeAreTheMusicMakers/comments/a354ql/whats_the_cutoff_length_between_ep_and_album/ + if len(self.song_collection) < 9: + self.album_type = AlbumType.EP + return + def update_tracksort(self): """ This updates the tracksort attributes, of the songs in @@ -525,6 +544,9 @@ class Artist(Base): self.label_collection.extend(object_list) return + def _compile(self): + self.update_albumsort() + def update_albumsort(self): """ This updates the albumsort attributes, of the albums in @@ -535,9 +557,6 @@ class Artist(Base): :return: """ - if len(self.main_album_collection) <= 0: - return - type_section: Dict[AlbumType, int] = defaultdict(lambda: 2, { AlbumType.OTHER: 0, # if I don't know it, I add it to the first section AlbumType.STUDIO_ALBUM: 0, @@ -580,7 +599,7 @@ class Artist(Base): album_list.extend(sections[section_index]) # replace the old collection with the new one - self.main_album_collection: Collection = Collection(data=album_list, element_type=Album) + self.main_album_collection._data = album_list INDEX_DEPENDS_ON = ("name", "source_collection", "contact_collection") @property diff --git a/music_kraken/pages/abstract.py b/music_kraken/pages/abstract.py index 4d123a9..a202b32 100644 --- a/music_kraken/pages/abstract.py +++ b/music_kraken/pages/abstract.py @@ -361,6 +361,7 @@ class Page: return download_result def _download_song(self, song: Song, naming_dict: NamingDict): + song.compile() if "genre" not in naming_dict and song.genre is not None: naming_dict["genre"] = song.genre diff --git a/pyproject.toml b/pyproject.toml index 62598b1..a569415 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,7 +69,7 @@ dependencies = [ "toml~=0.10.2", "typing_extensions~=4.7.1", - "python-sponsorblock~=0.1.dev1", + "python-sponsorblock~=0.1", "youtube_dl", ] dynamic = [