tyer tdat tdrc crap
This commit is contained in:
parent
9be971f1b3
commit
47f13045e7
@ -15,6 +15,7 @@ from utils.get_id3_tags import get_id3_tags
|
|||||||
from utils.set_id3_tag import set_id3_tag
|
from utils.set_id3_tag import set_id3_tag
|
||||||
from utils.update_song_in_database import update_song_in_database
|
from utils.update_song_in_database import update_song_in_database
|
||||||
from utils.id3_tag_mapping import id3_tag_mapping
|
from utils.id3_tag_mapping import id3_tag_mapping
|
||||||
|
# import re
|
||||||
|
|
||||||
|
|
||||||
class ID3LineEdit(QLineEdit):
|
class ID3LineEdit(QLineEdit):
|
||||||
@ -30,14 +31,14 @@ class ID3LineEdit(QLineEdit):
|
|||||||
|
|
||||||
|
|
||||||
class MetadataWindow(QDialog):
|
class MetadataWindow(QDialog):
|
||||||
refreshMusicTableSignal = pyqtSignal()
|
|
||||||
|
|
||||||
def __init__(self, refreshMusicTableSignal, songs: list, ids: list):
|
def __init__(self, refreshMusicTableSignal, songs: list, ids: list):
|
||||||
"""
|
"""
|
||||||
Window that allows batch editing of metadata for multiple files
|
Window that allows batch editing of metadata for multiple files
|
||||||
|
|
||||||
Input: songs
|
Input: songs, ids
|
||||||
- list of strings, absolute paths to mp3 files
|
- list of strings, absolute paths to mp3 files
|
||||||
|
- list of database song ids
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super(MetadataWindow, self).__init__()
|
super(MetadataWindow, self).__init__()
|
||||||
self.refreshMusicTableSignal = refreshMusicTableSignal
|
self.refreshMusicTableSignal = refreshMusicTableSignal
|
||||||
@ -89,12 +90,15 @@ class MetadataWindow(QDialog):
|
|||||||
|
|
||||||
# Field Creation
|
# Field Creation
|
||||||
if value == list(set(value)):
|
if value == list(set(value)):
|
||||||
|
print(value)
|
||||||
|
# If the ID3 tag is the same for every item we're editing
|
||||||
field_text = str(value[0]) if value else ""
|
field_text = str(value[0]) if value else ""
|
||||||
# Normal field
|
# Normal field
|
||||||
label = QLabel(str(self.id3_tag_mapping[tag]))
|
label = QLabel(str(self.id3_tag_mapping[tag]))
|
||||||
input_field = ID3LineEdit(field_text, tag)
|
input_field = ID3LineEdit(field_text, tag)
|
||||||
input_field.setStyleSheet(None)
|
input_field.setStyleSheet(None)
|
||||||
else:
|
else:
|
||||||
|
print(value)
|
||||||
# Danger field
|
# Danger field
|
||||||
# this means the metadata differs between the selected items for this tag
|
# this means the metadata differs between the selected items for this tag
|
||||||
# so be careful...dangerous
|
# so be careful...dangerous
|
||||||
@ -106,6 +110,7 @@ class MetadataWindow(QDialog):
|
|||||||
self.input_fields[tag] = input_field
|
self.input_fields[tag] = input_field
|
||||||
current_layout.addWidget(label)
|
current_layout.addWidget(label)
|
||||||
current_layout.addWidget(input_field)
|
current_layout.addWidget(input_field)
|
||||||
|
layout.addLayout(current_layout)
|
||||||
|
|
||||||
# Save button
|
# Save button
|
||||||
save_button = QPushButton("Save")
|
save_button = QPushButton("Save")
|
||||||
@ -119,6 +124,20 @@ class MetadataWindow(QDialog):
|
|||||||
for tag, field in self.input_fields.items():
|
for tag, field in self.input_fields.items():
|
||||||
if field.text() is not None and field.text() != "":
|
if field.text() is not None and field.text() != "":
|
||||||
if field.has_changed():
|
if field.has_changed():
|
||||||
|
# date crap...
|
||||||
|
# if tag == "TYER":
|
||||||
|
# continue
|
||||||
|
# if tag == "TDAT":
|
||||||
|
# match = re.match(
|
||||||
|
# r"(\d{4})[-/](\d{2})[-/](\d{2})", field.text()
|
||||||
|
# )
|
||||||
|
# if not match:
|
||||||
|
# continue
|
||||||
|
# year, _, _ = match.groups()
|
||||||
|
# _ = set_id3_tag(
|
||||||
|
# filepath=song[0], tag_name="TYER", value=str(year)
|
||||||
|
# )
|
||||||
|
# BUSINESS AS USUAL
|
||||||
# Update the ID3 tag if the tag is not blank,
|
# Update the ID3 tag if the tag is not blank,
|
||||||
# and has been edited
|
# and has been edited
|
||||||
success = set_id3_tag(
|
success = set_id3_tag(
|
||||||
|
|||||||
@ -44,7 +44,7 @@ class MusicTable(QTableView):
|
|||||||
# QTableView.__init__(self, parent)
|
# QTableView.__init__(self, parent)
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
# Necessary for actions related to cell values
|
# Necessary for actions related to cell values
|
||||||
# FIXME: why do these give me pyright errors
|
# FIXME: why does this give me pyright errors
|
||||||
self.model = QStandardItemModel(self)
|
self.model = QStandardItemModel(self)
|
||||||
# self.model = QAbstractItemModel(self)
|
# self.model = QAbstractItemModel(self)
|
||||||
self.setModel(self.model)
|
self.setModel(self.model)
|
||||||
|
|||||||
@ -10,4 +10,4 @@ from .delete_and_create_library_database import delete_and_create_library_databa
|
|||||||
from .update_song_in_database import update_song_in_database
|
from .update_song_in_database import update_song_in_database
|
||||||
from .scan_for_music import scan_for_music
|
from .scan_for_music import scan_for_music
|
||||||
from .add_files_to_library import add_files_to_library
|
from .add_files_to_library import add_files_to_library
|
||||||
from .handle_year_and_date_id3_tag import handle_year_and_date_id3_tag
|
from .convert_date_str_to_tyer_tdat_id3_tag import convert_date_str_to_tyer_tdat_id3_tag
|
||||||
|
|||||||
28
utils/convert_date_str_to_tyer_tdat_id3_tag.py
Normal file
28
utils/convert_date_str_to_tyer_tdat_id3_tag.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import re
|
||||||
|
from typing import Tuple
|
||||||
|
from mutagen.id3._frames import TYER, TDAT
|
||||||
|
|
||||||
|
|
||||||
|
def convert_date_str_to_tyer_tdat_id3_tag(date_str) -> Tuple:
|
||||||
|
"""
|
||||||
|
Handles date formatting when updating a date record in the music table
|
||||||
|
Date string format = YYYY-MM-DD
|
||||||
|
"""
|
||||||
|
if not date_str:
|
||||||
|
return None, None
|
||||||
|
match = re.match(r"(\d{4})[-/](\d{2})[-/](\d{2})", date_str)
|
||||||
|
if not match:
|
||||||
|
raise ValueError("Invalid date format")
|
||||||
|
# print(f"convert_date_str_to_tyer_tdat_id3_tag(): match: {match}")
|
||||||
|
year, month, day = match.groups()
|
||||||
|
# print(
|
||||||
|
# f"convert_date_str_to_tyer_tdat_id3_tag(): month: {month} | day: {day} | year: {year}"
|
||||||
|
# )
|
||||||
|
# only year
|
||||||
|
if not month or not day:
|
||||||
|
# print(TYER(encoding=3, text=year))
|
||||||
|
return TYER(encoding=3, text=year), None
|
||||||
|
else:
|
||||||
|
date_value = f"{day}{month}"
|
||||||
|
# print(TYER(encoding=3, text=year), TDAT(encoding=3, text=date_value))
|
||||||
|
return TYER(encoding=3, text=year), TDAT(encoding=3, text=date_value)
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import re
|
|
||||||
from mutagen.id3 import TYER, TDAT
|
|
||||||
|
|
||||||
|
|
||||||
def handle_year_and_date_id3_tag(date_str):
|
|
||||||
"""
|
|
||||||
Handles date formatting when updating a date record in the music table
|
|
||||||
Date format = YYYY-MM-DD
|
|
||||||
"""
|
|
||||||
match = re.match(r"(\d{4})[-/](\d{2})[-/](\d{2})", date_str)
|
|
||||||
if not match:
|
|
||||||
raise ValueError("Invalid date format")
|
|
||||||
print(f"handle_year_and_date_id3_tag(): match: {match}")
|
|
||||||
year, month, day = match.groups()
|
|
||||||
print(f"handle_year_and_date_id3_tag(): month: {month} | day: {day} | year: {year}")
|
|
||||||
# only year
|
|
||||||
if not month or not day:
|
|
||||||
print(TYER(encoding=3, text=year))
|
|
||||||
return TYER(encoding=3, text=year), None
|
|
||||||
else:
|
|
||||||
date_value = f"{day}{month}"
|
|
||||||
print(TYER(encoding=3, text=year), TDAT(encoding=3, text=date_value))
|
|
||||||
return TYER(encoding=3, text=year), TDAT(encoding=3, text=date_value)
|
|
||||||
@ -5,6 +5,9 @@ id3_tag_mapping = {
|
|||||||
"TPE2": "album_artist",
|
"TPE2": "album_artist",
|
||||||
"TCON": "genre",
|
"TCON": "genre",
|
||||||
"TRCK": "track_number",
|
"TRCK": "track_number",
|
||||||
|
"TDRC": "album_date",
|
||||||
|
# "TYER": "year",
|
||||||
|
# "TDAT": "date",
|
||||||
# "APIC": "album_cover",
|
# "APIC": "album_cover",
|
||||||
"TCOP": "copyright",
|
"TCOP": "copyright",
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import logging
|
import logging
|
||||||
from components import ErrorDialog
|
from components import ErrorDialog
|
||||||
from utils.handle_year_and_date_id3_tag import handle_year_and_date_id3_tag
|
from utils.convert_date_str_to_tyer_tdat_id3_tag import (
|
||||||
|
convert_date_str_to_tyer_tdat_id3_tag,
|
||||||
|
)
|
||||||
from mutagen.id3 import ID3
|
from mutagen.id3 import ID3
|
||||||
from mutagen.id3._util import ID3NoHeaderError
|
from mutagen.id3._util import ID3NoHeaderError
|
||||||
from mutagen.id3._frames import (
|
from mutagen.id3._frames import (
|
||||||
@ -9,6 +11,7 @@ from mutagen.id3._frames import (
|
|||||||
TPE1,
|
TPE1,
|
||||||
TALB,
|
TALB,
|
||||||
TRCK,
|
TRCK,
|
||||||
|
TDRC,
|
||||||
# TYER,
|
# TYER,
|
||||||
TCON,
|
TCON,
|
||||||
TPOS,
|
TPOS,
|
||||||
@ -46,6 +49,7 @@ mutagen_id3_tag_mapping = {
|
|||||||
"album": TALB, # Album/Movie/Show title
|
"album": TALB, # Album/Movie/Show title
|
||||||
"album_artist": TPE2, # Band/orchestra/accompaniment
|
"album_artist": TPE2, # Band/orchestra/accompaniment
|
||||||
"genre": TCON, # Content type
|
"genre": TCON, # Content type
|
||||||
|
"album_date": TDRC,
|
||||||
# "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
|
||||||
@ -97,15 +101,15 @@ def set_id3_tag(filepath: str, tag_name: str, value: str):
|
|||||||
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
|
# 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 = convert_date_str_to_tyer_tdat_id3_tag(value)
|
||||||
# always update TYER
|
# # always update TYER
|
||||||
audio_file.add(tyer_tag)
|
# audio_file.add(tyer_tag)
|
||||||
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
|
# Lyrics
|
||||||
elif tag_name == "lyrics" or tag_name == "USLT":
|
if tag_name == "lyrics" or tag_name == "USLT":
|
||||||
try:
|
try:
|
||||||
audio = ID3(filepath)
|
audio = ID3(filepath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user