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,)
|
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_data_changed()
|
||||||
self.disconnect_layout_changed()
|
self.disconnect_layout_changed()
|
||||||
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
|
self.vertical_scroll_position = self.verticalScrollBar().value() # type: ignore
|
||||||
@ -699,12 +702,12 @@ class MusicTable(QTableView):
|
|||||||
query = f"{query} WHERE {search_clause};"
|
query = f"{query} WHERE {search_clause};"
|
||||||
else:
|
else:
|
||||||
query = f"{query} AND {search_clause};"
|
query = f"{query} AND {search_clause};"
|
||||||
data = db.query(
|
data = db.query(query, (selected_playlist_id, params))
|
||||||
query,
|
else:
|
||||||
(selected_playlist_id, params),
|
data = db.query(query, (selected_playlist_id,))
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(f"load_music_table() | Unhandled exception: {e}")
|
error(f"load_music_table() | Unhandled exception 1: {e}")
|
||||||
return
|
return
|
||||||
else: # Load the library
|
else: # Load the library
|
||||||
try:
|
try:
|
||||||
@ -722,7 +725,7 @@ class MusicTable(QTableView):
|
|||||||
(params),
|
(params),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(f"load_music_table() | Unhandled exception: {e}")
|
error(f"load_music_table() | Unhandled exception 2: {e}")
|
||||||
return
|
return
|
||||||
# Populate the model
|
# Populate the model
|
||||||
row_count: int = 0
|
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
|
from PyQt5.QtCore import pyqtSignal, Qt, QPoint
|
||||||
import DBA
|
import DBA
|
||||||
from logging import debug
|
from logging import debug
|
||||||
|
|
||||||
from components import CreatePlaylistWindow
|
from components import CreatePlaylistWindow
|
||||||
|
|
||||||
|
|
||||||
class PlaylistWidgetItem(QTreeWidgetItem):
|
class PlaylistWidgetItem(QTreeWidgetItem):
|
||||||
def __init__(self, parent, id, name):
|
def __init__(self, parent, id, name):
|
||||||
super().__init__([name], 0)
|
super().__init__([name], 0)
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
|
||||||
# NOTE: ideas:
|
# NOTE: ideas:
|
||||||
# auto sort list (alphabetical?)
|
# auto sort list (alphabetical?)
|
||||||
# reorder list
|
# reorder list
|
||||||
# duplicate playlist
|
# duplicate playlist
|
||||||
|
|
||||||
|
|
||||||
class PlaylistsPane(QTreeWidget):
|
class PlaylistsPane(QTreeWidget):
|
||||||
playlistChoiceSignal = pyqtSignal(int)
|
playlistChoiceSignal = pyqtSignal(int)
|
||||||
playlistCreatedSignal = pyqtSignal()
|
playlistCreatedSignal = pyqtSignal()
|
||||||
@ -41,7 +52,9 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
self._playlists_root.takeChildren()
|
self._playlists_root.takeChildren()
|
||||||
# NOTE: implement user sorting by adding a column to playlist db table for 'rank' or something
|
# NOTE: implement user sorting by adding a column to playlist db table for 'rank' or something
|
||||||
with DBA.DBAccess() as db:
|
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:
|
for playlist in playlists:
|
||||||
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
branch = PlaylistWidgetItem(self, playlist[0], playlist[1])
|
||||||
self._playlists_root.addChild(branch)
|
self._playlists_root.addChild(branch)
|
||||||
@ -75,14 +88,19 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
Asks user for input
|
Asks user for input
|
||||||
Renames selected playlist based on user 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:
|
if len(text) > 64:
|
||||||
QMessageBox.warning(self, "WARNING", "Name must not exceed 64 characters")
|
QMessageBox.warning(self, "WARNING", "Name must not exceed 64 characters")
|
||||||
return
|
return
|
||||||
if ok:
|
if ok:
|
||||||
with DBA.DBAccess() as db:
|
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()
|
self.reload_playlists()
|
||||||
|
|
||||||
def delete_playlist(self, *args):
|
def delete_playlist(self, *args):
|
||||||
@ -96,23 +114,25 @@ class PlaylistsPane(QTreeWidget):
|
|||||||
)
|
)
|
||||||
if reply == QMessageBox.Yes:
|
if reply == QMessageBox.Yes:
|
||||||
with DBA.DBAccess() as db:
|
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
|
# reload
|
||||||
self.reload_playlists()
|
self.reload_playlists()
|
||||||
|
|
||||||
|
|
||||||
def playlist_clicked(self, item):
|
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:
|
if item == self._playlists_root or item == self._library_root:
|
||||||
self.playlist_db_id_choice = None
|
self.playlist_db_id_choice = None
|
||||||
self.all_songs_selected()
|
# self.all_songs_selected()
|
||||||
|
self.allSongsSignal.emit()
|
||||||
elif isinstance(item, PlaylistWidgetItem):
|
elif isinstance(item, PlaylistWidgetItem):
|
||||||
debug(f"ID: {item.id}, name: {item.text(0)}")
|
debug(f"ID: {item.id}, name: {item.text(0)}")
|
||||||
self.playlist_db_id_choice = item.id
|
self.playlist_db_id_choice = item.id
|
||||||
self.playlistChoiceSignal.emit(int(item.id))
|
self.playlistChoiceSignal.emit(int(item.id))
|
||||||
|
|
||||||
def all_songs_selected(self):
|
# def all_songs_selected(self):
|
||||||
"""Emits a signal to display all songs in the library"""
|
# """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
|
# # I have no idea why this has to be in its own function, but it does
|
||||||
# or else it doesn't work
|
# # or else it doesn't work
|
||||||
self.allSongsSignal.emit()
|
# self.allSongsSignal.emit()
|
||||||
|
|||||||
@ -147,6 +147,7 @@ class PreferencesWindow(QDialog):
|
|||||||
self.config.write(configfile)
|
self.config.write(configfile)
|
||||||
|
|
||||||
self.reloadConfigSignal.emit()
|
self.reloadConfigSignal.emit()
|
||||||
|
self.on_edit_toggled()
|
||||||
# only reload db if we changed the db
|
# only reload db if we changed the db
|
||||||
if self.current_category_str == "db":
|
if self.current_category_str == "db":
|
||||||
self.reloadDatabaseSignal.emit()
|
self.reloadDatabaseSignal.emit()
|
||||||
|
|||||||
@ -28,48 +28,48 @@ def add_files_to_database(files, progress_callback=None):
|
|||||||
config.read(cfg_file)
|
config.read(cfg_file)
|
||||||
if not files:
|
if not files:
|
||||||
return False, {"Failure": "All operations failed in add_files_to_database()"}
|
return False, {"Failure": "All operations failed in add_files_to_database()"}
|
||||||
extensions = config.get("settings", "extensions").split(",")
|
|
||||||
failed_dict = {}
|
failed_dict = {}
|
||||||
insert_data = [] # To store data for batch insert
|
insert_data = [] # To store data for batch insert
|
||||||
for filepath in files:
|
for filepath in files:
|
||||||
if any(filepath.lower().endswith(ext) for ext in extensions):
|
try:
|
||||||
if progress_callback:
|
progress_callback.emit(filepath)
|
||||||
progress_callback.emit(filepath)
|
except Exception:
|
||||||
filename = filepath.split("/")[-1]
|
pass
|
||||||
|
filename = filepath.split("/")[-1]
|
||||||
|
|
||||||
tags, details = get_tags(filepath)
|
tags, details = get_tags(filepath)
|
||||||
if details:
|
if details:
|
||||||
failed_dict[filepath] = details
|
failed_dict[filepath] = details
|
||||||
continue
|
continue
|
||||||
audio = id3_remap(tags)
|
audio = id3_remap(tags)
|
||||||
|
|
||||||
# Append data tuple to insert_data list
|
# Append data tuple to insert_data list
|
||||||
insert_data.append(
|
insert_data.append(
|
||||||
(
|
(
|
||||||
filepath,
|
filepath,
|
||||||
audio["title"],
|
audio["title"],
|
||||||
audio["album"],
|
audio["album"],
|
||||||
audio["artist"],
|
audio["artist"],
|
||||||
audio["track_number"],
|
audio["track_number"],
|
||||||
audio["genre"],
|
audio["genre"],
|
||||||
filename.split(".")[-1],
|
filename.split(".")[-1],
|
||||||
audio["date"],
|
audio["date"],
|
||||||
audio["bitrate"],
|
audio["bitrate"],
|
||||||
audio["length"],
|
audio["length"],
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# Check if batch size is reached
|
)
|
||||||
if len(insert_data) >= 1000:
|
# Check if batch size is reached
|
||||||
debug(f"inserting a LOT of songs: {len(insert_data)}")
|
if len(insert_data) >= 1000:
|
||||||
with DBA.DBAccess() as db:
|
debug(f"inserting a LOT of songs: {len(insert_data)}")
|
||||||
db.executemany(
|
with DBA.DBAccess() as db:
|
||||||
"INSERT OR IGNORE INTO song (filepath, title, album, artist, track_number, genre, codec, album_date, bitrate, length_seconds) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
db.executemany(
|
||||||
insert_data,
|
"INSERT OR IGNORE INTO song (filepath, title, album, artist, track_number, genre, codec, album_date, bitrate, length_seconds) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
)
|
insert_data,
|
||||||
insert_data = [] # Reset the insert_data list
|
)
|
||||||
else:
|
insert_data = [] # Reset the insert_data list
|
||||||
# continue adding files if we havent reached big length
|
else:
|
||||||
continue
|
# continue adding files if we havent reached big length
|
||||||
|
continue
|
||||||
# Insert any remaining data
|
# Insert any remaining data
|
||||||
debug("i check for insert data")
|
debug("i check for insert data")
|
||||||
if insert_data:
|
if insert_data:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user