def test_get_all_fingerprint(self): self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) hash_input = database.get_all_fingerprint() self.assertEqual(len(hash_input), 3) self.assertEqual(hash_input[0].size, 6000)
def test_hashing_and_query(self): # test hash_query if we do not remove the duplicates self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) hash_input = database.get_all_fingerprint() query_table = database.hashing(hash_input) info, min_distance = database.query_hash_nearest( 'MUSIC_test/test_12s.wav', query_table) self.assertEqual(info[0], 1) self.assertEqual(info[1], 'MUSIC_test/test_12s.wav') self.assertTrue(min_distance < 0.0001) # small error due to hashing
def test_insert_new_song(self): self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) self.assertTrue(database.insert_new_songs('MUSIC_test/test_12s.wav')) con = psycopg2.connect(database="music", user="******", password="******", host="localhost") cur = con.cursor() cur.execute("SELECT id from songs") i = cur.fetchall() self.assertEqual(len(i), 3) con.close()
def test_insert_new_info(self): info_list = ["abc"] col_name = "singer" self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) database.insert_new_info(info_list, col_name) con = psycopg2.connect(database="music", user="******", password="******", host="localhost") cur = con.cursor() cur.execute("SELECT singer from idx_table") i = cur.fetchall() self.assertEqual([('abc', )], i)
def test_build_table(self): self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) con = psycopg2.connect(database="music", user="******", password="******", host="localhost") cur = con.cursor() cur.execute("SELECT id, song_name from idx_table") i = cur.fetchone() self.assertEqual(i[0], 1) self.assertEqual(i[1], 'MUSIC_test/test_12s.wav') cur.execute("SELECT * from songs") i = cur.fetchone() self.assertEqual(i[0], 1) # line_id self.assertEqual(i[1], 1) # song_index self.assertEqual(len(i[2]), 6000) # first window's fingerprint con.close()
def test_detect_duplicate(self): self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) self.assertTrue(database.detect_duplicates('MUSIC_test/test_12s.wav'))
def test_query_song_info(self): self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) rtn = database.query_song_info(1) self.assertEqual(rtn[0], 1) self.assertEqual(rtn[1], 'MUSIC_test/test_12s.wav')
def test_query_song(self): self.assertTrue(database.init_db()) self.assertTrue(database.build_tables("MUSIC_test/")) rtn = database.query_song(1) self.assertEqual(rtn[0], 1) # song_index self.assertEqual(len(rtn[1]), 6000) # first window's fingerprint
def __init__(self, ui_file, parent=None): super(MainWindow, self).__init__(parent) ui_file = qtc.QFile(ui_file) ui_file.open(qtc.QFile.ReadOnly) loader = qtu.QUiLoader() self.window = loader.load(ui_file) ui_file.close() logger.info("Inteface loaded") self.window.closeEvent = self.closeEvent try: status = sync.get_file("podcasts.db") logger.info(f"Sync status: {status}") except Exception as e: logger.error(f"Unable to sync database: {e}") # build tables if needed db.build_tables() # create audio player self.player = qtm.QMediaPlayer() self.player.setNotifyInterval(1000) self.player.positionChanged.connect(self.update_time) self.player.stateChanged.connect(self.update_play_history) self.player.setVolume(50) # currently loaded media info self.podcast: str = None self.episode_date: str = None self.episode_title: str = None self.episode_url: str = None # set keyboard commands self.key_commands = { qtc.Qt.Key_Space: self.pause, qtc.Qt.Key_S: self.stop, qtc.Qt.Key_Left: self.skip_back, qtc.Qt.Key_Right: self.skip_forward, qtc.Qt.Key_VolumeMute: self.toggle_mute, } # LOAD Interface Items # Load Buttons and create connections self.btn_add_feed = self.window.findChild(qtw.QPushButton, "btn_add_feed") self.btn_add_feed.clicked.connect(self.add_new_feed) self.btn_delete_feed = self.window.findChild(qtw.QPushButton, "btn_delete_feed") self.btn_delete_feed.clicked.connect(self.delete_feed) self.btn_play = self.window.findChild(qtw.QPushButton, "btn_play") self.btn_play.clicked.connect(self.play) self.btn_stop = self.window.findChild(qtw.QPushButton, "btn_stop") self.btn_stop.clicked.connect(self.stop) self.btn_forward = self.window.findChild(qtw.QPushButton, "btn_forward") self.btn_forward.clicked.connect(self.skip_forward) self.btn_back = self.window.findChild(qtw.QPushButton, "btn_back") self.btn_back.clicked.connect(self.skip_back) self.btn_pause = self.window.findChild(qtw.QPushButton, "btn_pause") self.btn_pause.clicked.connect(self.pause) self.btn_mute = self.window.findChild(qtw.QPushButton, "btn_mute") self.btn_mute.clicked.connect(self.toggle_mute) self.btn_settings = self.window.findChild(qtw.QPushButton, "btn_settings") self.btn_settings.clicked.connect(self.open_settings) # Labels self.lbl_title = self.window.findChild(qtw.QLabel, "lbl_title") self.lbl_time = self.window.findChild(qtw.QLabel, "lbl_time") # ListWidgets self.lw_episode_list = self.window.findChild(qtw.QListWidget, "lw_episode_list") self.lw_feed_list = self.window.findChild(qtw.QListWidget, "lw_feed_list") self.lw_feed_list.itemSelectionChanged.connect(self.load_episode_list) self.lw_episode_list.itemSelectionChanged.connect(self.load_media) self.lw_episode_list.itemDoubleClicked.connect(self.play) # Misc interface items self.sldr_volume = self.window.findChild(qtw.QSlider, "sldr_volume") self.sldr_volume.setMinimum(-10) self.sldr_volume.setMaximum(110) self.sldr_volume.setValue(50) self.sldr_volume.sliderMoved.connect(self.change_volume) self.sldr_playtime = self.window.findChild(qtw.QSlider, "sldr_playtime") self.sldr_playtime.sliderMoved.connect(self.change_time) # Load data into interface self.load_feed_list() self.grabKeyboard() self.window.show() # Update feeds in separate thread self.update_feeds() # uncomment to allow functionality
def init_database(path): database.init_db() database.build_tables(path) return True