def refresh_lists(self): path = fetch_options()['paths']['playlist'] self.playlist_name.clear() self.playlist_list = ["No Playlist"] self.playlist_name.addItem("No Playlist") for item in listdir(path): if isfile(join(path, item)) and item.endswith(".lst"): self.playlist_list.append(item.split('.')[0]) self.playlist_name.addItem(item.split('.')[0])
def read_playlist(name): try: playlist = open(fetch_options()['paths']['playlist'] + name + ".lst", "rb") except IOError: return None data = playlist.read().decode() playlist.close() return data
def refresh(self): # Change it so it will go to same song. if self.playlist_name.currentText() != "No Playlist": return paths = fetch_options()['paths']['music_path'].split(';') current_songs = [ self.playlistModel.data(self.playlistModel.index(row, 0)) for row in range(self.playlistModel.rowCount()) ] for path in paths: if not path: continue for item in listdir(path): if isfile(join(path, item)) and item.endswith(".mp3") and ( item not in current_songs): self.playlist.addMedia( QMediaContent(QUrl.fromLocalFile(join(path, item))))
def move_files(self): """ Moves mp3 files and thumbnails to the default music folder and the thumbnail folder. When it is done calls the done_method. :return: """ self.label.setText("Moving to music folder...") default_path = fetch_options()['paths']['music_path'].split(';')[0] + "/" for item in os.listdir('.'): if os.path.isfile(item) and item.endswith(".mp3"): try: os.rename(item, default_path + item) except Exception as exc: print(exc) if os.path.isfile(item) and item.endswith(".jpg"): try: os.rename(item, THUMBNAILS + item) except Exception as exc: print(exc) self.done_method()
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setObjectName("Music Libraries") self.setWindowTitle("Music Libraries") #self.setWindowModality(Qt.WA_WindowModified) self.libraries = QTableWidget() add_paths = QToolButton(clicked=self.add_library) add_paths.setText("Add") remove_paths = QToolButton(clicked=self.remove_library) remove_paths.setText("Remove") save_paths = QToolButton(clicked=self.done_library) save_paths.setText("Done") self.items = 0 self.libraries.setRowCount(self.items) self.libraries.setColumnCount(1) self.libraries.horizontalHeader().setStretchLastSection(True) self.libraries.horizontalHeader().hide() paths = fetch_options()['paths']['music_path'].split(';') for path in paths: if len(path) > 1: self.add_to_table(path) controls_l = QHBoxLayout() controls_l.setAlignment(Qt.AlignLeft) controls_l.addWidget(add_paths) controls_l.addWidget(remove_paths) controls_l.addWidget(save_paths) main_l = QVBoxLayout() main_l.addWidget(self.libraries) main_l.addLayout(controls_l) self.setLayout(main_l)
#!/usr/bin/env python import os import re import os.path from PyQt5.QtCore import QThread import youtube_dl from core.config import fetch_options, get_default_path, parse_command options = fetch_options() FFMPEG_BIN = options['paths']['ffmpeg_bin'] MUSIC_PATH = get_default_path() YOUTUBE_CMD = options['commands']['download'] THUMBNAILS = options['paths']['thumbnails'] class YoutubeDownloader(QThread): def __init__(self, links, label, button, progress, done_method): QThread.__init__(self) """ Initializes class variables and creates a qprocess which is connected with the appropriate slots. :param links: :param label: :param button: :param progress: :param done_method: """ self.links = links self.label = label self.button = button
def refresh_lists(self): path = fetch_options()['paths']['playlist'] self.available_playlist.setStringList([ item.split('.')[0] for item in listdir(path) if isfile(join(path, item)) and item.endswith(".lst")])
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setObjectName("Playlist Manager") self.setWindowTitle("Playlist Manager") self.libraries = QTableWidget() self.items = 0 self.libraries.setRowCount(self.items) self.libraries.setColumnCount(1) self.libraries.horizontalHeader().setStretchLastSection(True) self.libraries.horizontalHeader().hide() paths = fetch_options()['paths']['music_path'].split(';') self.music_files = {} for path in paths: for item in listdir(path): if isfile(join(path, item)) and item.endswith(".mp3"): self.music_files[item] = join(path, item) self.libraries.setRowCount(self.items+1) self.libraries.setItem(self.items, 0, QTableWidgetItem(item)) self.items += 1 self.playlist = QTableWidget() self.playlist_items = 0 self.playlist.setRowCount(self.playlist_items) self.playlist.setColumnCount(1) self.playlist.horizontalHeader().setStretchLastSection(True) self.playlist.horizontalHeader().hide() self.add_button = QToolButton(clicked=self.add_to_table) self.add_button.setText("+") self.remove_button = QToolButton(clicked=self.remove_from_table) self.remove_button.setText("-") self.up_button = QToolButton(clicked=self.move_up) self.up_button.setIcon(self.style().standardIcon(QStyle.SP_ArrowUp)) self.down_button = QToolButton(clicked=self.move_down) self.down_button.setIcon(self.style().standardIcon(QStyle.SP_ArrowDown)) self.download_label = QLabel() self.song_search = QLineEdit() self.song_search.textChanged.connect(self.search) self.song_search.setClearButtonEnabled(True) self.playlist_name = QLineEdit() completer = QCompleter() self.available_playlist = QStringListModel() completer.setModel(self.available_playlist) completer.activated.connect(self.load) self.playlist_name.setCompleter(completer) self.refresh_lists() #self.load_button = QToolButton(clicked=self.load) #self.load_button.setText("Load") self.save_button = QToolButton(clicked=self.save) self.save_button.setText("Save") # Shortcuts QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self, self.song_search.setFocus) # Layouts playlist_controls = QVBoxLayout() playlist_controls.addWidget(self.add_button) playlist_controls.addWidget(self.remove_button) playlist_controls.addWidget(self.up_button) playlist_controls.addWidget(self.down_button) playlist_layout = QHBoxLayout() playlist_layout.addWidget(self.libraries) playlist_layout.addLayout(playlist_controls) playlist_layout.addWidget(self.playlist) action_layout = QHBoxLayout() action_layout.addWidget(self.playlist_name) #action_layout.addWidget(self.load_button) action_layout.addWidget(self.save_button) manager_layout = QVBoxLayout() manager_layout.addWidget(self.song_search) manager_layout.addLayout(playlist_layout) manager_layout.addLayout(action_layout) self.setLayout(manager_layout)
def create_playlist(name, songs): playlist = open(fetch_options()['paths']['playlist'] + name + ".lst", "wb") for song in songs: song_newline = song + "\n" playlist.write(song_newline.encode()) playlist.close()