remove unnecessary check for filetype when adding songs to database. fix query params for viewing playlists
This commit is contained in:
parent
98fd191ef3
commit
de260f3786
@ -674,6 +674,9 @@ class MusicTable(QTableView):
|
||||
|
||||
hint: You get a `playlist_id` from the signal emitted from PlaylistsPane as a tuple (1,)
|
||||
"""
|
||||
debug(
|
||||
f"load_music_table() | playlist id: \nTYPE: {type(playlist_id)}\nVALUE: {playlist_id}\n"
|
||||
)
|
||||
self.disconnect_data_changed()
|
||||
self.disconnect_layout_changed()
|
||||
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
|
||||
@ -699,12 +702,12 @@ class MusicTable(QTableView):
|
||||
query = f"{query} WHERE {search_clause};"
|
||||
else:
|
||||
query = f"{query} AND {search_clause};"
|
||||
data = db.query(
|
||||
query,
|
||||
(selected_playlist_id, params),
|
||||
)
|
||||
data = db.query(query, (selected_playlist_id, params))
|
||||
else:
|
||||
data = db.query(query, (selected_playlist_id,))
|
||||
|
||||
except Exception as e:
|
||||
error(f"load_music_table() | Unhandled exception: {e}")
|
||||
error(f"load_music_table() | Unhandled exception 1: {e}")
|
||||
return
|
||||
else: # Load the library
|
||||
try:
|
||||
@ -722,7 +725,7 @@ class MusicTable(QTableView):
|
||||
(params),
|
||||
)
|
||||
except Exception as e:
|
||||
error(f"load_music_table() | Unhandled exception: {e}")
|
||||
error(f"load_music_table() | Unhandled exception 2: {e}")
|
||||
return
|
||||
# Populate the model
|
||||
row_count: int = 0
|
||||
|
||||
@ -1,20 +1,31 @@
|
||||
from PyQt5.QtWidgets import QAction, QInputDialog, QListWidget, QMenu, QMessageBox, QTreeWidget, QTreeWidgetItem
|
||||
from PyQt5.QtWidgets import (
|
||||
QAction,
|
||||
QInputDialog,
|
||||
QListWidget,
|
||||
QMenu,
|
||||
QMessageBox,
|
||||
QTreeWidget,
|
||||
QTreeWidgetItem,
|
||||
)
|
||||
from PyQt5.QtCore import pyqtSignal, Qt, QPoint
|
||||
import DBA
|
||||
from logging import debug
|
||||
|
||||
from components import CreatePlaylistWindow
|
||||
|
||||
|
||||
class PlaylistWidgetItem(QTreeWidgetItem):
|
||||
def __init__(self, parent, id, name):
|
||||
super().__init__([name], 0)
|
||||
self.id = id
|
||||
|
||||
|
||||
# NOTE: ideas:
|
||||
# auto sort list (alphabetical?)
|
||||
# reorder list
|
||||
# duplicate playlist
|
||||
|
||||
|
||||
class PlaylistsPane(QTreeWidget):
|
||||
playlistChoiceSignal = pyqtSignal(int)
|
||||
playlistCreatedSignal = pyqtSignal()
|
||||
@ -41,7 +52,9 @@ class PlaylistsPane(QTreeWidget):
|
||||
self._playlists_root.takeChildren()
|
||||
# NOTE: implement user sorting by adding a column to playlist db table for 'rank' or something
|
||||
with DBA.DBAccess() as db:
|
||||
playlists = db.query("SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", ())
|
||||
playlists = db.query(
|
||||
"SELECT id, name FROM playlist ORDER BY date_created DESC LIMIT 1;", ()
|
||||
)
|
||||
for playlist in playlists:
|
||||
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
||||
self._playlists_root.addChild(branch)
|
||||
@ -75,14 +88,19 @@ class PlaylistsPane(QTreeWidget):
|
||||
Asks user for input
|
||||
Renames selected playlist based on user input
|
||||
"""
|
||||
text, ok = QInputDialog.getText(self, "Rename playlist", "New name: ")
|
||||
text, ok = QInputDialog.getText(
|
||||
self, "Rename playlist", "New name: "
|
||||
)
|
||||
|
||||
if len(text) > 64:
|
||||
QMessageBox.warning(self, "WARNING", "Name must not exceed 64 characters")
|
||||
return
|
||||
if ok:
|
||||
with DBA.DBAccess() as db:
|
||||
db.execute('UPDATE playlist SET name = ? WHERE id = ?;', (text, self.playlist_db_id_choice))
|
||||
db.execute(
|
||||
"UPDATE playlist SET name = ? WHERE id = ?;",
|
||||
(text, self.playlist_db_id_choice),
|
||||
)
|
||||
self.reload_playlists()
|
||||
|
||||
def delete_playlist(self, *args):
|
||||
@ -96,23 +114,25 @@ class PlaylistsPane(QTreeWidget):
|
||||
)
|
||||
if reply == QMessageBox.Yes:
|
||||
with DBA.DBAccess() as db:
|
||||
db.execute("DELETE FROM playlist WHERE id = ?;", (self.playlist_db_id_choice,))
|
||||
db.execute(
|
||||
"DELETE FROM playlist WHERE id = ?;", (self.playlist_db_id_choice,)
|
||||
)
|
||||
# reload
|
||||
self.reload_playlists()
|
||||
|
||||
|
||||
def playlist_clicked(self, item):
|
||||
"""Specific playlist index was clicked"""
|
||||
"""Specific playlist pane index was clicked"""
|
||||
if item == self._playlists_root or item == self._library_root:
|
||||
self.playlist_db_id_choice = None
|
||||
self.all_songs_selected()
|
||||
# self.all_songs_selected()
|
||||
self.allSongsSignal.emit()
|
||||
elif isinstance(item, PlaylistWidgetItem):
|
||||
debug(f"ID: {item.id}, name: {item.text(0)}")
|
||||
self.playlist_db_id_choice = item.id
|
||||
self.playlistChoiceSignal.emit(int(item.id))
|
||||
|
||||
def all_songs_selected(self):
|
||||
"""Emits a signal to display all songs in the library"""
|
||||
# I have no idea why this has to be in its own function, but it does
|
||||
# or else it doesn't work
|
||||
self.allSongsSignal.emit()
|
||||
# def all_songs_selected(self):
|
||||
# """Emits a signal to display all songs in the library"""
|
||||
# # I have no idea why this has to be in its own function, but it does
|
||||
# # or else it doesn't work
|
||||
# self.allSongsSignal.emit()
|
||||
|
||||
@ -147,6 +147,7 @@ class PreferencesWindow(QDialog):
|
||||
self.config.write(configfile)
|
||||
|
||||
self.reloadConfigSignal.emit()
|
||||
self.on_edit_toggled()
|
||||
# only reload db if we changed the db
|
||||
if self.current_category_str == "db":
|
||||
self.reloadDatabaseSignal.emit()
|
||||
|
||||
@ -28,13 +28,13 @@ def add_files_to_database(files, progress_callback=None):
|
||||
config.read(cfg_file)
|
||||
if not files:
|
||||
return False, {"Failure": "All operations failed in add_files_to_database()"}
|
||||
extensions = config.get("settings", "extensions").split(",")
|
||||
failed_dict = {}
|
||||
insert_data = [] # To store data for batch insert
|
||||
for filepath in files:
|
||||
if any(filepath.lower().endswith(ext) for ext in extensions):
|
||||
if progress_callback:
|
||||
try:
|
||||
progress_callback.emit(filepath)
|
||||
except Exception:
|
||||
pass
|
||||
filename = filepath.split("/")[-1]
|
||||
|
||||
tags, details = get_tags(filepath)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user