/
kushpel
/
plugins
Обзор
Документация
Войти
/
kushpel
/
plugins
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
source/strip_image_streams2/plugin.py
179 строк
6 KB
yajrendrag
add bmp to list of image codecs
01 окт 2024, 02:37
01 окт 2024, 02:37
09c517e
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Written by: Josh.5 <jsunnex@gmail.com> Date: 17 March 2021, (10:36 PM) Copyright: Copyright (C) 2021 Josh Sunnex This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. """ import logging import os from unmanic.libs.unplugins.settings import PluginSettings from strip_image_streams2.lib.ffmpeg import StreamMapper, Probe, Parser # Configure plugin logger logger = logging.getLogger("Unmanic.Plugin.strip_image_streams") class Settings(PluginSettings): settings = {} class PluginStreamMapper(StreamMapper): def __init__(self): super(PluginStreamMapper, self).__init__(logger, ['video']) def test_stream_needs_processing(self, stream_info: dict): """Check if the video stream is actually an image""" image_video_codecs = [ 'alias_pix', 'apng', 'bmp', 'brender_pix', 'dds', 'dpx', 'exr', 'fits', 'gif', 'mjpeg', 'mjpegb', 'pam', 'pbm', 'pcx', 'pfm', 'pgm', 'pgmyuv', 'pgx', 'photocd', 'pictor', 'pixlet', 'png', 'ppm', 'ptx', 'sgi', 'sunrast', 'tiff', 'vc1image', 'wmv3image', 'xbm', 'xface', 'xpm', 'xwd', ] if stream_info.get('codec_name').lower() in image_video_codecs: return True return False def custom_stream_mapping(self, stream_info: dict, stream_id: int): """Do not map the image streams matched above""" return { 'stream_mapping': [], 'stream_encoding': [], } def on_library_management_file_test(data): """ Runner function - enables additional actions during the library management file tests. The 'data' object argument includes: path - String containing the full path to the file being tested. issues - List of currently found issues for not processing the file. add_file_to_pending_tasks - Boolean, is the file currently marked to be added to the queue for processing. :param data: :return: """ # Get the path to the file abspath = data.get('path') # Get file probe probe = Probe(logger, allowed_mimetypes=['video']) if not probe.file(abspath): # File probe failed, skip the rest of this test return data # Get stream mapper mapper = PluginStreamMapper() mapper.set_probe(probe) if mapper.streams_need_processing(): # Mark this file to be added to the pending tasks data['add_file_to_pending_tasks'] = True logger.debug("File '{}' should be added to task list. Probe found streams require processing.".format(abspath)) else: logger.debug("File '{}' does not contain streams require processing.".format(abspath)) return data def on_worker_process(data): """ Runner function - enables additional configured processing jobs during the worker stages of a task. The 'data' object argument includes: exec_command - A command that Unmanic should execute. Can be empty. command_progress_parser - A function that Unmanic can use to parse the STDOUT of the command to collect progress stats. Can be empty. file_in - The source file to be processed by the command. file_out - The destination that the command should output (may be the same as the file_in if necessary). original_file_path - The absolute path to the original file. repeat - Boolean, should this runner be executed again once completed with the same variables. :param data: :return: """ # Default to no FFMPEG command required. This prevents the FFMPEG command from running if it is not required data['exec_command'] = [] data['repeat'] = False # Get the path to the file abspath = data.get('file_in') # Get file probe probe = Probe(logger, allowed_mimetypes=['video']) if not probe.file(abspath): # File probe failed, skip the rest of this test return data # Get stream mapper mapper = PluginStreamMapper() mapper.set_probe(probe) if mapper.streams_need_processing(): # Set the input file mapper.set_input_file(abspath) # Set the output file # Do not remux the file. Keep the file out in the same container mapper.set_output_file(data.get('file_out')) # Get generated ffmpeg args ffmpeg_args = mapper.get_ffmpeg_args() # Apply ffmpeg args to command data['exec_command'] = ['ffmpeg'] data['exec_command'] += ffmpeg_args # Set the parser parser = Parser(logger) parser.set_probe(probe) data['command_progress_parser'] = parser.parse_progress return data