auto
This commit is contained in:
parent
554b06a667
commit
ede768c8b5
@ -49,7 +49,7 @@ from utils.delete_song_id_from_database import delete_song_id_from_database
|
|||||||
from utils.add_files_to_database import add_files_to_database
|
from utils.add_files_to_database import add_files_to_database
|
||||||
from utils.get_reorganize_vars import get_reorganize_vars
|
from utils.get_reorganize_vars import get_reorganize_vars
|
||||||
from utils.update_song_in_database import update_song_in_database
|
from utils.update_song_in_database import update_song_in_database
|
||||||
from utils.get_id3_tags import get_id3_tags
|
from utils.get_id3_tags import get_id3_tags, id3_remap
|
||||||
from utils.get_album_art import get_album_art
|
from utils.get_album_art import get_album_art
|
||||||
from utils import set_id3_tag
|
from utils import set_id3_tag
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
@ -582,7 +582,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()
|
# current_song = self.get_selected_song_metadata()
|
||||||
|
current_song = get_id3_tags(selected_song_filepath)[0]
|
||||||
try:
|
try:
|
||||||
uslt_tags = [tag for tag in current_song.keys() if tag.startswith("USLT::")]
|
uslt_tags = [tag for tag in current_song.keys() if tag.startswith("USLT::")]
|
||||||
if uslt_tags:
|
if uslt_tags:
|
||||||
@ -848,13 +849,13 @@ class MusicTable(QTableView):
|
|||||||
"""Returns the currently playing song filepath"""
|
"""Returns the currently playing song filepath"""
|
||||||
return self.current_song_filepath
|
return self.current_song_filepath
|
||||||
|
|
||||||
def get_current_song_metadata(self) -> ID3 | dict:
|
def get_current_song_metadata(self) -> dict:
|
||||||
"""Returns the currently playing song's ID3 tags"""
|
"""Returns the currently playing song's ID3 tags"""
|
||||||
return get_id3_tags(self.current_song_filepath)[0]
|
return id3_remap(get_id3_tags(self.current_song_filepath)[0])
|
||||||
|
|
||||||
def get_selected_song_metadata(self) -> ID3 | dict:
|
def get_selected_song_metadata(self) -> dict:
|
||||||
"""Returns the selected song's ID3 tags"""
|
"""Returns the selected song's ID3 tags"""
|
||||||
return get_id3_tags(self.selected_song_filepath)[0]
|
return id3_remap(get_id3_tags(self.selected_song_filepath)[0])
|
||||||
|
|
||||||
def get_current_song_album_art(self) -> bytes:
|
def get_current_song_album_art(self) -> bytes:
|
||||||
"""Returns the APIC data (album art lol) for the currently playing song"""
|
"""Returns the APIC data (album art lol) for the currently playing song"""
|
||||||
|
|||||||
@ -2,8 +2,12 @@ import datetime
|
|||||||
from mutagen.id3._specs import ID3TimeStamp
|
from mutagen.id3._specs import ID3TimeStamp
|
||||||
|
|
||||||
|
|
||||||
def convert_id3_timestamp_to_datetime(timestamp: ID3TimeStamp):
|
def convert_id3_timestamp_to_datetime(timestamp):
|
||||||
"""Turns a mutagen ID3TimeStamp into a format that SQLite can use for Date field"""
|
"""Turns a mutagen ID3TimeStamp into a format that SQLite can use for Date field"""
|
||||||
|
if timestamp is None:
|
||||||
|
return
|
||||||
|
if not isinstance(timestamp, ID3TimeStamp):
|
||||||
|
return
|
||||||
if len(timestamp.text) == 4: # If only year is provided
|
if len(timestamp.text) == 4: # If only year is provided
|
||||||
datetime_obj = datetime.datetime.strptime(timestamp.text, "%Y")
|
datetime_obj = datetime.datetime.strptime(timestamp.text, "%Y")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -36,18 +36,22 @@ 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.
|
||||||
with words...
|
Add extra fields as well
|
||||||
"""
|
"""
|
||||||
return {
|
remap = {
|
||||||
"title": audio["TIT2"].text[0],
|
"title": audio.get("TIT2"),
|
||||||
"artist": audio["TPE1"].text[0],
|
"artist": audio.get("TPE1"),
|
||||||
"album": audio["TALB"].text[0],
|
"album": audio.get("TALB"),
|
||||||
"track_number": audio["TRCK"].text[0],
|
"track_number": audio.get("TRCK"),
|
||||||
"genre": audio["TCON"].text[0],
|
"genre": audio.get("TCON"),
|
||||||
"date": convert_id3_timestamp_to_datetime(audio["TDRC"].text[0]),
|
"date": convert_id3_timestamp_to_datetime(audio.get("TDRC")),
|
||||||
"bitrate": audio["TBIT"].text[0],
|
"bitrate": audio.get("TBIT"),
|
||||||
|
"lyrics": audio.get("USLT"),
|
||||||
}
|
}
|
||||||
|
if isinstance(audio, MP3):
|
||||||
|
remap["length"] = int(round(audio.info.length, 0))
|
||||||
|
return remap
|
||||||
|
|
||||||
|
|
||||||
def get_id3_tags(filename: str) -> tuple[MP3 | ID3 | FLAC, str]:
|
def get_id3_tags(filename: str) -> tuple[MP3 | ID3 | FLAC, str]:
|
||||||
@ -61,8 +65,13 @@ def get_id3_tags(filename: str) -> tuple[MP3 | ID3 | FLAC, str]:
|
|||||||
- filename
|
- filename
|
||||||
Returns
|
Returns
|
||||||
- tuple(ID3/dict, fail_reason)
|
- tuple(ID3/dict, fail_reason)
|
||||||
|
|
||||||
ID3 dict looks like this:
|
ID3 dict looks like this:
|
||||||
{'TIT2': TIT2(encoding=<Encoding.UTF8: 3>, text=['song title']), 'TSSE': TSSE(encoding=<Encoding.UTF8: 3>, text=['Lavf59.27.100'])}
|
{
|
||||||
|
'TIT2': TIT2(encoding=<Encoding.UTF8: 3>, text=['song title']),
|
||||||
|
'TSSE': TSSE(encoding=<Encoding.UTF8: 3>, text=['Lavf59.27.100'],
|
||||||
|
...
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
if filename.endswith(".mp3"):
|
if filename.endswith(".mp3"):
|
||||||
tags, details = get_mp3_tags(filename)
|
tags, details = get_mp3_tags(filename)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user