def addAlbum(self, dir_path: str): songs = [] for file_path in files_in_directory(dir_path): info = QFileInfo(file_path) if not info.isReadable(): logging.warning("File {} is not readable".format(file_path)) continue if info.isDir(): self.addAlbum(file_path) elif file_is_audio(file_path): item = self._create_song_item(file_path) item.setText(info.fileName()) songs.append(item) if len(songs) > 0: album_item = self._create_album_item(dir_path, songs) album_item.setText(dir_path) self.addTopLevelItem(album_item)
def write_bookmarks(self): if not self._modified: return dir_path = _config_dir() native_dir_path = QDir.toNativeSeparators(dir_path) dir = QFileInfo(dir_path) if not dir.isDir(): print('Creating {}...'.format(native_dir_path)) if not QDir(dir.absolutePath()).mkpath(dir.fileName()): warnings.warn('Cannot create {}.'.format(native_dir_path), RuntimeWarning) return serialized_model = _serialize_model(self._model, dir_path) bookmark_file_name = os.path.join(native_dir_path, _bookmark_file) print('Writing {}...'.format(bookmark_file_name)) with open(bookmark_file_name, 'w') as bookmark_file: jsons.dump(serialized_model, bookmark_file, indent=4)
def dropEvent(self, event: QDropEvent): if event.source(): super().dropEvent(event) else: for url in event.mimeData().urls(): info = QFileInfo(url.toLocalFile()) if not info.isReadable(): logging.warning("File {} is not readable".format( info.filePath())) continue if info.isDir(): if get_setting("dragAndDropBehavior" ) == SETTINGS_VALUES.DragAndDrop.ALBUM_MODE: self.addAlbum(url.toLocalFile()) else: for file_path in files_in_directory_and_subdirectories( info.filePath()): self.addSong(file_path) else: self.addSong(info.filePath())