Compare commits

..

No commits in common. "3d168821853772d9bb1e3c761cac735beb03709b" and "4b440378a5766fd088d6f5aefc5d50048ef79eb9" have entirely different histories.

6 changed files with 479 additions and 82 deletions

View File

@ -4,31 +4,15 @@ from appdirs import user_config_dir
from dataclasses import dataclass, asdict
from typing import Optional
@dataclass
class SQLiteMap:
title: Optional[str] = None
artist: Optional[str] = None
class SQLiteMap():
title: str
artist: str
album: Optional[str] = None
album_artist: Optional[str] = None
track_number: Optional[str] = None
genre: Optional[str] = None
length_seconds: Optional[str] = None
album_date: Optional[str] = None
codec: Optional[str] = None
filepath: Optional[str] = None
"""
db names are called FIELDS (e.g., title, track_number, length_seconds)
gui names are called HEADERS (e.g., title, track, length, year)
id3 names are called TAGS (e.g., TIT2, TPE1, TALB)
is dataclasses rly worth it?
"""
class HeaderTags:
class HeaderTags():
"""
Utility class to converting between different "standards" for tags (headers, id3, etc)
@ -36,8 +20,8 @@ class HeaderTags:
`gui`: dict = "db name": "gui string"
`id3`: dict = "db name": "id3 tag string"
`id3_keys`: dict = "id3 tag string": "db name"
`editable_fields`: list = "list of db names that are user editable"
`user_fields`: list = "list of db headers that the user has chosen to see in gui"
`editable_db_tags`: list = "list of db names that are user editable"
`user_headers`: list = "list of db headers that the user has chosen to see in gui"
"""
def __init__(self):
@ -47,43 +31,7 @@ class HeaderTags:
)
self.config = ConfigParser()
self.config.read(cfg_file)
print("header tag config")
print(self.config)
self.user_fields: list = str(self.config["table"]["columns"]).split(",")
self.editable_fields: list = [
"title",
"artist",
"album_artist",
"album",
"track_number",
"genre",
"album_date",
]
self.fields = SQLiteMap()
self.headers = SQLiteMap(
title="title",
artist="artist",
album="album",
album_artist="alb artist",
track_number="track",
genre="genre",
codec="codec",
length_seconds="length",
album_date="year",
filepath="path",
)
# self.id3 = SQLiteMap(
# title = "TIT2",
# artist = "TPE1",
# album = "TALB",
# album_artist = "TPE2",
# track_number = "TRCK",
# genre = "TCON",
# length_seconds = "TLEN",
# album_date = "TDRC",
# codec = None,
# filepath = None
# )
self.user_headers: list = str(self.config["table"]["columns"]).split(",")
self.db: dict = {
"title": "title",
"artist": "artist",
@ -126,10 +74,20 @@ class HeaderTags:
if v is not None:
self.id3_keys[v] = k
self.editable_db_tags: list = [
"title",
"artist",
"album_artist",
"album",
"track_number",
"genre",
"album_date",
]
def get_user_gui_headers(self) -> list:
"""Returns a list of headers for the GUI"""
gui_headers = []
for db, gui in asdict(self.headers).items():
if db in self.user_fields:
for db, gui in self.gui.items():
if db in self.user_headers:
gui_headers.append(gui)
return gui_headers

View File

@ -56,10 +56,9 @@ class MetadataWindow(QDialog):
layout.addWidget(category_label)
layout.addWidget(h_separator)
tag_sets: dict[str, list] = {}
tag_sets: dict = {}
# Get a dict of all tags for all songs
# e.g., { "TIT2": ["song_title1", "song_title2"], ... }
# e.g., { "title": ["song_title1", "song_title2"], ... }
for song in self.songs:
song_data = get_tags(song[0])[0]
if not song_data:
@ -72,7 +71,7 @@ class MetadataWindow(QDialog):
)
return
for key, tag in self.headers.id3.items():
if key not in self.headers.editable_fields:
if key not in self.headers.editable_db_tags:
continue
if tag is not None:
try:

View File

@ -1,5 +1,7 @@
from mutagen.id3 import ID3
from json import load as jsonload
import DBA
from pprint import pprint
from PyQt5.QtGui import (
QColor,
QDragMoveEvent,
@ -16,10 +18,12 @@ from PyQt5.QtWidgets import (
QAction,
QHeaderView,
QMenu,
QPlainTextEdit,
QTableView,
QShortcut,
QMessageBox,
QAbstractItemView,
QVBoxLayout,
)
from PyQt5.QtCore import (
QItemSelectionModel,
@ -28,6 +32,7 @@ from PyQt5.QtCore import (
QModelIndex,
QThreadPool,
pyqtSignal,
QTimer,
)
from components.DebugWindow import DebugWindow
from components.ErrorDialog import ErrorDialog
@ -101,8 +106,6 @@ class MusicTable(QTableView):
)
self.config = ConfigParser()
self.config.read(cfg_file)
print("music table config:")
print(self.config)
# Threads
self.threadpool = QThreadPool
@ -126,6 +129,8 @@ class MusicTable(QTableView):
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
# header
# FIXME: table headers being resized and going out window bounds
# causing some recursion errors...
self.horizontal_header: QHeaderView = self.horizontalHeader()
assert self.horizontal_header is not None # i hate look at linting errors
self.horizontal_header.setStretchLastSection(True)
@ -339,7 +344,7 @@ class MusicTable(QTableView):
def on_sort(self):
debug("on_sort")
search_col_num = self.headers.user_fields.index("filepath")
search_col_num = self.headers.user_headers.index("filepath")
selected_qmodel_index = self.find_qmodel_index_by_value(
self.proxymodel, search_col_num, self.selected_song_filepath
)
@ -394,14 +399,18 @@ class MusicTable(QTableView):
if isinstance(self.model2, QStandardItemModel):
debug("on_cell_data_changed")
# get the ID of the row that was edited
id_index = self.model2.index(topLeft.row(), 0)
id_index = self.model2.index(topLeft.row(), 0) # ID is column 0, always
# get the db song_id from the row
song_id = self.model2.data(id_index, Qt.ItemDataRole.UserRole)
user_index = self.headers.user_fields.index("filepath")
filepath = self.currentIndex().siblingAtColumn(user_index).data()
# get the filepath through a series of steps...
# NOTE: filepath is always the last column
filepath_column_idx = self.model2.columnCount() - 1
filepath_index = self.model2.index(topLeft.row(), filepath_column_idx)
filepath = self.model2.data(filepath_index)
# update the ID3 information
user_input_data = topLeft.data()
edited_column_name = self.headers.user_fields[topLeft.column()]
# edited_column_name = self.database_columns[topLeft.column()]
edited_column_name = self.headers.user_headers[topLeft.column()]
debug(f"on_cell_data_changed | edited column name: {edited_column_name}")
response = set_tag(filepath, edited_column_name, user_input_data)
if response:
@ -676,12 +685,12 @@ class MusicTable(QTableView):
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
self.model2.clear()
self.model2.setHorizontalHeaderLabels(self.headers.get_user_gui_headers())
fields = ", ".join(self.headers.user_fields)
search_clause = (
"title LIKE %?% AND artist LIKE %?% and album LIKE %?%"
if self.search_string
else ""
)
fields = ", ".join(self.headers.user_headers)
params = ""
if playlist_id: # Load a playlist
selected_playlist_id = playlist_id[0]
@ -753,7 +762,7 @@ class MusicTable(QTableView):
print(f"load music table current filepath: {current_song_filepath}")
for row in range(self.model2.rowCount()):
real_index = self.model2.index(
row, self.headers.user_fields.index("filepath")
row, self.headers.user_headers.index("filepath")
)
if real_index.data() == current_song_filepath:
print("is it true?")
@ -855,7 +864,9 @@ class MusicTable(QTableView):
selected_rows = self.get_selected_rows()
filepaths = []
for row in selected_rows:
idx = self.proxymodel.index(row, self.headers.user_fields.index("filepath"))
idx = self.proxymodel.index(
row, self.headers.user_headers.index("filepath")
)
filepaths.append(idx.data())
return filepaths
@ -892,8 +903,8 @@ class MusicTable(QTableView):
def set_selected_song_filepath(self) -> None:
"""Sets the filepath of the currently selected song"""
try:
user_index = self.headers.user_fields.index("filepath")
filepath = self.currentIndex().siblingAtColumn(user_index).data()
table_index = self.headers.user_headers.index("filepath")
filepath = self.currentIndex().siblingAtColumn(table_index).data()
except ValueError:
# if the user doesnt have filepath selected as a header, retrieve the file from db
row = self.currentIndex().row()
@ -914,7 +925,7 @@ class MusicTable(QTableView):
# update the filepath
if not filepath:
path = self.current_song_qmodel_index.siblingAtColumn(
self.headers.user_fields.index("filepath")
self.headers.user_headers.index("filepath")
).data()
self.current_song_filepath: str = path
else:

View File

@ -162,8 +162,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
/ "config.ini"
)
self.config.read(self.cfg_file)
print("main config:")
print(self.config)
self.threadpool: QThreadPool = QThreadPool()
# UI
self.setupUi(self)
@ -394,7 +392,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
prev_row, index.column()
)
prev_filepath = prev_index.siblingAtColumn(
self.headers.user_fields.index("filepath")
self.headers.user_headers.index("filepath")
).data()
if prev_filepath is None:
return
@ -418,7 +416,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
next_row, index.column()
)
next_filepath = next_index.siblingAtColumn(
self.headers.user_fields.index("filepath")
self.headers.user_headers.index("filepath")
).data()
if next_filepath is None:
return

432
ui.ui Normal file
View File

@ -0,0 +1,432 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1152</width>
<height>894</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="statusTip">
<string/>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="20">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="SearchLineEdit" name="lineEditSearch"/>
</item>
<item>
<layout class="QHBoxLayout" name="hLayoutHead" stretch="1,0,6">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<layout class="QVBoxLayout" name="vlayoutAlbumArt">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<widget class="AlbumArtGraphicsView" name="albumGraphicsView">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="vLayoutSongDetails"/>
</item>
<item>
<layout class="QVBoxLayout" name="vLayoutPlaybackVisuals">
<item>
<widget class="PlotWidget" name="PlotWidget" native="true"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="hLayoutMusicTable" stretch="0,10">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="PlaylistsPane" name="playlistTreeView"/>
</item>
</layout>
</item>
<item>
<widget class="MusicTable" name="tableView"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="hLayoutCurrentSongDetails" stretch="0">
<property name="spacing">
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" name="hLayoutSongDetails" stretch="0,0,0">
<item>
<widget class="QLabel" name="artistLabel"/>
</item>
<item>
<widget class="QLabel" name="titleLabel"/>
</item>
<item>
<widget class="QLabel" name="albumLabel"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="hLayoutPlayback" stretch="4,0">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QSlider" name="playbackSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="timeHorizontalLayout2">
<item>
<widget class="QLabel" name="startTimeLabel">
<property name="font">
<font>
<family>Monospace</family>
<italic>false</italic>
</font>
</property>
<property name="text">
<string>00:00</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="slashLabel">
<property name="font">
<font>
<family>Monospace</family>
<italic>false</italic>
</font>
</property>
<property name="text">
<string>/</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="endTimeLabel">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>00:00</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="hLayoutControls" stretch="1,0,1,1,1,0,1">
<property name="spacing">
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" name="hLayoutVolume">
<item>
<widget class="QLabel" name="volumeLabel">
<property name="text">
<string>50</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="volumeSlider">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>101</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="previousButton">
<property name="font">
<font>
<pointsize>28</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="playButton">
<property name="font">
<font>
<pointsize>28</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="font">
<font>
<pointsize>28</pointsize>
</font>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSlider" name="speedSlider">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="speedLabel">
<property name="font">
<font>
<family>Monospace</family>
</font>
</property>
<property name="text">
<string>1.00</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1152</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpenFiles"/>
<addaction name="actionNewPlaylist"/>
<addaction name="actionExportPlaylist"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionPreferences"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
</widget>
<widget class="QMenu" name="menuQuick_Actions">
<property name="title">
<string>Quick-Actions</string>
</property>
<addaction name="actionScanLibraries"/>
<addaction name="actionDeleteLibrary"/>
<addaction name="actionDeleteDatabase"/>
<addaction name="actionSortColumns"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuQuick_Actions"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionPreferences">
<property name="text">
<string>Preferences</string>
</property>
<property name="statusTip">
<string>Open preferences</string>
</property>
</action>
<action name="actionScanLibraries">
<property name="text">
<string>Scan libraries</string>
</property>
</action>
<action name="actionDeleteLibrary">
<property name="text">
<string>Delete Library</string>
</property>
</action>
<action name="actionSortColumns">
<property name="text">
<string>Sort Columns</string>
</property>
</action>
<action name="actionOpenFiles">
<property name="text">
<string>Open file(s)</string>
</property>
</action>
<action name="actionDeleteDatabase">
<property name="text">
<string>Delete Database</string>
</property>
</action>
<action name="actionNewPlaylist">
<property name="text">
<string>New playlist</string>
</property>
</action>
<action name="actionExportPlaylist">
<property name="text">
<string>Export playlist</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>PlotWidget</class>
<extends>QWidget</extends>
<header>pyqtgraph</header>
<container>1</container>
</customwidget>
<customwidget>
<class>MusicTable</class>
<extends>QTableView</extends>
<header>components</header>
</customwidget>
<customwidget>
<class>AlbumArtGraphicsView</class>
<extends>QGraphicsView</extends>
<header>components</header>
</customwidget>
<customwidget>
<class>PlaylistsPane</class>
<extends>QTreeView</extends>
<header>components</header>
</customwidget>
<customwidget>
<class>SearchLineEdit</class>
<extends>QLineEdit</extends>
<header>components</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -107,7 +107,6 @@ def set_tag(filepath: str, tag_name: str, value: str):
# if tdat_tag:
# # update TDAT if we have it
# audio_file.add(tdat_tag)
# Lyrics
if tag_name == "lyrics" or tag_name == "USLT":
try: