def test_scan_videopath_recursive_relative_current(self): with ChangeDirectoryScope(Path(__file__).resolve().parent): videos, subtitles = scan_videopath(Path('.'), ProgressCallback(), recursive=True) self.assertTrue(len(videos) > 0) video = next(video for video in videos if video.get_filepath().resolve() == RESOURCE_AVI)
def test_scan_videopath_recursive_relative_parent(self): with ChangeDirectoryScope((RESOURCE_PATH / 'child')): videos, subtitles = scan_videopath(Path('..'), ProgressCallback(), recursive=True) self.assertTrue(len(videos) > 0) print(videos) print(videos[0].get_filepath().resolve()) video = next(video for video in videos if video.get_filepath().resolve() == RESOURCE_AVI)
def on_browse_folder(self): # FIXME: refactor/generalize calls to mainwindow/workingDirectory settings = QSettings() path = settings.value('mainwindow/workingDirectory', '') directory = QFileDialog.getExistingDirectory(self, _('Select a directory'), path) if not directory: return settings.setValue('mainwindow/workingDirectory', directory) callback = ProgressCallbackWidget(self) callback.show() log.debug('on_browse_folder({folder})'.format(folder=directory)) videos, subs = scan_videopath(Path(directory), callback=callback, recursive=False) log.debug('#videos: {nb_vids}, #subtitles: {nb_subs}'.format( nb_vids=len(videos), nb_subs=len(subs))) self._uploadModel.set_videos(videos) self.upload_data_changed.emit()
def on_edit_item(self, index): row, col = index.row(), index.column() settings = QSettings() working_directory = settings.value('mainwindow/workingDirectory', '') if col == UploadDataItem.COL_VIDEO: dialog_title = _("Browse video...") extensions = get_select_videos() else: # if col == UploadDataItem.COL_SUB: dialog_title = _("Browse subtitle...") extensions = get_select_subtitles() file_path, t = QFileDialog.getOpenFileName(self, dialog_title, working_directory, extensions) if not file_path: return file_path = Path(file_path) settings.setValue('mainwindow/workingDirectory', str(file_path.parent)) model = self._uploadModel if col == UploadDataItem.COL_VIDEO: callback = ProgressCallbackWidget(self) callback.show() videos, subs = scan_videopath(file_path, callback=callback, recursive=False) video = videos[0] index = model.createIndex(row, UploadDataItem.COL_VIDEO) model.setData(index, video, Qt.UserRole) elif col == UploadDataItem.COL_SUB: subtitle = LocalSubtitleFile(file_path) index = model.createIndex(row, UploadDataItem.COL_SUB) model.setData(index, subtitle, Qt.UserRole) else: log.warning( 'on_edit_item: nknown column: {column}'.format(column=col)) self.upload_data_changed.emit()
def test_scan_videopath_recursive(self): videos, subtitles = scan_videopath(Path(__file__).resolve().parent, ProgressCallback(), recursive=True) video = next(video for video in videos if video.get_filepath().resolve() == RESOURCE_AVI)
def test_scan_videopath(self): videos, subtitles = scan_videopath(RESOURCE_PATH, ProgressCallback(), recursive=False) video = next(video for video in videos if video.get_filepath().resolve() == RESOURCE_AVI)
def test_scan_videopath_no_vid(self): videos, subtitles = scan_videopath(Path(__file__).resolve().parent, ProgressCallback(), recursive=False) self.assertTrue(len(videos) == 0)