Song db search works, very messy

This commit is contained in:
Keith Edmunds 2021-03-20 23:52:38 +00:00
parent d50120b3e5
commit cbcfd4a5bf
4 changed files with 94 additions and 54 deletions

42
app.py
View File

@ -17,6 +17,29 @@ from tinytag import TinyTag
from main_window_ui import Ui_MainWindow from main_window_ui import Ui_MainWindow
from dlg_search_database_ui import Ui_Dialog from dlg_search_database_ui import Ui_Dialog
from songdb import Tracks
import sqlalchemy
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
# "Constants"
DISPLAY_SQL = False
MYSQL_CONNECT = "mysql+mysqldb://songdb:songdb@localhost/songdb"
# Declare mapping
Base = declarative_base()
engine = sqlalchemy.create_engine(f"{MYSQL_CONNECT}?charset=utf8",
encoding='utf-8',
echo=DISPLAY_SQL)
Base.metadata.create_all(engine)
# Create a Session
Session = sessionmaker(bind=engine)
session = Session()
class RepeatedTimer: class RepeatedTimer:
def __init__(self, interval, function, *args, **kwargs): def __init__(self, interval, function, *args, **kwargs):
@ -83,7 +106,7 @@ class Track:
audio_segment - the segment to find silence in audio_segment - the segment to find silence in
silence_threshold - the upper bound for how quiet is silent in dFBS silence_threshold - the upper bound for how quiet is silent in dFBS
chunk_size - chunk size for interating over the segment in ms chunk_size - chunk size for interating over the segment in ms
dlg_search_database_ui
https://github.com/jiaaro/pydub/blob/master/pydub/silence.py https://github.com/jiaaro/pydub/blob/master/pydub/silence.py
""" """
@ -176,7 +199,7 @@ class Window(QMainWindow, Ui_MainWindow):
# import ipdb; ipdb.set_trace() # import ipdb; ipdb.set_trace()
def selectDatabase(self): def selectDatabase(self):
dlg = DbDialog() dlg = DbDialog(self)
dlg.exec() dlg.exec()
def selectFile(self): def selectFile(self):
@ -204,14 +227,27 @@ class Window(QMainWindow, Ui_MainWindow):
item = QTableWidgetItem(track.path) item = QTableWidgetItem(track.path)
pl.setItem(row, 6, item) pl.setItem(row, 6, item)
class DbDialog(QDialog): class DbDialog(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
self.ui = Ui_Dialog() self.ui = Ui_Dialog()
self.ui.setupUi(self) self.ui.setupUi(self)
import ipdb; ipdb.set_trace() self.ui.lineEdit.textEdited.connect(self.chars_typed)
# import ipdb; ipdb.set_trace()
# self.lineEdit.clicked.connect(self.selectFile) # self.lineEdit.clicked.connect(self.selectFile)
def chars_typed(self, s):
print(f"chars_typed({s})")
if len(s) >= 3:
# matches = Tracks.search_titles(s)
matches = session.query(Tracks).filter(
Tracks.title.ilike(f"%{s}%")).all()
if matches:
# import ipdb; ipdb.set_trace()
songs = [t.title for t in matches]
self.ui.listWidget.clear()
self.ui.listWidget.addItems(songs)

View File

@ -2,39 +2,41 @@
# Form implementation generated from reading ui file 'ui/dlg_SearchDatabase.ui' # Form implementation generated from reading ui file 'ui/dlg_SearchDatabase.ui'
# #
# Created by: PyQt5 UI code generator 5.11.3 # Created by: PyQt5 UI code generator 5.15.2
# #
# WARNING! All changes made in this file will be lost! # WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object): class Ui_Dialog(object):
def setupUi(self, Dialog): def setupUi(self, Dialog):
Dialog.setObjectName("Dialog") Dialog.setObjectName("Dialog")
Dialog.resize(383, 272) Dialog.resize(383, 272)
self.widget = QtWidgets.QWidget(Dialog) self.gridLayout_2 = QtWidgets.QGridLayout(Dialog)
self.widget.setGeometry(QtCore.QRect(10, 20, 361, 242)) self.gridLayout_2.setObjectName("gridLayout_2")
self.widget.setObjectName("widget") self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setObjectName("verticalLayout")
self.gridLayout = QtWidgets.QGridLayout() self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout") self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(self.widget) self.label = QtWidgets.QLabel(Dialog)
self.label.setObjectName("label") self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(self.widget) self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setObjectName("lineEdit") self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
self.verticalLayout.addLayout(self.gridLayout) self.verticalLayout.addLayout(self.gridLayout)
self.listWidget = QtWidgets.QListWidget(self.widget) self.listWidget = QtWidgets.QListWidget(Dialog)
self.listWidget.setObjectName("listWidget") self.listWidget.setObjectName("listWidget")
self.verticalLayout.addWidget(self.listWidget) self.verticalLayout.addWidget(self.listWidget)
self.buttonBox = QtWidgets.QDialogButtonBox(self.widget) self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox") self.buttonBox.setObjectName("buttonBox")
self.verticalLayout.addWidget(self.buttonBox) self.verticalLayout.addWidget(self.buttonBox)
self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.retranslateUi(Dialog) self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept) self.buttonBox.accepted.connect(Dialog.accept)
@ -45,4 +47,3 @@ class Ui_Dialog(object):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog")) Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "Title:")) self.label.setText(_translate("Dialog", "Title:"))

View File

@ -57,6 +57,15 @@ class Tracks(Base):
return track return track
@staticmethod
def search_titles(text):
return Tracks.query.filter(
Tracks.title.ilike(text)
).all()
def main(): def main():
"Main loop" "Main loop"

View File

@ -13,15 +13,8 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<widget class="QWidget" name=""> <layout class="QGridLayout" name="gridLayout_2">
<property name="geometry"> <item row="0" column="0">
<rect>
<x>10</x>
<y>20</y>
<width>361</width>
<height>242</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@ -51,7 +44,8 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </item>
</layout>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>