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()
Exemple #2
0
    def add_to_queue(self):
        if not self.main.encoding_checks():
            return False

        if not self.main.build_commands():
            return False

        for video in self.app.fastflix.conversion_list:
            if video.status.complete:
                continue
            if self.app.fastflix.current_video.source == video.source:
                source_in_queue = True
            if self.app.fastflix.current_video.video_settings.output_path == video.video_settings.output_path:
                raise FastFlixInternalException(
                    f"{video.video_settings.output_path} {t('out file is already in queue')}"
                )

        # if source_in_queue:
        # TODO ask if ok
        # return

        self.app.fastflix.conversion_list.append(
            copy.deepcopy(self.app.fastflix.current_video))
        self.new_source()
        save_queue(self.app.fastflix.conversion_list,
                   self.app.fastflix.queue_path, self.app.fastflix.config)
Exemple #3
0
    def queue_startup_check(self, queue_file=None):
        new_queue = get_queue(queue_file or self.app.fastflix.queue_path)

        remove_vids = []
        for i, video in enumerate(new_queue):
            if video.status.complete:
                remove_vids.append(video)
            else:
                video.status.clear()

        for video in remove_vids:
            new_queue.remove(video)

        if queue_file:
            self.app.fastflix.conversion_list = new_queue
        elif 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",
            ):

                self.app.fastflix.conversion_list = new_queue
        self.new_source()
        save_queue(self.app.fastflix.conversion_list,
                   self.app.fastflix.queue_path, self.app.fastflix.config)
Exemple #4
0
 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()
Exemple #5
0
 def manually_save_queue(self):
     filename = QtWidgets.QFileDialog.getSaveFileName(
         self,
         caption=t("Save Queue"),
         dir=os.path.expanduser("~"),
         filter=f"FastFlix Queue File (*.yaml)",
     )
     if filename and filename[0]:
         save_queue(self.app.fastflix.conversion_list, filename[0],
                    self.app.fastflix.config)
         message(t("Queue saved to") + f"{filename[0]}")
Exemple #6
0
 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()
Exemple #7
0
    def remove_item(self, video, part_of_clear=False):
        if self.app.fastflix.currently_encoding:
            # TODO error
            return

        for i, vid in enumerate(self.app.fastflix.conversion_list):
            if vid.uuid == video.uuid:
                pos = i
                break
        else:
            logger.error("No matching video found to remove from queue")
            return
        self.app.fastflix.conversion_list.pop(pos)

        if not part_of_clear:
            self.new_source()
        save_queue(self.app.fastflix.conversion_list,
                   self.app.fastflix.queue_path, self.app.fastflix.config)
Exemple #8
0
    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()
Exemple #9
0
    def reorder(self, update=True):
        if self.app.fastflix.currently_encoding:
            # TODO error?
            logger.warning("Reorder queue called while encoding")
            return
        super().reorder(update=update)
        # TODO find better reorder method
        self.app.fastflix.conversion_list = []
        for track in self.tracks:
            self.app.fastflix.conversion_list.append(track.video)

        for track in self.tracks:
            track.widgets.up_button.setDisabled(False)
            track.widgets.down_button.setDisabled(False)
        if self.tracks:
            self.tracks[0].widgets.up_button.setDisabled(True)
            self.tracks[-1].widgets.down_button.setDisabled(True)
        save_queue(self.app.fastflix.conversion_list,
                   self.app.fastflix.queue_path, self.app.fastflix.config)
    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(
            QtGui.QIcon(
                get_icon("onyx-clear-queue", self.app.fastflix.config.theme)),
            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(
            QtGui.QIcon(get_icon("onyx-pause",
                                 self.app.fastflix.config.theme)),
            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(
            QtGui.QIcon(get_icon("onyx-pause",
                                 self.app.fastflix.config.theme)),
            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)