Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh5 committed Aug 28, 2021
0 parents commit 2f42e0e
Show file tree
Hide file tree
Showing 9 changed files with 899 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/__pycache__
*.py[cod]
**/site-packages
settings.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/ffmpeg"]
path = lib/ffmpeg
url = [email protected]:Josh5/unmanic.plugin.helpers.ffmpeg.git
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

**<span style="color:#56adda">0.0.1</span>**
- Initial version
15 changes: 15 additions & 0 deletions info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"author": "Josh.5",
"compatibility": [
1
],
"description": "Remux a video file to the configured container",
"icon": "",
"id": "video_remuxer",
"name": "Remux Video Files",
"priorities": {
"on_worker_process": 0
},
"tags": "video,ffmpeg",
"version": "0.0.1"
}
23 changes: 23 additions & 0 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
plugins.__init__.py
Written by: Josh.5 <[email protected]>
Date: 28 Aug 2021, (11:55 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/>.
"""
1 change: 1 addition & 0 deletions lib/ffmpeg
Submodule ffmpeg added at 9a86b8
176 changes: 176 additions & 0 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
plugins.__init__.py
Written by: Josh.5 <[email protected]>
Date: 28 Aug 2021, (11:55 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 video_remuxer.lib.ffmpeg import StreamMapper, Probe, Parser

# Configure plugin logger
logger = logging.getLogger("Unmanic.Plugin.video_remuxer")


class Settings(PluginSettings):
settings = {
"dest_container": "mkv",
}

def __init__(self):
self.form_settings = {
"dest_container": {
"label": "Set the output container",
"input_type": "select",
"select_options": [
{
'value': "mkv",
'label': ".mkv - Matroska",
},
{
'value': "avi",
'label': ".avi - AVI (Audio Video Interleaved)",
},
{
'value': "mov",
'label': ".mov - QuickTime / MOV",
},
{
'value': "mp4",
'label': ".mp4 - MP4 (MPEG-4 Part 14)",
},
],
},
}


class PluginStreamMapper(StreamMapper):
def __init__(self):
super(PluginStreamMapper, self).__init__(logger, ['video', 'audio', 'subtitle', 'data', 'attachment'])

def test_stream_needs_processing(self, stream_info: dict):
return False


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)
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)

# Set the input file
mapper.set_input_file(abspath)

settings = Settings()
container_extension = settings.get_setting('dest_container')

if mapper.container_needs_remuxing(container_extension):
# 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 file needs to be processed.".format(abspath))
else:
logger.debug("File '{}' is already the required format.".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:
"""
# Get the path to the file
abspath = data.get('file_in')

# Get file probe
probe = Probe(logger)
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)

# Set the input file
mapper.set_input_file(abspath)

settings = Settings()
container_extension = settings.get_setting('dest_container')

if mapper.container_needs_remuxing(container_extension):
# Map streams (copy from source to destination)
mapper.streams_need_processing()

# Set the input file
mapper.set_input_file(abspath)

# Set the output file
split_file_out = os.path.splitext(data.get('file_out'))
mapper.set_output_file("{}.{}".format(split_file_out[0], container_extension.lstrip('.')))

# 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
Empty file added requirements.txt
Empty file.

0 comments on commit 2f42e0e

Please sign in to comment.