def main(): app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(True) db_path = "./yue.db" sqlstore = SQLStore(db_path) Library.init(sqlstore) PlaylistManager.init(sqlstore) #playlist = Library.instance().search("(.abm 0 limited execution)") #uids = [s[Song.uid] for s in playlist] uids = list(PlaylistManager.instance().openPlaylist("Nexus5x").iter()) dp = None # [("limited","limited"),] pdialog = SyncProfileDialog() if pdialog.exec_(): s = pdialog.export_settings() #s['no_exec'] = True sdialog = SyncDialog(uids, s, dp) sdialog.start() sdialog.show() sys.exit(app.exec_())
def test_library_findpath(self): if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) lib.insert(artist="artist1", album='album1', title='title1', path='C:\\path\\to\\file.mp3') lib.insert(artist="artist2", album='album2', title='title2', path='C:/path/to/file.mp3') lib.insert(artist="artist3", album='album3', title='title3', path='C:/file.mp3') # return the one file which is at the root directory res = list(lib.searchDirectory("C:\\", False)) self.assertEqual(len(res), 1) # show that the search result is a song dictionary self.assertEqual(res[0]['artist'], 'artist3') # return all songs, regardless of directory or toothpicks res = list(lib.searchDirectory("C:\\", True)) self.assertEqual(len(res), 3) # find a file that matches exactly res = list(lib.searchPath("C:\\file.mp3")) self.assertEqual(len(res), 1) pl = PlaylistManager(sqlstore).openPlaylist("current") pl.set([1, 2]) result = list(lib.searchPlaylist('current')) self.assertEqual(len(result), 2) result = list( lib.searchPlaylist('current', "art = art", invert=False, orderby="artist", reverse=True, limit=1)) self.assertEqual(result[0]['artist'], 'artist2') result = list(lib.searchPlaylist('current', invert=True)) self.assertEqual(result[0]['artist'], 'artist3') result = list(lib.searchPlaylist('current', "art = art", invert=True)) self.assertEqual(result[0]['artist'], 'artist3')
def onNewPlaylist(self): name = PlaylistTabView.defaultName count = 1 while name in self.playlist_names: name = PlaylistTabView.defaultName + " (%d)" % count count += 1 # create, but then open through normal means print(name) PlaylistManager.instance().openPlaylist(name) self.onOpenPlaylist(name) self.refresh()
def test_playlist_shuffle(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) lib = Library(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([1, 2, 3, 4, 5]) pl.shuffle_range(1, 3) # these two values should be the same every time. key = pl.get(0) self.assertEqual(1, key) key = pl.get(4) self.assertEqual(5, key)
def test_playlist_insert_end(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([1, 2, 3, 4, 5]) size = pl.size() value = 10 pl.insert(size, value) self.assertEqual(pl.size(), size + 1) new_value = pl.get(size) self.assertEqual(new_value, value)
def main(): app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(True) db_path = "./yue.db" sqlstore = SQLStore(db_path) Library.init(sqlstore) PlaylistManager.init(sqlstore) window = OpenPlaylistDialog() window.show() sys.exit(app.exec_())
def test_playlist_reinsert_simple(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([1, 2, 3, 4, 5]) pl.reinsert(3, 1) expected = [1, 4, 2, 3, 5] for i, v in enumerate(expected): actual = pl.get(i) self.assertEqual(actual, v, "%d %d" % (v, actual)) idx, key = pl.current() self.assertEqual(idx, 0) self.assertEqual(key, 1) # move current into the middle pl.reinsert(0, 2) expected = [4, 2, 1, 3, 5] for i, v in enumerate(expected): actual = pl.get(i) self.assertEqual(actual, v, "%d %d" % (v, actual)) idx, key = pl.current() self.assertEqual(idx, 2) self.assertEqual(key, 1) # move one below current above pl.reinsert(4, 0) expected = [5, 4, 2, 1, 3] actual = [] for i in range(len(expected)): actual.append(pl.get(i)) self.assertEqual(actual, expected, "%s %s" % (expected, actual)) idx, key = pl.current() self.assertEqual(idx, 3) self.assertEqual(key, 1) # move one above current below pl.reinsert(0, 4) expected = [4, 2, 1, 3, 5] actual = [] for i in range(len(expected)): actual.append(pl.get(i)) self.assertEqual(actual, expected, "%s %s" % (expected, actual)) idx, key = pl.current() self.assertEqual(idx, 2) self.assertEqual(key, 1)
def __init__(self, text='', title='Open Playlist', prompt='', parent=None): super(OpenPlaylistDialog, self).__init__(parent) self.setWindowTitle(title) self.resize(320, 240) hbox = QHBoxLayout() vbox = QVBoxLayout(self) self.table = SelectTable(self) self.btna = QPushButton("Accept") self.btnc = QPushButton("Cancel") hbox.addWidget(self.btnc) hbox.addWidget(self.btna) if len(prompt) > 0: vbox.addWidget(QLabel(prompt)) vbox.addWidget(self.table.container) vbox.addLayout(hbox) # cant edit the current playlist because reasons data = [[ x, ] for x in sorted(PlaylistManager.instance().names()) if x != "current"] self.table.setData(data) self.btna.clicked.connect(self.accept) self.btnc.clicked.connect(self.reject) self.selected_name = None
def test_playlist_append(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([]) self.assertEqual(pl.size(), 0) pl.append(10) self.assertEqual(pl.size(), 1) self.assertEqual(pl.get(0), 10) pl.append(20) self.assertEqual(pl.size(), 2) self.assertEqual(pl.get(1), 20)
def __init__(self, device, root): super(PlaybackController, self).__init__() self.root = root self.device = device device.on_load.connect(self.on_song_load) device.on_song_tick.connect(self.on_song_tick) device.on_state_changed.connect(self.on_state_changed) device.on_song_end.connect(self.on_song_end) device.on_playlist_end.connect(self.on_playlist_end) self.stop_index = -1 self.thread = PlaybackThread(device) self.thread.start() self.one_shot = False self.playlist = PlaylistManager.instance().openCurrent() if self.dspSupported(): s = Settings.instance() if s["volume_equalizer"]: self.device.setEQEnabled(True) self.last_tick = 0
def setData(self, name, pl, data, dirty): self.playlist_name = name self.playlist = PlaylistManager.instance().openPlaylist(name) self.playlist_data = data self.dirty = dirty self.refresh()
def test_playlist_insert_begin(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([1, 2, 3, 4, 5]) first = pl.get(0) size = pl.size() value = 10 pl.insert(0, value) self.assertEqual(pl.size(), size + 1) new_first = pl.get(0) self.assertEqual(new_first, value) new_second = pl.get(1) self.assertEqual(new_second, first)
def post_init(self): # create a new empty playlist self.active_list = PlaylistTabView.defaultName pl = PlaylistManager.instance().openPlaylist(self.active_list) data = set() self.open_playlists[self.active_list] = PlModel( self.active_list, pl, data) self.viewEdit.setData(self.active_list, pl, data, False) self.refresh()
def refresh(self): blacklist = ("current", ) self.playlist_names = [ x for x in sorted(PlaylistManager.instance().names()) if x not in blacklist ] self.tableList.setData([[ x, ] for x in self.playlist_names])
def test_playlist_create(self): # removing / creating db is slow # therefore it is only done for this test if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) self.assertEqual(pl.size(), 0) data = [1, 2, 3, 4, 5] pl.set(data) self.assertEqual(pl.size(), len(data))
def main(): app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(True) db_path = "./yue.db" sqlstore = SQLStore(db_path) Library.init(sqlstore) PlaylistManager.init(sqlstore) table = LibraryTree() table.refreshData() table.container.resize(640, 320) table.container.show() #table.checkable= True #table.setStyleSheet('font-size: 12pt;') sys.exit(app.exec_())
def onRenamePlaylist(self, old_name, new_name): print("boo") PlaylistManager.instance().renamePlaylist(old_name, new_name) self.refresh() if old_name not in self.open_playlists: return print("boo") # update the internal data model mdl = self.open_playlists[old_name] del self.open_playlists[old_name] self.open_playlists[new_name] = mdl if self.active_list == old_name: n, p, d, r = self.viewEdit.getData() self.viewEdit.setData(new_name, p, d, r)
def load(self): dialog = OpenPlaylistDialog(self) if dialog.exec_(): self.playlist_name = dialog.text() self.playlist = PlaylistManager.instance().openPlaylist( self.playlist_name) self.playlist_data = set(self.playlist.iter()) self.on_rename.emit(self, self.playlist_name) self.refresh() return QMessageBox.Save return QMessageBox.Cancel
def main(): db_path = "./libimport.db" sqlstore = SQLStore(db_path) Library.init(sqlstore) PlaylistManager.init(sqlstore) pl = PlaylistManager.instance().openPlaylist("current") device = BassSoundDevice(pl, "./lib/win32/x86_64", True) songs = Library.instance().search(None, orderby=Song.random, limit=5) lst = [s['uid'] for s in songs] pl.set(lst) print("supports float", BassPlayer.supportsFloat()) device.setVolume(.25) device.play_index(0) YueRepl(device=device).repl()
def test_playlist_delete(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([1, 2, 3, 4, 5]) # delete first pl.delete(0) self.assertEqual(pl.get(0), 2) # delete last pl.delete(pl.size() - 1) self.assertEqual(pl.get(pl.size() - 1), 4) # delete middle pl.delete(pl.size() // 2) self.assertEqual(pl.size(), 2) self.assertEqual(pl.get(0), 2) self.assertEqual(pl.get(1), 4)
def main(): ffmpeg = r"C:\ffmpeg\bin\ffmpeg.exe" db_path = "yue.db" #target = "ftp://*****:*****@192.168.0.9:2121/Music" target = "test" transcode = SyncManager.T_NON_MP3 equalize = True bitrate = 320 run = True no_exec = False format = SyncManager.P_M3U target_prefix = os.getcwd() sqlstore = SQLStore(db_path) Library.init(sqlstore) PlaylistManager.init(sqlstore) library = Library.instance() playlist = library.search("(.abm 0 limited execution)") uids = [s[Song.uid] for s in playlist] print(os.path.realpath(db_path)) print("lib", len(library)) dp = [ ("limited", "limited"), ] sm = SyncManager(library, uids, target, ffmpeg, transcode=transcode, equalize=equalize, dynamic_playlists=dp, target_prefix=target_prefix, playlist_format=format, no_exec=no_exec) sm.run()
def test_playlist_next_prev(self): sqlstore = SQLStore(DB_PATH) pm = PlaylistManager(sqlstore) pl = pm.openPlaylist(PL_NAME) pl.set([1, 2, 3, 4, 5]) idx, key = pl.current() self.assertEqual(idx, 0) self.assertEqual(key, 1) idx, key = pl.next() self.assertEqual(idx, 1) self.assertEqual(key, 2) idx, key = pl.prev() self.assertEqual(idx, 0) self.assertEqual(key, 1) with self.assertRaises(StopIteration): pl.prev() pl.set_index(4) with self.assertRaises(StopIteration): pl.next()
def save(self): dialog = RenameDialog(self.playlist_name, "Save As") if dialog.exec_(): name = dialog.text().strip() if name: self.playlist_name = dialog.text() self.playlist = PlaylistManager.instance().openPlaylist( self.playlist_name) self.playlist.set(list(self.playlist_data)) self.on_rename.emit(self, self.playlist_name) if self.dirty: self.dirtyChanged.emit(False) self.dirty = False return QMessageBox.Save return QMessageBox.Cancel
def onOpenPlaylist(self, name): n, _, d, r = self.viewEdit.getData() if n in self.open_playlists: print("saving data for " + n, len(d)) self.open_playlists[n].data = d self.open_playlists[n].dirty = r if name not in self.open_playlists: print("open data for " + name) pl = PlaylistManager.instance().openPlaylist(name) data = set(pl.iter()) model = PlModel(name, pl, data) self.open_playlists[name] = model else: model = self.open_playlists[name] print("restore data for " + name, len(model.data)) self.viewEdit.setData(name, model.playlist, model.data, model.dirty) self.active_list = name
def onDeletePlaylist(self, name): PlaylistManager.instance().deletePlaylist(name) self.refresh()
def save_yue(self, name, query): songs = self.library.search(query, orderby=[Song.artist, Song.album]) uids = [song[Song.uid] for song in songs] pm = PlaylistManager(self.library.sqlstore) pl = pm.openPlaylist(name) pl.set(uids)
def __init__(self, playlist_name=None, parent=None): super(PlaylistEditView, self).__init__(parent) self.dirty = False self.vbox = QVBoxLayout(self) self.vbox.setContentsMargins(0, 0, 0, 0) self.hbox1 = QHBoxLayout() self.hbox1.setContentsMargins(0, 0, 0, 0) self.hbox2 = QHBoxLayout() self.hbox2.setContentsMargins(0, 0, 0, 0) self.hbox3 = QHBoxLayout() self.lbll = QLabel("Library") self.lbll.setAlignment(Qt.AlignHCenter) self.lblp = QLabel("Playlist") self.lblp.setAlignment(Qt.AlignHCenter) self.hbox3.addWidget(self.lbll) self.hbox3.addWidget(self.lblp) self.hbox3.setContentsMargins(0, 0, 0, 0) self.toolbar = QToolBar(self) self.toolbar.addAction(QIcon(':/img/app_save.png'), "save", self.save) #self.toolbar.addAction(QIcon(':/img/app_open.png'),"load", self.load) #self.toolbar.addAction(QIcon(':/img/app_newlist.png'),"Play",self.create_playlist) self.toolbar.addAction(QIcon(':/img/app_export.png'), "Export", self.export_playlist) self.toolbar.addAction(QIcon(':/img/app_import.png'), "Import", self.import_playlist) self.toolbar.addAction(QIcon(':/img/app_sync.png'), "sync", self.sync) self.tbl_lib = LibraryEditTable(self) self.tbl_pl = PlayListEditTable(self) self.tbl_lib.setSibling(self.tbl_pl) self.tbl_pl.setSibling(self.tbl_lib) # needed for song sort self.tbl_lib.update_data.connect(self.onUpdate) self.tbl_pl.update_data.connect(self.onUpdate) #self.tbl_pl.update_data.connect(self.onUpdate) self.txt_search = LineEdit_Search(self, self.tbl_pl, placeholder="Search Playlist") self.txt_search.textEdited.connect(self.onTextChanged) self.lbl_error = QLabel("") self.hbox1.addWidget(self.txt_search) self.hbox2.addWidget(self.tbl_lib.container) self.hbox2.addWidget(self.tbl_pl.container) self.vbox.addWidget(self.toolbar) self.vbox.addLayout(self.hbox1) self.vbox.addWidget(self.lbl_error) self.vbox.addLayout(self.hbox3) self.vbox.addLayout(self.hbox2) self.lbl_error.hide() if playlist_name is not None: self.playlist_name = playlist_name self.playlist = PlaylistManager.instance().openPlaylist( self.playlist_name) self.playlist_data = set(self.playlist.iter()) self.refresh() else: self.playlist_name = None self.playlist = None self.playlist_data = set()