Exemple #1
0
    def run(self):
        """
        run the encoding
        """
        # probe file first
        frame_count = self.ffmpeg_probe_frame_count()

        if frame_count == -1:
            app.logger.debug("Probing of " + self.file.filename +
                             " failed - aborting...")
            ProcessRepository.file_failed(self.file)
            return

        # app.logger.debug("Probing of " + file.filename + " successful.. frame count: " + str(frame_count))
        split_path = os.path.split(self.file.filename)
        path = split_path[0]
        original_filename = split_path[1]
        filename_noext = os.path.split(
            os.path.splitext(original_filename)[0])[1]
        # form output filename and store it in self.file for later use
        self.file.output_filename = filename_noext + ".pyencode"

        cmd = ["ffmpeg"]
        cmd.extend(["-i", self.file.filename])
        # add parameters from config
        cmd.extend(shlex.split(config.get("encoding", "parameters")))
        cmd.extend(["-y", path + os.sep + self.file.output_filename])

        app.logger.debug("Starting encoding of " + self.file.filename +
                         " with %s" % " ".join(cmd))

        for info in self.run_ffmpeg(cmd, frame_count):
            if info["return_code"] != -1:
                app.logger.debug(
                    "Error occured while running ffmpeg. Last lines of output: "
                )
                app.logger.debug("\n".join(info["last_lines"]))
                ProcessRepository.file_failed(self.file)
                return

            # store information in database
            # convert kB to bytes
            info["ffmpeg_size"] *= 1024

            # we don't need the return_code anymore (and don't want to store it)
            info.pop("return_code")

            # update file in DB
            File.query.filter_by(id=self.file.id).update(info)
            db.session.commit()

            # update self.file
            for k in info:
                setattr(self.file, k, info[k])

            # tell ProcessRepository there's some progress going on
            ProcessRepository.file_progress(self.file)

        if self.active:
            ProcessRepository.file_done(self.file)
Exemple #2
0
    def test_file_done():
        with patch("os.rename") as m_rename:
            with patch("os.remove") as m_remove:
                # add fake_file to database in order to test renaming
                filename = "ThisIsAmazing.11.12.10.PyEncode.Is.The.Best.SEPARATOR.1080p.MP4-ABC.mp4"
                path = "/this/path/is/fake"
                fake_file = File(id=1, filename=path + os.sep + filename)
                fake_file.output_filename = filename + ".pyencode"
                db.session.add(fake_file)
                db.session.commit()

                # set options we want to test
                config["encoding"]["delete_old_file"] = "True"
                config["encoding"]["rename_enabled"] = "True"
                config["encoding"][
                    "rename_search"] = r"(?P<head>.+)(?P<resolution>1080|720|2160)(?:p|P)\.(?P<tail>.+)\.(?P<extension>\w{3})"
                config["encoding"][
                    "rename_replace"] = r"\g<head>720p.\g<tail>-selfmade.mkv"
                expected_filename = "ThisIsAmazing.11.12.10.PyEncode.Is.The.Best.SEPARATOR.720p.MP4-ABC-selfmade.mkv"

                ProcessRepository.processes[fake_file.id] = None
                ProcessRepository.file_done(fake_file)
                m_remove.assert_called_once_with(fake_file.filename)
                m_rename.assert_called_once_with(
                    path + os.sep + fake_file.output_filename,
                    path + os.sep + expected_filename)

        return
    def test_file_done():
        with patch("os.rename") as m_rename:
            with patch("os.remove") as m_remove:
                # add fake_file to database in order to test renaming
                filename = "ThisIsAmazing.11.12.10.PyEncode.Is.The.Best.SEPARATOR.1080p.MP4-ABC.mp4"
                path = "/this/path/is/fake"
                fake_file = File(id=1, filename=path + os.sep + filename)
                fake_file.output_filename = filename + ".pyencode"
                db.session.add(fake_file)
                db.session.commit()

                # set options we want to test
                config["encoding"]["delete_old_file"] = "True"
                config["encoding"]["rename_enabled"] = "True"
                config["encoding"][
                    "rename_search"] = r"(?P<head>.+)(?P<resolution>1080|720|2160)(?:p|P)\.(?P<tail>.+)\.(?P<extension>\w{3})"
                config["encoding"]["rename_replace"] = r"\g<head>720p.\g<tail>-selfmade.mkv"
                expected_filename = "ThisIsAmazing.11.12.10.PyEncode.Is.The.Best.SEPARATOR.720p.MP4-ABC-selfmade.mkv"

                ProcessRepository.processes[fake_file.id] = None
                ProcessRepository.file_done(fake_file)
                m_remove.assert_called_once_with(fake_file.filename)
                m_rename.assert_called_once_with(path + os.sep + fake_file.output_filename,
                                                 path + os.sep + expected_filename)

        return
Exemple #4
0
    def run(self):
        """
        run the encoding
        """
        # probe file first
        frame_count = self.ffmpeg_probe_frame_count()

        if frame_count == -1:
            app.logger.debug("Probing of " + self.file.filename + " failed - aborting...")
            ProcessRepository.file_failed(self.file)
            return

        # app.logger.debug("Probing of " + file.filename + " successful.. frame count: " + str(frame_count))
        split_path = os.path.split(self.file.filename)
        path = split_path[0]
        original_filename = split_path[1]
        filename_noext = os.path.split(os.path.splitext(original_filename)[0])[1]
        # form output filename and store it in self.file for later use
        self.file.output_filename = filename_noext + ".pyencode"

        cmd = ["ffmpeg"]
        cmd.extend(["-i", self.file.filename])
        # add parameters from config
        cmd.extend(shlex.split(config.get("encoding", "parameters")))
        cmd.extend(["-y", path + os.sep + self.file.output_filename])

        app.logger.debug("Starting encoding of " + self.file.filename + " with %s" % " ".join(cmd))

        for info in self.run_ffmpeg(cmd, frame_count):
            if info["return_code"] != -1:
                app.logger.debug("Error occured while running ffmpeg. Last lines of output: ")
                app.logger.debug("\n".join(info["last_lines"]))
                ProcessRepository.file_failed(self.file)
                return

            # store information in database
            # convert kB to bytes
            info["ffmpeg_size"] *= 1024

            # we don't need the return_code anymore (and don't want to store it)
            info.pop("return_code")

            # update file in DB
            File.query.filter_by(id=self.file.id).update(info)
            db.session.commit()

            # update self.file
            for k in info:
                setattr(self.file, k, info[k])

            # tell ProcessRepository there's some progress going on
            ProcessRepository.file_progress(self.file)

        if self.active:
            ProcessRepository.file_done(self.file)