Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2015 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of toktokkie.
6toktokkie is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11toktokkie is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with toktokkie. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from abc import ABC
21from typing import List
22from toktokkie.enums import IdType
23from toktokkie.metadata.base.components.RenameOperation import RenameOperation
24from toktokkie.metadata.base.Renamer import Renamer
25from toktokkie.metadata.music.MusicExtras import MusicExtras
26from toktokkie.metadata.music.components.MusicThemeSong import \
27 MusicThemeSong
30class MusicRenamer(Renamer, MusicExtras, ABC):
31 """
32 Implements the Renamer functionality for music metadata
33 """
35 def create_rename_operations(self) -> List[RenameOperation]:
36 """
37 Creates renaming operations for movie metadata
38 :return: The renaming operations
39 """
40 operations = [] # type: List[RenameOperation]
42 theme_songs = {x.name: x for x in self.theme_songs}
44 for album in self.albums:
46 if album.name in theme_songs:
47 theme_song = theme_songs[album.name] # type: MusicThemeSong
48 series_name = self.load_title_and_year(
49 [IdType.ANILIST], theme_song.series_ids
50 )[0]
52 for song in album.songs:
53 if song.title.startswith(theme_song.name):
54 continue # Skip renaming full version
55 else:
56 new_name = "{} {} - {}.{}".format(
57 series_name,
58 theme_song.theme_type,
59 theme_song.name,
60 song.format
61 )
62 operations.append(RenameOperation(song.path, new_name))
64 for vid in album.videos:
65 new_name = "{} {} - {}-video.{}".format(
66 series_name,
67 theme_song.theme_type,
68 theme_song.name,
69 vid.format
70 )
71 operations.append(RenameOperation(vid.path, new_name))
72 break
74 else:
75 tracks = []
76 for song in album.songs:
77 track_number = str(song.tracknumber[0]).zfill(2)
78 videos = [x for x in album.videos if x.title == song.title]
79 video = None if len(videos) == 0 else videos[0]
80 tracks.append((track_number, song, video))
82 tracks.sort(key=lambda x: x[0]) # Sort for better UX
84 if len(tracks) != 1:
85 for track_number, song, video in tracks:
86 operations.append(RenameOperation(
87 song.path,
88 f"{track_number} - {song.title}.{song.format}"
89 ))
90 if video is not None:
91 operations.append(RenameOperation(
92 video.path,
93 f"{track_number} - {song.title}"
94 f"-video.{video.format}"
95 ))
96 else:
97 _, song, video = tracks[0]
98 operations.append(RenameOperation(
99 song.path, f"{album.name}.{song.format}"
100 ))
101 if video is not None:
102 operations.append(RenameOperation(
103 video.path, f"{album.name}-video.{video.format}"
104 ))
106 return operations