def queue_startup_check(self): new_queue = get_queue(self.app.fastflix.queue_path, self.app.fastflix.config) # self.app.fastflix.queue.append(item) reset_vids = [] remove_vids = [] for i, video in enumerate(new_queue): if video.status.running: reset_vids.append(i) if video.status.complete: remove_vids.append(video) for index in reset_vids: vid: Video = new_queue.pop(index) vid.status.clear() new_queue.insert(index, vid) for video in remove_vids: new_queue.remove(video) if new_queue: if yes_no_message( f"{t('Not all items in the queue were completed')}\n" f"{t('Would you like to keep them in the queue?')}", title="Recover Queue Items", ): with self.app.fastflix.queue_lock: for item in new_queue: self.app.fastflix.queue.append(item) # self.app.fastflix.queue = [] with self.app.fastflix.queue_lock: save_queue(self.app.fastflix.queue, self.app.fastflix.queue_path, self.app.fastflix.config) self.new_source()
def clear_complete(self): for queued_item in self.tracks: if queued_item.video.status.complete: self.remove_item(queued_item.video, part_of_clear=True) with self.app.fastflix.queue_lock: save_queue(self.app.fastflix.queue, self.app.fastflix.queue_path, self.app.fastflix.config) self.new_source()
def remove_item(self, video, part_of_clear=False): with self.app.fastflix.queue_lock: for i, vid in enumerate(self.app.fastflix.queue): if vid.uuid == video.uuid: pos = i break else: logger.error("No matching video found to remove from queue") return self.app.fastflix.queue.pop(pos) if not part_of_clear: save_queue(self.app.fastflix.queue, self.app.fastflix.queue_path, self.app.fastflix.config) if not part_of_clear: self.new_source()
def retry_video(self, current_video): with self.app.fastflix.queue_lock: for i, video in enumerate(self.app.fastflix.queue): if video.uuid == current_video.uuid: video_pos = i break else: logger.error( f"Can't find video {current_video.uuid} in queue to update its status" ) return video = self.app.fastflix.queue.pop(video_pos) video.status.cancelled = False video.status.current_command = 0 self.app.fastflix.queue.insert(video_pos, video) save_queue(self.app.fastflix.queue, self.app.fastflix.queue_path, self.app.fastflix.config) self.new_source()
def __init__(self, parent, app: FastFlixApp): self.main = parent.main self.app = app self.paused = False self.encode_paused = False self.encoding = False top_layout = QtWidgets.QHBoxLayout() top_layout.addWidget(QtWidgets.QLabel(t("Queue"))) top_layout.addStretch(1) self.clear_queue = QtWidgets.QPushButton( self.app.style().standardIcon( QtWidgets.QStyle.SP_LineEditClearButton), t("Clear Completed")) self.clear_queue.clicked.connect(self.clear_complete) self.clear_queue.setFixedWidth(120) self.clear_queue.setToolTip(t("Remove completed tasks")) self.pause_queue = QtWidgets.QPushButton( self.app.style().standardIcon(QtWidgets.QStyle.SP_MediaPause), t("Pause Queue")) self.pause_queue.clicked.connect(self.pause_resume_queue) # pause_queue.setFixedHeight(40) self.pause_queue.setFixedWidth(120) self.pause_queue.setToolTip( t("Wait for the current command to finish," " and stop the next command from processing")) self.pause_encode = QtWidgets.QPushButton( self.app.style().standardIcon(QtWidgets.QStyle.SP_MediaPause), t("Pause Encode")) self.pause_encode.clicked.connect(self.pause_resume_encode) # pause_queue.setFixedHeight(40) self.pause_encode.setFixedWidth(120) self.pause_encode.setToolTip(t("Pause / Resume the current command")) self.after_done_combo = QtWidgets.QComboBox() self.after_done_combo.addItem("None") actions = set() if reusables.win_based: actions.update(done_actions["windows"].keys()) elif sys.platform == "darwin": actions.update(["shutdown", "restart"]) else: actions.update(done_actions["linux"].keys()) if self.app.fastflix.config.custom_after_run_scripts: actions.update(self.app.fastflix.config.custom_after_run_scripts) self.after_done_combo.addItems(sorted(actions)) self.after_done_combo.setToolTip( "Run a command after conversion completes") self.after_done_combo.currentIndexChanged.connect( lambda: self.set_after_done()) self.after_done_combo.setMaximumWidth(150) top_layout.addWidget(QtWidgets.QLabel(t("After Conversion"))) top_layout.addWidget(self.after_done_combo, QtCore.Qt.AlignRight) top_layout.addWidget(self.pause_encode, QtCore.Qt.AlignRight) top_layout.addWidget(self.pause_queue, QtCore.Qt.AlignRight) top_layout.addWidget(self.clear_queue, QtCore.Qt.AlignRight) super().__init__(app, parent, t("Queue"), "queue", top_row_layout=top_layout) try: self.queue_startup_check() except Exception: logger.exception( "Could not load queue as it is outdated or malformed. Deleting for safety." ) save_queue([], queue_file=self.app.fastflix.queue_path, config=self.app.fastflix.config)