diff --git a/bin/ffx.py b/bin/ffx.py index b1849f1..52300d5 100755 --- a/bin/ffx.py +++ b/bin/ffx.py @@ -4,7 +4,7 @@ import os, sys, subprocess, json, click, time from textual.app import App, ComposeResult from textual.screen import Screen -from textual.widgets import Header, Footer, Placeholder +from textual.widgets import Header, Footer, Placeholder, Label VERSION='0.1.0' @@ -35,7 +35,7 @@ MKVMERGE_METADATA_KEYS = ['BPS', '_STATISTICS_WRITING_DATE_UTC', '_STATISTICS_TAGS'] -FILE_EXTENSION = ['mkv', 'mp4', 'avi', 'flv', 'webm'] +FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm'] COMMAND_TOKENS = ['ffmpeg', '-y', '-i'] @@ -65,6 +65,14 @@ class DashboardScreen(Screen): yield Placeholder("Dashboard Screen") 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): def __init__(self): @@ -87,29 +95,31 @@ class HelpScreen(Screen): class ModesApp(App): BINDINGS = [ - ("d", "switch_mode('dashboard')", "Dashboard"), - ("s", "switch_mode('settings')", "Settings"), - ("h", "switch_mode('help')", "Help"), + ("q", "quit()", "Quit"), + # ("d", "switch_mode('dashboard')", "Dashboard"), + # ("s", "switch_mode('settings')", "Settings"), + # ("h", "switch_mode('help')", "Help"), ] MODES = { + "warning": WarningScreen, "dashboard": DashboardScreen, "settings": SettingsScreen, "help": HelpScreen, } + def __init__(self, context = {}): super().__init__() self.context = context def on_mount(self) -> None: - self.switch_mode("dashboard") + self.switch_mode("warning") def getContext(self): return self.context - def executeProcess(commandSequence): process = subprocess.Popen(commandSequence, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -363,13 +373,28 @@ def convert(ctx, paths, label, video_encoder, quality, preset, stereo_bitrate, a Suffices will we appended to filename in case of multiple created files or if the filename has not changed.""" - #startTime = time.perf_counter() + startTime = time.perf_counter() + + context = ctx.obj + + for sourcePath in paths: - #sourcePath = paths[0] - #targetFilename = paths[1] - #if not os.path.isfile(sourcePath): - # raise click.ClickException(f"There is no file with path {sourcePath}") + if not os.path.isfile(sourcePath): + click.echo(f"There is no file with path {sourcePath}, skipping ...") + + 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"src: {sourcePath} tgt: {targetFilename}") @@ -497,15 +522,16 @@ def convert(ctx, paths, label, video_encoder, quality, preset, stereo_bitrate, a #executeProcess(commandSequence2) - #click.echo('\nDONE\n') - - #endTime = time.perf_counter() - #click.echo(f"Time elapsed {endTime - startTime}") - app = ModesApp(ctx.obj) app.run() - click.echo(f"app result: {app.getContext()}") + click.echo('\nDONE\n') + + endTime = time.perf_counter() + click.echo(f"Time elapsed {endTime - startTime}") + + + # click.echo(f"app result: {app.getContext()}")