def request_list_data(self, command): self.debug('request_list_data', command) if command == 'start_list': db_data = self.db_helper.get_list_data(True) list_data = [ [CatMovie(item), CatFile(item)] if item is not None else None for item in db_data ] self.signal_fill_items_to_list.emit(list_data) if command == 'add_list': db_data = self.db_helper.get_list_data() list_data = [ [CatMovie(item), CatFile(item)] if item is not None else None for item in db_data ] self.signal_add_items_to_list.emit(list_data) if command == 'start_files_tree': db_data = self.db_helper.get_files_tree_data() tree_data = {} for key in db_data: tree_data[key] = [[CatMovie(item), CatFile(item)] for item in db_data[key]] self.signal_add_items_to_files_tree.emit(tree_data)
def add_files(self): for i in range(self.listWidget.count()): lw_item = self.listWidget.item(i) if not lw_item.checkState(): continue lw_item.setIcon(QApplication.style().standardIcon( QStyle.SP_MediaPlay)) lw_item.setFlags(lw_item.flags() & Qt.ItemIsSelectable) file_name = lw_item.data(Qt.UserRole) self.current_item = i self.file = CatFile() self.signal_parse_file.emit(file_name) break
def __init__(self, fname): self.fname = fname self.frames = [] probe = ffmpeg.probe(fname) video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) audio_streams = (stream for stream in probe['streams'] if stream['codec_type'] == 'audio') sub_streams = (stream for stream in probe['streams'] if stream['codec_type'] == 'subtitle') self.file = CatFile() self.file.name = fname.split('/')[-1] self.file.path = '/'.join(fname.split('/')[:-1]) + '/' self.file.size = probe['format']['size'] self.file.resolution = str(video_stream['width']) + 'x' + str( video_stream['height']) self.file.codec = video_stream['codec_name'] self.file.bitrate = probe['format']['bit_rate'] self.file.length = float(probe['format']['duration']) self.file.audio = ",".join([ x['tags']['language'] if 'tags' in x and 'language' in x['tags'] else 'unknown' for x in audio_streams ]) self.file.subtitles = ",".join([ x['tags']['language'] if 'tags' in x and 'language' in x['tags'] else 'unknown' for x in sub_streams ]) self.frame_count = math.floor(self.file.length * eval(video_stream['avg_frame_rate']))
def prepare(self, movie: CatMovie = None, file: CatFile = None): self.set_loading('frames', False) self.set_loading('poster', False) self.progressBar.setValue(0) self.lineEdit_movie_name.reset() if movie is None: self.movie = CatMovie() self.movie.fill_widget(self) else: self.movie = CatMovie().set_data(movie) self.movie.id = movie.id self.movie.fill_widget(self) self.lineEdit_movie_name.signal_search_movie.emit(self.movie.name) if file is None: self.file = CatFile() self.file.fill_widget(self) else: self.file = CatFile().set_data(file) self.file.id = file.id self.file.fill_widget(self)
def update_db(self, movie: CatMovie, file: CatFile): id, error = self.db_helper.update_movie(movie) if error is not None: self.signal_update_db_result.emit(error) return if file.movie_id == -1: file.movie_id = id error = self.db_helper.update_file(file) if error is not None: self.signal_update_db_result.emit(error) return self.request_list_data('start_list') self.signal_update_db_result.emit(None)
class FilesFoundDialog(QDialog, data.design_dialog_found_files.Ui_Dialog): signal_parse_file = pyqtSignal(str) signal_send_breaker = pyqtSignal(str) signal_db_updater = pyqtSignal(CatMovie, CatFile) signal_send_breaker = pyqtSignal(str) def __init__(self, parent=None): super(FilesFoundDialog, self).__init__(parent) self.setupUi(self) self.current_item = None self.file = None self.progressBar.setMaximum(20 - 1) self.pushButton_add.clicked.connect(self.add_files) def prepare(self): self.progressBar.setValue(0) self.listWidget.clear() def closeEvent(self, event): self.current_item = None self.file = None self.signal_send_breaker.emit('filesfound_dialog') @pyqtSlot(str) def add_file_to_list(self, data): print(data) myQListWidgetItem = QListWidgetItem(data.split('/')[-1]) # myQListWidgetItem.setSizeHint(cwidget.sizeHint()) myQListWidgetItem.setData(Qt.UserRole, data) myQListWidgetItem.setFlags(myQListWidgetItem.flags() | Qt.ItemIsUserCheckable) myQListWidgetItem.setCheckState(Qt.Checked) self.listWidget.addItem(myQListWidgetItem) @pyqtSlot() def add_files(self): for i in range(self.listWidget.count()): lw_item = self.listWidget.item(i) if not lw_item.checkState(): continue lw_item.setIcon(QApplication.style().standardIcon( QStyle.SP_MediaPlay)) lw_item.setFlags(lw_item.flags() & Qt.ItemIsSelectable) file_name = lw_item.data(Qt.UserRole) self.current_item = i self.file = CatFile() self.signal_parse_file.emit(file_name) break @pyqtSlot(CatFile) def receive_parsed_file(self, file: CatFile): if self.file is not None: self.file.set_data(file) @pyqtSlot(list) def receive_parsed_frames(self, frames): if self.file is not None: self.file.frames = frames self.listWidget.takeItem(self.current_item) movie = CatMovie() movie.name = self.file.name self.signal_db_updater.emit(movie, self.file) self.add_files()
class EditDialog(QDialog, data.design_dialog_edit.Ui_Dialog): movie: CatMovie = None file: CatFile = None signal_db_updater = pyqtSignal(CatMovie, CatFile) signal_parse_video = pyqtSignal(str) signal_send_breaker = pyqtSignal(str) DEBUG = False def __init__(self, parent=None): super(EditDialog, self).__init__(parent) self.setupUi(self) self.pushButton_save.clicked.connect(self.on_click_save) self.pushButton_open.clicked.connect(self.on_click_openfile) self.horizontalSlider.valueChanged.connect(self.slider_changed) self.loading = False self.loader_movie: QMovie = QMovie('data/loader.gif') self.label_loading.setMovie(self.loader_movie) def closeEvent(self, event): self.movie = None self.file = None self.signal_send_breaker.emit('edit_dialog') @pyqtSlot() def on_click_save(self): self.movie.load_from_widget(self) self.file.load_from_widget(self) self.signal_db_updater.emit(self.movie, self.file) @pyqtSlot() def on_click_openfile(self): fname, _filter = QFileDialog.getOpenFileName( self, 'Open file', filter='Video (*.mkv *.avi *.mp4 *.webm)') if fname: self.set_loading('frames', True) self.progressBar.setMaximum(20 - 1) self.signal_parse_video.emit(fname) @pyqtSlot() def slider_changed(self): self.file.show_frame(self.label_frames, self.sender().value()) @pyqtSlot(str) def update_db_result(self, error): if error != "": QMessageBox.warning(self, "Warning", error) else: self.accept() @pyqtSlot(CatFile) def receive_file(self, file: CatFile): if self.file is not None: self.file.set_data(file) self.file.fill_widget(self) @pyqtSlot(list) def receive_frames(self, frames): if self.file is not None: self.file.frames = frames self.horizontalSlider.setMaximum(len(self.file.frames) - 1) self.file.show_frame(self.label_frames, 0) self.set_loading('frames', False) @pyqtSlot(bytes) def update_poster(self, image): if not image: image = None if not self.movie is None: self.movie.poster = image self.movie.show_poster(self.label_poster) @pyqtSlot(list) def receive_movie(self, data): if self.DEBUG: print('receive_movie', data) self.movie.set_data(CatMovie(data)) self.movie.fill_widget(self) def prepare(self, movie: CatMovie = None, file: CatFile = None): self.set_loading('frames', False) self.set_loading('poster', False) self.progressBar.setValue(0) self.lineEdit_movie_name.reset() if movie is None: self.movie = CatMovie() self.movie.fill_widget(self) else: self.movie = CatMovie().set_data(movie) self.movie.id = movie.id self.movie.fill_widget(self) self.lineEdit_movie_name.signal_search_movie.emit(self.movie.name) if file is None: self.file = CatFile() self.file.fill_widget(self) else: self.file = CatFile().set_data(file) self.file.id = file.id self.file.fill_widget(self) @pyqtSlot(str, bool) def set_loading(self, type, loading): if self.DEBUG: print('set_loading', type, loading) if type == 'frames': self.loading = loading if loading: self.label_loading.setMovie(self.loader_movie) self.loader_movie.start() self.pushButton_save.setEnabled(False) else: self.label_loading.clear() self.loader_movie.stop() self.pushButton_save.setEnabled(True) if type == 'movie': if loading: self.label_loading.setMovie(self.loader_movie) self.loader_movie.start() self.pushButton_save.setEnabled(False) else: self.label_loading.clear() self.loader_movie.stop() self.pushButton_save.setEnabled(True) if type == 'poster': if loading: self.label_poster.setMovie(self.loader_movie) self.loader_movie.start() else: self.label_poster.clear() self.loader_movie.stop()