Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ac0c76d65 | ||
| dd8f472ac5 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +0,0 @@
|
|||||||
__pycache__
|
|
||||||
junk/
|
|
||||||
.vscode/launch.json
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from ffx.pattern_controller import PatternController
|
|
||||||
|
|
||||||
from ffx.model.show import Base
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
|
|
||||||
from sqlalchemy.orm import relationship, sessionmaker, Mapped, backref
|
|
||||||
|
|
||||||
filename = 'Boruto.Naruto.Next.Generations.S01E256.GerEngSub.AAC.1080p.WebDL.x264-Tanuki.mkv'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Data 'input' variable
|
|
||||||
context = {}
|
|
||||||
|
|
||||||
# Initialize DB
|
|
||||||
homeDir = os.path.expanduser("~")
|
|
||||||
ffxVarDir = os.path.join(homeDir, '.local', 'var', 'ffx')
|
|
||||||
if not os.path.exists(ffxVarDir):
|
|
||||||
os.makedirs(ffxVarDir)
|
|
||||||
|
|
||||||
context['database_url'] = f"sqlite:///{os.path.join(ffxVarDir, 'ffx.db')}"
|
|
||||||
context['database_engine'] = create_engine(context['database_url'])
|
|
||||||
context['database_session'] = sessionmaker(bind=context['database_engine'])
|
|
||||||
|
|
||||||
Base.metadata.create_all(context['database_engine'])
|
|
||||||
|
|
||||||
|
|
||||||
pc = PatternController(context)
|
|
||||||
|
|
||||||
|
|
||||||
print(pc.matchFilename(filename))
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#! /usr/bin/python3
|
#! /usr/bin/python3
|
||||||
|
|
||||||
import os, sys, subprocess, json, click, time, re
|
import os, sys, subprocess, json, click, time
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.screen import Screen
|
from textual.screen import Screen
|
||||||
from textual.widgets import Header, Footer, Placeholder, Label
|
from textual.widgets import Header, Footer, Placeholder
|
||||||
|
|
||||||
|
|
||||||
VERSION='0.1.0'
|
VERSION='0.1.0'
|
||||||
@@ -35,7 +35,7 @@ MKVMERGE_METADATA_KEYS = ['BPS',
|
|||||||
'_STATISTICS_WRITING_DATE_UTC',
|
'_STATISTICS_WRITING_DATE_UTC',
|
||||||
'_STATISTICS_TAGS']
|
'_STATISTICS_TAGS']
|
||||||
|
|
||||||
FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm']
|
FILE_EXTENSION = ['mkv', 'mp4', 'avi', 'flv', 'webm']
|
||||||
|
|
||||||
|
|
||||||
COMMAND_TOKENS = ['ffmpeg', '-y', '-i']
|
COMMAND_TOKENS = ['ffmpeg', '-y', '-i']
|
||||||
@@ -50,9 +50,6 @@ STREAM_LAYOUT_5_1 = '5.1(side)'
|
|||||||
STREAM_LAYOUT_STEREO = 'stereo'
|
STREAM_LAYOUT_STEREO = 'stereo'
|
||||||
STREAM_LAYOUT_6CH = '6ch'
|
STREAM_LAYOUT_6CH = '6ch'
|
||||||
|
|
||||||
SEASON_EPISODE_INDICATOR_MATCH = '([sS][0-9]+)([eE][0-9]+)'
|
|
||||||
SEASON_INDICATOR_MATCH = '([sS][0-9]+)'
|
|
||||||
EPISODE_INDICATOR_MATCH = '([eE][0-9]+)'
|
|
||||||
|
|
||||||
|
|
||||||
class DashboardScreen(Screen):
|
class DashboardScreen(Screen):
|
||||||
@@ -68,14 +65,6 @@ class DashboardScreen(Screen):
|
|||||||
yield Placeholder("Dashboard Screen")
|
yield Placeholder("Dashboard Screen")
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
class WarningScreen(Screen):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
context = self.app.getContext()
|
|
||||||
def compose(self) -> ComposeResult:
|
|
||||||
yield Label("Warning! This file is not compliant to the defined source schema!")
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsScreen(Screen):
|
class SettingsScreen(Screen):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -98,31 +87,29 @@ class HelpScreen(Screen):
|
|||||||
class ModesApp(App):
|
class ModesApp(App):
|
||||||
|
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
("q", "quit()", "Quit"),
|
("d", "switch_mode('dashboard')", "Dashboard"),
|
||||||
# ("d", "switch_mode('dashboard')", "Dashboard"),
|
("s", "switch_mode('settings')", "Settings"),
|
||||||
# ("s", "switch_mode('settings')", "Settings"),
|
("h", "switch_mode('help')", "Help"),
|
||||||
# ("h", "switch_mode('help')", "Help"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MODES = {
|
MODES = {
|
||||||
"warning": WarningScreen,
|
|
||||||
"dashboard": DashboardScreen,
|
"dashboard": DashboardScreen,
|
||||||
"settings": SettingsScreen,
|
"settings": SettingsScreen,
|
||||||
"help": HelpScreen,
|
"help": HelpScreen,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, context = {}):
|
def __init__(self, context = {}):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.context = context
|
self.context = context
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
self.switch_mode("warning")
|
self.switch_mode("dashboard")
|
||||||
|
|
||||||
def getContext(self):
|
def getContext(self):
|
||||||
return self.context
|
return self.context
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def executeProcess(commandSequence):
|
def executeProcess(commandSequence):
|
||||||
|
|
||||||
process = subprocess.Popen(commandSequence, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
process = subprocess.Popen(commandSequence, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
@@ -367,10 +354,8 @@ def streams(filename):
|
|||||||
@click.option("-c", "--clear-metadata", is_flag=True, default=False)
|
@click.option("-c", "--clear-metadata", is_flag=True, default=False)
|
||||||
@click.option("-d", "--denoise", is_flag=True, default=False)
|
@click.option("-d", "--denoise", is_flag=True, default=False)
|
||||||
|
|
||||||
@click.option("-o", "--output-directory", type=str, default='')
|
|
||||||
|
|
||||||
|
def convert(ctx, paths, label, video_encoder, quality, preset, stereo_bitrate, ac3_bitrate, dts_bitrate, crop, clear_metadata, default_subtitle, forced_audio, default_audio, denoise):
|
||||||
def convert(ctx, paths, label, video_encoder, quality, preset, stereo_bitrate, ac3_bitrate, dts_bitrate, crop, clear_metadata, default_subtitle, forced_audio, default_audio, denoise, output_directory):
|
|
||||||
"""Batch conversion of audiovideo files in format suitable for web playback, e.g. jellyfin
|
"""Batch conversion of audiovideo files in format suitable for web playback, e.g. jellyfin
|
||||||
|
|
||||||
Files found under PATHS will be converted according to parameters.
|
Files found under PATHS will be converted according to parameters.
|
||||||
@@ -378,79 +363,56 @@ def convert(ctx, paths, label, video_encoder, quality, preset, stereo_bitrate, a
|
|||||||
Suffices will we appended to filename in case of multiple created files
|
Suffices will we appended to filename in case of multiple created files
|
||||||
or if the filename has not changed."""
|
or if the filename has not changed."""
|
||||||
|
|
||||||
startTime = time.perf_counter()
|
#startTime = time.perf_counter()
|
||||||
|
|
||||||
context = ctx.obj
|
#sourcePath = paths[0]
|
||||||
|
#targetFilename = paths[1]
|
||||||
|
|
||||||
|
#if not os.path.isfile(sourcePath):
|
||||||
|
# raise click.ClickException(f"There is no file with path {sourcePath}")
|
||||||
|
|
||||||
|
#click.echo(f"src: {sourcePath} tgt: {targetFilename}")
|
||||||
|
|
||||||
|
|
||||||
click.echo(f"\nVideo encoder: {video_encoder}")
|
#click.echo(f"ve={video_encoder}")
|
||||||
|
|
||||||
qualityTokens = quality.split(',')
|
|
||||||
q_list = [q for q in qualityTokens if q.isnumeric()]
|
|
||||||
|
|
||||||
click.echo(f"Qualities: {q_list}")
|
|
||||||
|
|
||||||
|
|
||||||
ctx.obj['bitrates'] = {}
|
#qualityTokens = quality.split(',')
|
||||||
ctx.obj['bitrates']['stereo'] = str(stereo_bitrate) if str(stereo_bitrate).endswith('k') else f"{stereo_bitrate}k"
|
|
||||||
ctx.obj['bitrates']['ac3'] = str(ac3_bitrate) if str(ac3_bitrate).endswith('k') else f"{ac3_bitrate}k"
|
|
||||||
ctx.obj['bitrates']['dts'] = str(dts_bitrate) if str(dts_bitrate).endswith('k') else f"{dts_bitrate}k"
|
|
||||||
|
|
||||||
click.echo(f"Stereo bitrate: {ctx.obj['bitrates']['stereo']}")
|
#q_list = [q for q in qualityTokens if q.isnumeric()]
|
||||||
click.echo(f"AC3 bitrate: {ctx.obj['bitrates']['ac3']}")
|
|
||||||
click.echo(f"DTS bitrate: {ctx.obj['bitrates']['dts']}")
|
|
||||||
|
|
||||||
ctx.obj['perform_crop'] = (crop != 'none')
|
#click.echo(q_list)
|
||||||
|
|
||||||
if ctx.obj['perform_crop']:
|
#ctx.obj['bitrates'] = {}
|
||||||
|
#ctx.obj['bitrates']['stereo'] = str(stereo_bitrate) if str(stereo_bitrate).endswith('k') else f"{stereo_bitrate}k"
|
||||||
cropTokens = crop.split(',')
|
#ctx.obj['bitrates']['ac3'] = str(ac3_bitrate) if str(ac3_bitrate).endswith('k') else f"{ac3_bitrate}k"
|
||||||
|
#ctx.obj['bitrates']['dts'] = str(dts_bitrate) if str(dts_bitrate).endswith('k') else f"{dts_bitrate}k"
|
||||||
if cropTokens and len(cropTokens) == 2:
|
|
||||||
|
|
||||||
ctx.obj['crop_start'], ctx.obj['crop_length'] = crop.split(',')
|
|
||||||
else:
|
|
||||||
ctx.obj['crop_start'] = DEFAULT_CROP_START
|
|
||||||
ctx.obj['crop_length'] = DEFAULT_CROP_LENGTH
|
|
||||||
|
|
||||||
click.echo(f"crop start={ctx.obj['crop_start']} length={ctx.obj['crop_length']}")
|
|
||||||
|
|
||||||
|
|
||||||
click.echo(f"\nRunning {len(paths) * len(q_list)} jobs")
|
#click.echo(f"a={ctx.obj['bitrates']['stereo']}")
|
||||||
|
#click.echo(f"ac3={ctx.obj['bitrates']['ac3']}")
|
||||||
|
#click.echo(f"dts={ctx.obj['bitrates']['dts']}")
|
||||||
|
|
||||||
|
|
||||||
se_match = re.compile(SEASON_EPISODE_INDICATOR_MATCH)
|
#performCrop = (crop != 'none')
|
||||||
s_match = re.compile(SEASON_INDICATOR_MATCH)
|
|
||||||
e_match = re.compile(EPISODE_INDICATOR_MATCH)
|
|
||||||
|
|
||||||
|
|
||||||
for sourcePath in paths:
|
#if performCrop:
|
||||||
|
|
||||||
|
#cropTokens = crop.split(',')
|
||||||
|
|
||||||
|
#if cropTokens and len(cropTokens) == 2:
|
||||||
|
|
||||||
|
#cropStart, cropLength = crop.split(',')
|
||||||
|
#else:
|
||||||
|
#cropStart = DEFAULT_CROP_START
|
||||||
|
#cropLength = DEFAULT_CROP_LENGTH
|
||||||
|
|
||||||
|
#click.echo(f"crop start={cropStart} length={cropLength}")
|
||||||
|
|
||||||
|
|
||||||
if not os.path.isfile(sourcePath):
|
|
||||||
click.echo(f"There is no file with path {sourcePath}, skipping ...")
|
|
||||||
continue
|
|
||||||
|
|
||||||
sourceDirectory = os.path.dirname(sourcePath)
|
|
||||||
sourceFilename = os.path.basename(sourcePath)
|
|
||||||
sourcePathTokens = sourceFilename.split('.')
|
|
||||||
|
|
||||||
if sourcePathTokens[-1] in FILE_EXTENSIONS:
|
|
||||||
sourceFileBasename = '.'.join(sourcePathTokens[:-1])
|
|
||||||
sourceFilenameExtension = sourcePathTokens[-1]
|
|
||||||
else:
|
|
||||||
sourceFileBasename = sourceFilename
|
|
||||||
sourceFilenameExtension = ''
|
|
||||||
|
|
||||||
#click.echo(f"dir={sourceDirectory} base={sourceFileBasename} ext={sourceFilenameExtension}")
|
|
||||||
|
|
||||||
click.echo(f"\nProcessing file {sourcePath}")
|
|
||||||
|
|
||||||
|
|
||||||
se_result = se_match.search(sourceFilename)
|
|
||||||
s_result = s_match.search(sourceFilename)
|
|
||||||
e_result = e_match.search(sourceFilename)
|
|
||||||
|
|
||||||
|
#click.echo(f"\nRunning {len(q_list)} jobs")
|
||||||
|
|
||||||
|
|
||||||
#streamDescriptor = getStreamDescriptor(sourcePath)
|
#streamDescriptor = getStreamDescriptor(sourcePath)
|
||||||
@@ -535,18 +497,15 @@ def convert(ctx, paths, label, video_encoder, quality, preset, stereo_bitrate, a
|
|||||||
#executeProcess(commandSequence2)
|
#executeProcess(commandSequence2)
|
||||||
|
|
||||||
|
|
||||||
#app = ModesApp(ctx.obj)
|
#click.echo('\nDONE\n')
|
||||||
#app.run()
|
|
||||||
|
|
||||||
#click.confirm('Warning! This file is not compliant to the defined source schema! Do you want to continue?', abort=True)
|
#endTime = time.perf_counter()
|
||||||
|
#click.echo(f"Time elapsed {endTime - startTime}")
|
||||||
|
|
||||||
click.echo('\nDONE\n')
|
app = ModesApp(ctx.obj)
|
||||||
|
app.run()
|
||||||
|
|
||||||
endTime = time.perf_counter()
|
click.echo(f"app result: {app.getContext()}")
|
||||||
click.echo(f"Time elapsed {endTime - startTime}")
|
|
||||||
|
|
||||||
|
|
||||||
# click.echo(f"app result: {app.getContext()}")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
32
bin/check.py
32
bin/check.py
@@ -1,32 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from ffx.pattern_controller import PatternController
|
|
||||||
|
|
||||||
from ffx.model.show import Base
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
|
|
||||||
from sqlalchemy.orm import relationship, sessionmaker, Mapped, backref
|
|
||||||
|
|
||||||
filename = 'Boruto.Naruto.Next.Generations.S01E256.GerEngSub.AAC.1080p.WebDL.x264-Tanuki.mkv'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Data 'input' variable
|
|
||||||
context = {}
|
|
||||||
|
|
||||||
# Initialize DB
|
|
||||||
homeDir = os.path.expanduser("~")
|
|
||||||
ffxVarDir = os.path.join(homeDir, '.local', 'var', 'ffx')
|
|
||||||
if not os.path.exists(ffxVarDir):
|
|
||||||
os.makedirs(ffxVarDir)
|
|
||||||
|
|
||||||
context['database_url'] = f"sqlite:///{os.path.join(ffxVarDir, 'ffx.db')}"
|
|
||||||
context['database_engine'] = create_engine(context['database_url'])
|
|
||||||
context['database_session'] = sessionmaker(bind=context['database_engine'])
|
|
||||||
|
|
||||||
Base.metadata.create_all(context['database_engine'])
|
|
||||||
|
|
||||||
|
|
||||||
pc = PatternController(context)
|
|
||||||
|
|
||||||
|
|
||||||
print(pc.matchFilename(filename))
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
from ffx.helper import dictDiff
|
|
||||||
|
|
||||||
a = {'name': 'yolo', 'mass': 56}
|
|
||||||
b = {'name': 'zolo', 'mass': 58}
|
|
||||||
|
|
||||||
print(dictDiff(a, b))
|
|
||||||
1174
bin/ffx.py
1174
bin/ffx.py
File diff suppressed because it is too large
Load Diff
@@ -1,66 +0,0 @@
|
|||||||
import os, re, click
|
|
||||||
|
|
||||||
class FileProperties():
|
|
||||||
|
|
||||||
FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm']
|
|
||||||
|
|
||||||
SEASON_EPISODE_INDICATOR_MATCH = '[sS]([0-9]+)[eE]([0-9]+)'
|
|
||||||
EPISODE_INDICATOR_MATCH = '[eE]([0-9]+)'
|
|
||||||
|
|
||||||
def ___init__(self, sourcePath, ):
|
|
||||||
|
|
||||||
|
|
||||||
# Separate basedir, basename and extension for current source file
|
|
||||||
self.__sourceDirectory = os.path.dirname(sourcePath)
|
|
||||||
self.__sourceFilename = os.path.basename(sourcePath)
|
|
||||||
sourcePathTokens = self.__sourceFilename.split('.')
|
|
||||||
|
|
||||||
if sourcePathTokens[-1] in FilenameController.FILE_EXTENSIONS:
|
|
||||||
self.__sourceFileBasename = '.'.join(sourcePathTokens[:-1])
|
|
||||||
self.__sourceFilenameExtension = sourcePathTokens[-1]
|
|
||||||
else:
|
|
||||||
self.__sourceFileBasename = self.__sourceFilename
|
|
||||||
self.__sourceFilenameExtension = ''
|
|
||||||
|
|
||||||
|
|
||||||
se_match = re.compile(FilenameController.SEASON_EPISODE_INDICATOR_MATCH)
|
|
||||||
e_match = re.compile(FilenameController.EPISODE_INDICATOR_MATCH)
|
|
||||||
|
|
||||||
se_result = se_match.search(self.__sourceFilename)
|
|
||||||
e_result = e_match.search(self.__sourceFilename)
|
|
||||||
|
|
||||||
self.__season = -1
|
|
||||||
self.__episode = -1
|
|
||||||
file_index = 0
|
|
||||||
|
|
||||||
if se_result is not None:
|
|
||||||
self.__season = int(se_result.group(1))
|
|
||||||
self.__episode = int(se_result.group(2))
|
|
||||||
elif e_result is not None:
|
|
||||||
self.__episode = int(e_result.group(1))
|
|
||||||
else:
|
|
||||||
file_index += 1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
matchingFileSubtitleDescriptors = sorted([d for d in availableFileSubtitleDescriptors if d['season'] == season and d['episode'] == episode], key=lambda d: d['stream']) if availableFileSubtitleDescriptors else []
|
|
||||||
|
|
||||||
print(f"season={season} episode={episode} file={file_index}")
|
|
||||||
|
|
||||||
|
|
||||||
# Assemble target filename tokens
|
|
||||||
targetFilenameTokens = []
|
|
||||||
targetFilenameExtension = DEFAULT_FILE_EXTENSION
|
|
||||||
|
|
||||||
if label:
|
|
||||||
targetFilenameTokens = [label]
|
|
||||||
|
|
||||||
if season > -1 and episode > -1:
|
|
||||||
targetFilenameTokens += [f"S{season:0{season_digits}d}E{episode:0{episode_digits}d}"]
|
|
||||||
elif episode > -1:
|
|
||||||
targetFilenameTokens += [f"E{episode:0{episode_digits}d}"]
|
|
||||||
else:
|
|
||||||
targetFilenameTokens += [f"{file_index:0{index_digits}d}"]
|
|
||||||
|
|
||||||
else:
|
|
||||||
targetFilenameTokens = [sourceFileBasename]
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
import click
|
|
||||||
from enum import Enum
|
|
||||||
from .track_type import TrackType
|
|
||||||
|
|
||||||
class AudioLayout(Enum):
|
|
||||||
|
|
||||||
LAYOUT_STEREO = {"label": "stereo", "index": 1}
|
|
||||||
LAYOUT_5_1 = {"label": "5.1(side)", "index": 2}
|
|
||||||
LAYOUT_6_1 = {"label": "6.1", "index": 3}
|
|
||||||
LAYOUT_7_1 = {"label": "7.1", "index": 4} #TODO: Does this exist?
|
|
||||||
|
|
||||||
LAYOUT_6CH = {"label": "6ch", "index": 5}
|
|
||||||
|
|
||||||
LAYOUT_UNDEFINED = {"label": "undefined", "index": 0}
|
|
||||||
|
|
||||||
|
|
||||||
def label(self):
|
|
||||||
"""Returns the audio layout as string"""
|
|
||||||
return str(self.value['label'])
|
|
||||||
|
|
||||||
def index(self):
|
|
||||||
"""Returns the audio layout as integer"""
|
|
||||||
return int(self.value['index'])
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fromLabel(label : str):
|
|
||||||
try:
|
|
||||||
|
|
||||||
return [a for a in AudioLayout if a.value['label'] == str(label)][0]
|
|
||||||
except:
|
|
||||||
raise click.ClickException('fromLabel failed')
|
|
||||||
return AudioLayout.LAYOUT_UNDEFINED
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fromIndex(index : int):
|
|
||||||
try:
|
|
||||||
return [a for a in AudioLayout if a.value['index'] == int(index)][0]
|
|
||||||
except:
|
|
||||||
raise click.ClickException('fromIndex failed')
|
|
||||||
return AudioLayout.LAYOUT_UNDEFINED
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def identify(streamObj):
|
|
||||||
|
|
||||||
FFPROBE_LAYOUT_KEY = 'channel_layout'
|
|
||||||
FFPROBE_CHANNELS_KEY = 'channels'
|
|
||||||
FFPROBE_CODEC_TYPE_KEY = 'codec_type'
|
|
||||||
|
|
||||||
if (type(streamObj) is not dict
|
|
||||||
or FFPROBE_CODEC_TYPE_KEY not in streamObj.keys()
|
|
||||||
or streamObj[FFPROBE_CODEC_TYPE_KEY] != TrackType.AUDIO.label()):
|
|
||||||
raise Exception('Not an ffprobe audio stream object')
|
|
||||||
|
|
||||||
if FFPROBE_LAYOUT_KEY in streamObj.keys():
|
|
||||||
matchingLayouts = [l for l in AudioLayout if l.label() == streamObj[FFPROBE_LAYOUT_KEY]]
|
|
||||||
if matchingLayouts:
|
|
||||||
return matchingLayouts[0]
|
|
||||||
|
|
||||||
if (FFPROBE_CHANNELS_KEY in streamObj.keys()
|
|
||||||
and int(streamObj[FFPROBE_CHANNELS_KEY]) == 6):
|
|
||||||
|
|
||||||
return AudioLayout.LAYOUT_6CH
|
|
||||||
|
|
||||||
return AudioLayout.LAYOUT_UNDEFINED
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Placeholder, Label
|
|
||||||
|
|
||||||
class DashboardScreen(Screen):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
context = self.app.getContext()
|
|
||||||
context['dashboard'] = 'dashboard'
|
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
|
||||||
yield Header(show_clock=True)
|
|
||||||
yield Placeholder("Dashboard Screen")
|
|
||||||
yield Footer()
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
from sqlalchemy.orm import sessionmaker
|
|
||||||
|
|
||||||
from ffx.model.show import Base, Show
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
from ffx.model.track import Track
|
|
||||||
|
|
||||||
from ffx.model.media_tag import MediaTag
|
|
||||||
from ffx.model.track_tag import TrackTag
|
|
||||||
|
|
||||||
|
|
||||||
def databaseContext():
|
|
||||||
|
|
||||||
databaseContext = {}
|
|
||||||
|
|
||||||
# Initialize DB
|
|
||||||
homeDir = os.path.expanduser("~")
|
|
||||||
ffxVarDir = os.path.join(homeDir, '.local', 'var', 'ffx')
|
|
||||||
if not os.path.exists(ffxVarDir):
|
|
||||||
os.makedirs(ffxVarDir)
|
|
||||||
|
|
||||||
databaseContext['url'] = f"sqlite:///{os.path.join(ffxVarDir, 'ffx.db')}"
|
|
||||||
databaseContext['engine'] = create_engine(databaseContext['url'])
|
|
||||||
databaseContext['session'] = sessionmaker(bind=databaseContext['engine'])
|
|
||||||
|
|
||||||
Base.metadata.create_all(databaseContext['engine'])
|
|
||||||
|
|
||||||
# isSyncronuous = False
|
|
||||||
# while not isSyncronuous:
|
|
||||||
# while True:
|
|
||||||
# try:
|
|
||||||
# with databaseContext['database_engine'].connect() as connection:
|
|
||||||
# connection.execute(sqlalchemy.text('PRAGMA foreign_keys=ON;'))
|
|
||||||
# #isSyncronuous = True
|
|
||||||
# break
|
|
||||||
# except sqlite3.OperationalError:
|
|
||||||
# time.sleep(0.1)
|
|
||||||
|
|
||||||
return databaseContext
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
from textual.app import App
|
|
||||||
|
|
||||||
from .shows_screen import ShowsScreen
|
|
||||||
from .media_details_screen import MediaDetailsScreen
|
|
||||||
|
|
||||||
|
|
||||||
class FfxApp(App):
|
|
||||||
|
|
||||||
TITLE = "FFX"
|
|
||||||
|
|
||||||
BINDINGS = [
|
|
||||||
("q", "quit()", "Quit"),
|
|
||||||
("h", "switch_mode('help')", "Help"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, context = {}):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
# Data 'input' variable
|
|
||||||
self.context = context
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
|
||||||
|
|
||||||
if 'command' in self.context.keys():
|
|
||||||
|
|
||||||
if self.context['command'] == 'shows':
|
|
||||||
self.push_screen(ShowsScreen())
|
|
||||||
|
|
||||||
if self.context['command'] == 'inspect':
|
|
||||||
self.push_screen(MediaDetailsScreen())
|
|
||||||
|
|
||||||
|
|
||||||
def getContext(self):
|
|
||||||
"""Data 'output' method"""
|
|
||||||
return self.context
|
|
||||||
|
|
||||||
@@ -1,458 +1,2 @@
|
|||||||
import os, click, re
|
|
||||||
|
|
||||||
from ffx.media_descriptor import MediaDescriptor
|
|
||||||
from ffx.helper import DIFF_ADDED_KEY, DIFF_REMOVED_KEY, DIFF_CHANGED_KEY
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
from ffx.model.track import Track
|
|
||||||
from ffx.audio_layout import AudioLayout
|
|
||||||
from ffx.track_type import TrackType
|
|
||||||
from ffx.video_encoder import VideoEncoder
|
|
||||||
from ffx.process import executeProcess
|
|
||||||
|
|
||||||
|
|
||||||
class FfxController():
|
class FfxController():
|
||||||
|
pass
|
||||||
COMMAND_TOKENS = ['ffmpeg', '-y']
|
|
||||||
NULL_TOKENS = ['-f', 'null', '/dev/null'] # -f null /dev/null
|
|
||||||
|
|
||||||
TEMP_FILE_NAME = "ffmpeg2pass-0.log"
|
|
||||||
|
|
||||||
DEFAULT_VIDEO_ENCODER = VideoEncoder.VP9.label()
|
|
||||||
|
|
||||||
DEFAULT_QUALITY = 23
|
|
||||||
DEFAULT_AV1_PRESET = 5
|
|
||||||
|
|
||||||
DEFAULT_FILE_FORMAT = 'webm'
|
|
||||||
DEFAULT_FILE_EXTENSION = 'webm'
|
|
||||||
|
|
||||||
DEFAULT_STEREO_BANDWIDTH = "128"
|
|
||||||
DEFAULT_AC3_BANDWIDTH = "256"
|
|
||||||
DEFAULT_DTS_BANDWIDTH = "320"
|
|
||||||
|
|
||||||
DEFAULT_CROP_START = 60
|
|
||||||
DEFAULT_CROP_LENGTH = 180
|
|
||||||
|
|
||||||
MKVMERGE_METADATA_KEYS = ['BPS',
|
|
||||||
'NUMBER_OF_FRAMES',
|
|
||||||
'NUMBER_OF_BYTES',
|
|
||||||
'_STATISTICS_WRITING_APP',
|
|
||||||
'_STATISTICS_WRITING_DATE_UTC',
|
|
||||||
'_STATISTICS_TAGS']
|
|
||||||
|
|
||||||
INPUT_FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm']
|
|
||||||
|
|
||||||
CHANNEL_MAP_5_1 = 'FL-FL|FR-FR|FC-FC|LFE-LFE|SL-BL|SR-BR:5.1'
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self,
|
|
||||||
context : dict,
|
|
||||||
targetMediaDescriptor : MediaDescriptor,
|
|
||||||
sourceMediaDescriptor : MediaDescriptor = None):
|
|
||||||
|
|
||||||
self.__context = context
|
|
||||||
self.__sourceMediaDescriptor = sourceMediaDescriptor
|
|
||||||
self.__targetMediaDescriptor = targetMediaDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
def generateAV1Tokens(self, quality, preset, subIndex : int = 0):
|
|
||||||
|
|
||||||
return [f"-c:v:{int(subIndex)}", 'libsvtav1',
|
|
||||||
'-svtav1-params', f"crf={quality}:preset={preset}:tune=0:enable-overlays=1:scd=1:scm=0",
|
|
||||||
'-pix_fmt', 'yuv420p10le']
|
|
||||||
|
|
||||||
|
|
||||||
# -c:v:0 libvpx-vp9 -row-mt 1 -crf 32 -pass 1 -speed 4 -frame-parallel 0 -g 9999 -aq-mode 0
|
|
||||||
def generateVP9Pass1Tokens(self, quality, subIndex : int = 0):
|
|
||||||
|
|
||||||
return [f"-c:v:{int(subIndex)}",
|
|
||||||
'libvpx-vp9',
|
|
||||||
'-row-mt', '1',
|
|
||||||
'-crf', str(quality),
|
|
||||||
'-pass', '1',
|
|
||||||
'-speed', '4',
|
|
||||||
'-frame-parallel', '0',
|
|
||||||
'-g', '9999',
|
|
||||||
'-aq-mode', '0']
|
|
||||||
|
|
||||||
# -c:v:0 libvpx-vp9 -row-mt 1 -crf 32 -pass 2 -frame-parallel 0 -g 9999 -aq-mode 0 -auto-alt-ref 1 -lag-in-frames 25
|
|
||||||
def generateVP9Pass2Tokens(self, quality, subIndex : int = 0):
|
|
||||||
|
|
||||||
return [f"-c:v:{int(subIndex)}",
|
|
||||||
'libvpx-vp9',
|
|
||||||
'-row-mt', '1',
|
|
||||||
'-crf', str(quality),
|
|
||||||
'-pass', '2',
|
|
||||||
'-frame-parallel', '0',
|
|
||||||
'-g', '9999',
|
|
||||||
'-aq-mode', '0',
|
|
||||||
'-auto-alt-ref', '1',
|
|
||||||
'-lag-in-frames', '25']
|
|
||||||
|
|
||||||
|
|
||||||
def generateCropTokens(self):
|
|
||||||
|
|
||||||
if 'crop_start' in self.__context.keys() and 'crop_length' in self.__context.keys():
|
|
||||||
cropStart = int(self.__context['crop_start'])
|
|
||||||
cropLength = int(self.__context['crop_length'])
|
|
||||||
else:
|
|
||||||
cropStart = FfxController.DEFAULT_CROP_START
|
|
||||||
cropLength = FfxController.DEFAULT_CROP_LENGTH
|
|
||||||
|
|
||||||
return ['-ss', str(cropStart), '-t', str(cropLength)]
|
|
||||||
|
|
||||||
|
|
||||||
def generateDenoiseTokens(self, spatial=5, patch=7, research=7, hw=False):
|
|
||||||
filterName = 'nlmeans_opencl' if hw else 'nlmeans'
|
|
||||||
return ['-vf', f"{filterName}=s={spatial}:p={patch}:r={research}"]
|
|
||||||
|
|
||||||
|
|
||||||
def generateOutputTokens(self, filepath, format, ext):
|
|
||||||
outputFilePath = f"{filepath}.{ext}"
|
|
||||||
return ['-f', format, outputFilePath]
|
|
||||||
|
|
||||||
|
|
||||||
def generateAudioEncodingTokens(self):
|
|
||||||
"""Generates ffmpeg options audio streams including channel remapping, codec and bitrate"""
|
|
||||||
|
|
||||||
audioTokens = []
|
|
||||||
|
|
||||||
#sourceAudioTrackDescriptors = [smd for smd in self.__sourceMediaDescriptor.getAllTrackDescriptors() if smd.getType() == TrackType.AUDIO]
|
|
||||||
# targetAudioTrackDescriptors = [rtd for rtd in self.__targetMediaDescriptor.getReorderedTrackDescriptors() if rtd.getType() == TrackType.AUDIO]
|
|
||||||
targetAudioTrackDescriptors = [td for td in self.__targetMediaDescriptor.getAllTrackDescriptors() if td.getType() == TrackType.AUDIO]
|
|
||||||
|
|
||||||
trackSubIndex = 0
|
|
||||||
for trackDescriptor in targetAudioTrackDescriptors:
|
|
||||||
|
|
||||||
# Calculate source sub index
|
|
||||||
#changedTargetTrackDescriptor : TrackDescriptor = targetAudioTrackDescriptors[trackDescriptor.getIndex()]
|
|
||||||
#changedTargetTrackSourceIndex = changedTargetTrackDescriptor.getSourceIndex()
|
|
||||||
#sourceSubIndex = sourceAudioTrackDescriptors[changedTargetTrackSourceIndex].getSubIndex()
|
|
||||||
|
|
||||||
trackAudioLayout = trackDescriptor.getAudioLayout()
|
|
||||||
|
|
||||||
#TODO: Sollte nicht die sub index unverändert bleiben wenn jellyfin reordering angewendet wurde?
|
|
||||||
# siehe auch: MediaDescriptor.getInputMappingTokens()
|
|
||||||
#trackSubIndex = trackDescriptor.getSubIndex()
|
|
||||||
|
|
||||||
if trackAudioLayout == AudioLayout.LAYOUT_6_1:
|
|
||||||
audioTokens += [f"-c:a:{trackSubIndex}",
|
|
||||||
'libopus',
|
|
||||||
f"-filter:a:{trackSubIndex}",
|
|
||||||
'channelmap=channel_layout=6.1',
|
|
||||||
f"-b:a:{trackSubIndex}",
|
|
||||||
self.__context['bitrates']['dts']]
|
|
||||||
|
|
||||||
if trackAudioLayout == AudioLayout.LAYOUT_5_1:
|
|
||||||
audioTokens += [f"-c:a:{trackSubIndex}",
|
|
||||||
'libopus',
|
|
||||||
f"-filter:a:{trackSubIndex}",
|
|
||||||
f"channelmap={FfxController.CHANNEL_MAP_5_1}",
|
|
||||||
f"-b:a:{trackSubIndex}",
|
|
||||||
self.__context['bitrates']['ac3']]
|
|
||||||
|
|
||||||
if trackAudioLayout == AudioLayout.LAYOUT_STEREO:
|
|
||||||
audioTokens += [f"-c:a:{trackSubIndex}",
|
|
||||||
'libopus',
|
|
||||||
f"-b:a:{trackSubIndex}",
|
|
||||||
self.__context['bitrates']['stereo']]
|
|
||||||
|
|
||||||
if trackAudioLayout == AudioLayout.LAYOUT_6CH:
|
|
||||||
audioTokens += [f"-c:a:{trackSubIndex}",
|
|
||||||
'libopus',
|
|
||||||
f"-filter:a:{trackSubIndex}",
|
|
||||||
f"channelmap={FfxController.CHANNEL_MAP_5_1}",
|
|
||||||
f"-b:a:{trackSubIndex}",
|
|
||||||
self.__context['bitrates']['ac3']]
|
|
||||||
trackSubIndex += 1
|
|
||||||
return audioTokens
|
|
||||||
|
|
||||||
|
|
||||||
# -disposition:s:0 default -disposition:s:1 0
|
|
||||||
def generateDispositionTokens(self):
|
|
||||||
|
|
||||||
# sourceTrackDescriptors = [] if self.__sourceMediaDescriptor is None else self.__sourceMediaDescriptor.getAllTrackDescriptors()
|
|
||||||
targetTrackDescriptors = self.__targetMediaDescriptor.getAllTrackDescriptors()
|
|
||||||
|
|
||||||
dispositionTokens = []
|
|
||||||
|
|
||||||
# raise click.ClickException(f"ttd subindices: {[t.getSubIndex() for t in targetTrackDescriptors]}")
|
|
||||||
|
|
||||||
#TODO: Sorting here is for the sole purpose to let the tokens appear with ascending subindices. Why necessary? Jellyfin order?
|
|
||||||
# for trackDescriptor in sorted(targetTrackDescriptors.copy(), key=lambda d: d.getSubIndex()):
|
|
||||||
for trackDescriptor in targetTrackDescriptors:
|
|
||||||
|
|
||||||
#HINT: No dispositions for pgs subtitle tracks that have no external file source
|
|
||||||
if (trackDescriptor.getExternalSourceFilePath()
|
|
||||||
or trackDescriptor.getCodec() != TrackDescriptor.CODEC_PGS):
|
|
||||||
|
|
||||||
subIndex = trackDescriptor.getSubIndex()
|
|
||||||
streamIndicator = trackDescriptor.getType().indicator()
|
|
||||||
dispositionSet = trackDescriptor.getDispositionSet()
|
|
||||||
|
|
||||||
if dispositionSet:
|
|
||||||
dispositionTokens += [f"-disposition:{streamIndicator}:{subIndex}", '+'.join([d.label() for d in dispositionSet])]
|
|
||||||
else:
|
|
||||||
dispositionTokens += [f"-disposition:{streamIndicator}:{subIndex}", '0']
|
|
||||||
|
|
||||||
return dispositionTokens
|
|
||||||
|
|
||||||
|
|
||||||
# def generateMetadataTokens(self):
|
|
||||||
# """Source media descriptor is mandatory"""
|
|
||||||
#
|
|
||||||
# metadataTokens = []
|
|
||||||
#
|
|
||||||
# # click.echo(f"source media descriptor: track indices={[d.getIndex() for d in sourceMediaDescriptor.getAllTrackDescriptors()]}")
|
|
||||||
# # click.echo(f"target media descriptor: track indices={[d.getIndex() for d in targetMediaDescriptor.getAllTrackDescriptors()]}")
|
|
||||||
#
|
|
||||||
# # +jellyfin -jellyfin
|
|
||||||
# mediaDifferences = self.__targetMediaDescriptor.compare(self.__sourceMediaDescriptor)
|
|
||||||
#
|
|
||||||
# # media diff {'tracks': {'changed': {4: {'tags': {'added': {'Yolo'}}}}}}
|
|
||||||
#
|
|
||||||
# click.echo(f"media diff {mediaDifferences}")
|
|
||||||
#
|
|
||||||
# if MediaDescriptor.TAGS_KEY in mediaDifferences.keys():
|
|
||||||
#
|
|
||||||
# sourceTags = self.__sourceMediaDescriptor.getTags()
|
|
||||||
# targetTags = self.__targetMediaDescriptor.getTags()
|
|
||||||
#
|
|
||||||
# #TODO: Warum erscheint nur -1 im output?
|
|
||||||
# if DIFF_REMOVED_KEY in mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
# # for removedTagKey in mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
# # row = (f"removed media tag: key='{removedTagKey}' value='{sourceTags[removedTagKey]}'",)
|
|
||||||
# # self.differencesTable.add_row(*map(str, row))
|
|
||||||
# pass
|
|
||||||
# #metadataTokens += [f"-map_metadata:g", "-1"]
|
|
||||||
#
|
|
||||||
# #for targetMediaTagKey in targetTags:
|
|
||||||
# #metadataTokens += [f"-metadata:g", f"{targetMediaTagKey}={targetTags[targetMediaTagKey]}"]
|
|
||||||
#
|
|
||||||
# else:
|
|
||||||
#
|
|
||||||
# if DIFF_ADDED_KEY in mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
# for addedTagKey in mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
# # row = (f"added media tag: key='{addedTagKey}' value='{targetTags[addedTagKey]}'",)
|
|
||||||
# click.echo(f"added metadata key='{addedTagKey}' value='{targetTags[addedTagKey]}'->'{targetTags[addedTagKey]}'")
|
|
||||||
# # self.differencesTable.add_row(*map(str, row))
|
|
||||||
# #pass
|
|
||||||
# metadataTokens += [f"-metadata:g", f"{addedTagKey}={targetTags[addedTagKey]}"]
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# if DIFF_CHANGED_KEY in mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
# for changedTagKey in mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_CHANGED_KEY]:
|
|
||||||
# #row = (f"changed media tag: key='{changedTagKey}' value='{sourceTags[changedTagKey]}'->'{targetTags[changedTagKey]}'",)
|
|
||||||
# click.echo(f"changed metadata key='{changedTagKey}' value='{sourceTags[changedTagKey]}'->'{targetTags[changedTagKey]}'")
|
|
||||||
# # self.differencesTable.add_row(*map(str, row))
|
|
||||||
# #pass
|
|
||||||
# metadataTokens += [f"-metadata:g", f"{changedTagKey}={targetTags[changedTagKey]}"]
|
|
||||||
#
|
|
||||||
# if MediaDescriptor.TRACKS_KEY in mediaDifferences.keys():
|
|
||||||
#
|
|
||||||
# sourceTrackDescriptors = self.__sourceMediaDescriptor.getAllTrackDescriptors()
|
|
||||||
# targetTrackDescriptors = self.__targetMediaDescriptor.getReorderedTrackDescriptors()
|
|
||||||
#
|
|
||||||
# if DIFF_ADDED_KEY in mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
# addedTracksIndices = mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY]
|
|
||||||
# raise click.ClickException(f"FfxController.generateMetadataTokens(): Adding tracks is not supported. Track indices {addedTracksIndices}")
|
|
||||||
#
|
|
||||||
# #raise click.ClickException(f"add track {mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY]}")
|
|
||||||
# #for addedTrackIndex in mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
# #addedTrack : Track = targetTrackDescriptors[addedTrackIndex]
|
|
||||||
# # row = (f"added {addedTrack.getType().label()} track: index={addedTrackIndex} lang={addedTrack.getLanguage().threeLetter()}",)
|
|
||||||
# # self.differencesTable.add_row(*map(str, row))
|
|
||||||
#
|
|
||||||
# if DIFF_REMOVED_KEY in mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
# removedTracksIndices = mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY].keys()
|
|
||||||
# raise click.ClickException(f"FfxController.generateMetadataTokens(): Removing tracks is not supported. Track indices {removedTracksIndices}")
|
|
||||||
# #for removedTrackIndex in mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
# # row = (f"removed track: index={removedTrackIndex}",)
|
|
||||||
# # self.differencesTable.add_row(*map(str, row))
|
|
||||||
#
|
|
||||||
# # media diff {'tracks': {'changed': {4: {'tags': {'added': {'Yolo'}}}}}}
|
|
||||||
# if DIFF_CHANGED_KEY in mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
# for changedTrackIndex in mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_CHANGED_KEY].keys():
|
|
||||||
#
|
|
||||||
# changedTargetTrackDescriptor : TrackDescriptor = targetTrackDescriptors[changedTrackIndex]
|
|
||||||
# changedTargetTrackSourceIndex = changedTargetTrackDescriptor.getSourceIndex()
|
|
||||||
# changedTargetSourceSubIndex = sourceTrackDescriptors[changedTargetTrackSourceIndex].getSubIndex()
|
|
||||||
# # changedSourceTrackDescriptor : TrackDescriptor = sourceTrackDescriptors[changedTargetTrackSourceIndex]
|
|
||||||
# # changedSourceTrackSubIndex = changedSourceTrackDescriptor.getSubIndex()
|
|
||||||
#
|
|
||||||
# changedTrackDiff : dict = mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_CHANGED_KEY][changedTrackIndex]
|
|
||||||
#
|
|
||||||
# if MediaDescriptor.TAGS_KEY in changedTrackDiff.keys():
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# if DIFF_REMOVED_KEY in changedTrackDiff[MediaDescriptor.TAGS_KEY]:
|
|
||||||
# #for removedTagKey in changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
# # row = (f"changed {changedTargetTrackDescriptor.getType().label()} track index={changedTrackIndex} removed key={removedTagKey}",)
|
|
||||||
# # self.differencesTable.add_row(*map(str, row))
|
|
||||||
#
|
|
||||||
# #addedTagValue = targetTrackDescriptors[changedTargetTrackSourceIndex].getTags()[addedTagKey]
|
|
||||||
#
|
|
||||||
# metadataTokens += [f"-map_metadata:s:{changedTargetTrackDescriptor.getType().indicator()}:{changedTargetSourceSubIndex}", "-1"]
|
|
||||||
#
|
|
||||||
# for targetTrackTagKey, targetTrackTagValue in changedTargetTrackDescriptor.getTags():
|
|
||||||
# metadataTokens += [f"-metadata:s:{changedTargetTrackDescriptor.getType().indicator()}:{changedTargetSourceSubIndex}",
|
|
||||||
# f"{targetTrackTagKey}={targetTrackTagValue}"]
|
|
||||||
#
|
|
||||||
# else:
|
|
||||||
#
|
|
||||||
# # media diff {'tracks': {'changed': {4: {'tags': {'added': {'Yolo'}}}}}}
|
|
||||||
# if DIFF_ADDED_KEY in changedTrackDiff[MediaDescriptor.TAGS_KEY]:
|
|
||||||
# for addedTagKey in changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
#
|
|
||||||
# addedTagValue = targetTrackDescriptors[changedTargetTrackSourceIndex].getTags()[addedTagKey]
|
|
||||||
#
|
|
||||||
# # addedTagValue = changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY][addedTagKey]
|
|
||||||
#
|
|
||||||
# # click.echo(f"addedTagValue={addedTagValue}")
|
|
||||||
# # click.echo(f"sourceTrackDescriptors: subindex={[s.getSubIndex() for s in sourceTrackDescriptors]} sourceindex={[s.getSourceIndex() for s in sourceTrackDescriptors]} tags={[s.getTags() for s in sourceTrackDescriptors]}")
|
|
||||||
# # click.echo(f"targetTrackDescriptors: subindex={[t.getSubIndex() for t in targetTrackDescriptors]} sourceindex={[t.getSourceIndex() for t in targetTrackDescriptors]} tags={[t.getTags() for t in targetTrackDescriptors]}")
|
|
||||||
# # click.echo(f"changed track_index={changedTrackIndex} indicator={changedTargetTrackDescriptor.getType().indicator()} key={addedTagKey} value={addedTagValue} source_index={changedSourceTrackIndex}")
|
|
||||||
#
|
|
||||||
# metadataTokens += [f"-metadata:s:{changedTargetTrackDescriptor.getType().indicator()}:{changedTargetSourceSubIndex}",
|
|
||||||
# f"{addedTagKey}={addedTagValue}"]
|
|
||||||
#
|
|
||||||
# # media diff {'tracks': {'changed': {4: {'tags': {'added': {'Yolo'}}}}}}
|
|
||||||
# if DIFF_CHANGED_KEY in changedTrackDiff[MediaDescriptor.TAGS_KEY]:
|
|
||||||
# for changedTagKey in changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_CHANGED_KEY]:
|
|
||||||
#
|
|
||||||
# changedTagValue = targetTrackDescriptors[changedTargetTrackSourceIndex].getTags()[changedTagKey]
|
|
||||||
# # sourceSubIndex = sourceTrackDescriptors[changedTargetTrackSourceIndex].getSubIndex()
|
|
||||||
# # addedTagValue = changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY][addedTagKey]
|
|
||||||
#
|
|
||||||
# # click.echo(f"addedTagValue={addedTagValue}")
|
|
||||||
# # click.echo(f"sourceTrackDescriptors: subindex={[s.getSubIndex() for s in sourceTrackDescriptors]} sourceindex={[s.getSourceIndex() for s in sourceTrackDescriptors]} tags={[s.getTags() for s in sourceTrackDescriptors]}")
|
|
||||||
# # click.echo(f"targetTrackDescriptors: subindex={[t.getSubIndex() for t in targetTrackDescriptors]} sourceindex={[t.getSourceIndex() for t in targetTrackDescriptors]} tags={[t.getTags() for t in targetTrackDescriptors]}")
|
|
||||||
# # click.echo(f"changed track_index={changedTrackIndex} indicator={changedTargetTrackDescriptor.getType().indicator()} key={addedTagKey} value={addedTagValue} source_index={changedSourceTrackIndex}")
|
|
||||||
#
|
|
||||||
# metadataTokens += [f"-metadata:s:{changedTargetTrackDescriptor.getType().indicator()}:{changedTargetSourceSubIndex}",
|
|
||||||
# f"{changedTagKey}={changedTagValue}"]
|
|
||||||
#
|
|
||||||
# # if TrackDescriptor.DISPOSITION_SET_KEY in changedTrackDiff.keys():
|
|
||||||
#
|
|
||||||
# # if DIFF_ADDED_KEY in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY]:
|
|
||||||
# # for addedDisposition in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY][DIFF_ADDED_KEY]:
|
|
||||||
# # # row = (f"changed {changedTargetTrackDescriptor.getType().label()} track index={changedTrackIndex} added disposition={addedDisposition.label()}",)
|
|
||||||
# # # self.differencesTable.add_row(*map(str, row))
|
|
||||||
# # pass
|
|
||||||
#
|
|
||||||
# # if DIFF_REMOVED_KEY in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY]:
|
|
||||||
# # for removedDisposition in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
# # # row = (f"changed {changedTargetTrackDescriptor.getType().label()} track index={changedTrackIndex} removed disposition={removedDisposition.label()}",)
|
|
||||||
# # # self.differencesTable.add_row(*map(str, row))
|
|
||||||
# # pass
|
|
||||||
|
|
||||||
# return metadataTokens
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generateMetadataTokens(self):
|
|
||||||
|
|
||||||
metadataTokens = []
|
|
||||||
|
|
||||||
for tagKey, tagValue in self.__targetMediaDescriptor.getTags().items():
|
|
||||||
metadataTokens += [f"-metadata:g",
|
|
||||||
f"{tagKey}={tagValue}"]
|
|
||||||
|
|
||||||
#HINT: With current ffmpeg version track metadata tags are not passed to the outfile
|
|
||||||
for td in self.__targetMediaDescriptor.getAllTrackDescriptors():
|
|
||||||
|
|
||||||
for tagKey, tagValue in td.getTags().items():
|
|
||||||
|
|
||||||
metadataTokens += [f"-metadata:s:{td.getType().indicator()}:{td.getSubIndex()}",
|
|
||||||
f"{tagKey}={tagValue}"]
|
|
||||||
|
|
||||||
return metadataTokens
|
|
||||||
|
|
||||||
|
|
||||||
def runJob(self,
|
|
||||||
sourcePath,
|
|
||||||
targetPath,
|
|
||||||
videoEncoder: VideoEncoder = VideoEncoder.VP9,
|
|
||||||
quality: int = DEFAULT_QUALITY,
|
|
||||||
preset: int = DEFAULT_AV1_PRESET,
|
|
||||||
denoise: bool = False):
|
|
||||||
|
|
||||||
|
|
||||||
commandTokens = FfxController.COMMAND_TOKENS + ['-i', sourcePath]
|
|
||||||
|
|
||||||
if videoEncoder == VideoEncoder.AV1:
|
|
||||||
|
|
||||||
commandSequence = (commandTokens
|
|
||||||
+ self.__targetMediaDescriptor.getImportFileTokens()
|
|
||||||
+ self.__targetMediaDescriptor.getInputMappingTokens()
|
|
||||||
+ self.generateDispositionTokens())
|
|
||||||
|
|
||||||
if not self.__sourceMediaDescriptor is None:
|
|
||||||
commandSequence += self.generateMetadataTokens()
|
|
||||||
|
|
||||||
if denoise:
|
|
||||||
commandSequence += self.generateDenoiseTokens()
|
|
||||||
|
|
||||||
commandSequence += (self.generateAudioEncodingTokens()
|
|
||||||
+ self.generateAV1Tokens(int(quality), int(preset))
|
|
||||||
+ self.generateAudioEncodingTokens())
|
|
||||||
|
|
||||||
if self.__context['perform_crop']:
|
|
||||||
commandSequence += FfxController.generateCropTokens()
|
|
||||||
|
|
||||||
commandSequence += self.generateOutputTokens(targetPath,
|
|
||||||
FfxController.DEFAULT_FILE_FORMAT,
|
|
||||||
FfxController.DEFAULT_FILE_EXTENSION)
|
|
||||||
|
|
||||||
click.echo(f"Command: {' '.join(commandSequence)}")
|
|
||||||
|
|
||||||
if not self.__context['dry_run']:
|
|
||||||
executeProcess(commandSequence)
|
|
||||||
|
|
||||||
|
|
||||||
if videoEncoder == VideoEncoder.VP9:
|
|
||||||
|
|
||||||
commandSequence1 = (commandTokens
|
|
||||||
+ self.__targetMediaDescriptor.getInputMappingTokens(only_video=True)
|
|
||||||
+ self.generateVP9Pass1Tokens(int(quality)))
|
|
||||||
|
|
||||||
if self.__context['perform_crop']:
|
|
||||||
commandSequence1 += self.generateCropTokens()
|
|
||||||
|
|
||||||
commandSequence1 += FfxController.NULL_TOKENS
|
|
||||||
|
|
||||||
click.echo(f"Command 1: {' '.join(commandSequence1)}")
|
|
||||||
|
|
||||||
if os.path.exists(FfxController.TEMP_FILE_NAME):
|
|
||||||
os.remove(FfxController.TEMP_FILE_NAME)
|
|
||||||
|
|
||||||
if not self.__context['dry_run']:
|
|
||||||
executeProcess(commandSequence1)
|
|
||||||
|
|
||||||
commandSequence2 = (commandTokens
|
|
||||||
+ self.__targetMediaDescriptor.getImportFileTokens()
|
|
||||||
+ self.__targetMediaDescriptor.getInputMappingTokens()
|
|
||||||
+ self.generateDispositionTokens())
|
|
||||||
|
|
||||||
if not self.__sourceMediaDescriptor is None:
|
|
||||||
commandSequence2 += self.generateMetadataTokens()
|
|
||||||
|
|
||||||
if denoise:
|
|
||||||
commandSequence2 += self.generateDenoiseTokens()
|
|
||||||
|
|
||||||
commandSequence2 += self.generateVP9Pass2Tokens(int(quality)) + self.generateAudioEncodingTokens()
|
|
||||||
|
|
||||||
if self.__context['perform_crop']:
|
|
||||||
commandSequence2 += self.generateCropTokens()
|
|
||||||
|
|
||||||
commandSequence2 += self.generateOutputTokens(targetPath,
|
|
||||||
FfxController.DEFAULT_FILE_FORMAT,
|
|
||||||
FfxController.DEFAULT_FILE_EXTENSION)
|
|
||||||
|
|
||||||
click.echo(f"Command 2: {' '.join(commandSequence2)}")
|
|
||||||
|
|
||||||
if not self.__context['dry_run']:
|
|
||||||
out, err, rc = executeProcess(commandSequence2)
|
|
||||||
if rc:
|
|
||||||
raise click.ClickException(f"Command resulted in error: rc={rc} error={err}")
|
|
||||||
|
|
||||||
|
|||||||
2
bin/ffx/file_pattern.py
Normal file
2
bin/ffx/file_pattern.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class FilePattern():
|
||||||
|
pass
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
import os, re, click, json
|
|
||||||
|
|
||||||
from .media_descriptor import MediaDescriptor
|
|
||||||
from .pattern_controller import PatternController
|
|
||||||
|
|
||||||
from .process import executeProcess
|
|
||||||
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
from ffx.ffx_controller import FfxController
|
|
||||||
from ffx.show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
class FileProperties():
|
|
||||||
|
|
||||||
FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm']
|
|
||||||
|
|
||||||
SEASON_EPISODE_INDICATOR_MATCH = '[sS]([0-9]+)[eE]([0-9]+)'
|
|
||||||
EPISODE_INDICATOR_MATCH = '[eE]([0-9]+)'
|
|
||||||
|
|
||||||
DEFAULT_INDEX_DIGITS = 3
|
|
||||||
|
|
||||||
def __init__(self, context, sourcePath):
|
|
||||||
|
|
||||||
self.context = context
|
|
||||||
|
|
||||||
# Separate basedir, basename and extension for current source file
|
|
||||||
self.__sourcePath = sourcePath
|
|
||||||
|
|
||||||
self.__sourceDirectory = os.path.dirname(self.__sourcePath)
|
|
||||||
self.__sourceFilename = os.path.basename(self.__sourcePath)
|
|
||||||
|
|
||||||
sourcePathTokens = self.__sourceFilename.split('.')
|
|
||||||
|
|
||||||
if sourcePathTokens[-1] in FileProperties.FILE_EXTENSIONS:
|
|
||||||
self.__sourceFileBasename = '.'.join(sourcePathTokens[:-1])
|
|
||||||
self.__sourceFilenameExtension = sourcePathTokens[-1]
|
|
||||||
else:
|
|
||||||
self.__sourceFileBasename = self.__sourceFilename
|
|
||||||
self.__sourceFilenameExtension = ''
|
|
||||||
|
|
||||||
|
|
||||||
self.__pc = PatternController(context)
|
|
||||||
|
|
||||||
matchResult = self.__pc.matchFilename(self.__sourceFilename)
|
|
||||||
|
|
||||||
self.__pattern: Pattern = matchResult['pattern'] if matchResult else None
|
|
||||||
|
|
||||||
matchedGroups = matchResult['match'].groups() if matchResult else {}
|
|
||||||
seIndicator = matchedGroups[0] if matchedGroups else self.__sourceFilename
|
|
||||||
|
|
||||||
se_match = re.search(FileProperties.SEASON_EPISODE_INDICATOR_MATCH, seIndicator)
|
|
||||||
e_match = re.search(FileProperties.EPISODE_INDICATOR_MATCH, seIndicator)
|
|
||||||
|
|
||||||
self.__season = -1
|
|
||||||
self.__episode = -1
|
|
||||||
|
|
||||||
if se_match is not None:
|
|
||||||
self.__season = int(se_match.group(1))
|
|
||||||
self.__episode = int(se_match.group(2))
|
|
||||||
elif e_match is not None:
|
|
||||||
self.__episode = int(e_match.group(1))
|
|
||||||
|
|
||||||
|
|
||||||
def getFormatData(self):
|
|
||||||
"""
|
|
||||||
"format": {
|
|
||||||
"filename": "Downloads/nagatoro_s02/nagatoro_s01e02.mkv",
|
|
||||||
"nb_streams": 18,
|
|
||||||
"nb_programs": 0,
|
|
||||||
"nb_stream_groups": 0,
|
|
||||||
"format_name": "matroska,webm",
|
|
||||||
"format_long_name": "Matroska / WebM",
|
|
||||||
"start_time": "0.000000",
|
|
||||||
"duration": "1420.063000",
|
|
||||||
"size": "1489169824",
|
|
||||||
"bit_rate": "8389316",
|
|
||||||
"probe_score": 100,
|
|
||||||
"tags": {
|
|
||||||
"PUBLISHER": "Crunchyroll",
|
|
||||||
"ENCODER": "Lavf58.29.100"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
ffprobeOutput, ffprobeError, returnCode = executeProcess(["ffprobe",
|
|
||||||
"-hide_banner",
|
|
||||||
"-show_format",
|
|
||||||
"-of", "json",
|
|
||||||
self.__sourcePath])
|
|
||||||
|
|
||||||
|
|
||||||
if 'Invalid data found when processing input' in ffprobeError:
|
|
||||||
raise Exception(f"File {self.__sourcePath} does not contain valid stream data")
|
|
||||||
|
|
||||||
|
|
||||||
if returnCode != 0:
|
|
||||||
raise Exception(f"ffprobe returned with error {returnCode}")
|
|
||||||
|
|
||||||
|
|
||||||
return json.loads(ffprobeOutput)['format']
|
|
||||||
|
|
||||||
#[{'index': 0, 'codec_name': 'vp9', 'codec_long_name': 'Google VP9', 'profile': 'Profile 0', 'codec_type': 'video', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'width': 1920, 'height': 1080, 'coded_width': 1920, 'coded_height': 1080, 'closed_captions': 0, 'film_grain': 0, 'has_b_frames': 0, 'sample_aspect_ratio': '1:1', 'display_aspect_ratio': '16:9', 'pix_fmt': 'yuv420p', 'level': -99, 'color_range': 'tv', 'chroma_location': 'left', 'field_order': 'progressive', 'refs': 1, 'r_frame_rate': '24000/1001', 'avg_frame_rate': '24000/1001', 'time_base': '1/1000', 'start_pts': 0, 'start_time': '0.000000', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0, 'non_diegetic': 0, 'captions': 0, 'descriptions': 0, 'metadata': 0, 'dependent': 0, 'still_image': 0}, 'tags': {'BPS': '7974017', 'NUMBER_OF_FRAMES': '34382', 'NUMBER_OF_BYTES': '1429358655', '_STATISTICS_WRITING_APP': "mkvmerge v63.0.0 ('Everything') 64-bit", '_STATISTICS_WRITING_DATE_UTC': '2023-10-07 13:59:46', '_STATISTICS_TAGS': 'BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES', 'ENCODER': 'Lavc61.3.100 libvpx-vp9', 'DURATION': '00:23:54.016000000'}}]
|
|
||||||
#[{'index': 1, 'codec_name': 'opus', 'codec_long_name': 'Opus (Opus Interactive Audio Codec)', 'codec_type': 'audio', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'sample_fmt': 'fltp', 'sample_rate': '48000', 'channels': 2, 'channel_layout': 'stereo', 'bits_per_sample': 0, 'initial_padding': 312, 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/1000', 'start_pts': -7, 'start_time': '-0.007000', 'extradata_size': 19, 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0, 'non_diegetic': 0, 'captions': 0, 'descriptions': 0, 'metadata': 0, 'dependent': 0, 'still_image': 0}, 'tags': {'language': 'jpn', 'title': 'Japanisch', 'BPS': '128000', 'NUMBER_OF_FRAMES': '61763', 'NUMBER_OF_BYTES': '22946145', '_STATISTICS_WRITING_APP': "mkvmerge v63.0.0 ('Everything') 64-bit", '_STATISTICS_WRITING_DATE_UTC': '2023-10-07 13:59:46', '_STATISTICS_TAGS': 'BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES', 'ENCODER': 'Lavc61.3.100 libopus', 'DURATION': '00:23:54.141000000'}}]
|
|
||||||
|
|
||||||
#[{'index': 2, 'codec_name': 'webvtt', 'codec_long_name': 'WebVTT subtitle', 'codec_type': 'subtitle', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/1000', 'start_pts': -7, 'start_time': '-0.007000', 'duration_ts': 1434141, 'duration': '1434.141000', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0, 'non_diegetic': 0, 'captions': 0, 'descriptions': 0, 'metadata': 0, 'dependent': 0, 'still_image': 0}, 'tags': {'language': 'ger', 'title': 'Deutsch [Full]', 'BPS': '118', 'NUMBER_OF_FRAMES': '300', 'NUMBER_OF_BYTES': '21128', '_STATISTICS_WRITING_APP': "mkvmerge v63.0.0 ('Everything') 64-bit", '_STATISTICS_WRITING_DATE_UTC': '2023-10-07 13:59:46', '_STATISTICS_TAGS': 'BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES', 'ENCODER': 'Lavc61.3.100 webvtt', 'DURATION': '00:23:54.010000000'}}, {'index': 3, 'codec_name': 'webvtt', 'codec_long_name': 'WebVTT subtitle', 'codec_type': 'subtitle', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/1000', 'start_pts': -7, 'start_time': '-0.007000', 'duration_ts': 1434141, 'duration': '1434.141000', 'disposition': {'default': 0, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0, 'non_diegetic': 0, 'captions': 0, 'descriptions': 0, 'metadata': 0, 'dependent': 0, 'still_image': 0}, 'tags': {'language': 'eng', 'title': 'Englisch [Full]', 'BPS': '101', 'NUMBER_OF_FRAMES': '276', 'NUMBER_OF_BYTES': '16980', '_STATISTICS_WRITING_APP': "mkvmerge v63.0.0 ('Everything') 64-bit", '_STATISTICS_WRITING_DATE_UTC': '2023-10-07 13:59:46', '_STATISTICS_TAGS': 'BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES', 'ENCODER': 'Lavc61.3.100 webvtt', 'DURATION': '00:23:53.230000000'}}]
|
|
||||||
|
|
||||||
|
|
||||||
def getStreamData(self):
|
|
||||||
"""Returns ffprobe stream data as array with elements according to the following example
|
|
||||||
{
|
|
||||||
"index": 4,
|
|
||||||
"codec_name": "hdmv_pgs_subtitle",
|
|
||||||
"codec_long_name": "HDMV Presentation Graphic Stream subtitles",
|
|
||||||
"codec_type": "subtitle",
|
|
||||||
"codec_tag_string": "[0][0][0][0]",
|
|
||||||
"codec_tag": "0x0000",
|
|
||||||
"r_frame_rate": "0/0",
|
|
||||||
"avg_frame_rate": "0/0",
|
|
||||||
"time_base": "1/1000",
|
|
||||||
"start_pts": 0,
|
|
||||||
"start_time": "0.000000",
|
|
||||||
"duration_ts": 1421035,
|
|
||||||
"duration": "1421.035000",
|
|
||||||
"disposition": {
|
|
||||||
"default": 1,
|
|
||||||
"dub": 0,
|
|
||||||
"original": 0,
|
|
||||||
"comment": 0,
|
|
||||||
"lyrics": 0,
|
|
||||||
"karaoke": 0,
|
|
||||||
"forced": 0,
|
|
||||||
"hearing_impaired": 0,
|
|
||||||
"visual_impaired": 0,
|
|
||||||
"clean_effects": 0,
|
|
||||||
"attached_pic": 0,
|
|
||||||
"timed_thumbnails": 0,
|
|
||||||
"non_diegetic": 0,
|
|
||||||
"captions": 0,
|
|
||||||
"descriptions": 0,
|
|
||||||
"metadata": 0,
|
|
||||||
"dependent": 0,
|
|
||||||
"still_image": 0
|
|
||||||
},
|
|
||||||
"tags": {
|
|
||||||
"language": "ger",
|
|
||||||
"title": "German Full"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
ffprobeOutput, ffprobeError, returnCode = executeProcess(["ffprobe",
|
|
||||||
"-hide_banner",
|
|
||||||
"-show_streams",
|
|
||||||
"-of", "json",
|
|
||||||
self.__sourcePath])
|
|
||||||
|
|
||||||
if 'Invalid data found when processing input' in ffprobeError:
|
|
||||||
raise Exception(f"File {self.__sourcePath} does not contain valid stream data")
|
|
||||||
|
|
||||||
|
|
||||||
if returnCode != 0:
|
|
||||||
raise Exception(f"ffprobe returned with error {returnCode}")
|
|
||||||
|
|
||||||
|
|
||||||
return json.loads(ffprobeOutput)['streams']
|
|
||||||
|
|
||||||
|
|
||||||
def getMediaDescriptor(self):
|
|
||||||
return MediaDescriptor.fromFfprobe(self.getFormatData(), self.getStreamData())
|
|
||||||
|
|
||||||
|
|
||||||
def getShowId(self) -> int:
|
|
||||||
"""Result is -1 if the filename did not match anything in database"""
|
|
||||||
return self.__pattern.getShowId() if self.__pattern is not None else -1
|
|
||||||
|
|
||||||
def getPattern(self) -> Pattern:
|
|
||||||
"""Result is None if the filename did not match anything in database"""
|
|
||||||
return self.__pattern
|
|
||||||
|
|
||||||
|
|
||||||
def getSeason(self):
|
|
||||||
return int(self.__season)
|
|
||||||
|
|
||||||
def getEpisode(self):
|
|
||||||
return int(self.__episode)
|
|
||||||
|
|
||||||
|
|
||||||
def getFilename(self):
|
|
||||||
return self.__sourceFilename
|
|
||||||
|
|
||||||
def getFileBasename(self):
|
|
||||||
return self.__sourceFileBasename
|
|
||||||
|
|
||||||
|
|
||||||
def assembleTargetFileBasename(self,
|
|
||||||
label: str = "",
|
|
||||||
quality: int = -1,
|
|
||||||
fileIndex: int = -1,
|
|
||||||
indexDigits: int = DEFAULT_INDEX_DIGITS,
|
|
||||||
extraTokens: list = []):
|
|
||||||
|
|
||||||
if 'show_descriptor' in self.context.keys():
|
|
||||||
season_digits = self.context['show_descriptor'][ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY]
|
|
||||||
episode_digits = self.context['show_descriptor'][ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY]
|
|
||||||
else:
|
|
||||||
season_digits = ShowDescriptor.DEFAULT_INDICATOR_SEASON_DIGITS
|
|
||||||
episode_digits = ShowDescriptor.DEFAULT_INDICATOR_EPISODE_DIGITS
|
|
||||||
|
|
||||||
targetFilenameTokens = []
|
|
||||||
|
|
||||||
# targetFilenameExtension = FfxController.DEFAULT_FILE_EXTENSION if extension is None else str(extension)
|
|
||||||
|
|
||||||
if not label:
|
|
||||||
targetFilenameTokens = [self.__sourceFileBasename]
|
|
||||||
else:
|
|
||||||
targetFilenameTokens = [label]
|
|
||||||
|
|
||||||
if fileIndex > -1:
|
|
||||||
targetFilenameTokens += [f"{fileIndex:0{indexDigits}d}"]
|
|
||||||
elif self.__season > -1 and self.__episode > -1:
|
|
||||||
targetFilenameTokens += [f"S{self.__season:0{season_digits}d}E{self.__episode:0{episode_digits}d}"]
|
|
||||||
elif self.__episode > -1:
|
|
||||||
targetFilenameTokens += [f"E{self.__episode:0{episode_digits}d}"]
|
|
||||||
|
|
||||||
if quality != -1:
|
|
||||||
targetFilenameTokens += [f"q{quality}"]
|
|
||||||
|
|
||||||
# In case source and target filenames are the same add an extension to distinct output from input
|
|
||||||
#if not label and self.__sourceFilenameExtension == targetFilenameExtension:
|
|
||||||
# targetFilenameTokens += ['ffx']
|
|
||||||
targetFilenameTokens += extraTokens
|
|
||||||
|
|
||||||
targetFilename = '_'.join(targetFilenameTokens)
|
|
||||||
|
|
||||||
click.echo(f"Target filename: {targetFilename}")
|
|
||||||
|
|
||||||
return targetFilename
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Placeholder, Label
|
|
||||||
|
|
||||||
class HelpScreen(Screen):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
context = self.app.getContext()
|
|
||||||
def compose(self) -> ComposeResult:
|
|
||||||
yield Placeholder("Help Screen")
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
DIFF_ADDED_KEY = 'added'
|
|
||||||
DIFF_REMOVED_KEY = 'removed'
|
|
||||||
DIFF_CHANGED_KEY = 'changed'
|
|
||||||
DIFF_UNCHANGED_KEY = 'unchanged'
|
|
||||||
|
|
||||||
def dictDiff(a : dict, b : dict):
|
|
||||||
|
|
||||||
a_keys = set(a.keys())
|
|
||||||
b_keys = set(b.keys())
|
|
||||||
|
|
||||||
a_only = a_keys - b_keys
|
|
||||||
b_only = b_keys - a_keys
|
|
||||||
a_b = a_keys & b_keys
|
|
||||||
|
|
||||||
changed = {k for k in a_b if a[k] != b[k]}
|
|
||||||
|
|
||||||
diffResult = {}
|
|
||||||
|
|
||||||
|
|
||||||
if a_only:
|
|
||||||
diffResult[DIFF_REMOVED_KEY] = a_only
|
|
||||||
diffResult[DIFF_UNCHANGED_KEY] = b_keys
|
|
||||||
if b_only:
|
|
||||||
diffResult[DIFF_ADDED_KEY] = b_only
|
|
||||||
if changed:
|
|
||||||
diffResult[DIFF_CHANGED_KEY] = changed
|
|
||||||
|
|
||||||
return diffResult
|
|
||||||
|
|
||||||
|
|
||||||
def setDiff(a : set, b : set) -> set:
|
|
||||||
|
|
||||||
a_only = a - b
|
|
||||||
b_only = b - a
|
|
||||||
|
|
||||||
diffResult = {}
|
|
||||||
|
|
||||||
if a_only:
|
|
||||||
diffResult[DIFF_REMOVED_KEY] = a_only
|
|
||||||
if b_only:
|
|
||||||
diffResult[DIFF_ADDED_KEY] = b_only
|
|
||||||
|
|
||||||
return diffResult
|
|
||||||
|
|
||||||
def filterFilename(fileName: str) -> str:
|
|
||||||
fileName = str(fileName).replace(':', ';')
|
|
||||||
return fileName
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
class IsoLanguage(Enum):
|
class LanguageData(Enum):
|
||||||
|
|
||||||
AFRIKAANS = {"name": "Afrikaans", "iso639_1": "af", "iso639_2": "afr"}
|
AFRIKAANS = {"name": "Afrikaans", "iso639_1": "af", "iso639_2": "afr"}
|
||||||
ALBANIAN = {"name": "Albanian", "iso639_1": "sq", "iso639_2": "alb"}
|
ALBANIAN = {"name": "Albanian", "iso639_1": "sq", "iso639_2": "alb"}
|
||||||
@@ -73,34 +73,21 @@ class IsoLanguage(Enum):
|
|||||||
VIETNAMESE = {"name": "Vietnamese", "iso639_1": "vi", "iso639_2": "vie"}
|
VIETNAMESE = {"name": "Vietnamese", "iso639_1": "vi", "iso639_2": "vie"}
|
||||||
WELSH = {"name": "Welsh", "iso639_1": "cy", "iso639_2": "wel"}
|
WELSH = {"name": "Welsh", "iso639_1": "cy", "iso639_2": "wel"}
|
||||||
|
|
||||||
UNDEFINED = {"name": "undefined", "iso639_1": "xx", "iso639_2": "und"}
|
def find(name : str):
|
||||||
|
|
||||||
|
closestMatches = difflib.get_close_matches(name, [l.value["name"] for l in LanguageData], n=1)
|
||||||
|
|
||||||
@staticmethod
|
if closestMatches:
|
||||||
def find(label : str):
|
foundLangs = [l for l in LanguageData if l.value['name'] == closestMatches[0]]
|
||||||
|
return foundLangs[0] if foundLangs else None
|
||||||
closestMatches = difflib.get_close_matches(label, [l.value["name"] for l in IsoLanguage], n=1)
|
else:
|
||||||
|
return None
|
||||||
if closestMatches:
|
|
||||||
foundLangs = [l for l in IsoLanguage if l.value['name'] == closestMatches[0]]
|
|
||||||
return foundLangs[0] if foundLangs else IsoLanguage.UNDEFINED
|
|
||||||
else:
|
|
||||||
return IsoLanguage.UNDEFINED
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def findThreeLetter(theeLetter : str):
|
|
||||||
foundLangs = [l for l in IsoLanguage if l.value['iso639_2'] == str(theeLetter)]
|
|
||||||
return foundLangs[0] if foundLangs else IsoLanguage.UNDEFINED
|
|
||||||
|
|
||||||
|
|
||||||
def label(self):
|
|
||||||
return str(self.value['name'])
|
|
||||||
|
|
||||||
def twoLetter(self):
|
|
||||||
return str(self.value['iso639_1'])
|
|
||||||
|
|
||||||
def threeLetter(self):
|
|
||||||
return str(self.value['iso639_2'])
|
|
||||||
|
|
||||||
|
def get(lang : str):
|
||||||
|
|
||||||
|
selectedLangs = [l for l in LanguageData if l.value['iso639_2'] == lang]
|
||||||
|
|
||||||
|
if selectedLangs:
|
||||||
|
return selectedLangs[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
@@ -1,429 +0,0 @@
|
|||||||
import os
|
|
||||||
import re
|
|
||||||
import click
|
|
||||||
|
|
||||||
from typing import List, Self
|
|
||||||
|
|
||||||
from ffx.track_type import TrackType
|
|
||||||
from ffx.track_disposition import TrackDisposition
|
|
||||||
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
from ffx.helper import dictDiff, DIFF_ADDED_KEY, DIFF_CHANGED_KEY, DIFF_REMOVED_KEY
|
|
||||||
|
|
||||||
|
|
||||||
class MediaDescriptor:
|
|
||||||
"""This class represents the structural content of a media file including streams and metadata"""
|
|
||||||
|
|
||||||
CONTEXT_KEY = "context"
|
|
||||||
|
|
||||||
TAGS_KEY = "tags"
|
|
||||||
TRACKS_KEY = "tracks"
|
|
||||||
|
|
||||||
TRACK_DESCRIPTOR_LIST_KEY = "track_descriptors"
|
|
||||||
CLEAR_TAGS_FLAG_KEY = "clear_tags"
|
|
||||||
|
|
||||||
FFPROBE_DISPOSITION_KEY = "disposition"
|
|
||||||
FFPROBE_TAGS_KEY = "tags"
|
|
||||||
FFPROBE_CODEC_TYPE_KEY = "codec_type"
|
|
||||||
|
|
||||||
JELLYFIN_ORDER_FLAG_KEY = "jellyfin_order"
|
|
||||||
|
|
||||||
EXCLUDED_MEDIA_TAGS = ["creation_time"]
|
|
||||||
|
|
||||||
SEASON_EPISODE_STREAM_LANGUAGE_MATCH = '[sS]([0-9]+)[eE]([0-9]+)_([0-9]+)_([a-z]{3})'
|
|
||||||
SUBTITLE_FILE_EXTENSION = 'vtt'
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
|
|
||||||
if MediaDescriptor.TAGS_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[MediaDescriptor.TAGS_KEY]) is not dict:
|
|
||||||
raise TypeError(
|
|
||||||
f"MediaDescriptor.__init__(): Argument {MediaDescriptor.TAGS_KEY} is required to be of type dict"
|
|
||||||
)
|
|
||||||
self.__mediaTags = kwargs[MediaDescriptor.TAGS_KEY]
|
|
||||||
else:
|
|
||||||
self.__mediaTags = {}
|
|
||||||
|
|
||||||
if MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY in kwargs.keys():
|
|
||||||
if (
|
|
||||||
type(kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY]) is not list
|
|
||||||
): # Use List typehint for TrackDescriptor as well if it works
|
|
||||||
raise TypeError(
|
|
||||||
f"MediaDescriptor.__init__(): Argument {MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY} is required to be of type list"
|
|
||||||
)
|
|
||||||
for d in kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY]:
|
|
||||||
if type(d) is not TrackDescriptor:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): All elements of argument list {MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY} are required to be of type TrackDescriptor"
|
|
||||||
)
|
|
||||||
self.__trackDescriptors = kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY]
|
|
||||||
else:
|
|
||||||
self.__trackDescriptors = []
|
|
||||||
|
|
||||||
if MediaDescriptor.JELLYFIN_ORDER_FLAG_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[MediaDescriptor.JELLYFIN_ORDER_FLAG_KEY]) is not bool:
|
|
||||||
raise TypeError(
|
|
||||||
f"MediaDescriptor.__init__(): Argument {MediaDescriptor.JELLYFIN_ORDER_FLAG_KEY} is required to be of type bool"
|
|
||||||
)
|
|
||||||
self.__jellyfinOrder = kwargs[MediaDescriptor.JELLYFIN_ORDER_FLAG_KEY]
|
|
||||||
else:
|
|
||||||
self.__jellyfinOrder = False
|
|
||||||
|
|
||||||
|
|
||||||
def setDefaultSubTrack(self, trackType: TrackType, subIndex: int):
|
|
||||||
for t in self.getAllTrackDescriptors():
|
|
||||||
if t.getType() == trackType:
|
|
||||||
t.setDispositionFlag(
|
|
||||||
TrackDisposition.DEFAULT, t.getSubIndex() == int(subIndex)
|
|
||||||
)
|
|
||||||
|
|
||||||
def setForcedSubTrack(self, trackType: TrackType, subIndex: int):
|
|
||||||
for t in self.getAllTrackDescriptors():
|
|
||||||
if t.getType() == trackType:
|
|
||||||
t.setDispositionFlag(
|
|
||||||
TrackDisposition.FORCED, t.getSubIndex() == int(subIndex)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def checkConfiguration(self):
|
|
||||||
|
|
||||||
videoTracks = self.getVideoTracks()
|
|
||||||
audioTracks = self.getAudioTracks()
|
|
||||||
subtitleTracks = self.getSubtitleTracks()
|
|
||||||
|
|
||||||
if len([v for v in videoTracks if v.getDispositionFlag(TrackDisposition.DEFAULT)]) > 1:
|
|
||||||
raise ValueError('More than one default video track')
|
|
||||||
if len([a for a in audioTracks if a.getDispositionFlag(TrackDisposition.DEFAULT)]) > 1:
|
|
||||||
raise ValueError('More than one default audio track')
|
|
||||||
if len([s for s in subtitleTracks if s.getDispositionFlag(TrackDisposition.DEFAULT)]) > 1:
|
|
||||||
raise ValueError('More than one default subtitle track')
|
|
||||||
|
|
||||||
if len([v for v in videoTracks if v.getDispositionFlag(TrackDisposition.FORCED)]) > 1:
|
|
||||||
raise ValueError('More than one forced video track')
|
|
||||||
if len([a for a in audioTracks if a.getDispositionFlag(TrackDisposition.FORCED)]) > 1:
|
|
||||||
raise ValueError('More than one forced audio track')
|
|
||||||
if len([s for s in subtitleTracks if s.getDispositionFlag(TrackDisposition.FORCED)]) > 1:
|
|
||||||
raise ValueError('More than one forced subtitle track')
|
|
||||||
|
|
||||||
trackDescriptors = videoTracks + audioTracks + subtitleTracks
|
|
||||||
sourceIndices = [
|
|
||||||
t.getSourceIndex() for t in trackDescriptors
|
|
||||||
]
|
|
||||||
if len(set(sourceIndices)) < len(trackDescriptors):
|
|
||||||
raise ValueError('Multiple streams originating from the same source stream')
|
|
||||||
|
|
||||||
|
|
||||||
def applyJellyfinOrder(self):
|
|
||||||
"""Reorder subtracks in types with default the last, then make subindices flat again"""
|
|
||||||
|
|
||||||
# videoTracks = self.sortSubIndices(self.getVideoTracks())
|
|
||||||
# audioTracks = self.sortSubIndices(self.getAudioTracks())
|
|
||||||
# subtitleTracks = self.sortSubIndices(self.getSubtitleTracks())
|
|
||||||
|
|
||||||
self.checkConfiguration()
|
|
||||||
|
|
||||||
# from self.__trackDescriptors
|
|
||||||
videoTracks = self.getVideoTracks()
|
|
||||||
audioTracks = self.getAudioTracks()
|
|
||||||
subtitleTracks = self.getSubtitleTracks()
|
|
||||||
|
|
||||||
defaultVideoTracks = [v for v in videoTracks if v.getDispositionFlag(TrackDisposition.DEFAULT)]
|
|
||||||
defaultAudioTracks = [a for a in audioTracks if a.getDispositionFlag(TrackDisposition.DEFAULT)]
|
|
||||||
defaultSubtitleTracks = [s for s in subtitleTracks if s.getDispositionFlag(TrackDisposition.DEFAULT)]
|
|
||||||
|
|
||||||
if defaultVideoTracks:
|
|
||||||
videoTracks.append(videoTracks.pop(videoTracks.index(defaultVideoTracks[0])))
|
|
||||||
self.sortSubIndices(videoTracks)
|
|
||||||
if defaultAudioTracks:
|
|
||||||
audioTracks.append(audioTracks.pop(audioTracks.index(defaultAudioTracks[0])))
|
|
||||||
self.sortSubIndices(audioTracks)
|
|
||||||
if defaultSubtitleTracks:
|
|
||||||
subtitleTracks.append(subtitleTracks.pop(subtitleTracks.index(defaultSubtitleTracks[0])))
|
|
||||||
self.sortSubIndices(subtitleTracks)
|
|
||||||
|
|
||||||
self.__trackDescriptors = videoTracks + audioTracks + subtitleTracks
|
|
||||||
self.sortIndices(self.__trackDescriptors)
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fromFfprobe(cls, formatData, streamData):
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
if MediaDescriptor.FFPROBE_TAGS_KEY in formatData.keys():
|
|
||||||
kwargs[MediaDescriptor.TAGS_KEY] = formatData[
|
|
||||||
MediaDescriptor.FFPROBE_TAGS_KEY
|
|
||||||
]
|
|
||||||
|
|
||||||
kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY] = []
|
|
||||||
|
|
||||||
# TODO: Evtl obsolet
|
|
||||||
subIndexCounters = {}
|
|
||||||
|
|
||||||
for streamObj in streamData:
|
|
||||||
|
|
||||||
ffprobeCodecType = streamObj[MediaDescriptor.FFPROBE_CODEC_TYPE_KEY]
|
|
||||||
trackType = TrackType.fromLabel(ffprobeCodecType)
|
|
||||||
|
|
||||||
if trackType != TrackType.UNKNOWN:
|
|
||||||
|
|
||||||
if trackType not in subIndexCounters.keys():
|
|
||||||
subIndexCounters[trackType] = 0
|
|
||||||
|
|
||||||
kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY].append(
|
|
||||||
TrackDescriptor.fromFfprobe(
|
|
||||||
streamObj, subIndex=subIndexCounters[trackType]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
subIndexCounters[trackType] += 1
|
|
||||||
|
|
||||||
return cls(**kwargs)
|
|
||||||
|
|
||||||
def getTags(self):
|
|
||||||
return self.__mediaTags
|
|
||||||
|
|
||||||
|
|
||||||
def sortSubIndices(
|
|
||||||
self, descriptors: List[TrackDescriptor]
|
|
||||||
) -> List[TrackDescriptor]:
|
|
||||||
subIndex = 0
|
|
||||||
for d in descriptors:
|
|
||||||
d.setSubIndex(subIndex)
|
|
||||||
subIndex += 1
|
|
||||||
return descriptors
|
|
||||||
|
|
||||||
def sortIndices(
|
|
||||||
self, descriptors: List[TrackDescriptor]
|
|
||||||
) -> List[TrackDescriptor]:
|
|
||||||
index = 0
|
|
||||||
for d in descriptors:
|
|
||||||
d.setIndex(index)
|
|
||||||
index += 1
|
|
||||||
return descriptors
|
|
||||||
|
|
||||||
|
|
||||||
def getAllTrackDescriptors(self) -> List[TrackDescriptor]:
|
|
||||||
return self.getVideoTracks() + self.getAudioTracks() + self.getSubtitleTracks()
|
|
||||||
|
|
||||||
def getVideoTracks(self) -> List[TrackDescriptor]:
|
|
||||||
return [
|
|
||||||
v for v in self.__trackDescriptors if v.getType() == TrackType.VIDEO
|
|
||||||
]
|
|
||||||
|
|
||||||
def getAudioTracks(self) -> List[TrackDescriptor]:
|
|
||||||
return [
|
|
||||||
a for a in self.__trackDescriptors if a.getType() == TrackType.AUDIO
|
|
||||||
]
|
|
||||||
|
|
||||||
def getSubtitleTracks(self) -> List[TrackDescriptor]:
|
|
||||||
return [
|
|
||||||
s
|
|
||||||
for s in self.__trackDescriptors
|
|
||||||
if s.getType() == TrackType.SUBTITLE
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def compare(self, vsMediaDescriptor: Self):
|
|
||||||
|
|
||||||
if not isinstance(vsMediaDescriptor, self.__class__):
|
|
||||||
raise click.ClickException(
|
|
||||||
f"MediaDescriptor.compare(): Argument is required to be of type {self.__class__}"
|
|
||||||
)
|
|
||||||
|
|
||||||
vsTags = vsMediaDescriptor.getTags()
|
|
||||||
tags = self.getTags()
|
|
||||||
|
|
||||||
# tags ist leer
|
|
||||||
# click.echo(f"tags={tags} vsTags={vsTags}")
|
|
||||||
# raise click.Abort
|
|
||||||
|
|
||||||
# HINT: Some tags differ per file, for example creation_time, so these are removed before diff
|
|
||||||
for emt in MediaDescriptor.EXCLUDED_MEDIA_TAGS:
|
|
||||||
if emt in tags.keys():
|
|
||||||
del tags[emt]
|
|
||||||
if emt in vsTags.keys():
|
|
||||||
del vsTags[emt]
|
|
||||||
|
|
||||||
tagsDiff = dictDiff(vsTags, tags)
|
|
||||||
|
|
||||||
compareResult = {}
|
|
||||||
|
|
||||||
if tagsDiff:
|
|
||||||
compareResult[MediaDescriptor.TAGS_KEY] = tagsDiff
|
|
||||||
|
|
||||||
# Target track configuration (from DB)
|
|
||||||
# tracks = self.getAllTrackDescriptors()
|
|
||||||
tracks = self.getAllTrackDescriptors() # filtern
|
|
||||||
numTracks = len(tracks)
|
|
||||||
|
|
||||||
# Current track configuration (of file)
|
|
||||||
vsTracks = vsMediaDescriptor.getAllTrackDescriptors()
|
|
||||||
numVsTracks = len(vsTracks)
|
|
||||||
|
|
||||||
maxNumOfTracks = max(numVsTracks, numTracks)
|
|
||||||
|
|
||||||
trackCompareResult = {}
|
|
||||||
|
|
||||||
for tp in range(maxNumOfTracks):
|
|
||||||
|
|
||||||
# inspect/update funktionier nur so
|
|
||||||
if self.__jellyfinOrder:
|
|
||||||
vsTrackIndex = tracks[tp].getSourceIndex()
|
|
||||||
else:
|
|
||||||
vsTrackIndex = tp
|
|
||||||
# vsTrackIndex = tracks[tp].getSourceIndex()
|
|
||||||
|
|
||||||
# Will trigger if tracks are missing in file
|
|
||||||
if tp > (numVsTracks - 1):
|
|
||||||
if DIFF_ADDED_KEY not in trackCompareResult.keys():
|
|
||||||
trackCompareResult[DIFF_ADDED_KEY] = set()
|
|
||||||
trackCompareResult[DIFF_ADDED_KEY].add(tracks[tp].getIndex())
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Will trigger if tracks are missing in DB definition
|
|
||||||
# New tracks will be added per update via this way
|
|
||||||
if tp > (numTracks - 1):
|
|
||||||
if DIFF_REMOVED_KEY not in trackCompareResult.keys():
|
|
||||||
trackCompareResult[DIFF_REMOVED_KEY] = {}
|
|
||||||
trackCompareResult[DIFF_REMOVED_KEY][
|
|
||||||
vsTracks[vsTrackIndex].getIndex()
|
|
||||||
] = vsTracks[vsTrackIndex]
|
|
||||||
continue
|
|
||||||
|
|
||||||
# assumption is made here that the track order will not change for all files of a sequence
|
|
||||||
trackDiff = tracks[tp].compare(vsTracks[vsTrackIndex])
|
|
||||||
|
|
||||||
if trackDiff:
|
|
||||||
if DIFF_CHANGED_KEY not in trackCompareResult.keys():
|
|
||||||
trackCompareResult[DIFF_CHANGED_KEY] = {}
|
|
||||||
trackCompareResult[DIFF_CHANGED_KEY][
|
|
||||||
vsTracks[vsTrackIndex].getIndex()
|
|
||||||
] = trackDiff
|
|
||||||
|
|
||||||
if trackCompareResult:
|
|
||||||
compareResult[MediaDescriptor.TRACKS_KEY] = trackCompareResult
|
|
||||||
|
|
||||||
return compareResult
|
|
||||||
|
|
||||||
def getImportFileTokens(self, use_sub_index: bool = True):
|
|
||||||
|
|
||||||
# reorderedTrackDescriptors = self.getReorderedTrackDescriptors()
|
|
||||||
importFileTokens = []
|
|
||||||
|
|
||||||
#for rtd in reorderedTrackDescriptors:
|
|
||||||
for td in self.__trackDescriptors:
|
|
||||||
|
|
||||||
importedFilePath = td.getExternalSourceFilePath()
|
|
||||||
|
|
||||||
if importedFilePath:
|
|
||||||
importFileTokens += [
|
|
||||||
"-i",
|
|
||||||
importedFilePath,
|
|
||||||
]
|
|
||||||
|
|
||||||
return importFileTokens
|
|
||||||
|
|
||||||
|
|
||||||
def getInputMappingTokens(self, use_sub_index: bool = True, only_video: bool = False):
|
|
||||||
|
|
||||||
# reorderedTrackDescriptors = self.getReorderedTrackDescriptors()
|
|
||||||
inputMappingTokens = []
|
|
||||||
|
|
||||||
filePointer = 1
|
|
||||||
#for rtd in reorderedTrackDescriptors:
|
|
||||||
for td in self.__trackDescriptors:
|
|
||||||
|
|
||||||
trackType = td.getType()
|
|
||||||
|
|
||||||
if (trackType == TrackType.VIDEO or not only_video):
|
|
||||||
|
|
||||||
importedFilePath = td.getExternalSourceFilePath()
|
|
||||||
|
|
||||||
if use_sub_index:
|
|
||||||
|
|
||||||
if importedFilePath:
|
|
||||||
|
|
||||||
inputMappingTokens += [
|
|
||||||
"-map",
|
|
||||||
f"{filePointer}:{trackType.indicator()}:0",
|
|
||||||
]
|
|
||||||
filePointer += 1
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
if td.getCodec() != TrackDescriptor.CODEC_PGS:
|
|
||||||
inputMappingTokens += [
|
|
||||||
"-map",
|
|
||||||
f"0:{trackType.indicator()}:{td.getSubIndex()}",
|
|
||||||
]
|
|
||||||
|
|
||||||
else:
|
|
||||||
if td.getCodec() != TrackDescriptor.CODEC_PGS:
|
|
||||||
inputMappingTokens += ["-map", f"0:{td.getIndex()}"]
|
|
||||||
|
|
||||||
return inputMappingTokens
|
|
||||||
|
|
||||||
def searchSubtitleFiles(self, searchDirectory, prefix):
|
|
||||||
|
|
||||||
sesl_match = re.compile(MediaDescriptor.SEASON_EPISODE_STREAM_LANGUAGE_MATCH)
|
|
||||||
|
|
||||||
subtitleFileDescriptors = []
|
|
||||||
for subtitleFilename in os.listdir(searchDirectory):
|
|
||||||
if subtitleFilename.startswith(prefix) and subtitleFilename.endswith(
|
|
||||||
"." + MediaDescriptor.SUBTITLE_FILE_EXTENSION
|
|
||||||
):
|
|
||||||
sesl_result = sesl_match.search(subtitleFilename)
|
|
||||||
if sesl_result is not None:
|
|
||||||
subtitleFilePath = os.path.join(searchDirectory, subtitleFilename)
|
|
||||||
if os.path.isfile(subtitleFilePath):
|
|
||||||
|
|
||||||
subtitleFileDescriptor = {}
|
|
||||||
subtitleFileDescriptor["path"] = subtitleFilePath
|
|
||||||
subtitleFileDescriptor["season"] = int(sesl_result.group(1))
|
|
||||||
subtitleFileDescriptor["episode"] = int(sesl_result.group(2))
|
|
||||||
subtitleFileDescriptor["index"] = int(sesl_result.group(3))
|
|
||||||
subtitleFileDescriptor["language"] = sesl_result.group(4)
|
|
||||||
|
|
||||||
subtitleFileDescriptors.append(subtitleFileDescriptor)
|
|
||||||
|
|
||||||
click.echo(f"Available subtitle files {subtitleFileDescriptors}\n")
|
|
||||||
|
|
||||||
return subtitleFileDescriptors
|
|
||||||
|
|
||||||
|
|
||||||
def importSubtitles(self, searchDirectory, prefix, season: int = -1, episode: int = -1):
|
|
||||||
|
|
||||||
click.echo(f"Season: {season} Episode: {episode}")
|
|
||||||
|
|
||||||
availableFileSubtitleDescriptors = self.searchSubtitleFiles(searchDirectory, prefix)
|
|
||||||
|
|
||||||
click.echo(f"availableFileSubtitleDescriptors: {availableFileSubtitleDescriptors}")
|
|
||||||
|
|
||||||
subtitleTracks = self.getSubtitleTracks()
|
|
||||||
|
|
||||||
click.echo(f"subtitleTracks: {[s.getIndex() for s in subtitleTracks]}")
|
|
||||||
|
|
||||||
# if len(availableFileSubtitleDescriptors) != len(subtitleTracks):
|
|
||||||
# raise click.ClickException(f"MediaDescriptor.importSubtitles(): Number if subtitle files not matching number of subtitle tracks")
|
|
||||||
|
|
||||||
matchingSubtitleFileDescriptors = (
|
|
||||||
sorted(
|
|
||||||
[
|
|
||||||
d
|
|
||||||
for d in availableFileSubtitleDescriptors
|
|
||||||
if d["season"] == int(season) and d["episode"] == int(episode)
|
|
||||||
],
|
|
||||||
key=lambda d: d["index"],
|
|
||||||
)
|
|
||||||
if availableFileSubtitleDescriptors
|
|
||||||
else []
|
|
||||||
)
|
|
||||||
|
|
||||||
click.echo(f"matchingSubtitleFileDescriptors: {matchingSubtitleFileDescriptors}")
|
|
||||||
|
|
||||||
for msfd in matchingSubtitleFileDescriptors:
|
|
||||||
matchingSubtitleTrackDescriptor = [s for s in subtitleTracks if s.getIndex() == msfd["index"]]
|
|
||||||
if matchingSubtitleTrackDescriptor:
|
|
||||||
click.echo(f"Found matching subtitle file {msfd["path"]}\n")
|
|
||||||
matchingSubtitleTrackDescriptor[0].setExternalSourceFilePath(msfd["path"])
|
|
||||||
@@ -1,644 +0,0 @@
|
|||||||
import os, click, re
|
|
||||||
|
|
||||||
from textual import events
|
|
||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button, Input, DataTable
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from ffx.model.show import Show
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
|
|
||||||
from .pattern_controller import PatternController
|
|
||||||
from .show_controller import ShowController
|
|
||||||
from .track_controller import TrackController
|
|
||||||
from .tag_controller import TagController
|
|
||||||
|
|
||||||
from .track_details_screen import TrackDetailsScreen
|
|
||||||
from .track_delete_screen import TrackDeleteScreen
|
|
||||||
from .show_details_screen import ShowDetailsScreen
|
|
||||||
from .pattern_details_screen import PatternDetailsScreen
|
|
||||||
|
|
||||||
from ffx.track_type import TrackType
|
|
||||||
from ffx.model.track import Track
|
|
||||||
|
|
||||||
from ffx.track_disposition import TrackDisposition
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
from ffx.show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
from textual.widgets._data_table import CellDoesNotExist
|
|
||||||
|
|
||||||
from ffx.media_descriptor import MediaDescriptor
|
|
||||||
from ffx.file_properties import FileProperties
|
|
||||||
|
|
||||||
from ffx.helper import DIFF_ADDED_KEY, DIFF_CHANGED_KEY, DIFF_REMOVED_KEY
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class MediaDetailsScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 5 8;
|
|
||||||
grid-rows: 8 2 2 2 8 2 2 8;
|
|
||||||
grid-columns: 25 25 100 10 75;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataTable {
|
|
||||||
min-height: 40;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
.five {
|
|
||||||
column-span: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.triple {
|
|
||||||
row-span: 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
|
|
||||||
.yellow {
|
|
||||||
tint: yellow 40%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#differences-table {
|
|
||||||
row-span: 8;
|
|
||||||
/* tint: magenta 40%; */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* #pattern_input {
|
|
||||||
tint: red 40%;
|
|
||||||
}*/
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
BINDINGS = [
|
|
||||||
("n", "new_pattern", "New Pattern"),
|
|
||||||
("u", "update_pattern", "Update Pattern"),
|
|
||||||
("e", "edit_pattern", "Edit Pattern"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__pc = PatternController(context = self.context)
|
|
||||||
self.__sc = ShowController(context = self.context)
|
|
||||||
self.__tc = TrackController(context = self.context)
|
|
||||||
self.__tac = TagController(context = self.context)
|
|
||||||
|
|
||||||
if not 'command' in self.context.keys() or self.context['command'] != 'inspect':
|
|
||||||
raise click.ClickException(f"MediaDetailsScreen.__init__(): Can only perform command 'inspect'")
|
|
||||||
|
|
||||||
if not 'arguments' in self.context.keys() or not 'filename' in self.context['arguments'].keys() or not self.context['arguments']['filename']:
|
|
||||||
raise click.ClickException(f"MediaDetailsScreen.__init__(): Argument 'filename' is required to be provided for command 'inspect'")
|
|
||||||
|
|
||||||
self.__mediaFilename = self.context['arguments']['filename']
|
|
||||||
|
|
||||||
if not os.path.isfile(self.__mediaFilename):
|
|
||||||
raise click.ClickException(f"MediaDetailsScreen.__init__(): Media file {self.__mediaFilename} does not exist")
|
|
||||||
|
|
||||||
self.loadProperties()
|
|
||||||
|
|
||||||
|
|
||||||
def getRowIndexFromShowId(self, showId : int) -> int:
|
|
||||||
"""Find the index of the row where the value in the specified column matches the target_value."""
|
|
||||||
|
|
||||||
for rowKey, row in self.showsTable.rows.items(): # dict[RowKey, Row]
|
|
||||||
|
|
||||||
rowData = self.showsTable.get_row(rowKey)
|
|
||||||
|
|
||||||
try:
|
|
||||||
if showId == int(rowData[0]):
|
|
||||||
return int(self.showsTable.get_row_index(rowKey))
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def loadProperties(self):
|
|
||||||
|
|
||||||
self.__mediaFileProperties = FileProperties(self.context, self.__mediaFilename)
|
|
||||||
self.__currentMediaDescriptor = self.__mediaFileProperties.getMediaDescriptor()
|
|
||||||
|
|
||||||
#HINT: This is None if the filename did not match anything in database
|
|
||||||
self.__currentPattern = self.__mediaFileProperties.getPattern()
|
|
||||||
|
|
||||||
# keine tags vorhanden
|
|
||||||
self.__targetMediaDescriptor = self.__currentPattern.getMediaDescriptor() if self.__currentPattern is not None else None
|
|
||||||
|
|
||||||
# Enumerating differences between media descriptors
|
|
||||||
# from file (=current) vs from stored in database (=target)
|
|
||||||
try:
|
|
||||||
self.__mediaDifferences = self.__targetMediaDescriptor.compare(self.__currentMediaDescriptor) if self.__currentPattern is not None else {}
|
|
||||||
except ValueError:
|
|
||||||
self.__mediaDifferences = {}
|
|
||||||
|
|
||||||
|
|
||||||
def updateDifferences(self):
|
|
||||||
|
|
||||||
self.loadProperties()
|
|
||||||
|
|
||||||
self.differencesTable.clear()
|
|
||||||
|
|
||||||
if MediaDescriptor.TAGS_KEY in self.__mediaDifferences.keys():
|
|
||||||
|
|
||||||
currentTags = self.__currentMediaDescriptor.getTags()
|
|
||||||
targetTags = self.__targetMediaDescriptor.getTags()
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in self.__mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
for addedTagKey in self.__mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
row = (f"added media tag: key='{addedTagKey}' value='{targetTags[addedTagKey]}'",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in self.__mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
for removedTagKey in self.__mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
row = (f"removed media tag: key='{removedTagKey}' value='{currentTags[removedTagKey]}'",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if DIFF_CHANGED_KEY in self.__mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
for changedTagKey in self.__mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_CHANGED_KEY]:
|
|
||||||
row = (f"changed media tag: key='{changedTagKey}' value='{currentTags[changedTagKey]}'->'{targetTags[changedTagKey]}'",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if MediaDescriptor.TRACKS_KEY in self.__mediaDifferences.keys():
|
|
||||||
|
|
||||||
currentTracks = self.__currentMediaDescriptor.getAllTrackDescriptors() # 0,1,2,3
|
|
||||||
targetTracks = self.__targetMediaDescriptor.getAllTrackDescriptors() # 0 <- from DB
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
|
|
||||||
#raise click.ClickException(f"add track {self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY]}")
|
|
||||||
for addedTrackIndex in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
addedTrack : Track = targetTracks[addedTrackIndex]
|
|
||||||
row = (f"added {addedTrack.getType().label()} track: index={addedTrackIndex} lang={addedTrack.getLanguage().threeLetter()}",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
for removedTrackIndex in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
row = (f"removed track: index={removedTrackIndex}",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if DIFF_CHANGED_KEY in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
for changedTrackIndex in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_CHANGED_KEY].keys():
|
|
||||||
|
|
||||||
changedTrack : Track = targetTracks[changedTrackIndex]
|
|
||||||
changedTrackDiff : dict = self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_CHANGED_KEY][changedTrackIndex]
|
|
||||||
|
|
||||||
if MediaDescriptor.TAGS_KEY in changedTrackDiff.keys():
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in changedTrackDiff[MediaDescriptor.TAGS_KEY]:
|
|
||||||
for addedTagKey in changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
addedTagValue = changedTrack.getTags()[addedTagKey]
|
|
||||||
row = (f"changed {changedTrack.getType().label()} track index={changedTrackIndex} added key={addedTagKey} value={addedTagValue}",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in changedTrackDiff[MediaDescriptor.TAGS_KEY]:
|
|
||||||
for removedTagKey in changedTrackDiff[MediaDescriptor.TAGS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
row = (f"changed {changedTrack.getType().label()} track index={changedTrackIndex} removed key={removedTagKey}",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if TrackDescriptor.DISPOSITION_SET_KEY in changedTrackDiff.keys():
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY]:
|
|
||||||
for addedDisposition in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY][DIFF_ADDED_KEY]:
|
|
||||||
row = (f"changed {changedTrack.getType().label()} track index={changedTrackIndex} added disposition={addedDisposition.label()}",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY]:
|
|
||||||
for removedDisposition in changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
row = (f"changed {changedTrack.getType().label()} track index={changedTrackIndex} removed disposition={removedDisposition.label()}",)
|
|
||||||
self.differencesTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
if self.__currentPattern is None:
|
|
||||||
row = (' ', '<New show>', ' ') # Convert each element to a string before adding
|
|
||||||
self.showsTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
for show in self.__sc.getAllShows():
|
|
||||||
row = (int(show.id), show.name, show.year) # Convert each element to a string before adding
|
|
||||||
self.showsTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
for mediaTagKey, mediaTagValue in self.__currentMediaDescriptor.getTags().items():
|
|
||||||
row = (mediaTagKey, mediaTagValue) # Convert each element to a string before adding
|
|
||||||
self.mediaTagsTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
self.updateTracks()
|
|
||||||
|
|
||||||
|
|
||||||
if self.__currentPattern is not None:
|
|
||||||
|
|
||||||
showIdentifier = self.__currentPattern.getShowId()
|
|
||||||
showRowIndex = self.getRowIndexFromShowId(showIdentifier)
|
|
||||||
if showRowIndex is not None:
|
|
||||||
self.showsTable.move_cursor(row=showRowIndex)
|
|
||||||
|
|
||||||
self.query_one("#pattern_input", Input).value = self.__currentPattern.getPattern()
|
|
||||||
|
|
||||||
self.updateDifferences()
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
self.query_one("#pattern_input", Input).value = self.__mediaFilename
|
|
||||||
self.highlightPattern(True)
|
|
||||||
|
|
||||||
|
|
||||||
def highlightPattern(self, state : bool):
|
|
||||||
if state:
|
|
||||||
self.query_one("#pattern_input", Input).styles.background = 'red'
|
|
||||||
else:
|
|
||||||
self.query_one("#pattern_input", Input).styles.background = None
|
|
||||||
|
|
||||||
|
|
||||||
def updateTracks(self):
|
|
||||||
|
|
||||||
self.tracksTable.clear()
|
|
||||||
|
|
||||||
trackDescriptorList = self.__currentMediaDescriptor.getAllTrackDescriptors()
|
|
||||||
|
|
||||||
typeCounter = {}
|
|
||||||
|
|
||||||
for td in trackDescriptorList:
|
|
||||||
|
|
||||||
trackType = td.getType()
|
|
||||||
if not trackType in typeCounter.keys():
|
|
||||||
typeCounter[trackType] = 0
|
|
||||||
|
|
||||||
dispoSet = td.getDispositionSet()
|
|
||||||
|
|
||||||
row = (td.getIndex(),
|
|
||||||
trackType.label(),
|
|
||||||
typeCounter[trackType],
|
|
||||||
td.getAudioLayout().label() if trackType == TrackType.AUDIO else ' ',
|
|
||||||
td.getLanguage().label(),
|
|
||||||
td.getTitle(),
|
|
||||||
'Yes' if TrackDisposition.DEFAULT in dispoSet else 'No',
|
|
||||||
'Yes' if TrackDisposition.FORCED in dispoSet else 'No')
|
|
||||||
|
|
||||||
self.tracksTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
typeCounter[trackType] += 1
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
# Create the DataTable widget
|
|
||||||
self.showsTable = DataTable(classes="two")
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_show_id = self.showsTable.add_column("ID", width=10)
|
|
||||||
self.column_key_show_name = self.showsTable.add_column("Name", width=50)
|
|
||||||
self.column_key_show_year = self.showsTable.add_column("Year", width=10)
|
|
||||||
|
|
||||||
self.showsTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
|
|
||||||
self.mediaTagsTable = DataTable(classes="two")
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_track_tag_key = self.mediaTagsTable.add_column("Key", width=20)
|
|
||||||
self.column_key_track_tag_value = self.mediaTagsTable.add_column("Value", width=100)
|
|
||||||
|
|
||||||
self.mediaTagsTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
|
|
||||||
self.tracksTable = DataTable(classes="two")
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_track_index = self.tracksTable.add_column("Index", width=5)
|
|
||||||
self.column_key_track_type = self.tracksTable.add_column("Type", width=10)
|
|
||||||
self.column_key_track_sub_index = self.tracksTable.add_column("Subindex", width=5)
|
|
||||||
self.column_key_track_layout = self.tracksTable.add_column("Layout", width=10)
|
|
||||||
self.column_key_track_language = self.tracksTable.add_column("Language", width=15)
|
|
||||||
self.column_key_track_title = self.tracksTable.add_column("Title", width=48)
|
|
||||||
self.column_key_track_default = self.tracksTable.add_column("Default", width=8)
|
|
||||||
self.column_key_track_forced = self.tracksTable.add_column("Forced", width=8)
|
|
||||||
|
|
||||||
self.tracksTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
|
|
||||||
# Create the DataTable widget
|
|
||||||
self.differencesTable = DataTable(id='differences-table') # classes="triple"
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_differences = self.differencesTable.add_column("Differences (file->db)", width=70)
|
|
||||||
|
|
||||||
self.differencesTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
# 1
|
|
||||||
yield Static("Show")
|
|
||||||
yield self.showsTable
|
|
||||||
yield Static(" ")
|
|
||||||
yield self.differencesTable
|
|
||||||
|
|
||||||
# 2
|
|
||||||
yield Static(" ")
|
|
||||||
yield Button("Substitute", id="pattern_button")
|
|
||||||
yield Static(" ", classes="two")
|
|
||||||
|
|
||||||
# 3
|
|
||||||
yield Static("Pattern")
|
|
||||||
yield Input(type="text", id='pattern_input', classes="two")
|
|
||||||
|
|
||||||
yield Static(" ")
|
|
||||||
|
|
||||||
# 4
|
|
||||||
yield Static(" ", classes="four")
|
|
||||||
|
|
||||||
# 5
|
|
||||||
yield Static("Media Tags")
|
|
||||||
yield self.mediaTagsTable
|
|
||||||
yield Static(" ")
|
|
||||||
|
|
||||||
# 6
|
|
||||||
yield Static(" ", classes="four")
|
|
||||||
|
|
||||||
# 7
|
|
||||||
yield Static(" ")
|
|
||||||
yield Button("Set Default", id="select_default_button")
|
|
||||||
yield Button("Set Forced", id="select_forced_button")
|
|
||||||
yield Static(" ")
|
|
||||||
# 8
|
|
||||||
yield Static("Streams")
|
|
||||||
yield self.tracksTable
|
|
||||||
yield Static(" ")
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
def getPatternDescriptorFromInput(self):
|
|
||||||
"""Returns show id and pattern from corresponding inputs"""
|
|
||||||
patternDescriptor = {}
|
|
||||||
try:
|
|
||||||
patternDescriptor['show_id'] = self.getSelectedShowDescriptor().getId()
|
|
||||||
patternDescriptor['pattern'] = str(self.query_one("#pattern_input", Input).value)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return patternDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
if event.button.id == "pattern_button":
|
|
||||||
|
|
||||||
INDICATOR_PATTERN = '([sS][0-9]+[eE][0-9]+)'
|
|
||||||
|
|
||||||
pattern = self.query_one("#pattern_input", Input).value
|
|
||||||
|
|
||||||
patternMatch = re.search(INDICATOR_PATTERN, pattern)
|
|
||||||
|
|
||||||
if patternMatch:
|
|
||||||
self.query_one("#pattern_input", Input).value = pattern.replace(patternMatch.group(1), INDICATOR_PATTERN)
|
|
||||||
|
|
||||||
|
|
||||||
if event.button.id == "select_default_button":
|
|
||||||
selectedTrackDescriptor = self.getSelectedTrackDescriptor()
|
|
||||||
self.__currentMediaDescriptor.setDefaultSubTrack(selectedTrackDescriptor.getType(), selectedTrackDescriptor.getSubIndex())
|
|
||||||
self.updateTracks()
|
|
||||||
|
|
||||||
if event.button.id == "select_forced_button":
|
|
||||||
selectedTrackDescriptor = self.getSelectedTrackDescriptor()
|
|
||||||
self.__currentMediaDescriptor.setForcedSubTrack(selectedTrackDescriptor.getType(), selectedTrackDescriptor.getSubIndex())
|
|
||||||
self.updateTracks()
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedTrackDescriptor(self):
|
|
||||||
"""Returns a partial track descriptor"""
|
|
||||||
try:
|
|
||||||
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.tracksTable.coordinate_to_cell_key(self.tracksTable.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_track_data = self.tracksTable.get_row(row_key)
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.INDEX_KEY] = int(selected_track_data[0])
|
|
||||||
kwargs[TrackDescriptor.TRACK_TYPE_KEY] = TrackType.fromLabel(selected_track_data[1])
|
|
||||||
kwargs[TrackDescriptor.SUB_INDEX_KEY] = int(selected_track_data[2])
|
|
||||||
|
|
||||||
return TrackDescriptor(**kwargs)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedShowDescriptor(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.showsTable.coordinate_to_cell_key(self.showsTable.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_row_data = self.showsTable.get_row(row_key)
|
|
||||||
|
|
||||||
try:
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
kwargs[ShowDescriptor.ID_KEY] = int(selected_row_data[0])
|
|
||||||
kwargs[ShowDescriptor.NAME_KEY] = str(selected_row_data[1])
|
|
||||||
kwargs[ShowDescriptor.YEAR_KEY] = int(selected_row_data[2])
|
|
||||||
|
|
||||||
return ShowDescriptor(**kwargs)
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def handle_new_pattern(self, showDescriptor: ShowDescriptor):
|
|
||||||
|
|
||||||
show = (showDescriptor.getId(), showDescriptor.getName(), showDescriptor.getYear())
|
|
||||||
self.showsTable.add_row(*map(str, show))
|
|
||||||
|
|
||||||
showRowIndex = self.getRowIndexFromShowId(showDescriptor.getId())
|
|
||||||
if showRowIndex is not None:
|
|
||||||
self.showsTable.move_cursor(row=showRowIndex)
|
|
||||||
|
|
||||||
patternDescriptor = self.getPatternDescriptorFromInput()
|
|
||||||
|
|
||||||
if patternDescriptor:
|
|
||||||
patternId = self.__pc.addPattern(patternDescriptor)
|
|
||||||
|
|
||||||
self.highlightPattern(False)
|
|
||||||
|
|
||||||
for tagKey, tagValue in self.__currentMediaDescriptor.getTags().items():
|
|
||||||
self.__tac.updateMediaTag(patternId, tagKey, tagValue)
|
|
||||||
|
|
||||||
for trackDescriptor in self.__currentMediaDescriptor.getAllTrackDescriptors():
|
|
||||||
self.__tc.addTrack(trackDescriptor, patternId = patternId)
|
|
||||||
|
|
||||||
|
|
||||||
def action_new_pattern(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.__currentMediaDescriptor.checkConfiguration()
|
|
||||||
except ValueError:
|
|
||||||
return
|
|
||||||
|
|
||||||
selectedShowDescriptor = self.getSelectedShowDescriptor()
|
|
||||||
|
|
||||||
#HINT: Callback is invoked after this method has exited. As a workaround the callback is executed directly
|
|
||||||
# from here with a mock-up screen result containing the necessary part of keys to perform correctly.
|
|
||||||
if selectedShowDescriptor is None:
|
|
||||||
self.app.push_screen(ShowDetailsScreen(), self.handle_new_pattern)
|
|
||||||
else:
|
|
||||||
self.handle_new_pattern(selectedShowDescriptor)
|
|
||||||
|
|
||||||
|
|
||||||
def action_update_pattern(self):
|
|
||||||
"""When updating the database the actions must reverse the difference (eq to diff db->file)"""
|
|
||||||
|
|
||||||
if self.__currentPattern is not None:
|
|
||||||
patternDescriptor = self.getPatternDescriptorFromInput()
|
|
||||||
if (patternDescriptor
|
|
||||||
and self.__currentPattern.getPattern() != patternDescriptor['pattern']):
|
|
||||||
return self.__pc.updatePattern(self.__currentPattern.getId(), patternDescriptor)
|
|
||||||
|
|
||||||
self.loadProperties()
|
|
||||||
|
|
||||||
if MediaDescriptor.TAGS_KEY in self.__mediaDifferences.keys():
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in self.__mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
for addedTagKey in self.__mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
self.__tac.deleteMediaTagByKey(self.__currentPattern.getId(), addedTagKey)
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in self.__mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
for removedTagKey in self.__mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_REMOVED_KEY]:
|
|
||||||
currentTags = self.__currentMediaDescriptor.getTags()
|
|
||||||
self.__tac.updateMediaTag(self.__currentPattern.getId(), removedTagKey, currentTags[removedTagKey])
|
|
||||||
|
|
||||||
if DIFF_CHANGED_KEY in self.__mediaDifferences[MediaDescriptor.TAGS_KEY].keys():
|
|
||||||
for changedTagKey in self.__mediaDifferences[MediaDescriptor.TAGS_KEY][DIFF_CHANGED_KEY]:
|
|
||||||
currentTags = self.__currentMediaDescriptor.getTags()
|
|
||||||
self.__tac.updateMediaTag(self.__currentPattern.getId(), changedTagKey, currentTags[changedTagKey])
|
|
||||||
|
|
||||||
if MediaDescriptor.TRACKS_KEY in self.__mediaDifferences.keys():
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
|
|
||||||
for addedTrackIndex in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_ADDED_KEY]:
|
|
||||||
targetTracks = [t for t in self.__targetMediaDescriptor.getAllTrackDescriptors() if t.getIndex() == addedTrackIndex]
|
|
||||||
if targetTracks:
|
|
||||||
self.__tc.deleteTrack(targetTracks[0].getId()) # id
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
for removedTrackIndex, removedTrack in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_REMOVED_KEY].items():
|
|
||||||
|
|
||||||
# Track per inspect/update hinzufügen
|
|
||||||
self.__tc.addTrack(removedTrack, patternId = self.__currentPattern.getId())
|
|
||||||
|
|
||||||
if DIFF_CHANGED_KEY in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY].keys():
|
|
||||||
|
|
||||||
# [vsTracks[tp].getIndex()] = trackDiff
|
|
||||||
for changedTrackIndex, changedTrackDiff in self.__mediaDifferences[MediaDescriptor.TRACKS_KEY][DIFF_CHANGED_KEY].items():
|
|
||||||
|
|
||||||
changedTargetTracks = [t for t in self.__targetMediaDescriptor.getAllTrackDescriptors() if t.getIndex() == changedTrackIndex]
|
|
||||||
changedTargeTrackId = changedTargetTracks[0].getId() if changedTargetTracks else None
|
|
||||||
changedTargetTrackIndex = changedTargetTracks[0].getIndex() if changedTargetTracks else None
|
|
||||||
|
|
||||||
changedCurrentTracks = [t for t in self.__currentMediaDescriptor.getAllTrackDescriptors() if t.getIndex() == changedTrackIndex]
|
|
||||||
# changedCurrentTrackId #HINT: Undefined as track descriptors do not come from file with track_id
|
|
||||||
|
|
||||||
if TrackDescriptor.TAGS_KEY in changedTrackDiff.keys():
|
|
||||||
changedTrackTagsDiff = changedTrackDiff[TrackDescriptor.TAGS_KEY]
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in changedTrackTagsDiff.keys():
|
|
||||||
for addedTrackTagKey in changedTrackTagsDiff[DIFF_ADDED_KEY]:
|
|
||||||
|
|
||||||
if changedTargetTracks:
|
|
||||||
self.__tac.deleteTrackTagByKey(changedTargeTrackId, addedTrackTagKey)
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in changedTrackTagsDiff.keys():
|
|
||||||
for removedTrackTagKey in changedTrackTagsDiff[DIFF_REMOVED_KEY]:
|
|
||||||
if changedCurrentTracks:
|
|
||||||
self.__tac.updateTrackTag(changedTargeTrackId, removedTrackTagKey, changedCurrentTracks[0].getTags()[removedTrackTagKey])
|
|
||||||
|
|
||||||
if DIFF_CHANGED_KEY in changedTrackTagsDiff.keys():
|
|
||||||
for changedTrackTagKey in changedTrackTagsDiff[DIFF_CHANGED_KEY]:
|
|
||||||
if changedCurrentTracks:
|
|
||||||
self.__tac.updateTrackTag(changedTargeTrackId, changedTrackTagKey, changedCurrentTracks[0].getTags()[changedTrackTagKey])
|
|
||||||
|
|
||||||
if TrackDescriptor.DISPOSITION_SET_KEY in changedTrackDiff.keys():
|
|
||||||
changedTrackDispositionDiff = changedTrackDiff[TrackDescriptor.DISPOSITION_SET_KEY]
|
|
||||||
|
|
||||||
if DIFF_ADDED_KEY in changedTrackDispositionDiff.keys():
|
|
||||||
for changedTrackAddedDisposition in changedTrackDispositionDiff[DIFF_ADDED_KEY]:
|
|
||||||
if changedTargetTrackIndex is not None:
|
|
||||||
self.__tc.setDispositionState(self.__currentPattern.getId(), changedTargetTrackIndex, changedTrackAddedDisposition, False)
|
|
||||||
|
|
||||||
if DIFF_REMOVED_KEY in changedTrackDispositionDiff.keys():
|
|
||||||
for changedTrackRemovedDisposition in changedTrackDispositionDiff[DIFF_REMOVED_KEY]:
|
|
||||||
if changedTargetTrackIndex is not None:
|
|
||||||
self.__tc.setDispositionState(self.__currentPattern.getId(), changedTargetTrackIndex, changedTrackRemovedDisposition, True)
|
|
||||||
|
|
||||||
|
|
||||||
self.updateDifferences()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def action_edit_pattern(self):
|
|
||||||
|
|
||||||
patternDescriptor = {}
|
|
||||||
patternDescriptor['show_id'] = self.getSelectedShowDescriptor().getId()
|
|
||||||
patternDescriptor['pattern'] = self.getPatternFromInput()
|
|
||||||
|
|
||||||
if patternDescriptor['pattern']:
|
|
||||||
|
|
||||||
selectedPatternId = self.__pc.findPattern(patternDescriptor)
|
|
||||||
|
|
||||||
if selectedPatternId is None:
|
|
||||||
raise click.ClickException(f"MediaDetailsScreen.action_edit_pattern(): Pattern to edit has no id")
|
|
||||||
|
|
||||||
self.app.push_screen(PatternDetailsScreen(patternId = selectedPatternId, showId = self.getSelectedShowDescriptor().getId()), self.handle_edit_pattern) # <-
|
|
||||||
|
|
||||||
|
|
||||||
def handle_edit_pattern(self, screenResult):
|
|
||||||
self.query_one("#pattern_input", Input).value = screenResult['pattern']
|
|
||||||
self.updateDifferences()
|
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# from typing import List
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, Enum
|
|
||||||
from sqlalchemy.orm import relationship, declarative_base, sessionmaker
|
|
||||||
|
|
||||||
from .show import Base
|
|
||||||
|
|
||||||
|
|
||||||
class MediaTag(Base):
|
|
||||||
"""
|
|
||||||
relationship(argument, opt1, opt2, ...)
|
|
||||||
argument is string of class or Mapped class of the target entity
|
|
||||||
backref creates a bi-directional corresponding relationship (back_populates preferred)
|
|
||||||
back_populates points to the corresponding relationship (the actual class attribute identifier)
|
|
||||||
|
|
||||||
See: https://docs.sqlalchemy.org/en/(14|20)/orm/basic_relationships.html
|
|
||||||
"""
|
|
||||||
|
|
||||||
__tablename__ = 'media_tags'
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
id = Column(Integer, primary_key=True)
|
|
||||||
|
|
||||||
key = Column(String)
|
|
||||||
value = Column(String)
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
pattern_id = Column(Integer, ForeignKey('patterns.id', ondelete="CASCADE"))
|
|
||||||
pattern = relationship('Pattern', back_populates='media_tags')
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
|
|
||||||
from sqlalchemy.orm import relationship, sessionmaker, Mapped, backref
|
|
||||||
|
|
||||||
from .show import Base, Show
|
|
||||||
from .track import Track
|
|
||||||
|
|
||||||
from ffx.media_descriptor import MediaDescriptor
|
|
||||||
from ffx.show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
class Pattern(Base):
|
|
||||||
|
|
||||||
__tablename__ = 'patterns'
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
id = Column(Integer, primary_key=True)
|
|
||||||
pattern = Column(String)
|
|
||||||
|
|
||||||
# v2.0
|
|
||||||
# id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
||||||
# pattern: Mapped[str] = mapped_column(String, nullable=False)
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
show_id = Column(Integer, ForeignKey('shows.id', ondelete="CASCADE"))
|
|
||||||
show = relationship(Show, back_populates='patterns', lazy='joined')
|
|
||||||
|
|
||||||
# v2.0
|
|
||||||
# show_id: Mapped[int] = mapped_column(ForeignKey("shows.id", ondelete="CASCADE"))
|
|
||||||
# show: Mapped["Show"] = relationship(back_populates="patterns")
|
|
||||||
|
|
||||||
tracks = relationship('Track', back_populates='pattern', cascade="all, delete", lazy='joined')
|
|
||||||
|
|
||||||
|
|
||||||
media_tags = relationship('MediaTag', back_populates='pattern', cascade="all, delete", lazy='joined')
|
|
||||||
|
|
||||||
|
|
||||||
def getId(self):
|
|
||||||
return int(self.id)
|
|
||||||
|
|
||||||
def getShowId(self):
|
|
||||||
return int(self.show_id)
|
|
||||||
|
|
||||||
def getShowDescriptor(self) -> ShowDescriptor:
|
|
||||||
click.echo(f"self.show {self.show} id={self.show_id}")
|
|
||||||
return self.show.getDescriptor()
|
|
||||||
|
|
||||||
def getId(self):
|
|
||||||
return int(self.id)
|
|
||||||
|
|
||||||
def getPattern(self):
|
|
||||||
return str(self.pattern)
|
|
||||||
|
|
||||||
def getTags(self):
|
|
||||||
return {str(t.key):str(t.value) for t in self.media_tags}
|
|
||||||
|
|
||||||
|
|
||||||
def getMediaDescriptor(self):
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
kwargs[MediaDescriptor.TAGS_KEY] = self.getTags()
|
|
||||||
|
|
||||||
kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY] = []
|
|
||||||
|
|
||||||
# Set ordered subindices
|
|
||||||
subIndexCounter = {}
|
|
||||||
for track in self.tracks:
|
|
||||||
trackType = track.getType()
|
|
||||||
if not trackType in subIndexCounter.keys():
|
|
||||||
subIndexCounter[trackType] = 0
|
|
||||||
kwargs[MediaDescriptor.TRACK_DESCRIPTOR_LIST_KEY].append(track.getDescriptor(subIndex = subIndexCounter[trackType]))
|
|
||||||
subIndexCounter[trackType] += 1
|
|
||||||
|
|
||||||
return MediaDescriptor(**kwargs)
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
# from typing import List
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
|
|
||||||
from sqlalchemy.orm import relationship, declarative_base, sessionmaker
|
|
||||||
|
|
||||||
from ffx.show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
class Show(Base):
|
|
||||||
"""
|
|
||||||
relationship(argument, opt1, opt2, ...)
|
|
||||||
argument is string of class or Mapped class of the target entity
|
|
||||||
backref creates a bi-directional corresponding relationship (back_populates preferred)
|
|
||||||
back_populates points to the corresponding relationship (the actual class attribute identifier)
|
|
||||||
|
|
||||||
See: https://docs.sqlalchemy.org/en/(14|20)/orm/basic_relationships.html
|
|
||||||
"""
|
|
||||||
|
|
||||||
__tablename__ = 'shows'
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
id = Column(Integer, primary_key=True)
|
|
||||||
|
|
||||||
name = Column(String)
|
|
||||||
year = Column(Integer)
|
|
||||||
|
|
||||||
# v2.0
|
|
||||||
# id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
||||||
# name: Mapped[str] = mapped_column(String, nullable=False)
|
|
||||||
# year: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
#patterns = relationship('Pattern', back_populates='show', cascade="all, delete", passive_deletes=True)
|
|
||||||
patterns = relationship('Pattern', back_populates='show', cascade="all, delete")
|
|
||||||
# patterns = relationship('Pattern', back_populates='show', cascade="all")
|
|
||||||
|
|
||||||
# v2.0
|
|
||||||
# patterns: Mapped[List["Pattern"]] = relationship(back_populates="show", cascade="all, delete")
|
|
||||||
|
|
||||||
index_season_digits = Column(Integer, default=ShowDescriptor.DEFAULT_INDEX_SEASON_DIGITS)
|
|
||||||
index_episode_digits = Column(Integer, default=ShowDescriptor.DEFAULT_INDEX_EPISODE_DIGITS)
|
|
||||||
indicator_season_digits = Column(Integer, default=ShowDescriptor.DEFAULT_INDICATOR_SEASON_DIGITS)
|
|
||||||
indicator_episode_digits = Column(Integer, default=ShowDescriptor.DEFAULT_INDICATOR_EPISODE_DIGITS)
|
|
||||||
|
|
||||||
|
|
||||||
def getDescriptor(self):
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
kwargs[ShowDescriptor.ID_KEY] = int(self.id)
|
|
||||||
kwargs[ShowDescriptor.NAME_KEY] = str(self.name)
|
|
||||||
kwargs[ShowDescriptor.YEAR_KEY] = int(self.year)
|
|
||||||
kwargs[ShowDescriptor.INDEX_SEASON_DIGITS_KEY] = int(self.index_season_digits)
|
|
||||||
kwargs[ShowDescriptor.INDEX_EPISODE_DIGITS_KEY] = int(self.index_episode_digits)
|
|
||||||
kwargs[ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY] = int(self.indicator_season_digits)
|
|
||||||
kwargs[ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY] = int(self.indicator_episode_digits)
|
|
||||||
|
|
||||||
return ShowDescriptor(**kwargs)
|
|
||||||
@@ -1,213 +0,0 @@
|
|||||||
# from typing import List
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
|
|
||||||
from sqlalchemy.orm import relationship, declarative_base, sessionmaker
|
|
||||||
|
|
||||||
from .show import Base
|
|
||||||
|
|
||||||
from ffx.track_type import TrackType
|
|
||||||
|
|
||||||
from ffx.iso_language import IsoLanguage
|
|
||||||
|
|
||||||
from ffx.track_disposition import TrackDisposition
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
from ffx.audio_layout import AudioLayout
|
|
||||||
|
|
||||||
import click
|
|
||||||
|
|
||||||
class Track(Base):
|
|
||||||
"""
|
|
||||||
relationship(argument, opt1, opt2, ...)
|
|
||||||
argument is string of class or Mapped class of the target entity
|
|
||||||
backref creates a bi-directional corresponding relationship (back_populates preferred)
|
|
||||||
back_populates points to the corresponding relationship (the actual class attribute identifier)
|
|
||||||
|
|
||||||
See: https://docs.sqlalchemy.org/en/(14|20)/orm/basic_relationships.html
|
|
||||||
"""
|
|
||||||
|
|
||||||
__tablename__ = 'tracks'
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement = True)
|
|
||||||
|
|
||||||
# P=pattern_id+sub_index+track_type
|
|
||||||
track_type = Column(Integer) # TrackType
|
|
||||||
|
|
||||||
index = Column(Integer)
|
|
||||||
source_index = Column(Integer)
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
pattern_id = Column(Integer, ForeignKey('patterns.id', ondelete="CASCADE"))
|
|
||||||
pattern = relationship('Pattern', back_populates='tracks')
|
|
||||||
|
|
||||||
track_tags = relationship('TrackTag', back_populates='track', cascade="all, delete", lazy="joined")
|
|
||||||
|
|
||||||
disposition_flags = Column(Integer)
|
|
||||||
|
|
||||||
codec_name = Column(String)
|
|
||||||
audio_layout = Column(Integer)
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
|
|
||||||
trackType = kwargs.pop('track_type', None)
|
|
||||||
if trackType is not None:
|
|
||||||
self.track_type = int(trackType)
|
|
||||||
|
|
||||||
dispositionSet = kwargs.pop(TrackDescriptor.DISPOSITION_SET_KEY, set())
|
|
||||||
self.disposition_flags = int(TrackDisposition.toFlags(dispositionSet))
|
|
||||||
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fromFfprobeStreamObj(cls, streamObj, patternId):
|
|
||||||
"""{
|
|
||||||
'index': 4,
|
|
||||||
'codec_name': 'hdmv_pgs_subtitle',
|
|
||||||
'codec_long_name': 'HDMV Presentation Graphic Stream subtitles',
|
|
||||||
'codec_type': 'subtitle',
|
|
||||||
'codec_tag_string': '[0][0][0][0]',
|
|
||||||
'codec_tag': '0x0000',
|
|
||||||
'r_frame_rate': '0/0',
|
|
||||||
'avg_frame_rate': '0/0',
|
|
||||||
'time_base': '1/1000',
|
|
||||||
'start_pts': 0,
|
|
||||||
'start_time': '0.000000',
|
|
||||||
'duration_ts': 1421035,
|
|
||||||
'duration': '1421.035000',
|
|
||||||
'disposition': {
|
|
||||||
'default': 1,
|
|
||||||
'dub': 0,
|
|
||||||
'original': 0,
|
|
||||||
'comment': 0,
|
|
||||||
'lyrics': 0,
|
|
||||||
'karaoke': 0,
|
|
||||||
'forced': 0,
|
|
||||||
'hearing_impaired': 0,
|
|
||||||
'visual_impaired': 0,
|
|
||||||
'clean_effects': 0,
|
|
||||||
'attached_pic': 0,
|
|
||||||
'timed_thumbnails': 0,
|
|
||||||
'non_diegetic': 0,
|
|
||||||
'captions': 0,
|
|
||||||
'descriptions': 0,
|
|
||||||
'metadata': 0,
|
|
||||||
'dependent': 0,
|
|
||||||
'still_image': 0
|
|
||||||
},
|
|
||||||
'tags': {
|
|
||||||
'language': 'ger',
|
|
||||||
'title': 'German Full'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement = True)
|
|
||||||
|
|
||||||
# P=pattern_id+sub_index+track_type
|
|
||||||
track_type = Column(Integer) # TrackType
|
|
||||||
sub_index = Column(Integer)
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
pattern_id = Column(Integer, ForeignKey('patterns.id', ondelete='CASCADE'))
|
|
||||||
pattern = relationship('Pattern', back_populates='tracks')
|
|
||||||
|
|
||||||
|
|
||||||
language = Column(String) # IsoLanguage threeLetter
|
|
||||||
title = Column(String)
|
|
||||||
|
|
||||||
|
|
||||||
track_tags = relationship('TrackTag', back_populates='track', cascade='all, delete')
|
|
||||||
|
|
||||||
|
|
||||||
disposition_flags = Column(Integer)
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
trackType = streamObj[TrackDescriptor.FFPROBE_CODEC_TYPE_KEY]
|
|
||||||
|
|
||||||
if trackType in [t.label() for t in TrackType]:
|
|
||||||
|
|
||||||
return cls(pattern_id = patternId,
|
|
||||||
track_type = trackType,
|
|
||||||
codec_name = streamObj[TrackDescriptor.FFPROBE_CODEC_NAME_KEY],
|
|
||||||
disposition_flags = sum([2**t.index() for (k,v) in streamObj[TrackDescriptor.FFPROBE_DISPOSITION_KEY].items()
|
|
||||||
if v and (t := TrackDisposition.find(k)) is not None]),
|
|
||||||
audio_layout = AudioLayout.identify(streamObj))
|
|
||||||
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def getId(self):
|
|
||||||
return int(self.id)
|
|
||||||
|
|
||||||
def getPatternId(self):
|
|
||||||
return int(self.pattern_id)
|
|
||||||
|
|
||||||
def getType(self):
|
|
||||||
return TrackType.fromIndex(self.track_type)
|
|
||||||
|
|
||||||
def getCodec(self):
|
|
||||||
return str(self.codec_name)
|
|
||||||
|
|
||||||
def getIndex(self):
|
|
||||||
return int(self.index) if self.index is not None else -1
|
|
||||||
|
|
||||||
def getSourceIndex(self):
|
|
||||||
return int(self.source_index) if self.source_index is not None else -1
|
|
||||||
|
|
||||||
def getLanguage(self):
|
|
||||||
tags = {t.key:t.value for t in self.track_tags}
|
|
||||||
return IsoLanguage.findThreeLetter(tags['language']) if 'language' in tags.keys() else IsoLanguage.UNDEFINED
|
|
||||||
|
|
||||||
def getTitle(self):
|
|
||||||
tags = {t.key:t.value for t in self.track_tags}
|
|
||||||
return tags['title'] if 'title' in tags.keys() else ''
|
|
||||||
|
|
||||||
def getDispositionSet(self):
|
|
||||||
return TrackDisposition.toSet(self.disposition_flags)
|
|
||||||
|
|
||||||
def getAudioLayout(self):
|
|
||||||
return AudioLayout.fromIndex(self.audio_layout)
|
|
||||||
|
|
||||||
def getTags(self):
|
|
||||||
return {str(t.key):str(t.value) for t in self.track_tags}
|
|
||||||
|
|
||||||
|
|
||||||
def setDisposition(self, disposition : TrackDisposition):
|
|
||||||
self.disposition_flags = self.disposition_flags | int(2**disposition.index())
|
|
||||||
|
|
||||||
def resetDisposition(self, disposition : TrackDisposition):
|
|
||||||
self.disposition_flags = self.disposition_flags & sum([2**d.index() for d in TrackDisposition if d != disposition])
|
|
||||||
|
|
||||||
def getDisposition(self, disposition : TrackDisposition):
|
|
||||||
return bool(self.disposition_flags & 2**disposition.index())
|
|
||||||
|
|
||||||
|
|
||||||
def getDescriptor(self, subIndex : int = -1) -> TrackDescriptor:
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.ID_KEY] = self.getId()
|
|
||||||
kwargs[TrackDescriptor.PATTERN_ID_KEY] = self.getPatternId()
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.INDEX_KEY] = self.getIndex()
|
|
||||||
kwargs[TrackDescriptor.SOURCE_INDEX_KEY] = self.getSourceIndex()
|
|
||||||
|
|
||||||
if subIndex > -1:
|
|
||||||
kwargs[TrackDescriptor.SUB_INDEX_KEY] = subIndex
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.TRACK_TYPE_KEY] = self.getType()
|
|
||||||
kwargs[TrackDescriptor.CODEC_NAME_KEY] = self.getCodec()
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.DISPOSITION_SET_KEY] = self.getDispositionSet()
|
|
||||||
kwargs[TrackDescriptor.TAGS_KEY] = self.getTags()
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.AUDIO_LAYOUT_KEY] = self.getAudioLayout()
|
|
||||||
|
|
||||||
return TrackDescriptor(**kwargs)
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# from typing import List
|
|
||||||
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, Enum
|
|
||||||
from sqlalchemy.orm import relationship, declarative_base, sessionmaker
|
|
||||||
|
|
||||||
from .show import Base
|
|
||||||
|
|
||||||
|
|
||||||
class TrackTag(Base):
|
|
||||||
"""
|
|
||||||
relationship(argument, opt1, opt2, ...)
|
|
||||||
argument is string of class or Mapped class of the target entity
|
|
||||||
backref creates a bi-directional corresponding relationship (back_populates preferred)
|
|
||||||
back_populates points to the corresponding relationship (the actual class attribute identifier)
|
|
||||||
|
|
||||||
See: https://docs.sqlalchemy.org/en/(14|20)/orm/basic_relationships.html
|
|
||||||
"""
|
|
||||||
|
|
||||||
__tablename__ = 'track_tags'
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
id = Column(Integer, primary_key=True)
|
|
||||||
|
|
||||||
key = Column(String)
|
|
||||||
value = Column(String)
|
|
||||||
|
|
||||||
# v1.x
|
|
||||||
track_id = Column(Integer, ForeignKey('tracks.id', ondelete="CASCADE"))
|
|
||||||
track = relationship('Track', back_populates='track_tags')
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
import click, re
|
|
||||||
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
|
|
||||||
|
|
||||||
class PatternController():
|
|
||||||
|
|
||||||
def __init__(self, context):
|
|
||||||
|
|
||||||
self.context = context
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
|
|
||||||
def addPattern(self, patternDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.show_id == int(patternDescriptor['show_id']))
|
|
||||||
|
|
||||||
if not q.count():
|
|
||||||
pattern = Pattern(show_id = int(patternDescriptor['show_id']),
|
|
||||||
pattern = str(patternDescriptor['pattern']))
|
|
||||||
s.add(pattern)
|
|
||||||
s.commit()
|
|
||||||
return pattern.getId()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.addPattern(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def updatePattern(self, patternId, patternDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.id == int(patternId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
pattern = q.first()
|
|
||||||
|
|
||||||
pattern.show_id = int(patternDescriptor['show_id'])
|
|
||||||
pattern.pattern = str(patternDescriptor['pattern'])
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.updatePattern(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def findPattern(self, patternDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.show_id == int(patternDescriptor['show_id']), Pattern.pattern == str(patternDescriptor['pattern']))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
pattern = q.first()
|
|
||||||
return int(pattern.id)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.findPattern(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def getPattern(self, patternId : int):
|
|
||||||
|
|
||||||
if type(patternId) is not int:
|
|
||||||
raise ValueError(f"PatternController.getPattern(): Argument patternId is required to be of type int")
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.id == int(patternId))
|
|
||||||
|
|
||||||
return q.first() if q.count() else None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.getPattern(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def deletePattern(self, patternId):
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.id == int(patternId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
#DAFUQ: https://stackoverflow.com/a/19245058
|
|
||||||
# q.delete()
|
|
||||||
pattern = q.first()
|
|
||||||
s.delete(pattern)
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.deletePattern(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def matchFilename(self, filename : str) -> re.Match:
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern)
|
|
||||||
|
|
||||||
matchResult = {}
|
|
||||||
|
|
||||||
for pattern in q.all():
|
|
||||||
patternMatch = re.search(str(pattern.pattern), str(filename))
|
|
||||||
if patternMatch:
|
|
||||||
matchResult['match'] = patternMatch
|
|
||||||
matchResult['pattern'] = pattern
|
|
||||||
|
|
||||||
return matchResult
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.matchFilename(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def getMediaDescriptor(self, patternId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.id == int(patternId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return q.first().getMediaDescriptor()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"PatternController.getPatternDescriptor(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from .show_controller import ShowController
|
|
||||||
from .pattern_controller import PatternController
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class PatternDeleteScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 2;
|
|
||||||
grid-rows: 2 auto;
|
|
||||||
grid-columns: 30 330;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, patternId = None, showId = None):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__pc = PatternController(context = self.context)
|
|
||||||
self.__sc = ShowController(context = self.context)
|
|
||||||
|
|
||||||
self.pattern_id = patternId
|
|
||||||
self.pattern_obj = self.__pc.getPatternDescriptor(patternId) if patternId is not None else {}
|
|
||||||
self.show_obj = self.__sc.getShowDescriptor(showId) if showId is not None else {}
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
if self.show_obj:
|
|
||||||
self.query_one("#showlabel", Static).update(f"{self.show_obj['id']} - {self.show_obj['name']} ({self.show_obj['year']})")
|
|
||||||
if self.pattern_obj:
|
|
||||||
self.query_one("#patternlabel", Static).update(str(self.pattern_obj['pattern']))
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
yield Static("Are you sure to delete the following filename pattern?", id="toplabel", classes="two")
|
|
||||||
|
|
||||||
yield Static("", classes="two")
|
|
||||||
|
|
||||||
yield Static("Pattern")
|
|
||||||
yield Static("", id="patternlabel")
|
|
||||||
|
|
||||||
yield Static("", classes="two")
|
|
||||||
|
|
||||||
yield Static("from show")
|
|
||||||
yield Static("", id="showlabel")
|
|
||||||
|
|
||||||
yield Static("", classes="two")
|
|
||||||
|
|
||||||
yield Button("Delete", id="delete_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
if event.button.id == "delete_button":
|
|
||||||
|
|
||||||
if self.pattern_id is None:
|
|
||||||
raise click.ClickException('PatternDeleteScreen.on_button_pressed(): pattern id is undefined')
|
|
||||||
|
|
||||||
if self.__pc.deletePattern(self.pattern_id):
|
|
||||||
self.dismiss(self.pattern_obj)
|
|
||||||
|
|
||||||
else:
|
|
||||||
#TODO: Meldung
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
@@ -1,457 +0,0 @@
|
|||||||
import click, re
|
|
||||||
|
|
||||||
from textual import events
|
|
||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button, Input, DataTable
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from ffx.model.show import Show
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
from ffx.model.track import Track
|
|
||||||
|
|
||||||
from .pattern_controller import PatternController
|
|
||||||
from .show_controller import ShowController
|
|
||||||
from .track_controller import TrackController
|
|
||||||
from .tag_controller import TagController
|
|
||||||
|
|
||||||
from .track_details_screen import TrackDetailsScreen
|
|
||||||
from .track_delete_screen import TrackDeleteScreen
|
|
||||||
|
|
||||||
from .tag_details_screen import TagDetailsScreen
|
|
||||||
from .tag_delete_screen import TagDeleteScreen
|
|
||||||
|
|
||||||
from ffx.track_type import TrackType
|
|
||||||
|
|
||||||
from ffx.track_disposition import TrackDisposition
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
from textual.widgets._data_table import CellDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class PatternDetailsScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 5 13;
|
|
||||||
grid-rows: 2 2 2 2 2 8 2 2 8 2 2 2 2;
|
|
||||||
grid-columns: 25 25 25 25 25;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataTable {
|
|
||||||
min-height: 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
.five {
|
|
||||||
column-span: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
|
|
||||||
.yellow {
|
|
||||||
tint: yellow 40%;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, patternId = None, showId = None):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__pc = PatternController(context = self.context)
|
|
||||||
self.__sc = ShowController(context = self.context)
|
|
||||||
self.__tc = TrackController(context = self.context)
|
|
||||||
self.__tac = TagController(context = self.context)
|
|
||||||
|
|
||||||
self.__pattern : Pattern = self.__pc.getPattern(patternId) if patternId is not None else None
|
|
||||||
self.__showDescriptor = self.__sc.getShowDescriptor(showId) if showId is not None else None
|
|
||||||
|
|
||||||
|
|
||||||
#TODO: per controller
|
|
||||||
def loadTracks(self, show_id):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
tracks = {}
|
|
||||||
tracks['audio'] = {}
|
|
||||||
tracks['subtitle'] = {}
|
|
||||||
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.show_id == int(show_id))
|
|
||||||
|
|
||||||
return [{'id': int(p.id), 'pattern': p.pattern} for p in q.all()]
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"loadTracks(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def updateTracks(self):
|
|
||||||
|
|
||||||
self.tracksTable.clear()
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
|
|
||||||
tracks = self.__tc.findTracks(self.__pattern.getId())
|
|
||||||
|
|
||||||
typeCounter = {}
|
|
||||||
|
|
||||||
for tr in tracks:
|
|
||||||
|
|
||||||
td : TrackDescriptor = tr.getDescriptor()
|
|
||||||
|
|
||||||
trackType = td.getType()
|
|
||||||
if not trackType in typeCounter.keys():
|
|
||||||
typeCounter[trackType] = 0
|
|
||||||
|
|
||||||
dispoSet = td.getDispositionSet()
|
|
||||||
|
|
||||||
row = (td.getIndex(),
|
|
||||||
trackType.label(),
|
|
||||||
typeCounter[trackType],
|
|
||||||
td.getAudioLayout().label() if trackType == TrackType.AUDIO else ' ',
|
|
||||||
td.getLanguage().label(),
|
|
||||||
td.getTitle(),
|
|
||||||
'Yes' if TrackDisposition.DEFAULT in dispoSet else 'No',
|
|
||||||
'Yes' if TrackDisposition.FORCED in dispoSet else 'No')
|
|
||||||
|
|
||||||
self.tracksTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
typeCounter[trackType] += 1
|
|
||||||
|
|
||||||
def updateTags(self):
|
|
||||||
|
|
||||||
self.tagsTable.clear()
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
|
|
||||||
# raise click.ClickException(f"patternid={self.__pattern.getId()}") # 1
|
|
||||||
|
|
||||||
tags = self.__tac.findAllMediaTags(self.__pattern.getId())
|
|
||||||
|
|
||||||
#raise click.ClickException(f"tags={tags}") # encoder:blah
|
|
||||||
|
|
||||||
for tagKey, tagValue in tags.items():
|
|
||||||
row = (tagKey, tagValue)
|
|
||||||
self.tagsTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
if not self.__showDescriptor is None:
|
|
||||||
self.query_one("#showlabel", Static).update(f"{self.__showDescriptor.getId()} - {self.__showDescriptor.getName()} ({self.__showDescriptor.getYear()})")
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
|
|
||||||
self.query_one("#pattern_input", Input).value = str(self.__pattern.getPattern())
|
|
||||||
|
|
||||||
self.updateTags()
|
|
||||||
self.updateTracks()
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
|
|
||||||
self.tagsTable = DataTable(classes="five")
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_tag_key = self.tagsTable.add_column("Key", width=10)
|
|
||||||
self.column_key_tag_value = self.tagsTable.add_column("Value", width=100)
|
|
||||||
|
|
||||||
self.tagsTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
|
|
||||||
self.tracksTable = DataTable(id="tracks_table", classes="five")
|
|
||||||
|
|
||||||
self.column_key_track_index = self.tracksTable.add_column("Index", width=5)
|
|
||||||
self.column_key_track_type = self.tracksTable.add_column("Type", width=10)
|
|
||||||
self.column_key_track_sub_index = self.tracksTable.add_column("Subindex", width=5)
|
|
||||||
self.column_key_track_audio_layout = self.tracksTable.add_column("Layout", width=10)
|
|
||||||
self.column_key_track_language = self.tracksTable.add_column("Language", width=15)
|
|
||||||
self.column_key_track_title = self.tracksTable.add_column("Title", width=48)
|
|
||||||
self.column_key_track_default = self.tracksTable.add_column("Default", width=8)
|
|
||||||
self.column_key_track_forced = self.tracksTable.add_column("Forced", width=8)
|
|
||||||
|
|
||||||
self.tracksTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
# 1
|
|
||||||
yield Static("Edit filename pattern" if self.__pattern is not None else "New filename pattern", id="toplabel")
|
|
||||||
yield Input(type="text", id="pattern_input", classes="four")
|
|
||||||
|
|
||||||
# 2
|
|
||||||
yield Static("from show")
|
|
||||||
yield Static("", id="showlabel", classes="three")
|
|
||||||
yield Button("Substitute pattern", id="pattern_button")
|
|
||||||
|
|
||||||
# 3
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
# 4
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 5
|
|
||||||
yield Static("Media Tags")
|
|
||||||
yield Static(" ")
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
yield Button("Add", id="button_add_tag")
|
|
||||||
yield Button("Edit", id="button_edit_tag")
|
|
||||||
yield Button("Delete", id="button_delete_tag")
|
|
||||||
else:
|
|
||||||
yield Static(" ")
|
|
||||||
yield Static(" ")
|
|
||||||
yield Static(" ")
|
|
||||||
# 6
|
|
||||||
yield self.tagsTable
|
|
||||||
|
|
||||||
# 7
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 8
|
|
||||||
yield Static("Streams")
|
|
||||||
yield Static(" ")
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
yield Button("Add", id="button_add_track")
|
|
||||||
yield Button("Edit", id="button_edit_track")
|
|
||||||
yield Button("Delete", id="button_delete_track")
|
|
||||||
else:
|
|
||||||
yield Static(" ")
|
|
||||||
yield Static(" ")
|
|
||||||
yield Static(" ")
|
|
||||||
# 9
|
|
||||||
yield self.tracksTable
|
|
||||||
|
|
||||||
# 10
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 11
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 12
|
|
||||||
yield Button("Save", id="save_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
yield Static(" ", classes="three")
|
|
||||||
|
|
||||||
# 13
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
def getPatternFromInput(self):
|
|
||||||
return str(self.query_one("#pattern_input", Input).value)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedTrackDescriptor(self):
|
|
||||||
|
|
||||||
if not self.__pattern:
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.tracksTable.coordinate_to_cell_key(self.tracksTable.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_track_data = self.tracksTable.get_row(row_key)
|
|
||||||
|
|
||||||
trackIndex = int(selected_track_data[0])
|
|
||||||
trackSubIndex = int(selected_track_data[2])
|
|
||||||
|
|
||||||
return self.__tc.getTrack(self.__pattern.getId(), trackIndex).getDescriptor(subIndex=trackSubIndex)
|
|
||||||
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedTag(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.tagsTable.coordinate_to_cell_key(self.tagsTable.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_tag_data = self.tagsTable.get_row(row_key)
|
|
||||||
|
|
||||||
tagKey = str(selected_tag_data[0])
|
|
||||||
tagValue = str(selected_tag_data[1])
|
|
||||||
|
|
||||||
return tagKey, tagValue
|
|
||||||
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
# Check if the button pressed is the one we are interested in
|
|
||||||
if event.button.id == "save_button":
|
|
||||||
|
|
||||||
patternDescriptor = {}
|
|
||||||
patternDescriptor['show_id'] = self.__showDescriptor.getId()
|
|
||||||
patternDescriptor['pattern'] = self.getPatternFromInput()
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
|
|
||||||
if self.__pc.updatePattern(self.__pattern.getId(), patternDescriptor):
|
|
||||||
self.dismiss(patternDescriptor)
|
|
||||||
else:
|
|
||||||
#TODO: Meldung
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
else:
|
|
||||||
patternId = self.__pc.addPattern(patternDescriptor)
|
|
||||||
if patternId is not None:
|
|
||||||
|
|
||||||
self.dismiss(patternDescriptor)
|
|
||||||
else:
|
|
||||||
#TODO: Meldung
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
|
|
||||||
# Save pattern when just created before adding streams
|
|
||||||
if self.__pattern is not None:
|
|
||||||
|
|
||||||
numTracks = len(self.tracksTable.rows)
|
|
||||||
|
|
||||||
if event.button.id == "button_add_track":
|
|
||||||
self.app.push_screen(TrackDetailsScreen(patternId = self.__pattern.getId(), index = numTracks), self.handle_add_track)
|
|
||||||
|
|
||||||
selectedTrack = self.getSelectedTrackDescriptor()
|
|
||||||
if selectedTrack is not None:
|
|
||||||
if event.button.id == "button_edit_track":
|
|
||||||
self.app.push_screen(TrackDetailsScreen(trackDescriptor = selectedTrack), self.handle_edit_track)
|
|
||||||
if event.button.id == "button_delete_track":
|
|
||||||
self.app.push_screen(TrackDeleteScreen(trackDescriptor = selectedTrack), self.handle_delete_track)
|
|
||||||
|
|
||||||
|
|
||||||
if event.button.id == "button_add_tag":
|
|
||||||
if self.__pattern is not None:
|
|
||||||
self.app.push_screen(TagDetailsScreen(), self.handle_update_tag)
|
|
||||||
|
|
||||||
if event.button.id == "button_edit_tag":
|
|
||||||
tagKey, tagValue = self.getSelectedTag()
|
|
||||||
self.app.push_screen(TagDetailsScreen(key=tagKey, value=tagValue), self.handle_update_tag)
|
|
||||||
|
|
||||||
if event.button.id == "button_delete_tag":
|
|
||||||
tagKey, tagValue = self.getSelectedTag()
|
|
||||||
self.app.push_screen(TagDeleteScreen(key=tagKey, value=tagValue), self.handle_delete_tag)
|
|
||||||
|
|
||||||
|
|
||||||
if event.button.id == "pattern_button":
|
|
||||||
|
|
||||||
INDICATOR_PATTERN = '([sS][0-9]+[eE][0-9]+)'
|
|
||||||
|
|
||||||
pattern = self.query_one("#pattern_input", Input).value
|
|
||||||
|
|
||||||
patternMatch = re.search(INDICATOR_PATTERN, pattern)
|
|
||||||
|
|
||||||
if patternMatch:
|
|
||||||
self.query_one("#pattern_input", Input).value = pattern.replace(patternMatch.group(1), INDICATOR_PATTERN)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_add_track(self, trackDescriptor : TrackDescriptor):
|
|
||||||
|
|
||||||
dispoSet = trackDescriptor.getDispositionSet()
|
|
||||||
trackType = trackDescriptor.getType()
|
|
||||||
index = trackDescriptor.getIndex()
|
|
||||||
subIndex = trackDescriptor.getSubIndex()
|
|
||||||
language = trackDescriptor.getLanguage()
|
|
||||||
title = trackDescriptor.getTitle()
|
|
||||||
|
|
||||||
row = (index,
|
|
||||||
trackType.label(),
|
|
||||||
subIndex,
|
|
||||||
" ",
|
|
||||||
language.label(),
|
|
||||||
title,
|
|
||||||
'Yes' if TrackDisposition.DEFAULT in dispoSet else 'No',
|
|
||||||
'Yes' if TrackDisposition.FORCED in dispoSet else 'No')
|
|
||||||
|
|
||||||
self.tracksTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
|
|
||||||
def handle_edit_track(self, trackDescriptor : TrackDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
row_key, col_key = self.tracksTable.coordinate_to_cell_key(self.tracksTable.cursor_coordinate)
|
|
||||||
|
|
||||||
self.tracksTable.update_cell(row_key, self.column_key_track_audio_layout, trackDescriptor.getAudioLayout().label())
|
|
||||||
self.tracksTable.update_cell(row_key, self.column_key_track_language, trackDescriptor.getLanguage().label())
|
|
||||||
self.tracksTable.update_cell(row_key, self.column_key_track_title, trackDescriptor.getTitle())
|
|
||||||
self.tracksTable.update_cell(row_key, self.column_key_track_default, 'Yes' if TrackDisposition.DEFAULT in trackDescriptor.getDispositionSet() else 'No')
|
|
||||||
self.tracksTable.update_cell(row_key, self.column_key_track_forced, 'Yes' if TrackDisposition.FORCED in trackDescriptor.getDispositionSet() else 'No')
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def handle_delete_track(self, trackDescriptor : TrackDescriptor):
|
|
||||||
self.updateTracks()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_update_tag(self, tag):
|
|
||||||
|
|
||||||
if self.__pattern is None:
|
|
||||||
raise click.ClickException(f"PatternDetailsScreen.handle_update_tag: pattern not set")
|
|
||||||
|
|
||||||
if self.__tac.updateMediaTag(self.__pattern.getId(), tag[0], tag[1]) is not None:
|
|
||||||
self.updateTags()
|
|
||||||
|
|
||||||
def handle_delete_tag(self, tag):
|
|
||||||
|
|
||||||
if self.__pattern is None:
|
|
||||||
raise click.ClickException(f"PatternDetailsScreen.handle_delete_tag: pattern not set")
|
|
||||||
|
|
||||||
if self.__tac.deleteMediaTagByKey(self.__pattern.getId(), tag[0]):
|
|
||||||
self.updateTags()
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
def executeProcess(commandSequence: List[str]):
|
|
||||||
# process = subprocess.Popen([t.encode('utf-8') for t in commandSequence], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
process = subprocess.Popen(commandSequence, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
|
|
||||||
output, error = process.communicate()
|
|
||||||
# return output.decode('utf-8'), error.decode('utf-8'), process.returncode
|
|
||||||
return output, error, process.returncode
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Placeholder, Label
|
|
||||||
|
|
||||||
class SettingsScreen(Screen):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
context = self.app.getContext()
|
|
||||||
def compose(self) -> ComposeResult:
|
|
||||||
yield Placeholder("Settings Screen")
|
|
||||||
yield Footer()
|
|
||||||
2
bin/ffx/show.py
Normal file
2
bin/ffx/show.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class Show():
|
||||||
|
pass
|
||||||
@@ -1,133 +1,2 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from ffx.model.show import Show
|
|
||||||
from ffx.show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
class ShowController():
|
class ShowController():
|
||||||
|
pass
|
||||||
def __init__(self, context):
|
|
||||||
|
|
||||||
self.context = context
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
|
|
||||||
def getShowDescriptor(self, showId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Show).filter(Show.id == showId)
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
show: Show = q.first()
|
|
||||||
return show.getDescriptor()
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"ShowController.getShowDescriptor(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def getShow(self, showId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Show).filter(Show.id == showId)
|
|
||||||
|
|
||||||
return q.first() if q.count() else None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"ShowController.getShow(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def getAllShows(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Show)
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return q.all()
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"ShowController.getAllShows(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def updateShow(self, showDescriptor: ShowDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Show).filter(Show.id == showDescriptor.getId())
|
|
||||||
|
|
||||||
if not q.count():
|
|
||||||
show = Show(id = int(showDescriptor.getId()),
|
|
||||||
name = str(showDescriptor.getName()),
|
|
||||||
year = int(showDescriptor.getYear()),
|
|
||||||
index_season_digits = showDescriptor.getIndexSeasonDigits(),
|
|
||||||
index_episode_digits = showDescriptor.getIndexEpisodeDigits(),
|
|
||||||
indicator_season_digits = showDescriptor.getIndicatorSeasonDigits(),
|
|
||||||
indicator_episode_digits = showDescriptor.getIndicatorEpisodeDigits())
|
|
||||||
|
|
||||||
s.add(show)
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
|
|
||||||
currentShow = q.first()
|
|
||||||
|
|
||||||
changed = False
|
|
||||||
if currentShow.name != str(showDescriptor.getName()):
|
|
||||||
currentShow.name = str(showDescriptor.getName())
|
|
||||||
changed = True
|
|
||||||
if currentShow.year != int(showDescriptor.getYear()):
|
|
||||||
currentShow.year = int(showDescriptor.getYear())
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
if currentShow.index_season_digits != int(showDescriptor.getIndexSeasonDigits()):
|
|
||||||
currentShow.index_season_digits = int(showDescriptor.getIndexSeasonDigits())
|
|
||||||
changed = True
|
|
||||||
if currentShow.index_episode_digits != int(showDescriptor.getIndexEpisodeDigits()):
|
|
||||||
currentShow.index_episode_digits = int(showDescriptor.getIndexEpisodeDigits())
|
|
||||||
changed = True
|
|
||||||
if currentShow.indicator_season_digits != int(showDescriptor.getIndicatorSeasonDigits()):
|
|
||||||
currentShow.indicator_season_digits = int(showDescriptor.getIndicatorSeasonDigits())
|
|
||||||
changed = True
|
|
||||||
if currentShow.indicator_episode_digits != int(showDescriptor.getIndicatorEpisodeDigits()):
|
|
||||||
currentShow.indicator_episode_digits = int(showDescriptor.getIndicatorEpisodeDigits())
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
if changed:
|
|
||||||
s.commit()
|
|
||||||
return changed
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"ShowController.updateShow(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def deleteShow(self, show_id):
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Show).filter(Show.id == int(show_id))
|
|
||||||
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
#DAFUQ: https://stackoverflow.com/a/19245058
|
|
||||||
# q.delete()
|
|
||||||
show = q.first()
|
|
||||||
s.delete(show)
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"ShowController.deleteShow(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from .show_controller import ShowController
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class ShowDeleteScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 2;
|
|
||||||
grid-rows: 2 auto;
|
|
||||||
grid-columns: 30 auto;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, showId = None):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__sc = ShowController(context = self.context)
|
|
||||||
|
|
||||||
self.__showDescriptor = self.__sc.getShowDescriptor(showId) if showId is not None else {}
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
if not self.__showDescriptor is None:
|
|
||||||
self.query_one("#showlabel", Static).update(f"{self.__showDescriptor.getId()} - {self.__showDescriptor.getName()} ({self.__showDescriptor.getYear()})")
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
yield Static("Are you sure to delete the following show?", id="toplabel", classes="two")
|
|
||||||
|
|
||||||
yield Static("", classes="two")
|
|
||||||
|
|
||||||
yield Static("", id="showlabel")
|
|
||||||
yield Static("")
|
|
||||||
|
|
||||||
yield Static("", classes="two")
|
|
||||||
|
|
||||||
yield Static("", classes="two")
|
|
||||||
|
|
||||||
yield Button("Delete", id="delete_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
if event.button.id == "delete_button":
|
|
||||||
|
|
||||||
if not self.__showDescriptor is None:
|
|
||||||
if self.__sc.deleteShow(self.__showDescriptor.getId()):
|
|
||||||
self.dismiss(self.__showDescriptor)
|
|
||||||
|
|
||||||
else:
|
|
||||||
#TODO: Meldung
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from typing import List, Self
|
|
||||||
|
|
||||||
from ffx.track_type import TrackType
|
|
||||||
from ffx.track_disposition import TrackDisposition
|
|
||||||
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
from ffx.helper import dictDiff, DIFF_ADDED_KEY, DIFF_CHANGED_KEY, DIFF_REMOVED_KEY
|
|
||||||
|
|
||||||
|
|
||||||
class ShowDescriptor():
|
|
||||||
"""This class represents the structural content of a media file including streams and metadata"""
|
|
||||||
|
|
||||||
# CONTEXT_KEY = 'context'
|
|
||||||
|
|
||||||
ID_KEY = 'id'
|
|
||||||
NAME_KEY = 'name'
|
|
||||||
YEAR_KEY = 'year'
|
|
||||||
|
|
||||||
INDEX_SEASON_DIGITS_KEY = 'index_season_digits'
|
|
||||||
INDEX_EPISODE_DIGITS_KEY = 'index_episode_digits'
|
|
||||||
INDICATOR_SEASON_DIGITS_KEY = 'indicator_season_digits'
|
|
||||||
INDICATOR_EPISODE_DIGITS_KEY = 'indicator_episode_digits'
|
|
||||||
|
|
||||||
DEFAULT_INDEX_SEASON_DIGITS = 2
|
|
||||||
DEFAULT_INDEX_EPISODE_DIGITS = 2
|
|
||||||
DEFAULT_INDICATOR_SEASON_DIGITS = 2
|
|
||||||
DEFAULT_INDICATOR_EPISODE_DIGITS = 2
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
|
|
||||||
if ShowDescriptor.ID_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.ID_KEY]) is not int:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.ID_KEY} is required to be of type int")
|
|
||||||
self.__showId = kwargs[ShowDescriptor.ID_KEY]
|
|
||||||
else:
|
|
||||||
self.__showId = -1
|
|
||||||
|
|
||||||
if ShowDescriptor.NAME_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.NAME_KEY]) is not str:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.NAME_KEY} is required to be of type str")
|
|
||||||
self.__showName = kwargs[ShowDescriptor.NAME_KEY]
|
|
||||||
else:
|
|
||||||
self.__showName = ''
|
|
||||||
|
|
||||||
if ShowDescriptor.YEAR_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.YEAR_KEY]) is not int:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.YEAR_KEY} is required to be of type int")
|
|
||||||
self.__showYear = kwargs[ShowDescriptor.YEAR_KEY]
|
|
||||||
else:
|
|
||||||
self.__showYear = -1
|
|
||||||
|
|
||||||
if ShowDescriptor.INDEX_SEASON_DIGITS_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.INDEX_SEASON_DIGITS_KEY]) is not int:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.INDEX_SEASON_DIGITS_KEY} is required to be of type int")
|
|
||||||
self.__indexSeasonDigits = kwargs[ShowDescriptor.INDEX_SEASON_DIGITS_KEY]
|
|
||||||
else:
|
|
||||||
self.__indexSeasonDigits = -1
|
|
||||||
|
|
||||||
if ShowDescriptor.INDEX_EPISODE_DIGITS_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.INDEX_EPISODE_DIGITS_KEY]) is not int:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.INDEX_EPISODE_DIGITS_KEY} is required to be of type int")
|
|
||||||
self.__indexEpisodeDigits = kwargs[ShowDescriptor.INDEX_EPISODE_DIGITS_KEY]
|
|
||||||
else:
|
|
||||||
self.__indexEpisodeDigits = -1
|
|
||||||
|
|
||||||
if ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY]) is not int:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY} is required to be of type int")
|
|
||||||
self.__indicatorSeasonDigits = kwargs[ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY]
|
|
||||||
else:
|
|
||||||
self.__indicatorSeasonDigits = -1
|
|
||||||
|
|
||||||
if ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY]) is not int:
|
|
||||||
raise TypeError(f"ShowDescriptor.__init__(): Argument {ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY} is required to be of type int")
|
|
||||||
self.__indicatorEpisodeDigits = kwargs[ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY]
|
|
||||||
else:
|
|
||||||
self.__indicatorEpisodeDigits = -1
|
|
||||||
|
|
||||||
|
|
||||||
def getId(self):
|
|
||||||
return self.__showId
|
|
||||||
def getName(self):
|
|
||||||
return self.__showName
|
|
||||||
def getYear(self):
|
|
||||||
return self.__showYear
|
|
||||||
|
|
||||||
def getIndexSeasonDigits(self):
|
|
||||||
return self.__indexSeasonDigits
|
|
||||||
def getIndexEpisodeDigits(self):
|
|
||||||
return self.__indexEpisodeDigits
|
|
||||||
def getIndicatorSeasonDigits(self):
|
|
||||||
return self.__indicatorSeasonDigits
|
|
||||||
def getIndicatorEpisodeDigits(self):
|
|
||||||
return self.__indicatorEpisodeDigits
|
|
||||||
|
|
||||||
def getFilenamePrefix(self):
|
|
||||||
return f"{self.__showName} ({str(self.__showYear)})"
|
|
||||||
@@ -1,361 +0,0 @@
|
|||||||
import click
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button, DataTable, Input
|
|
||||||
from textual.containers import Grid
|
|
||||||
from textual.widgets._data_table import CellDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
from ffx.model.show import Show
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
|
|
||||||
from .pattern_details_screen import PatternDetailsScreen
|
|
||||||
from .pattern_delete_screen import PatternDeleteScreen
|
|
||||||
|
|
||||||
from .show_controller import ShowController
|
|
||||||
from .pattern_controller import PatternController
|
|
||||||
from .tmdb_controller import TmdbController
|
|
||||||
|
|
||||||
from .show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
from .helper import filterFilename
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class ShowDetailsScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 5 14;
|
|
||||||
grid-rows: 2 2 2 2 2 2 2 2 2 2 2 6 2 2;
|
|
||||||
grid-columns: 30 30 30 30 30;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
DataTable {
|
|
||||||
column-span: 2;
|
|
||||||
min-height: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
.five {
|
|
||||||
column-span: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
BINDINGS = [
|
|
||||||
("a", "add_pattern", "Add Pattern"),
|
|
||||||
("e", "edit_pattern", "Edit Pattern"),
|
|
||||||
("r", "remove_pattern", "Remove Pattern"),
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, showId = None):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__sc = ShowController(context = self.context)
|
|
||||||
self.__pc = PatternController(context = self.context)
|
|
||||||
self.__tc = TmdbController()
|
|
||||||
|
|
||||||
self.__showDescriptor = self.__sc.getShowDescriptor(showId) if showId is not None else None
|
|
||||||
|
|
||||||
|
|
||||||
def loadPatterns(self, show_id : int):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Pattern).filter(Pattern.show_id == int(show_id))
|
|
||||||
|
|
||||||
return [{'id': int(p.id), 'pattern': str(p.pattern)} for p in q.all()]
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"ShowDetailsScreen.loadPatterns(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
if not self.__showDescriptor is None:
|
|
||||||
|
|
||||||
self.query_one("#id_static", Static).update(str(self.__showDescriptor.getId()))
|
|
||||||
self.query_one("#name_input", Input).value = str(self.__showDescriptor.getName())
|
|
||||||
self.query_one("#year_input", Input).value = str(self.__showDescriptor.getYear())
|
|
||||||
|
|
||||||
self.query_one("#index_season_digits_input", Input).value = str(self.__showDescriptor.getIndexSeasonDigits())
|
|
||||||
self.query_one("#index_episode_digits_input", Input).value = str(self.__showDescriptor.getIndexEpisodeDigits())
|
|
||||||
self.query_one("#indicator_season_digits_input", Input).value = str(self.__showDescriptor.getIndicatorSeasonDigits())
|
|
||||||
self.query_one("#indicator_episode_digits_input", Input).value = str(self.__showDescriptor.getIndicatorEpisodeDigits())
|
|
||||||
|
|
||||||
showId = int(self.__showDescriptor.getId())
|
|
||||||
#raise click.ClickException(f"show_id {showId}")
|
|
||||||
patternList = self.loadPatterns(showId)
|
|
||||||
# raise click.ClickException(f"patternList {patternList}")
|
|
||||||
for pattern in patternList:
|
|
||||||
row = (pattern['pattern'],)
|
|
||||||
self.patternTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
self.query_one("#index_season_digits_input", Input).value = "2"
|
|
||||||
self.query_one("#index_episode_digits_input", Input).value = "2"
|
|
||||||
self.query_one("#indicator_season_digits_input", Input).value = "2"
|
|
||||||
self.query_one("#indicator_episode_digits_input", Input).value = "2"
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedPatternDescriptor(self):
|
|
||||||
|
|
||||||
selectedPattern = {}
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.patternTable.coordinate_to_cell_key(self.patternTable.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_row_data = self.patternTable.get_row(row_key)
|
|
||||||
|
|
||||||
selectedPattern['show_id'] = self.__showDescriptor.getId()
|
|
||||||
selectedPattern['pattern'] = str(selected_row_data[0])
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return selectedPattern
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def action_add_pattern(self):
|
|
||||||
if not self.__showDescriptor is None:
|
|
||||||
self.app.push_screen(PatternDetailsScreen(showId = self.__showDescriptor.getId()), self.handle_add_pattern) # <-
|
|
||||||
|
|
||||||
|
|
||||||
def handle_add_pattern(self, screenResult):
|
|
||||||
|
|
||||||
pattern = (screenResult['pattern'],)
|
|
||||||
self.patternTable.add_row(*map(str, pattern))
|
|
||||||
|
|
||||||
|
|
||||||
def action_edit_pattern(self):
|
|
||||||
|
|
||||||
selectedPatternDescriptor = self.getSelectedPatternDescriptor()
|
|
||||||
|
|
||||||
if selectedPatternDescriptor:
|
|
||||||
|
|
||||||
selectedPatternId = self.__pc.findPattern(selectedPatternDescriptor)
|
|
||||||
|
|
||||||
if selectedPatternId is None:
|
|
||||||
raise click.ClickException(f"ShowDetailsScreen.action_edit_pattern(): Pattern to edit has no id")
|
|
||||||
|
|
||||||
self.app.push_screen(PatternDetailsScreen(patternId = selectedPatternId, showId = self.__showDescriptor.getId()), self.handle_edit_pattern) # <-
|
|
||||||
|
|
||||||
|
|
||||||
def handle_edit_pattern(self, screenResult):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
row_key, col_key = self.patternTable.coordinate_to_cell_key(self.patternTable.cursor_coordinate)
|
|
||||||
self.patternTable.update_cell(row_key, self.column_key_pattern, screenResult['pattern'])
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def action_remove_pattern(self):
|
|
||||||
|
|
||||||
selectedPatternDescriptor = self.getSelectedPatternDescriptor()
|
|
||||||
|
|
||||||
if selectedPatternDescriptor:
|
|
||||||
|
|
||||||
selectedPatternId = self.__pc.findPattern(selectedPatternDescriptor)
|
|
||||||
|
|
||||||
if selectedPatternId is None:
|
|
||||||
raise click.ClickException(f"ShowDetailsScreen.action_remove_pattern(): Pattern to remove has no id")
|
|
||||||
|
|
||||||
self.app.push_screen(PatternDeleteScreen(patternId = selectedPatternId, showId = self.__showDescriptor.getId()), self.handle_remove_pattern)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_remove_pattern(self, screenResult):
|
|
||||||
|
|
||||||
try:
|
|
||||||
row_key, col_key = self.patternTable.coordinate_to_cell_key(self.patternTable.cursor_coordinate)
|
|
||||||
self.patternTable.remove_row(row_key)
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
# Create the DataTable widget
|
|
||||||
self.patternTable = DataTable(classes="five")
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_pattern = self.patternTable.add_column("Pattern", width=150)
|
|
||||||
|
|
||||||
self.patternTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
# 1
|
|
||||||
yield Static("Show" if not self.__showDescriptor is None else "New Show", id="toplabel")
|
|
||||||
yield Button("Identify", id="identify_button")
|
|
||||||
yield Static(" ", classes="three")
|
|
||||||
|
|
||||||
# 2
|
|
||||||
yield Static("ID")
|
|
||||||
if not self.__showDescriptor is None:
|
|
||||||
yield Static("", id="id_static", classes="four")
|
|
||||||
else:
|
|
||||||
yield Input(type="integer", id="id_input", classes="four")
|
|
||||||
|
|
||||||
# 3
|
|
||||||
yield Static("Name")
|
|
||||||
yield Input(type="text", id="name_input", classes="four")
|
|
||||||
|
|
||||||
# 4
|
|
||||||
yield Static("Year")
|
|
||||||
yield Input(type="integer", id="year_input", classes="four")
|
|
||||||
|
|
||||||
#5
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
#6
|
|
||||||
yield Static("Index Season Digits")
|
|
||||||
yield Input(type="integer", id="index_season_digits_input", classes="four")
|
|
||||||
|
|
||||||
#7
|
|
||||||
yield Static("Index Episode Digits")
|
|
||||||
yield Input(type="integer", id="index_episode_digits_input", classes="four")
|
|
||||||
|
|
||||||
#8
|
|
||||||
yield Static("Indicator Season Digits")
|
|
||||||
yield Input(type="integer", id="indicator_season_digits_input", classes="four")
|
|
||||||
|
|
||||||
#9
|
|
||||||
yield Static("Indicator Edisode Digits")
|
|
||||||
yield Input(type="integer", id="indicator_episode_digits_input", classes="four")
|
|
||||||
|
|
||||||
# 10
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 11
|
|
||||||
yield Static("File patterns", classes="five")
|
|
||||||
# 12
|
|
||||||
yield self.patternTable
|
|
||||||
|
|
||||||
# 13
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 14
|
|
||||||
yield Button("Save", id="save_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
def getShowDescriptorFromInput(self):
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
try:
|
|
||||||
if self.__showDescriptor:
|
|
||||||
kwargs[ShowDescriptor.ID_KEY] = int(self.__showDescriptor.getId())
|
|
||||||
else:
|
|
||||||
kwargs[ShowDescriptor.ID_KEY] = int(self.query_one("#id_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
kwargs[ShowDescriptor.NAME_KEY] = str(self.query_one("#name_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
kwargs[ShowDescriptor.YEAR_KEY] = int(self.query_one("#year_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
kwargs[ShowDescriptor.INDEX_SEASON_DIGITS_KEY] = int(self.query_one("#index_season_digits_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
kwargs[ShowDescriptor.INDEX_EPISODE_DIGITS_KEY] = int(self.query_one("#index_episode_digits_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
kwargs[ShowDescriptor.INDICATOR_SEASON_DIGITS_KEY] = int(self.query_one("#indicator_season_digits_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
kwargs[ShowDescriptor.INDICATOR_EPISODE_DIGITS_KEY] = int(self.query_one("#indicator_episode_digits_input", Input).value)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return ShowDescriptor(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
# Check if the button pressed is the one we are interested in
|
|
||||||
if event.button.id == "save_button":
|
|
||||||
|
|
||||||
showDescriptor = self.getShowDescriptorFromInput()
|
|
||||||
|
|
||||||
if not showDescriptor is None:
|
|
||||||
if self.__sc.updateShow(showDescriptor):
|
|
||||||
self.dismiss(showDescriptor)
|
|
||||||
else:
|
|
||||||
#TODO: Meldung
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
|
|
||||||
if event.button.id == "identify_button":
|
|
||||||
|
|
||||||
showDescriptor = self.getShowDescriptorFromInput()
|
|
||||||
if not showDescriptor is None:
|
|
||||||
showResult = self.__tc.queryShow(showDescriptor.getId())
|
|
||||||
firstAirDate = datetime.strptime(showResult['first_air_date'], '%Y-%m-%d')
|
|
||||||
|
|
||||||
self.query_one("#name_input", Input).value = filterFilename(showResult['name'])
|
|
||||||
self.query_one("#year_input", Input).value = str(firstAirDate.year)
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Placeholder, Label, ListView, ListItem, Static, DataTable, Button
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from ffx.model.show import Show
|
|
||||||
|
|
||||||
from .show_controller import ShowController
|
|
||||||
|
|
||||||
from .show_details_screen import ShowDetailsScreen
|
|
||||||
from .show_delete_screen import ShowDeleteScreen
|
|
||||||
|
|
||||||
from ffx.show_descriptor import ShowDescriptor
|
|
||||||
|
|
||||||
from .help_screen import HelpScreen
|
|
||||||
|
|
||||||
from textual.widgets._data_table import CellDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
class ShowsScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 1;
|
|
||||||
grid-rows: 2 auto;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#top {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#two {
|
|
||||||
column-span: 2;
|
|
||||||
row-span: 2;
|
|
||||||
tint: magenta 40%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
BINDINGS = [
|
|
||||||
("e", "edit_show", "Edit Show"),
|
|
||||||
("n", "new_show", "New Show"),
|
|
||||||
("d", "delete_show", "Delete Show"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__sc = ShowController(context = self.context)
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedShowId(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_row_data = self.table.get_row(row_key)
|
|
||||||
|
|
||||||
return selected_row_data[0]
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def action_new_show(self):
|
|
||||||
self.app.push_screen(ShowDetailsScreen(), self.handle_new_screen)
|
|
||||||
|
|
||||||
def handle_new_screen(self, screenResult):
|
|
||||||
|
|
||||||
show = (screenResult['id'], screenResult['name'], screenResult['year'])
|
|
||||||
self.table.add_row(*map(str, show))
|
|
||||||
|
|
||||||
|
|
||||||
def action_edit_show(self):
|
|
||||||
|
|
||||||
selectedShowId = self.getSelectedShowId()
|
|
||||||
|
|
||||||
if selectedShowId is not None:
|
|
||||||
self.app.push_screen(ShowDetailsScreen(showId = selectedShowId), self.handle_edit_screen)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_edit_screen(self, showDescriptor: ShowDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
row_key, col_key = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
|
|
||||||
|
|
||||||
self.table.update_cell(row_key, self.column_key_name, showDescriptor.getName())
|
|
||||||
self.table.update_cell(row_key, self.column_key_year, showDescriptor.getYear())
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def action_delete_show(self):
|
|
||||||
|
|
||||||
selectedShowId = self.getSelectedShowId()
|
|
||||||
|
|
||||||
if selectedShowId is not None:
|
|
||||||
self.app.push_screen(ShowDeleteScreen(showId = selectedShowId), self.handle_delete_show)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_delete_show(self, showDescriptor: ShowDescriptor):
|
|
||||||
|
|
||||||
try:
|
|
||||||
row_key, col_key = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
|
|
||||||
self.table.remove_row(row_key)
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
|
||||||
for show in self.__sc.getAllShows():
|
|
||||||
row = (int(show.id), show.name, show.year) # Convert each element to a string before adding
|
|
||||||
self.table.add_row(*map(str, row))
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
# Create the DataTable widget
|
|
||||||
self.table = DataTable()
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_id = self.table.add_column("ID", width=10)
|
|
||||||
self.column_key_name = self.table.add_column("Name", width=50)
|
|
||||||
self.column_key_year = self.table.add_column("Year", width=10)
|
|
||||||
|
|
||||||
self.table.cursor_type = 'row'
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
yield Static("Shows")
|
|
||||||
|
|
||||||
yield self.table
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
56
bin/ffx/stream_descriptor.py
Normal file
56
bin/ffx/stream_descriptor.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
from language_data import LanguageData
|
||||||
|
from stream_type import StreamType
|
||||||
|
|
||||||
|
class StreamDescriptor():
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
streamType : StreamType,
|
||||||
|
language : LanguageData,
|
||||||
|
title : str,
|
||||||
|
codec : str,
|
||||||
|
subIndex : int = -1):
|
||||||
|
|
||||||
|
self.__streamType = streamType
|
||||||
|
self.__subIndex = subIndex
|
||||||
|
|
||||||
|
self.__streamLanguage = language
|
||||||
|
self.__streamTitle = title
|
||||||
|
|
||||||
|
self.__codecName = codec
|
||||||
|
|
||||||
|
# "index": 4,
|
||||||
|
# "codec_name": "hdmv_pgs_subtitle",
|
||||||
|
# "codec_long_name": "HDMV Presentation Graphic Stream subtitles",
|
||||||
|
# "codec_type": "subtitle",
|
||||||
|
# "codec_tag_string": "[0][0][0][0]",
|
||||||
|
# "codec_tag": "0x0000",
|
||||||
|
# "r_frame_rate": "0/0",
|
||||||
|
# "avg_frame_rate": "0/0",
|
||||||
|
# "time_base": "1/1000",
|
||||||
|
# "start_pts": 0,
|
||||||
|
# "start_time": "0.000000",
|
||||||
|
# "duration_ts": 1421035,
|
||||||
|
# "duration": "1421.035000",
|
||||||
|
# "disposition": {
|
||||||
|
# "default": 1,
|
||||||
|
# "dub": 0,
|
||||||
|
# "original": 0,
|
||||||
|
# "comment": 0,
|
||||||
|
# "lyrics": 0,
|
||||||
|
# "karaoke": 0,
|
||||||
|
# "forced": 0,
|
||||||
|
# "hearing_impaired": 0,
|
||||||
|
# "visual_impaired": 0,
|
||||||
|
# "clean_effects": 0,
|
||||||
|
# "attached_pic": 0,
|
||||||
|
# "timed_thumbnails": 0,
|
||||||
|
# "non_diegetic": 0,
|
||||||
|
# "captions": 0,
|
||||||
|
# "descriptions": 0,
|
||||||
|
# "metadata": 0,
|
||||||
|
# "dependent": 0,
|
||||||
|
# "still_image": 0
|
||||||
|
# },
|
||||||
|
# "tags": {
|
||||||
|
# "language": "ger",
|
||||||
|
# "title": "German Full"
|
||||||
6
bin/ffx/stream_type.py
Normal file
6
bin/ffx/stream_type.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
class StreamType(Enum):
|
||||||
|
VIDEO = 1
|
||||||
|
AUDIO = 2
|
||||||
|
SUBTITLE = 3
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from ffx.model.track import Track
|
|
||||||
|
|
||||||
from ffx.model.media_tag import MediaTag
|
|
||||||
from ffx.model.track_tag import TrackTag
|
|
||||||
|
|
||||||
|
|
||||||
class TagController():
|
|
||||||
|
|
||||||
def __init__(self, context):
|
|
||||||
|
|
||||||
self.context = context
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
|
|
||||||
def updateMediaTag(self, patternId, tagKey, tagValue):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(MediaTag).filter(MediaTag.pattern_id == int(patternId),
|
|
||||||
MediaTag.key == str(tagKey))
|
|
||||||
tag = q.first()
|
|
||||||
if tag:
|
|
||||||
tag.value = str(tagValue)
|
|
||||||
else:
|
|
||||||
tag = MediaTag(pattern_id = int(patternId),
|
|
||||||
key = str(tagKey),
|
|
||||||
value = str(tagValue))
|
|
||||||
s.add(tag)
|
|
||||||
s.commit()
|
|
||||||
|
|
||||||
return int(tag.id)
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.updateTrackTag(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def updateTrackTag(self, trackId, tagKey, tagValue):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(TrackTag).filter(TrackTag.track_id == int(trackId),
|
|
||||||
TrackTag.key == str(tagKey))
|
|
||||||
tag = q.first()
|
|
||||||
if tag:
|
|
||||||
tag.value = str(tagValue)
|
|
||||||
else:
|
|
||||||
tag = TrackTag(track_id = int(trackId),
|
|
||||||
key = str(tagKey),
|
|
||||||
value = str(tagValue))
|
|
||||||
s.add(tag)
|
|
||||||
s.commit()
|
|
||||||
|
|
||||||
return int(tag.id)
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.updateTrackTag(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def deleteMediaTagByKey(self, patternId, tagKey):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(MediaTag).filter(MediaTag.pattern_id == int(patternId),
|
|
||||||
MediaTag.key == str(tagKey))
|
|
||||||
if q.count():
|
|
||||||
tag = q.first()
|
|
||||||
s.delete(tag)
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.deleteMediaTagByKey(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def deleteTrackTagByKey(self, trackId, tagKey):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(TrackTag).filter(TrackTag.track_id == int(trackId),
|
|
||||||
TrackTag.key == str(tagKey))
|
|
||||||
tag = q.first()
|
|
||||||
if tag:
|
|
||||||
s.delete(tag)
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.deleteTrackTagByKey(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def findAllMediaTags(self, patternId) -> dict:
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(MediaTag).filter(MediaTag.pattern_id == int(patternId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return {t.key:t.value for t in q.all()}
|
|
||||||
else:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.findAllMediaTags(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def findAllTrackTags(self, trackId) -> dict:
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(TrackTag).filter(TrackTag.track_id == int(trackId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return {t.key:t.value for t in q.all()}
|
|
||||||
else:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.findAllTracks(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def findMediaTag(self, trackId : int, trackKey : str) -> MediaTag:
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Track).filter(MediaTag.track_id == int(trackId), MediaTag.key == str(trackKey))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return q.first()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.findMediaTag(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def findTrackTag(self, trackId : int, tagKey : str) -> TrackTag:
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(TrackTag).filter(TrackTag.track_id == int(trackId), TrackTag.key == str(tagKey))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return q.first()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.findTrackTag(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def deleteMediaTag(self, tagId) -> bool:
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(MediaTag).filter(MediaTag.id == int(tagId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
tag = q.first()
|
|
||||||
|
|
||||||
s.delete(tag)
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.deleteMediaTag(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def deleteTrackTag(self, tagId : int) -> bool:
|
|
||||||
|
|
||||||
if type(tagId) is not int:
|
|
||||||
raise TypeError('TagController.deleteTrackTag(): Argument tagId is required to be of type int')
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(TrackTag).filter(TrackTag.id == int(tagId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
tag = q.first()
|
|
||||||
|
|
||||||
s.delete(tag)
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TagController.deleteTrackTag(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class TagDeleteScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 4 9;
|
|
||||||
grid-rows: 2 2 2 2 2 2 2 2 2;
|
|
||||||
grid-columns: 30 30 30 30;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
.five {
|
|
||||||
column-span: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, key=None, value=None):
|
|
||||||
super().__init__()
|
|
||||||
self.__key = key
|
|
||||||
self.__value = value
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
self.query_one("#keylabel", Static).update(str(self.__key))
|
|
||||||
self.query_one("#valuelabel", Static).update(str(self.__value))
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
#1
|
|
||||||
yield Static(f"Are you sure to delete this tag ?", id="toplabel", classes="five")
|
|
||||||
|
|
||||||
#2
|
|
||||||
yield Static("Key")
|
|
||||||
yield Static(" ", id="keylabel", classes="four")
|
|
||||||
|
|
||||||
#3
|
|
||||||
yield Static("Value")
|
|
||||||
yield Static(" ", id="valuelabel", classes="four")
|
|
||||||
|
|
||||||
#4
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
#9
|
|
||||||
yield Button("Delete", id="delete_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
if event.button.id == "delete_button":
|
|
||||||
|
|
||||||
tag = (self.__key, self.__value)
|
|
||||||
self.dismiss(tag)
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button, Input
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class TagDetailsScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 5 20;
|
|
||||||
grid-rows: 2 2 2 2 2 3 2 2 2 2 2 6 2 2 6 2 2 2 2 6;
|
|
||||||
grid-columns: 25 25 25 25 225;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
SelectionList {
|
|
||||||
border: none;
|
|
||||||
min-height: 6;
|
|
||||||
}
|
|
||||||
Select {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
DataTable {
|
|
||||||
min-height: 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
.five {
|
|
||||||
column-span: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, key=None, value=None):
|
|
||||||
super().__init__()
|
|
||||||
self.__key = key
|
|
||||||
self.__value = value
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
if self.__key is not None:
|
|
||||||
self.query_one("#key_input", Input).value = str(self.__key)
|
|
||||||
|
|
||||||
if self.__value is not None:
|
|
||||||
self.query_one("#value_input", Input).value = str(self.__value)
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
# 8
|
|
||||||
yield Static("Key")
|
|
||||||
yield Input(id="key_input", classes="four")
|
|
||||||
|
|
||||||
yield Static("Value")
|
|
||||||
yield Input(id="value_input", classes="four")
|
|
||||||
|
|
||||||
# 17
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 18
|
|
||||||
yield Button("Save", id="save_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
# 19
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 20
|
|
||||||
yield Static(" ", classes="five", id="messagestatic")
|
|
||||||
|
|
||||||
yield Footer(id="footer")
|
|
||||||
|
|
||||||
|
|
||||||
def getTagFromInput(self):
|
|
||||||
|
|
||||||
tagKey = self.query_one("#key_input", Input).value
|
|
||||||
tagValue = self.query_one("#value_input", Input).value
|
|
||||||
|
|
||||||
return (tagKey, tagValue)
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
# Check if the button pressed is the one we are interested in
|
|
||||||
if event.button.id == "save_button":
|
|
||||||
self.dismiss(self.getTagFromInput())
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
import os, click, requests, json
|
|
||||||
|
|
||||||
|
|
||||||
class TmdbController():
|
|
||||||
|
|
||||||
DEFAULT_LANGUAGE = 'de-DE'
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.__tmdbApiKey = os.environ['TMDB_API_KEY']
|
|
||||||
except KeyError:
|
|
||||||
click.ClickException('TMDB api key is not available, please set environment variable TMDB_API_KEY')
|
|
||||||
|
|
||||||
self.tmdbLanguage = TmdbController.DEFAULT_LANGUAGE
|
|
||||||
|
|
||||||
def queryShow(self, showId):
|
|
||||||
"""
|
|
||||||
First level keys in the response object:
|
|
||||||
adult bool
|
|
||||||
backdrop_path str
|
|
||||||
created_by []
|
|
||||||
episode_run_time []
|
|
||||||
first_air_date str YYYY-MM-DD
|
|
||||||
genres []
|
|
||||||
homepage str
|
|
||||||
id int
|
|
||||||
in_production bool
|
|
||||||
languages []
|
|
||||||
last_air_date str YYYY-MM-DD
|
|
||||||
last_episode_to_air {}
|
|
||||||
name str
|
|
||||||
next_episode_to_air null
|
|
||||||
networks []
|
|
||||||
number_of_episodes int
|
|
||||||
number_of_seasons int
|
|
||||||
origin_country []
|
|
||||||
original_language str
|
|
||||||
original_name str
|
|
||||||
overview str
|
|
||||||
popularity float
|
|
||||||
poster_path str
|
|
||||||
production_companies []
|
|
||||||
production_countries []
|
|
||||||
seasons []
|
|
||||||
spoken_languages []
|
|
||||||
status str
|
|
||||||
tagline str
|
|
||||||
type str
|
|
||||||
vote_average float
|
|
||||||
vote_count int
|
|
||||||
"""
|
|
||||||
|
|
||||||
urlParams = f"?language={self.tmdbLanguage}&api_key={self.__tmdbApiKey}"
|
|
||||||
|
|
||||||
tmdbUrl = f"https://api.themoviedb.org/3/tv/{showId}W{urlParams}"
|
|
||||||
|
|
||||||
#TODO Check for result
|
|
||||||
try:
|
|
||||||
#TODO: Content Type aware processing
|
|
||||||
# response = requests.get(tmdbUrl)
|
|
||||||
# response.encoding = 'utf-8'
|
|
||||||
# return response.json()
|
|
||||||
# response = requests.get(tmdbUrl)
|
|
||||||
|
|
||||||
# contentType = response.headers.get('Content-Type')
|
|
||||||
# print(content_type) # Example: 'application/json; charset=UTF-8'
|
|
||||||
|
|
||||||
# decoded_content = response.content.decode('utf-8')
|
|
||||||
# return json.loads(decoded_content)
|
|
||||||
return requests.get(tmdbUrl).json()
|
|
||||||
except:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def queryEpisode(self, showId, season, episode):
|
|
||||||
"""
|
|
||||||
First level keys in the response object:
|
|
||||||
air_date str 'YYY-MM-DD'
|
|
||||||
crew []
|
|
||||||
episode_number int
|
|
||||||
guest_stars []
|
|
||||||
name str
|
|
||||||
overview str
|
|
||||||
id int
|
|
||||||
production_code
|
|
||||||
runtime int
|
|
||||||
season_number int
|
|
||||||
still_path str '/filename.jpg'
|
|
||||||
vote_average float
|
|
||||||
vote_count int
|
|
||||||
"""
|
|
||||||
|
|
||||||
urlParams = f"?language={self.tmdbLanguage}&api_key={self.__tmdbApiKey}"
|
|
||||||
|
|
||||||
tmdbUrl = f"https://api.themoviedb.org/3/tv/{showId}/season/{season}/episode/{episode}{urlParams}"
|
|
||||||
|
|
||||||
#TODO Check for result
|
|
||||||
try:
|
|
||||||
return requests.get(tmdbUrl).json()
|
|
||||||
except:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def getEpisodeFileBasename(self,
|
|
||||||
showName,
|
|
||||||
episodeName,
|
|
||||||
season,
|
|
||||||
episode,
|
|
||||||
indexSeasonDigits = 2,
|
|
||||||
indexEpisodeDigits = 2,
|
|
||||||
indicatorSeasonDigits = 2,
|
|
||||||
indicatorEpisodeDigits = 2):
|
|
||||||
"""
|
|
||||||
One Piece:
|
|
||||||
indexSeasonDigits = 0,
|
|
||||||
indexEpisodeDigits = 4,
|
|
||||||
indicatorSeasonDigits = 2,
|
|
||||||
indicatorEpisodeDigits = 4
|
|
||||||
|
|
||||||
Three-Body:
|
|
||||||
indexSeasonDigits = 0,
|
|
||||||
indexEpisodeDigits = 2,
|
|
||||||
indicatorSeasonDigits = 2,
|
|
||||||
indicatorEpisodeDigits = 2
|
|
||||||
|
|
||||||
Dragonball:
|
|
||||||
indexSeasonDigits = 0,
|
|
||||||
indexEpisodeDigits = 3,
|
|
||||||
indicatorSeasonDigits = 2,
|
|
||||||
indicatorEpisodeDigits = 3
|
|
||||||
|
|
||||||
Boruto:
|
|
||||||
indexSeasonDigits = 0,
|
|
||||||
indexEpisodeDigits = 4,
|
|
||||||
indicatorSeasonDigits = 2,
|
|
||||||
indicatorEpisodeDigits = 4
|
|
||||||
"""
|
|
||||||
filenameTokens = [str(showName), ' - ']
|
|
||||||
|
|
||||||
if indexSeasonDigits:
|
|
||||||
filenameTokens += ['{num:{fill}{width}}'.format(num=season, fill='0', width=indexSeasonDigits)]
|
|
||||||
if indexEpisodeDigits:
|
|
||||||
filenameTokens += ['{num:{fill}{width}}'.format(num=episode, fill='0', width=indexEpisodeDigits)]
|
|
||||||
if indexSeasonDigits or indexEpisodeDigits:
|
|
||||||
filenameTokens += [' ']
|
|
||||||
|
|
||||||
filenameTokens += [episodeName]
|
|
||||||
|
|
||||||
if indicatorSeasonDigits or indicatorEpisodeDigits:
|
|
||||||
filenameTokens += [' - ']
|
|
||||||
if indicatorSeasonDigits:
|
|
||||||
filenameTokens += ['S{num:{fill}{width}}'.format(num=season, fill='0', width=indicatorSeasonDigits)]
|
|
||||||
if indicatorEpisodeDigits:
|
|
||||||
filenameTokens += ['E{num:{fill}{width}}'.format(num=episode, fill='0', width=indicatorEpisodeDigits)]
|
|
||||||
|
|
||||||
return ''.join(filenameTokens)
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from ffx.model.track import Track
|
|
||||||
|
|
||||||
from .track_type import TrackType
|
|
||||||
|
|
||||||
from .track_disposition import TrackDisposition
|
|
||||||
from .iso_language import IsoLanguage
|
|
||||||
|
|
||||||
from .track_type import TrackType
|
|
||||||
|
|
||||||
from ffx.model.track_tag import TrackTag
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
class TrackController():
|
|
||||||
|
|
||||||
def __init__(self, context):
|
|
||||||
|
|
||||||
self.context = context
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
|
|
||||||
def addTrack(self, trackDescriptor : TrackDescriptor, patternId = None):
|
|
||||||
|
|
||||||
# option to override pattern id in case track descriptor has not set it
|
|
||||||
patId = int(trackDescriptor.getPatternId() if patternId is None else patternId)
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
track = Track(pattern_id = patId,
|
|
||||||
track_type = int(trackDescriptor.getType().index()),
|
|
||||||
codec_name = str(trackDescriptor.getCodec()),
|
|
||||||
index = int(trackDescriptor.getIndex()),
|
|
||||||
source_index = int(trackDescriptor.getSourceIndex()),
|
|
||||||
disposition_flags = int(TrackDisposition.toFlags(trackDescriptor.getDispositionSet())),
|
|
||||||
audio_layout = trackDescriptor.getAudioLayout().index())
|
|
||||||
|
|
||||||
s.add(track)
|
|
||||||
s.commit()
|
|
||||||
|
|
||||||
for k,v in trackDescriptor.getTags().items():
|
|
||||||
|
|
||||||
tag = TrackTag(track_id = track.id,
|
|
||||||
key = k,
|
|
||||||
value = v)
|
|
||||||
s.add(tag)
|
|
||||||
s.commit()
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.addTrack(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def updateTrack(self, trackId, trackDescriptor : TrackDescriptor):
|
|
||||||
|
|
||||||
if type(trackDescriptor) is not TrackDescriptor:
|
|
||||||
raise TypeError('TrackController.updateTrack(): Argument trackDescriptor is required to be of type TrackDescriptor')
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Track).filter(Track.id == int(trackId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
track : Track = q.first()
|
|
||||||
|
|
||||||
track.track_type = int(trackDescriptor.getType().index())
|
|
||||||
track.codec_name = str(trackDescriptor.getCodec())
|
|
||||||
track.audio_layout = int(trackDescriptor.getAudioLayout().index())
|
|
||||||
|
|
||||||
track.disposition_flags = int(TrackDisposition.toFlags(trackDescriptor.getDispositionSet()))
|
|
||||||
|
|
||||||
descriptorTagKeys = trackDescriptor.getTags()
|
|
||||||
tagKeysInDescriptor = set(descriptorTagKeys.keys())
|
|
||||||
tagKeysInDb = {t.key for t in track.track_tags}
|
|
||||||
|
|
||||||
for k in tagKeysInDescriptor & tagKeysInDb: # to update
|
|
||||||
tags = [t for t in track.track_tags if t.key == k]
|
|
||||||
tags[0].value = descriptorTagKeys[k]
|
|
||||||
for k in tagKeysInDescriptor - tagKeysInDb: # to add
|
|
||||||
tag = TrackTag(track_id=track.id, key=k, value=descriptorTagKeys[k])
|
|
||||||
s.add(tag)
|
|
||||||
for k in tagKeysInDb - tagKeysInDescriptor: # to remove
|
|
||||||
tags = [t for t in track.track_tags if t.key == k]
|
|
||||||
s.delete(tags[0])
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.updateTrack(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def findTracks(self, patternId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(Track).filter(Track.pattern_id == int(patternId))
|
|
||||||
return [a for a in q.all()]
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.findTracks(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
#TODO: mit optionalem Parameter lösen ^
|
|
||||||
def findVideoTracks(self, patternId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(Track).filter(Track.pattern_id == int(patternId), Track.track_type == TrackType.VIDEO.index())
|
|
||||||
return [a for a in q.all()]
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.findVideoTracks(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def findAudioTracks(self, patternId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(Track).filter(Track.pattern_id == int(patternId), Track.track_type == TrackType.AUDIO.index())
|
|
||||||
return [a for a in q.all()]
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.findAudioTracks(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def findSubtitleTracks(self, patternId):
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(Track).filter(Track.pattern_id == int(patternId), Track.track_type == TrackType.SUBTITLE.index())
|
|
||||||
return [s for s in q.all()]
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.findSubtitleTracks(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def getTrack(self, patternId : int, index: int) -> Track:
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Track).filter(Track.pattern_id == int(patternId), Track.index == int(index))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
return q.first()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.getTrack(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def setDispositionState(self, patternId: int, index: int, disposition : TrackDisposition, state : bool):
|
|
||||||
|
|
||||||
if type(patternId) is not int:
|
|
||||||
raise TypeError('TrackController.setTrackDisposition(): Argument patternId is required to be of type int')
|
|
||||||
if type(index) is not int:
|
|
||||||
raise TypeError('TrackController.setTrackDisposition(): Argument index is required to be of type int')
|
|
||||||
if type(disposition) is not TrackDisposition:
|
|
||||||
raise TypeError('TrackController.setTrackDisposition(): Argument disposition is required to be of type TrackDisposition')
|
|
||||||
if type(state) is not bool:
|
|
||||||
raise TypeError('TrackController.setTrackDisposition(): Argument state is required to be of type bool')
|
|
||||||
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
q = s.query(Track).filter(Track.pattern_id == patternId, Track.index == index)
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
|
|
||||||
track : Track = q.first()
|
|
||||||
|
|
||||||
if state:
|
|
||||||
track.setDisposition(disposition)
|
|
||||||
else:
|
|
||||||
track.resetDisposition(disposition)
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.updateTrack(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
def deleteTrack(self, trackId):
|
|
||||||
try:
|
|
||||||
s = self.Session()
|
|
||||||
|
|
||||||
q = s.query(Track).filter(Track.id == int(trackId))
|
|
||||||
|
|
||||||
if q.count():
|
|
||||||
patternId = int(q.first().pattern_id)
|
|
||||||
|
|
||||||
q_siblings = s.query(Track).filter(Track.pattern_id == patternId).order_by(Track.index)
|
|
||||||
|
|
||||||
index = 0
|
|
||||||
for track in q_siblings.all():
|
|
||||||
|
|
||||||
if track.id == int(trackId):
|
|
||||||
s.delete(track)
|
|
||||||
else:
|
|
||||||
track.index = index
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
s.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
raise click.ClickException(f"TrackController.deleteTrack(): {repr(ex)}")
|
|
||||||
finally:
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
|
|
||||||
def setDefaultSubTrack(self, trackType, subIndex):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def setForcedSubTrack(self, trackType, subIndex):
|
|
||||||
pass
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from textual import events
|
|
||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
from ffx.model.track import Track
|
|
||||||
from ffx.track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
from .track_controller import TrackController
|
|
||||||
|
|
||||||
from .track_type import TrackType
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class TrackDeleteScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 4 9;
|
|
||||||
grid-rows: 2 2 2 2 2 2 2 2 2;
|
|
||||||
grid-columns: 30 30 30 30;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, trackDescriptor : TrackDescriptor):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
if type(trackDescriptor) is not TrackDescriptor:
|
|
||||||
raise click.ClickException('TrackDeleteScreen.init(): trackDescriptor is required to be of type TrackDescriptor')
|
|
||||||
|
|
||||||
self.__tc = TrackController(context = self.context)
|
|
||||||
|
|
||||||
self.__trackDescriptor = trackDescriptor
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
self.query_one("#subindexlabel", Static).update(str(self.__trackDescriptor.getSubIndex()))
|
|
||||||
self.query_one("#patternlabel", Static).update(str(self.__trackDescriptor.getPatternId()))
|
|
||||||
self.query_one("#languagelabel", Static).update(str(self.__trackDescriptor.getLanguage().label()))
|
|
||||||
self.query_one("#titlelabel", Static).update(str(str(self.__trackDescriptor.getTitle())))
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
#1
|
|
||||||
yield Static(f"Are you sure to delete the following {self.__trackDescriptor.getType().label()} track?", id="toplabel", classes="four")
|
|
||||||
|
|
||||||
#2
|
|
||||||
yield Static("sub index")
|
|
||||||
yield Static(" ", id="subindexlabel", classes="three")
|
|
||||||
|
|
||||||
#3
|
|
||||||
yield Static("from pattern")
|
|
||||||
yield Static(" ", id="patternlabel", classes="three")
|
|
||||||
|
|
||||||
#4
|
|
||||||
yield Static(" ", classes="four")
|
|
||||||
|
|
||||||
#5
|
|
||||||
yield Static("Language")
|
|
||||||
yield Static(" ", id="languagelabel", classes="three")
|
|
||||||
|
|
||||||
#6
|
|
||||||
yield Static("Title")
|
|
||||||
yield Static(" ", id="titlelabel", classes="three")
|
|
||||||
|
|
||||||
#7
|
|
||||||
yield Static(" ", classes="four")
|
|
||||||
|
|
||||||
#8
|
|
||||||
yield Static(" ", classes="four")
|
|
||||||
|
|
||||||
#9
|
|
||||||
yield Button("Delete", id="delete_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
if event.button.id == "delete_button":
|
|
||||||
|
|
||||||
track = self.__tc.getTrack(self.__trackDescriptor.getPatternId(), self.__trackDescriptor.getIndex())
|
|
||||||
|
|
||||||
if track is None:
|
|
||||||
raise click.ClickException(f"Track is none: patternId={self.__trackDescriptor.getPatternId()} type={self.__trackDescriptor.getType()} subIndex={self.__trackDescriptor.getSubIndex()}")
|
|
||||||
|
|
||||||
if track is not None:
|
|
||||||
|
|
||||||
if self.__tc.deleteTrack(track.getId()):
|
|
||||||
self.dismiss(self.__trackDescriptor)
|
|
||||||
|
|
||||||
else:
|
|
||||||
#TODO: Meldung
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
@@ -1,315 +0,0 @@
|
|||||||
import click
|
|
||||||
|
|
||||||
from .iso_language import IsoLanguage
|
|
||||||
from .track_type import TrackType
|
|
||||||
from .audio_layout import AudioLayout
|
|
||||||
from .track_disposition import TrackDisposition
|
|
||||||
|
|
||||||
from .helper import dictDiff, setDiff
|
|
||||||
|
|
||||||
|
|
||||||
class TrackDescriptor:
|
|
||||||
|
|
||||||
ID_KEY = "id"
|
|
||||||
INDEX_KEY = "index"
|
|
||||||
SOURCE_INDEX_KEY = "source_index"
|
|
||||||
SUB_INDEX_KEY = "sub_index"
|
|
||||||
PATTERN_ID_KEY = "pattern_id"
|
|
||||||
EXTERNAL_SOURCE_FILE_PATH_KEY = "external_source_file"
|
|
||||||
|
|
||||||
DISPOSITION_SET_KEY = "disposition_set"
|
|
||||||
TAGS_KEY = "tags"
|
|
||||||
|
|
||||||
TRACK_TYPE_KEY = "track_type"
|
|
||||||
CODEC_NAME_KEY = "codec_name"
|
|
||||||
AUDIO_LAYOUT_KEY = "audio_layout"
|
|
||||||
|
|
||||||
FFPROBE_INDEX_KEY = "index"
|
|
||||||
FFPROBE_DISPOSITION_KEY = "disposition"
|
|
||||||
FFPROBE_TAGS_KEY = "tags"
|
|
||||||
FFPROBE_CODEC_TYPE_KEY = "codec_type"
|
|
||||||
FFPROBE_CODEC_NAME_KEY = "codec_name"
|
|
||||||
|
|
||||||
CODEC_PGS = 'hdmv_pgs_subtitle'
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
|
|
||||||
if TrackDescriptor.ID_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.ID_KEY]) is not int:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.ID_KEY} is required to be of type int"
|
|
||||||
)
|
|
||||||
self.__trackId = kwargs[TrackDescriptor.ID_KEY]
|
|
||||||
else:
|
|
||||||
self.__trackId = -1
|
|
||||||
|
|
||||||
if TrackDescriptor.PATTERN_ID_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.PATTERN_ID_KEY]) is not int:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.PATTERN_ID_KEY} is required to be of type int"
|
|
||||||
)
|
|
||||||
self.__patternId = kwargs[TrackDescriptor.PATTERN_ID_KEY]
|
|
||||||
else:
|
|
||||||
self.__patternId = -1
|
|
||||||
|
|
||||||
if TrackDescriptor.EXTERNAL_SOURCE_FILE_PATH_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.EXTERNAL_SOURCE_FILE_PATH_KEY]) is not str:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.EXTERNAL_SOURCE_FILE_PATH_KEY} is required to be of type str"
|
|
||||||
)
|
|
||||||
self.__externalSourceFilePath = kwargs[TrackDescriptor.EXTERNAL_SOURCE_FILE_PATH_KEY]
|
|
||||||
else:
|
|
||||||
self.__externalSourceFilePath = ''
|
|
||||||
|
|
||||||
if TrackDescriptor.INDEX_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.INDEX_KEY]) is not int:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.INDEX_KEY} is required to be of type int"
|
|
||||||
)
|
|
||||||
self.__index = kwargs[TrackDescriptor.INDEX_KEY]
|
|
||||||
else:
|
|
||||||
self.__index = -1
|
|
||||||
|
|
||||||
if (
|
|
||||||
TrackDescriptor.SOURCE_INDEX_KEY in kwargs.keys()
|
|
||||||
and type(kwargs[TrackDescriptor.SOURCE_INDEX_KEY]) is int
|
|
||||||
):
|
|
||||||
self.__sourceIndex = kwargs[TrackDescriptor.SOURCE_INDEX_KEY]
|
|
||||||
else:
|
|
||||||
self.__sourceIndex = self.__index
|
|
||||||
|
|
||||||
if TrackDescriptor.SUB_INDEX_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.SUB_INDEX_KEY]) is not int:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.SUB_INDEX_KEY} is required to be of type int"
|
|
||||||
)
|
|
||||||
self.__subIndex = kwargs[TrackDescriptor.SUB_INDEX_KEY]
|
|
||||||
else:
|
|
||||||
self.__subIndex = -1
|
|
||||||
|
|
||||||
if TrackDescriptor.TRACK_TYPE_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.TRACK_TYPE_KEY]) is not TrackType:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.TRACK_TYPE_KEY} is required to be of type TrackType"
|
|
||||||
)
|
|
||||||
self.__trackType = kwargs[TrackDescriptor.TRACK_TYPE_KEY]
|
|
||||||
else:
|
|
||||||
self.__trackType = TrackType.UNKNOWN
|
|
||||||
|
|
||||||
if TrackDescriptor.CODEC_NAME_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.CODEC_NAME_KEY]) is not str:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.CODEC_NAME_KEY} is required to be of type str"
|
|
||||||
)
|
|
||||||
self.__codecName = kwargs[TrackDescriptor.CODEC_NAME_KEY]
|
|
||||||
else:
|
|
||||||
self.__codecName = ''
|
|
||||||
|
|
||||||
if TrackDescriptor.TAGS_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.TAGS_KEY]) is not dict:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.TAGS_KEY} is required to be of type dict"
|
|
||||||
)
|
|
||||||
self.__trackTags = kwargs[TrackDescriptor.TAGS_KEY]
|
|
||||||
else:
|
|
||||||
self.__trackTags = {}
|
|
||||||
|
|
||||||
if TrackDescriptor.DISPOSITION_SET_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.DISPOSITION_SET_KEY]) is not set:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.DISPOSITION_SET_KEY} is required to be of type set"
|
|
||||||
)
|
|
||||||
for d in kwargs[TrackDescriptor.DISPOSITION_SET_KEY]:
|
|
||||||
if type(d) is not TrackDisposition:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): All elements of argument set {TrackDescriptor.DISPOSITION_SET_KEY} is required to be of type TrackDisposition"
|
|
||||||
)
|
|
||||||
self.__dispositionSet = kwargs[TrackDescriptor.DISPOSITION_SET_KEY]
|
|
||||||
else:
|
|
||||||
self.__dispositionSet = set()
|
|
||||||
|
|
||||||
if TrackDescriptor.AUDIO_LAYOUT_KEY in kwargs.keys():
|
|
||||||
if type(kwargs[TrackDescriptor.AUDIO_LAYOUT_KEY]) is not AudioLayout:
|
|
||||||
raise TypeError(
|
|
||||||
f"TrackDesciptor.__init__(): Argument {TrackDescriptor.AUDIO_LAYOUT_KEY} is required to be of type AudioLayout"
|
|
||||||
)
|
|
||||||
self.__audioLayout = kwargs[TrackDescriptor.AUDIO_LAYOUT_KEY]
|
|
||||||
else:
|
|
||||||
self.__audioLayout = AudioLayout.LAYOUT_UNDEFINED
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fromFfprobe(cls, streamObj, subIndex: int = -1):
|
|
||||||
"""Processes ffprobe stream data as array with elements according to the following example
|
|
||||||
{
|
|
||||||
"index": 4,
|
|
||||||
"codec_name": "hdmv_pgs_subtitle",
|
|
||||||
"codec_long_name": "HDMV Presentation Graphic Stream subtitles",
|
|
||||||
"codec_type": "subtitle",
|
|
||||||
"codec_tag_string": "[0][0][0][0]",
|
|
||||||
"codec_tag": "0x0000",
|
|
||||||
"r_frame_rate": "0/0",
|
|
||||||
"avg_frame_rate": "0/0",
|
|
||||||
"time_base": "1/1000",
|
|
||||||
"start_pts": 0,
|
|
||||||
"start_time": "0.000000",
|
|
||||||
"duration_ts": 1421035,
|
|
||||||
"duration": "1421.035000",
|
|
||||||
"disposition": {
|
|
||||||
"default": 1,
|
|
||||||
"dub": 0,
|
|
||||||
"original": 0,
|
|
||||||
"comment": 0,
|
|
||||||
"lyrics": 0,
|
|
||||||
"karaoke": 0,
|
|
||||||
"forced": 0,
|
|
||||||
"hearing_impaired": 0,
|
|
||||||
"visual_impaired": 0,
|
|
||||||
"clean_effects": 0,
|
|
||||||
"attached_pic": 0,
|
|
||||||
"timed_thumbnails": 0,
|
|
||||||
"non_diegetic": 0,
|
|
||||||
"captions": 0,
|
|
||||||
"descriptions": 0,
|
|
||||||
"metadata": 0,
|
|
||||||
"dependent": 0,
|
|
||||||
"still_image": 0
|
|
||||||
},
|
|
||||||
"tags": {
|
|
||||||
"language": "ger",
|
|
||||||
"title": "German Full"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
trackType = (
|
|
||||||
TrackType.fromLabel(streamObj["codec_type"])
|
|
||||||
if "codec_type" in streamObj.keys()
|
|
||||||
else TrackType.UNKNOWN
|
|
||||||
)
|
|
||||||
|
|
||||||
if trackType != TrackType.UNKNOWN:
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.INDEX_KEY] = (
|
|
||||||
int(streamObj[TrackDescriptor.FFPROBE_INDEX_KEY])
|
|
||||||
if TrackDescriptor.FFPROBE_INDEX_KEY in streamObj.keys()
|
|
||||||
else -1
|
|
||||||
)
|
|
||||||
kwargs[TrackDescriptor.SOURCE_INDEX_KEY] = kwargs[TrackDescriptor.INDEX_KEY]
|
|
||||||
kwargs[TrackDescriptor.SUB_INDEX_KEY] = subIndex
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.TRACK_TYPE_KEY] = trackType
|
|
||||||
kwargs[TrackDescriptor.CODEC_NAME_KEY] = str(streamObj[TrackDescriptor.FFPROBE_CODEC_NAME_KEY])
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.DISPOSITION_SET_KEY] = (
|
|
||||||
{
|
|
||||||
t
|
|
||||||
for d in (
|
|
||||||
k
|
|
||||||
for (k, v) in streamObj[
|
|
||||||
TrackDescriptor.FFPROBE_DISPOSITION_KEY
|
|
||||||
].items()
|
|
||||||
if v
|
|
||||||
)
|
|
||||||
if (t := TrackDisposition.find(d)) is not None
|
|
||||||
}
|
|
||||||
if TrackDescriptor.FFPROBE_DISPOSITION_KEY in streamObj.keys()
|
|
||||||
else set()
|
|
||||||
)
|
|
||||||
kwargs[TrackDescriptor.TAGS_KEY] = (
|
|
||||||
streamObj[TrackDescriptor.FFPROBE_TAGS_KEY]
|
|
||||||
if TrackDescriptor.FFPROBE_TAGS_KEY in streamObj.keys()
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
kwargs[TrackDescriptor.AUDIO_LAYOUT_KEY] = (
|
|
||||||
AudioLayout.identify(streamObj)
|
|
||||||
if trackType == TrackType.AUDIO
|
|
||||||
else AudioLayout.LAYOUT_UNDEFINED
|
|
||||||
)
|
|
||||||
|
|
||||||
return cls(**kwargs)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def getId(self):
|
|
||||||
return self.__trackId
|
|
||||||
|
|
||||||
def getPatternId(self):
|
|
||||||
return self.__patternId
|
|
||||||
|
|
||||||
def getIndex(self):
|
|
||||||
return self.__index
|
|
||||||
|
|
||||||
def setIndex(self, index):
|
|
||||||
self.__index = index
|
|
||||||
|
|
||||||
def getSourceIndex(self):
|
|
||||||
return self.__sourceIndex
|
|
||||||
|
|
||||||
def getSubIndex(self):
|
|
||||||
return self.__subIndex
|
|
||||||
|
|
||||||
def setSubIndex(self, subIndex):
|
|
||||||
self.__subIndex = subIndex
|
|
||||||
|
|
||||||
def getType(self):
|
|
||||||
return self.__trackType
|
|
||||||
|
|
||||||
def getCodec(self):
|
|
||||||
return self.__codecName
|
|
||||||
|
|
||||||
def getLanguage(self):
|
|
||||||
if "language" in self.__trackTags.keys():
|
|
||||||
return IsoLanguage.findThreeLetter(self.__trackTags["language"])
|
|
||||||
else:
|
|
||||||
return IsoLanguage.UNDEFINED
|
|
||||||
|
|
||||||
def getTitle(self):
|
|
||||||
if "title" in self.__trackTags.keys():
|
|
||||||
return str(self.__trackTags["title"])
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def getAudioLayout(self):
|
|
||||||
return self.__audioLayout
|
|
||||||
|
|
||||||
def getTags(self):
|
|
||||||
return self.__trackTags
|
|
||||||
|
|
||||||
def getDispositionSet(self):
|
|
||||||
return self.__dispositionSet
|
|
||||||
|
|
||||||
def getDispositionFlag(self, disposition: TrackDisposition) -> bool:
|
|
||||||
return bool(disposition in self.__dispositionSet)
|
|
||||||
|
|
||||||
def setDispositionFlag(self, disposition: TrackDisposition, state: bool):
|
|
||||||
if state:
|
|
||||||
self.__dispositionSet.add(disposition)
|
|
||||||
else:
|
|
||||||
self.__dispositionSet.discard(disposition)
|
|
||||||
|
|
||||||
def compare(self, vsTrackDescriptor):
|
|
||||||
|
|
||||||
compareResult = {}
|
|
||||||
|
|
||||||
tagsDiffResult = dictDiff(vsTrackDescriptor.getTags(), self.getTags())
|
|
||||||
|
|
||||||
if tagsDiffResult:
|
|
||||||
compareResult[TrackDescriptor.TAGS_KEY] = tagsDiffResult
|
|
||||||
|
|
||||||
vsDispositions = vsTrackDescriptor.getDispositionSet()
|
|
||||||
dispositions = self.getDispositionSet()
|
|
||||||
|
|
||||||
dispositionDiffResult = setDiff(vsDispositions, dispositions)
|
|
||||||
|
|
||||||
if dispositionDiffResult:
|
|
||||||
compareResult[TrackDescriptor.DISPOSITION_SET_KEY] = dispositionDiffResult
|
|
||||||
|
|
||||||
return compareResult
|
|
||||||
|
|
||||||
def setExternalSourceFilePath(self, filePath: str):
|
|
||||||
self.__externalSourceFilePath = str(filePath)
|
|
||||||
|
|
||||||
def getExternalSourceFilePath(self):
|
|
||||||
return self.__externalSourceFilePath
|
|
||||||
@@ -1,411 +0,0 @@
|
|||||||
import click, time
|
|
||||||
|
|
||||||
from textual import events
|
|
||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Static, Button, SelectionList, Select, DataTable, Input
|
|
||||||
from textual.containers import Grid
|
|
||||||
|
|
||||||
from ffx.model.pattern import Pattern
|
|
||||||
from ffx.model.track import Track
|
|
||||||
|
|
||||||
from .track_controller import TrackController
|
|
||||||
from .pattern_controller import PatternController
|
|
||||||
from .tag_controller import TagController
|
|
||||||
|
|
||||||
from .track_type import TrackType
|
|
||||||
|
|
||||||
from .iso_language import IsoLanguage
|
|
||||||
from .track_disposition import TrackDisposition
|
|
||||||
from .audio_layout import AudioLayout
|
|
||||||
|
|
||||||
from .track_descriptor import TrackDescriptor
|
|
||||||
|
|
||||||
from .tag_details_screen import TagDetailsScreen
|
|
||||||
from .tag_delete_screen import TagDeleteScreen
|
|
||||||
|
|
||||||
from textual.widgets._data_table import CellDoesNotExist
|
|
||||||
|
|
||||||
|
|
||||||
# Screen[dict[int, str, int]]
|
|
||||||
class TrackDetailsScreen(Screen):
|
|
||||||
|
|
||||||
CSS = """
|
|
||||||
|
|
||||||
Grid {
|
|
||||||
grid-size: 5 24;
|
|
||||||
grid-rows: 2 2 2 2 2 3 3 2 2 3 2 2 2 2 2 6 2 2 6 2 2 2;
|
|
||||||
grid-columns: 25 25 25 25 125;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
padding: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
Button {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
SelectionList {
|
|
||||||
border: none;
|
|
||||||
min-height: 6;
|
|
||||||
}
|
|
||||||
Select {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
DataTable {
|
|
||||||
min-height: 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
#toplabel {
|
|
||||||
height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.two {
|
|
||||||
column-span: 2;
|
|
||||||
}
|
|
||||||
.three {
|
|
||||||
column-span: 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.four {
|
|
||||||
column-span: 4;
|
|
||||||
}
|
|
||||||
.five {
|
|
||||||
column-span: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
height: 100%;
|
|
||||||
border: solid green;
|
|
||||||
}
|
|
||||||
|
|
||||||
.yellow {
|
|
||||||
tint: yellow 40%;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, trackDescriptor : TrackDescriptor = None, patternId = None, trackType : TrackType = None, index = None, subIndex = None):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
|
||||||
self.Session = self.context['database']['session'] # convenience
|
|
||||||
|
|
||||||
self.__tc = TrackController(context = self.context)
|
|
||||||
self.__pc = PatternController(context = self.context)
|
|
||||||
self.__tac = TagController(context = self.context)
|
|
||||||
|
|
||||||
self.__isNew = trackDescriptor is None
|
|
||||||
if self.__isNew:
|
|
||||||
self.__trackType = trackType
|
|
||||||
self.__audioLayout = AudioLayout.LAYOUT_UNDEFINED
|
|
||||||
self.__index = index
|
|
||||||
self.__subIndex = subIndex
|
|
||||||
self.__trackDescriptor : TrackDescriptor = None
|
|
||||||
self.__pattern : Pattern = self.__pc.getPattern(patternId) if patternId is not None else {}
|
|
||||||
else:
|
|
||||||
self.__trackType = trackDescriptor.getType()
|
|
||||||
self.__audioLayout = trackDescriptor.getAudioLayout()
|
|
||||||
self.__index = trackDescriptor.getIndex()
|
|
||||||
self.__subIndex = trackDescriptor.getSubIndex()
|
|
||||||
self.__trackDescriptor : TrackDescriptor = trackDescriptor
|
|
||||||
self.__pattern : Pattern = self.__pc.getPattern(self.__trackDescriptor.getPatternId())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def updateTags(self):
|
|
||||||
|
|
||||||
self.trackTagsTable.clear()
|
|
||||||
|
|
||||||
trackId = self.__trackDescriptor.getId()
|
|
||||||
|
|
||||||
if trackId != -1:
|
|
||||||
|
|
||||||
trackTags = self.__tac.findAllTrackTags(trackId)
|
|
||||||
|
|
||||||
for k,v in trackTags.items():
|
|
||||||
|
|
||||||
if k != 'language' and k != 'title':
|
|
||||||
row = (k,v)
|
|
||||||
self.trackTagsTable.add_row(*map(str, row))
|
|
||||||
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
|
|
||||||
self.query_one("#index_label", Static).update(str(self.__index) if self.__index is not None else '-')
|
|
||||||
self.query_one("#subindex_label", Static).update(str(self.__subIndex)if self.__subIndex is not None else '-')
|
|
||||||
|
|
||||||
if self.__pattern is not None:
|
|
||||||
self.query_one("#pattern_label", Static).update(self.__pattern.getPattern())
|
|
||||||
|
|
||||||
if self.__trackType is not None:
|
|
||||||
self.query_one("#type_select", Select).value = self.__trackType.label()
|
|
||||||
if self.__trackType == TrackType.AUDIO:
|
|
||||||
self.query_one("#audio_layout_select", Select).value = self.__audioLayout.label()
|
|
||||||
|
|
||||||
for d in TrackDisposition:
|
|
||||||
|
|
||||||
dispositionIsSet = (self.__trackDescriptor is not None
|
|
||||||
and d in self.__trackDescriptor.getDispositionSet())
|
|
||||||
|
|
||||||
dispositionOption = (d.label(), d.index(), dispositionIsSet)
|
|
||||||
self.query_one("#dispositions_selection_list", SelectionList).add_option(dispositionOption)
|
|
||||||
|
|
||||||
if self.__trackDescriptor is not None:
|
|
||||||
|
|
||||||
self.query_one("#language_select", Select).value = self.__trackDescriptor.getLanguage().label()
|
|
||||||
self.query_one("#title_input", Input).value = self.__trackDescriptor.getTitle()
|
|
||||||
self.updateTags()
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
|
||||||
|
|
||||||
self.trackTagsTable = DataTable(classes="five")
|
|
||||||
|
|
||||||
# Define the columns with headers
|
|
||||||
self.column_key_track_tag_key = self.trackTagsTable.add_column("Key", width=10)
|
|
||||||
self.column_key_track_tag_value = self.trackTagsTable.add_column("Value", width=125)
|
|
||||||
|
|
||||||
self.trackTagsTable.cursor_type = 'row'
|
|
||||||
|
|
||||||
|
|
||||||
languages = [l.label() for l in IsoLanguage]
|
|
||||||
|
|
||||||
yield Header()
|
|
||||||
|
|
||||||
with Grid():
|
|
||||||
|
|
||||||
# 1
|
|
||||||
yield Static(f"New stream" if self.__isNew else f"Edit stream", id="toplabel", classes="five")
|
|
||||||
|
|
||||||
# 2
|
|
||||||
yield Static("for pattern")
|
|
||||||
yield Static("", id="pattern_label", classes="four")
|
|
||||||
|
|
||||||
# 3
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 4
|
|
||||||
yield Static("Index / Subindex")
|
|
||||||
yield Static("", id="index_label", classes="two")
|
|
||||||
yield Static("", id="subindex_label", classes="two")
|
|
||||||
|
|
||||||
# 5
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 6
|
|
||||||
yield Static("Type")
|
|
||||||
yield Select.from_values([t.label() for t in TrackType], classes="four", id="type_select")
|
|
||||||
|
|
||||||
# 7
|
|
||||||
yield Static("Audio Layout")
|
|
||||||
yield Select.from_values([t.label() for t in AudioLayout], classes="four", id="audio_layout_select")
|
|
||||||
|
|
||||||
# 8
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 9
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 10
|
|
||||||
yield Static("Language")
|
|
||||||
yield Select.from_values(languages, classes="four", id="language_select")
|
|
||||||
# 11
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 12
|
|
||||||
yield Static("Title")
|
|
||||||
yield Input(id="title_input", classes="four")
|
|
||||||
|
|
||||||
# 13
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 14
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 15
|
|
||||||
yield Static("Stream tags")
|
|
||||||
yield Static(" ")
|
|
||||||
yield Button("Add", id="button_add_stream_tag")
|
|
||||||
yield Button("Edit", id="button_edit_stream_tag")
|
|
||||||
yield Button("Delete", id="button_delete_stream_tag")
|
|
||||||
# 16
|
|
||||||
yield self.trackTagsTable
|
|
||||||
|
|
||||||
# 17
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 18
|
|
||||||
yield Static("Stream dispositions", classes="five")
|
|
||||||
|
|
||||||
# 19
|
|
||||||
yield SelectionList[int](
|
|
||||||
classes="five",
|
|
||||||
id = "dispositions_selection_list"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 20
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
# 21
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 22
|
|
||||||
yield Button("Save", id="save_button")
|
|
||||||
yield Button("Cancel", id="cancel_button")
|
|
||||||
|
|
||||||
# 23
|
|
||||||
yield Static(" ", classes="five")
|
|
||||||
|
|
||||||
# 24
|
|
||||||
yield Static(" ", classes="five", id="messagestatic")
|
|
||||||
|
|
||||||
|
|
||||||
yield Footer(id="footer")
|
|
||||||
|
|
||||||
|
|
||||||
def getTrackDescriptorFromInput(self):
|
|
||||||
|
|
||||||
kwargs = {}
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.PATTERN_ID_KEY] = int(self.__pattern.getId())
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.INDEX_KEY] = self.__index
|
|
||||||
kwargs[TrackDescriptor.SUB_INDEX_KEY] = self.__subIndex #!
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.TRACK_TYPE_KEY] = TrackType.fromLabel(self.query_one("#type_select", Select).value)
|
|
||||||
kwargs[TrackDescriptor.AUDIO_LAYOUT_KEY] = AudioLayout.fromLabel(self.query_one("#audio_layout_select", Select).value)
|
|
||||||
|
|
||||||
trackTags = {}
|
|
||||||
language = self.query_one("#language_select", Select).value
|
|
||||||
if language:
|
|
||||||
trackTags['language'] = IsoLanguage.find(language).threeLetter()
|
|
||||||
title = self.query_one("#title_input", Input).value
|
|
||||||
if title:
|
|
||||||
trackTags['title'] = title
|
|
||||||
|
|
||||||
tableTags = {row[0]:row[1] for r in self.trackTagsTable.rows if (row := self.trackTagsTable.get_row(r)) and row[0] != 'language' and row[0] != 'title'}
|
|
||||||
|
|
||||||
kwargs[TrackDescriptor.TAGS_KEY] = trackTags | tableTags
|
|
||||||
|
|
||||||
dispositionFlags = sum([2**f for f in self.query_one("#dispositions_selection_list", SelectionList).selected])
|
|
||||||
kwargs[TrackDescriptor.DISPOSITION_SET_KEY] = TrackDisposition.toSet(dispositionFlags)
|
|
||||||
|
|
||||||
return TrackDescriptor(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getSelectedTag(self):
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
# Fetch the currently selected row when 'Enter' is pressed
|
|
||||||
#selected_row_index = self.table.cursor_row
|
|
||||||
row_key, col_key = self.trackTagsTable.coordinate_to_cell_key(self.trackTagsTable.cursor_coordinate)
|
|
||||||
|
|
||||||
if row_key is not None:
|
|
||||||
selected_tag_data = self.trackTagsTable.get_row(row_key)
|
|
||||||
|
|
||||||
tagKey = str(selected_tag_data[0])
|
|
||||||
tagValue = str(selected_tag_data[1])
|
|
||||||
|
|
||||||
return tagKey, tagValue
|
|
||||||
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
except CellDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
||||||
|
|
||||||
# Check if the button pressed is the one we are interested in
|
|
||||||
if event.button.id == "save_button":
|
|
||||||
|
|
||||||
# Check for multiple default/forced disposition flags
|
|
||||||
|
|
||||||
if self.__trackType == TrackType.VIDEO:
|
|
||||||
trackList = self.__tc.findVideoTracks(self.__pattern.getId())
|
|
||||||
if self.__trackType == TrackType.AUDIO:
|
|
||||||
trackList = self.__tc.findAudioTracks(self.__pattern.getId())
|
|
||||||
elif self.__trackType == TrackType.SUBTITLE:
|
|
||||||
trackList = self.__tc.findSubtitleTracks(self.__pattern.getId())
|
|
||||||
else:
|
|
||||||
trackList = []
|
|
||||||
|
|
||||||
siblingTrackList = [t for t in trackList if t.getType() == self.__trackType and t.getIndex() != self.__index]
|
|
||||||
|
|
||||||
numDefaultTracks = len([t for t in siblingTrackList if TrackDisposition.DEFAULT in t.getDispositionSet()])
|
|
||||||
numForcedTracks = len([t for t in siblingTrackList if TrackDisposition.FORCED in t.getDispositionSet()])
|
|
||||||
|
|
||||||
self.__subIndex = len(trackList)
|
|
||||||
trackDescriptor = self.getTrackDescriptorFromInput()
|
|
||||||
|
|
||||||
if ((TrackDisposition.DEFAULT in trackDescriptor.getDispositionSet() and numDefaultTracks)
|
|
||||||
or (TrackDisposition.FORCED in trackDescriptor.getDispositionSet() and numForcedTracks)):
|
|
||||||
|
|
||||||
self.query_one("#messagestatic", Static).update("Cannot add another stream with disposition flag 'debug' or 'forced' set")
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
self.query_one("#messagestatic", Static).update(" ")
|
|
||||||
|
|
||||||
if self.__isNew:
|
|
||||||
|
|
||||||
# Track per Screen hinzufügen
|
|
||||||
self.__tc.addTrack(trackDescriptor)
|
|
||||||
self.dismiss(trackDescriptor)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
track = self.__tc.getTrack(self.__pattern.getId(), self.__index)
|
|
||||||
|
|
||||||
# Track per details screen updaten
|
|
||||||
if self.__tc.updateTrack(track.getId(), trackDescriptor):
|
|
||||||
self.dismiss(trackDescriptor)
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
|
||||||
self.app.pop_screen()
|
|
||||||
|
|
||||||
|
|
||||||
if event.button.id == "button_add_stream_tag":
|
|
||||||
if not self.__isNew:
|
|
||||||
self.app.push_screen(TagDetailsScreen(), self.handle_update_tag)
|
|
||||||
|
|
||||||
if event.button.id == "button_edit_stream_tag":
|
|
||||||
tagKey, tagValue = self.getSelectedTag()
|
|
||||||
self.app.push_screen(TagDetailsScreen(key=tagKey, value=tagValue), self.handle_update_tag)
|
|
||||||
|
|
||||||
if event.button.id == "button_delete_stream_tag":
|
|
||||||
tagKey, tagValue = self.getSelectedTag()
|
|
||||||
self.app.push_screen(TagDeleteScreen(key=tagKey, value=tagValue), self.handle_delete_tag)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_update_tag(self, tag):
|
|
||||||
|
|
||||||
trackId = self.__trackDescriptor.getId()
|
|
||||||
|
|
||||||
if trackId == -1:
|
|
||||||
raise click.ClickException(f"TrackDetailsScreen.handle_update_tag: trackId not set (-1) trackDescriptor={self.__trackDescriptor}")
|
|
||||||
|
|
||||||
if self.__tac.updateTrackTag(trackId, tag[0], tag[1]) is not None:
|
|
||||||
self.updateTags()
|
|
||||||
|
|
||||||
def handle_delete_tag(self, trackTag):
|
|
||||||
|
|
||||||
trackId = self.__trackDescriptor.getId()
|
|
||||||
|
|
||||||
if trackId == -1:
|
|
||||||
raise click.ClickException(f"TrackDetailsScreen.handle_delete_tag: trackId not set (-1) trackDescriptor={self.__trackDescriptor}")
|
|
||||||
|
|
||||||
tag = self.__tac.findTrackTag(trackId, trackTag[0])
|
|
||||||
|
|
||||||
if tag is not None:
|
|
||||||
if self.__tac.deleteTrackTag(tag.id):
|
|
||||||
self.updateTags()
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import difflib, click
|
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
class TrackDisposition(Enum):
|
|
||||||
|
|
||||||
DEFAULT = {"name": "default", "index": 0}
|
|
||||||
FORCED = {"name": "forced", "index": 1}
|
|
||||||
|
|
||||||
DUB = {"name": "dub", "index": 2}
|
|
||||||
ORIGINAL = {"name": "original", "index": 3}
|
|
||||||
COMMENT = {"name": "comment", "index": 4}
|
|
||||||
LYRICS = {"name": "lyrics", "index": 5}
|
|
||||||
KARAOKE = {"name": "karaoke", "index": 6}
|
|
||||||
HEARING_IMPAIRED = {"name": "hearing_impaired", "index": 7}
|
|
||||||
VISUAL_IMPAIRED = {"name": "visual_impaired", "index": 8}
|
|
||||||
CLEAN_EFFECTS = {"name": "clean_effects", "index": 9}
|
|
||||||
ATTACHED_PIC = {"name": "attached_pic", "index": 10}
|
|
||||||
TIMED_THUMBNAILS = {"name": "timed_thumbnails", "index": 11}
|
|
||||||
NON_DIEGETICS = {"name": "non_diegetic", "index": 12}
|
|
||||||
CAPTIONS = {"name": "captions", "index": 13}
|
|
||||||
DESCRIPTIONS = {"name": "descriptions", "index": 14}
|
|
||||||
METADATA = {"name": "metadata", "index": 15}
|
|
||||||
DEPENDENT = {"name": "dependent", "index": 16}
|
|
||||||
STILL_IMAGE = {"name": "still_image", "index": 17}
|
|
||||||
|
|
||||||
|
|
||||||
def label(self):
|
|
||||||
return str(self.value['name'])
|
|
||||||
|
|
||||||
def index(self):
|
|
||||||
return int(self.value['index'])
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def toFlags(dispositionSet):
|
|
||||||
"""Flags stored in integer bits (2**index)"""
|
|
||||||
|
|
||||||
if type(dispositionSet) is not set:
|
|
||||||
raise click.ClickException('TrackDisposition.toFlags(): Argument is not of type set')
|
|
||||||
|
|
||||||
flags = 0
|
|
||||||
for d in dispositionSet:
|
|
||||||
if type(d) is not TrackDisposition:
|
|
||||||
raise click.ClickException('TrackDisposition.toFlags(): Element not of type TrackDisposition')
|
|
||||||
flags += 2 ** d.index()
|
|
||||||
return flags
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def toSet(flags):
|
|
||||||
dispositionSet = set()
|
|
||||||
for d in TrackDisposition:
|
|
||||||
if flags & int(2 ** d.index()):
|
|
||||||
dispositionSet.add(d)
|
|
||||||
return dispositionSet
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def find(label):
|
|
||||||
matchingDispositions = [d for d in TrackDisposition if d.label() == str(label)]
|
|
||||||
if matchingDispositions:
|
|
||||||
return matchingDispositions[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
from enum import Enum
|
|
||||||
|
|
||||||
class TrackType(Enum):
|
|
||||||
|
|
||||||
VIDEO = {'label': 'video', 'index': 1}
|
|
||||||
AUDIO = {'label': 'audio', 'index': 2}
|
|
||||||
SUBTITLE = {'label': 'subtitle', 'index': 3}
|
|
||||||
|
|
||||||
UNKNOWN = {'label': 'unknown', 'index': 0}
|
|
||||||
|
|
||||||
|
|
||||||
def label(self):
|
|
||||||
"""Returns the stream type as string"""
|
|
||||||
return str(self.value['label'])
|
|
||||||
|
|
||||||
def indicator(self):
|
|
||||||
"""Returns the stream type as single letter"""
|
|
||||||
return self.label()[0]
|
|
||||||
|
|
||||||
def index(self):
|
|
||||||
"""Returns the stream type index"""
|
|
||||||
return int(self.value['index'])
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fromLabel(label : str):
|
|
||||||
tlist = [t for t in TrackType if t.value['label'] == str(label)]
|
|
||||||
if tlist:
|
|
||||||
return tlist[0]
|
|
||||||
else:
|
|
||||||
return TrackType.UNKNOWN
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fromIndex(index : int):
|
|
||||||
tlist = [t for t in TrackType if t.value['index'] == int(index)]
|
|
||||||
if tlist:
|
|
||||||
return tlist[0]
|
|
||||||
else:
|
|
||||||
return TrackType.UNKNOWN
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
from enum import Enum
|
|
||||||
|
|
||||||
class VideoEncoder(Enum):
|
|
||||||
|
|
||||||
AV1 = {'label': 'av1', 'index': 1}
|
|
||||||
VP9 = {'label': 'vp9', 'index': 2}
|
|
||||||
|
|
||||||
UNDEFINED = {'label': 'undefined', 'index': 0}
|
|
||||||
|
|
||||||
def label(self):
|
|
||||||
"""Returns the stream type as string"""
|
|
||||||
return str(self.value['label'])
|
|
||||||
|
|
||||||
def index(self):
|
|
||||||
"""Returns the stream type index"""
|
|
||||||
return int(self.value['index'])
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fromLabel(label : str):
|
|
||||||
tlist = [t for t in VideoEncoder if t.value['label'] == str(label)]
|
|
||||||
if tlist:
|
|
||||||
return tlist[0]
|
|
||||||
else:
|
|
||||||
return VideoEncoder.UNDEFINED
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fromIndex(index : int):
|
|
||||||
tlist = [t for t in VideoEncoder if t.value['index'] == int(index)]
|
|
||||||
if tlist:
|
|
||||||
return tlist[0]
|
|
||||||
else:
|
|
||||||
return VideoEncoder.UNDEFINED
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
from textual.app import App, ComposeResult
|
|
||||||
from textual.screen import Screen
|
|
||||||
from textual.widgets import Header, Footer, Placeholder, Label
|
|
||||||
|
|
||||||
class WarningScreen(Screen):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
context = self.app.getContext()
|
|
||||||
def compose(self) -> ComposeResult:
|
|
||||||
yield Label("Warning! This file is not compliant to the defined source schema!")
|
|
||||||
yield Footer()
|
|
||||||
Reference in New Issue
Block a user