edit metadata window clean up and doc string

This commit is contained in:
tsi-billypom 2024-08-12 11:35:10 -04:00
parent e3b93aa6b3
commit 010e4fa7fb

View File

@ -15,7 +15,10 @@ from utils.get_id3_tags import get_id3_tags
class MetadataWindow(QDialog): class MetadataWindow(QDialog):
def __init__(self, songs: list): def __init__(self, songs: list):
""" """
Takes in a list of songs (absolute paths) Window that allows batch editing of metadata for multiple files
Input: songs
- list of strings, absolute paths to mp3 files
""" """
super(MetadataWindow, self).__init__() super(MetadataWindow, self).__init__()
self.id3_tag_mapping = { self.id3_tag_mapping = {
@ -31,38 +34,33 @@ class MetadataWindow(QDialog):
self.setWindowTitle("Edit metadata") self.setWindowTitle("Edit metadata")
# self.setMinimumSize(600, 800) # self.setMinimumSize(600, 800)
layout = QVBoxLayout() layout = QVBoxLayout()
# h_separator = QFrame() h_separator = QFrame()
# h_separator.setFrameShape(QFrame.HLine) h_separator.setFrameShape(QFrame.HLine)
# Labels and categories and stuff # Labels and categories and stuff
# category_label = QLabel("Edit metadata") category_label = QLabel("Edit metadata")
# category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold category category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold category
# category_label.setStyleSheet("text-transform:uppercase;") # uppercase category category_label.setStyleSheet("text-transform:uppercase;") # uppercase category
# layout.addWidget(category_label) layout.addWidget(category_label)
# layout.addWidget(h_separator) layout.addWidget(h_separator)
# Editable fields
tag_sets: dict = {} tag_sets: dict = {}
# { "TIT2": ["song_title1", "song_title2"], ... } # Get a dict of all tags for all songs
# e.g., { "TIT2": ["song_title1", "song_title2"], ... }
for song in songs: for song in songs:
song_data = get_id3_tags(song) song_data = get_id3_tags(song)
print("song_data")
print(song_data)
for tag in self.id3_tag_mapping: for tag in self.id3_tag_mapping:
# See if the tag exists in the dict
# else, create it
try: try:
_ = tag_sets[tag] _ = tag_sets[tag]
except KeyError: except KeyError:
# If a tag doesn't exist in our dict, create an empty list
tag_sets[tag] = [] tag_sets[tag] = []
try: try:
tag_sets[tag].append(song_data[tag].text[0]) tag_sets[tag].append(song_data[tag].text[0])
except KeyError: except KeyError:
pass pass
print(f"tag sets: {tag_sets}") # UI Creation
current_layout = QHBoxLayout() current_layout = QHBoxLayout()
for idx, (tag, value) in enumerate(tag_sets.items()): for idx, (tag, value) in enumerate(tag_sets.items()):
# Layout creation # Layout creation
@ -73,7 +71,7 @@ class MetadataWindow(QDialog):
layout.addLayout(current_layout) layout.addLayout(current_layout)
current_layout = QHBoxLayout() current_layout = QHBoxLayout()
print(f"type: {type(value)} | value: {value}") # print(f"type: {type(value)} | value: {value}")
# Field Creation # Field Creation
if value == list(set(value)): if value == list(set(value)):
@ -85,6 +83,7 @@ class MetadataWindow(QDialog):
else: else:
# 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
field_text = str(value[0]) if value else "" field_text = str(value[0]) if value else ""
label = QLabel(str(self.id3_tag_mapping[tag])) label = QLabel(str(self.id3_tag_mapping[tag]))
input_field = QLineEdit(field_text) input_field = QLineEdit(field_text)