def do_filescan(self, arg): callback = self.get_callback() callback.set_title_text(_("Scanning...")) callback.set_label_text(_("Scanning files")) callback.set_finished_text(_("Scanning finished")) callback.set_block(True) callback.show() try: local_videos, local_subs = scan_videopaths( self.state.get_video_paths(), callback, recursive=self.state.recursive) except IllegalPathException as e: callback.finish() self.print( _('The video path "{}" does not exist').format(e.path())) return callback.finish() self.set_videos(local_videos) self.print( _('{}/{} videos/subtitles have been found').format( len(local_videos), len(local_subs)))
def do_upload_filescan(self, arg): if arg: self.echo(_('Unknown arguments: {}').format(arg)) return self._upload_movie = LocalMovie() callback = self.get_callback() callback.set_title_text(_('Scanning...')) callback.set_label_text(_('Scanning files')) callback.set_finished_text(_('Scanning finished')) callback.set_block(True) callback.show() try: local_videos, local_subs = scan_videopaths(self.state.get_video_paths(), callback, recursive=self.state.get_recursive()) except IllegalPathException as e: callback.finish() self.echo(_('The video path "{}" does not exist').format(e.path())) return callback.finish() local_videos.sort(key=lambda v : v.get_filename()) data = [] nb_subs = 0 langs = dict() for video in local_videos: try: subtitle = next(video.get_subtitles().iter_local_subtitles()) lang = subtitle.detect_language_contents() subtitle.set_language_if_unknown(lang) langs.setdefault(subtitle.get_language(), 0) langs[subtitle.get_language()] += 1 nb_subs += 1 except StopIteration: subtitle = None vid_sub = VideoSubtitle(video, subtitle) data.append(vid_sub) self._upload_movie.set_data(data) unk = UnknownLanguage.create_generic() if unk in langs: del langs[unk] if len(langs) == 1: lang = tuple(langs.keys())[0] else: lang = unk if self._upload_movie.get_language().is_generic(): self._upload_movie.set_language(lang) self.set_videos(local_videos) self.echo(_('{}/{} videos/subtitles have been found').format(len(data), nb_subs))
def _search_videos_raw(self, paths): # FIXME: must pass mainwindow as argument to ProgressCallbackWidget callback = ProgressCallbackWidget(self) callback.set_title_text(_("Scanning...")) callback.set_label_text(_("Scanning files")) callback.set_finished_text(_("Scanning finished")) callback.set_block(True) try: local_videos, local_subs = scan_videopaths(paths, callback=callback, recursive=True) except OSError: callback.cancel() QMessageBox.warning(self, _('Error'), _('Some directories are not accessible.')) if callback.canceled(): return callback.finish() log.debug("Videos found: %s" % local_videos) log.debug("Subtitles found: %s" % local_subs) self.hideInstructions() QCoreApplication.processEvents() if not local_videos: QMessageBox.about(self, _("Scan Results"), _("No video has been found!")) return total = len(local_videos) # FIXME: must pass mainwindow as argument to ProgressCallbackWidget # callback = ProgressCallbackWidget(self) # callback.set_title_text(_("Asking Server...")) # callback.set_label_text(_("Searching subtitles...")) # callback.set_updated_text(_("Searching subtitles ( %d / %d )")) # callback.set_finished_text(_("Search finished")) callback.set_block(True) callback.set_range(0, total) callback.show() callback.set_range(0, 2) download_callback = callback.get_child_progress(0, 1) # videoSearchResults = self.get_state().get_OSDBServer().SearchSubtitles("", videos_piece) remote_subs = self.get_state().get_OSDBServer().search_videos( videos=local_videos, callback=download_callback) self.videoModel.set_videos(local_videos) # self.onFilterLanguageVideo(self.ui.filterLanguageForVideo.get_selected_language()) if remote_subs is None: QMessageBox.about( self, _("Error"), _("Error contacting the server. Please try again later")) callback.finish()
def _search_videos_raw(self, paths): # FIXME: must pass mainwindow as argument to ProgressCallbackWidget callback = ProgressCallbackWidget(self) callback.set_title_text(_('Scanning...')) callback.set_label_text(_('Scanning files')) callback.set_finished_text(_('Scanning finished')) callback.set_block(True) callback.show() try: local_videos, local_subs = scan_videopaths(paths, callback=callback, recursive=True) except OSError: callback.cancel() QMessageBox.warning(self, _('Error'), _('Some directories are not accessible.')) if callback.canceled(): return callback.finish() log.debug('Videos found: {}'.format(local_videos)) log.debug('Subtitles found: {}'.format(local_subs)) self.hideInstructions() if not local_videos: QMessageBox.information(self, _('Scan Results'), _('No video has been found.')) return total = len(local_videos) # FIXME: must pass mainwindow as argument to ProgressCallbackWidget # callback = ProgressCallbackWidget(self) # callback.set_title_text(_('Asking Server...')) # callback.set_label_text(_('Searching subtitles...')) # callback.set_updated_text(_('Searching subtitles ( %d / %d )')) # callback.set_finished_text(_('Search finished')) callback.set_block(True) callback.set_range(0, total) callback.show() try: remote_subs = self._state.search_videos(local_videos, callback) except ProviderConnectionError: log.debug( 'Unable to search for subtitles of videos: videos={}'.format( list(v.get_filename() for v in local_videos))) QMessageBox.about(self, _('Error'), _('Unable to search for subtitles')) callback.finish() return self.videoModel.set_videos(local_videos) if remote_subs is None: QMessageBox.about( self, _('Error'), _('Error contacting the server. Please try again later')) callback.finish()