track number functionality
This commit is contained in:
parent
cd61d76cc8
commit
24128f97ba
@ -49,6 +49,7 @@ class MusicTable(QTableView):
|
|||||||
"title",
|
"title",
|
||||||
"artist",
|
"artist",
|
||||||
"album",
|
"album",
|
||||||
|
"track_number",
|
||||||
"genre",
|
"genre",
|
||||||
"codec",
|
"codec",
|
||||||
"year",
|
"year",
|
||||||
@ -59,9 +60,10 @@ class MusicTable(QTableView):
|
|||||||
"TIT2",
|
"TIT2",
|
||||||
"TPE1",
|
"TPE1",
|
||||||
"TALB",
|
"TALB",
|
||||||
|
"TRCK",
|
||||||
"content_type",
|
"content_type",
|
||||||
None,
|
None,
|
||||||
None,
|
"TDRC",
|
||||||
None,
|
None,
|
||||||
]
|
]
|
||||||
# db names of headers
|
# db names of headers
|
||||||
@ -327,7 +329,7 @@ class MusicTable(QTableView):
|
|||||||
try:
|
try:
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
data = db.query(
|
data = db.query(
|
||||||
"SELECT id, title, artist, album, genre, codec, album_date, filepath FROM song;",
|
"SELECT id, title, artist, album, track_number, genre, codec, album_date, filepath FROM song;",
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -34,6 +34,10 @@ def add_files_to_library(files):
|
|||||||
album = audio["TALB"].text[0]
|
album = audio["TALB"].text[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
album = ""
|
album = ""
|
||||||
|
try:
|
||||||
|
track_number = audio["TRCK"].text[0]
|
||||||
|
except KeyError:
|
||||||
|
track_number = 0
|
||||||
try:
|
try:
|
||||||
genre = audio["TCON"].text[0]
|
genre = audio["TCON"].text[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -54,6 +58,7 @@ def add_files_to_library(files):
|
|||||||
title,
|
title,
|
||||||
album,
|
album,
|
||||||
artist,
|
artist,
|
||||||
|
track_number,
|
||||||
genre,
|
genre,
|
||||||
filename.split(".")[-1],
|
filename.split(".")[-1],
|
||||||
date,
|
date,
|
||||||
@ -64,7 +69,7 @@ def add_files_to_library(files):
|
|||||||
if len(insert_data) >= 1000:
|
if len(insert_data) >= 1000:
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
db.executemany(
|
db.executemany(
|
||||||
"INSERT OR IGNORE INTO song (filepath, title, album, artist, genre, codec, album_date, bitrate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
"INSERT OR IGNORE INTO song (filepath, title, album, artist, track_number, genre, codec, album_date, bitrate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
insert_data,
|
insert_data,
|
||||||
)
|
)
|
||||||
insert_data = [] # Reset the insert_data list
|
insert_data = [] # Reset the insert_data list
|
||||||
@ -72,7 +77,7 @@ def add_files_to_library(files):
|
|||||||
if insert_data:
|
if insert_data:
|
||||||
with DBA.DBAccess() as db:
|
with DBA.DBAccess() as db:
|
||||||
db.executemany(
|
db.executemany(
|
||||||
"INSERT OR IGNORE INTO song (filepath, title, album, artist, genre, codec, album_date, bitrate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
"INSERT OR IGNORE INTO song (filepath, title, album, artist, track_number, genre, codec, album_date, bitrate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
insert_data,
|
insert_data,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|||||||
@ -7,6 +7,7 @@ CREATE TABLE song(
|
|||||||
title varchar(255),
|
title varchar(255),
|
||||||
album varchar(255),
|
album varchar(255),
|
||||||
artist varchar(255),
|
artist varchar(255),
|
||||||
|
track_number integer,
|
||||||
genre varchar(255),
|
genre varchar(255),
|
||||||
codec varchar(15),
|
codec varchar(15),
|
||||||
album_date date,
|
album_date date,
|
||||||
|
|||||||
@ -5,11 +5,14 @@ import os
|
|||||||
|
|
||||||
def get_id3_tags(file):
|
def get_id3_tags(file):
|
||||||
"""Get the ID3 tags for an audio file
|
"""Get the ID3 tags for an audio file
|
||||||
|
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
`file` | str | Fully qualified path to file
|
`file` | str | Fully qualified path to file
|
||||||
|
|
||||||
# Returns
|
# Returns
|
||||||
dict of all id3 tags
|
dict of all id3 tags
|
||||||
if all tags are empty, at minimum fill in the 'title'
|
at minimum we will get the filename as a title.[ID3:TIT2]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -20,9 +23,10 @@ def get_id3_tags(file):
|
|||||||
# Check if all tags are empty
|
# Check if all tags are empty
|
||||||
# tags_are_empty = all(not values for values in audio.values())
|
# tags_are_empty = all(not values for values in audio.values())
|
||||||
try:
|
try:
|
||||||
title = os.path.splitext(os.path.basename(file))[0]
|
if audio["TIT2"] is None:
|
||||||
frame = TIT2(encoding=3, text=[title])
|
title = os.path.splitext(os.path.basename(file))[0]
|
||||||
audio["TIT2"] = frame
|
frame = TIT2(encoding=3, text=[title])
|
||||||
|
audio["TIT2"] = frame
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"get_id3_tags.py | Exception: {e}")
|
print(f"get_id3_tags.py | Exception: {e}")
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -9,6 +9,7 @@ CREATE TABLE song(
|
|||||||
title varchar(255),
|
title varchar(255),
|
||||||
album varchar(255),
|
album varchar(255),
|
||||||
artist varchar(255),
|
artist varchar(255),
|
||||||
|
track_number integer,
|
||||||
genre varchar(255),
|
genre varchar(255),
|
||||||
codec varchar(15),
|
codec varchar(15),
|
||||||
album_date date,
|
album_date date,
|
||||||
|
|||||||
@ -87,15 +87,16 @@ def set_id3_tag(filepath: str, tag_name: str, value: str):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True / False"""
|
True / False"""
|
||||||
# print(
|
print(
|
||||||
# f"set_id3_tag.py | filepath: {filepath} | tag_name: {tag_name} | value: {value}"
|
f"set_id3_tag.py | filepath: {filepath} | tag_name: {tag_name} | value: {value}"
|
||||||
# )
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try: # Load existing tags
|
try: # Load existing tags
|
||||||
audio_file = ID3(filepath)
|
audio_file = ID3(filepath)
|
||||||
except ID3NoHeaderError: # Create new tags if none exist
|
except ID3NoHeaderError: # Create new tags if none exist
|
||||||
audio_file = ID3()
|
audio_file = ID3()
|
||||||
|
# Date handling - TDRC vs TYER+TDAT
|
||||||
if tag_name == "album_date":
|
if tag_name == "album_date":
|
||||||
tyer_tag, tdat_tag = handle_year_and_date_id3_tag(value)
|
tyer_tag, tdat_tag = handle_year_and_date_id3_tag(value)
|
||||||
# always update TYER
|
# always update TYER
|
||||||
@ -103,6 +104,7 @@ def set_id3_tag(filepath: str, tag_name: str, value: str):
|
|||||||
if tdat_tag:
|
if tdat_tag:
|
||||||
# update TDAT if we have it
|
# update TDAT if we have it
|
||||||
audio_file.add(tdat_tag)
|
audio_file.add(tdat_tag)
|
||||||
|
# Lyrics
|
||||||
elif tag_name == "lyrics" or tag_name == "USLT":
|
elif tag_name == "lyrics" or tag_name == "USLT":
|
||||||
try:
|
try:
|
||||||
audio = ID3(filepath)
|
audio = ID3(filepath)
|
||||||
@ -116,6 +118,7 @@ def set_id3_tag(filepath: str, tag_name: str, value: str):
|
|||||||
audio.add(frame)
|
audio.add(frame)
|
||||||
audio.save()
|
audio.save()
|
||||||
return True
|
return True
|
||||||
|
# Other
|
||||||
elif tag_name in id3_tag_mapping: # Tag accounted for
|
elif tag_name in id3_tag_mapping: # Tag accounted for
|
||||||
tag_class = id3_tag_mapping[tag_name]
|
tag_class = id3_tag_mapping[tag_name]
|
||||||
if issubclass(tag_class, Frame):
|
if issubclass(tag_class, Frame):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user