auto
This commit is contained in:
parent
ede768c8b5
commit
0f459d3216
@ -62,6 +62,43 @@ from appdirs import user_config_dir
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
|
||||||
|
class TableHeader:
|
||||||
|
def __init__(self):
|
||||||
|
self.db = {
|
||||||
|
"title": "title",
|
||||||
|
"artist": "artist",
|
||||||
|
"album": "album",
|
||||||
|
"track_number": "track_number",
|
||||||
|
"genre": "genre",
|
||||||
|
"codec": "codec",
|
||||||
|
"length_seconds": "length_seconds",
|
||||||
|
"album_date": "album_date",
|
||||||
|
"filepath": "filepath",
|
||||||
|
}
|
||||||
|
self.gui = {
|
||||||
|
"title": "Title",
|
||||||
|
"artist": "Artist",
|
||||||
|
"album": "Album",
|
||||||
|
"track_number": "Track",
|
||||||
|
"genre": "Genre",
|
||||||
|
"codec": "Codec",
|
||||||
|
"length_seconds": "Length",
|
||||||
|
"album_date": "Year",
|
||||||
|
"filepath": "Path",
|
||||||
|
}
|
||||||
|
self.id3 = {
|
||||||
|
"title": "TIT2",
|
||||||
|
"artist": "TPE1",
|
||||||
|
"album": "TALB",
|
||||||
|
"track_number": "TRCK",
|
||||||
|
"genre": "content_type",
|
||||||
|
"codec": None,
|
||||||
|
"length_seconds": "TLEN",
|
||||||
|
"album_date": "TDRC",
|
||||||
|
"filepath": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class MusicTable(QTableView):
|
class MusicTable(QTableView):
|
||||||
playlistStatsSignal = pyqtSignal(str)
|
playlistStatsSignal = pyqtSignal(str)
|
||||||
playPauseSignal = pyqtSignal()
|
playPauseSignal = pyqtSignal()
|
||||||
@ -103,28 +140,9 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
# Threads
|
# Threads
|
||||||
self.threadpool = QThreadPool
|
self.threadpool = QThreadPool
|
||||||
# gui names of headers
|
# headers class thing
|
||||||
self.table_headers = [
|
self.headers = TableHeader()
|
||||||
"title",
|
|
||||||
"artist",
|
|
||||||
"album",
|
|
||||||
"track",
|
|
||||||
"genre",
|
|
||||||
"codec",
|
|
||||||
"year",
|
|
||||||
"path",
|
|
||||||
]
|
|
||||||
# id3 names of headers
|
|
||||||
self.id3_headers = [
|
|
||||||
"TIT2",
|
|
||||||
"TPE1",
|
|
||||||
"TALB",
|
|
||||||
"TRCK",
|
|
||||||
"content_type",
|
|
||||||
None,
|
|
||||||
"TDRC",
|
|
||||||
None,
|
|
||||||
]
|
|
||||||
# db names of headers
|
# db names of headers
|
||||||
self.database_columns = str(self.config["table"]["columns"]).split(",")
|
self.database_columns = str(self.config["table"]["columns"]).split(",")
|
||||||
self.vertical_scroll_position = 0
|
self.vertical_scroll_position = 0
|
||||||
@ -582,17 +600,8 @@ class MusicTable(QTableView):
|
|||||||
selected_song_filepath = self.get_selected_song_filepath()
|
selected_song_filepath = self.get_selected_song_filepath()
|
||||||
if selected_song_filepath is None:
|
if selected_song_filepath is None:
|
||||||
return
|
return
|
||||||
# current_song = self.get_selected_song_metadata()
|
dic = id3_remap(get_id3_tags(selected_song_filepath)[0])
|
||||||
current_song = get_id3_tags(selected_song_filepath)[0]
|
lyrics = dic["lyrics"]
|
||||||
try:
|
|
||||||
uslt_tags = [tag for tag in current_song.keys() if tag.startswith("USLT::")]
|
|
||||||
if uslt_tags:
|
|
||||||
lyrics = next((current_song[tag].text for tag in uslt_tags), "")
|
|
||||||
else:
|
|
||||||
raise RuntimeError("No USLT tags found in song metadata")
|
|
||||||
except Exception as e:
|
|
||||||
error(f"show_lyrics_menu() | could not retrieve lyrics | {e}")
|
|
||||||
lyrics = ""
|
|
||||||
lyrics_window = LyricsWindow(selected_song_filepath, lyrics)
|
lyrics_window = LyricsWindow(selected_song_filepath, lyrics)
|
||||||
lyrics_window.exec_()
|
lyrics_window.exec_()
|
||||||
|
|
||||||
@ -687,7 +696,7 @@ class MusicTable(QTableView):
|
|||||||
self.disconnect_layout_changed()
|
self.disconnect_layout_changed()
|
||||||
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
|
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
|
||||||
self.model2.clear()
|
self.model2.clear()
|
||||||
self.model2.setHorizontalHeaderLabels(self.table_headers)
|
self.model2.setHorizontalHeaderLabels(self.headers.gui.values())
|
||||||
if playlist_id: # Load a playlist
|
if playlist_id: # Load a playlist
|
||||||
# Fetch playlist data
|
# Fetch playlist data
|
||||||
selected_playlist_id = playlist_id[0]
|
selected_playlist_id = playlist_id[0]
|
||||||
|
|||||||
@ -37,20 +37,25 @@ def get_mp3_tags(filename: str) -> tuple[MP3 | ID3 | FLAC, str]:
|
|||||||
def id3_remap(audio: MP3 | ID3 | FLAC) -> dict:
|
def id3_remap(audio: MP3 | ID3 | FLAC) -> dict:
|
||||||
"""
|
"""
|
||||||
Turns an ID3 dict into a normal dict that I, the human, can use.
|
Turns an ID3 dict into a normal dict that I, the human, can use.
|
||||||
Add extra fields as well
|
Add extra fields too :D yahooo
|
||||||
"""
|
"""
|
||||||
remap = {
|
remap = {}
|
||||||
"title": audio.get("TIT2"),
|
|
||||||
"artist": audio.get("TPE1"),
|
|
||||||
"album": audio.get("TALB"),
|
|
||||||
"track_number": audio.get("TRCK"),
|
|
||||||
"genre": audio.get("TCON"),
|
|
||||||
"date": convert_id3_timestamp_to_datetime(audio.get("TDRC")),
|
|
||||||
"bitrate": audio.get("TBIT"),
|
|
||||||
"lyrics": audio.get("USLT"),
|
|
||||||
}
|
|
||||||
if isinstance(audio, MP3):
|
if isinstance(audio, MP3):
|
||||||
remap["length"] = int(round(audio.info.length, 0))
|
# so ugly
|
||||||
|
uslt_tags = [tag for tag in audio.keys() if tag.startswith("USLT::")]
|
||||||
|
lyrics = next((audio[tag].text for tag in uslt_tags), "")
|
||||||
|
# so ugly
|
||||||
|
remap = {
|
||||||
|
"title": audio.get("TIT2"),
|
||||||
|
"artist": audio.get("TPE1"),
|
||||||
|
"album": audio.get("TALB"),
|
||||||
|
"track_number": audio.get("TRCK"),
|
||||||
|
"genre": audio.get("TCON"),
|
||||||
|
"date": convert_id3_timestamp_to_datetime(audio.get("TDRC")),
|
||||||
|
"bitrate": audio.get("TBIT"),
|
||||||
|
"lyrics": lyrics,
|
||||||
|
"length": int(round(audio.info.length, 0)),
|
||||||
|
}
|
||||||
return remap
|
return remap
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@ mutagen_id3_tag_mapping = {
|
|||||||
# "year": TYER, # Year of recording
|
# "year": TYER, # Year of recording
|
||||||
# "date": TDAT, # Date
|
# "date": TDAT, # Date
|
||||||
"lyrics": USLT, # Unsynchronized lyric/text transcription
|
"lyrics": USLT, # Unsynchronized lyric/text transcription
|
||||||
"track_number": TRCK, # Track number/Position in set
|
"track": TRCK, # Track number/Position in set
|
||||||
"album_cover": APIC, # Attached picture
|
"album_cover": APIC, # Attached picture
|
||||||
"composer": TCOM, # Composer
|
"composer": TCOM, # Composer
|
||||||
"conductor": TPE3, # Conductor/performer refinement
|
"conductor": TPE3, # Conductor/performer refinement
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user