click
Javanaut 1 year ago
parent 6fdcd20176
commit 20ae4e763f

@ -4,7 +4,7 @@ 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 from textual.widgets import Header, Footer, Placeholder, Label
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_EXTENSION = ['mkv', 'mp4', 'avi', 'flv', 'webm'] FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm']
COMMAND_TOKENS = ['ffmpeg', '-y', '-i'] COMMAND_TOKENS = ['ffmpeg', '-y', '-i']
@ -65,6 +65,14 @@ 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):
@ -87,29 +95,31 @@ class HelpScreen(Screen):
class ModesApp(App): class ModesApp(App):
BINDINGS = [ BINDINGS = [
("d", "switch_mode('dashboard')", "Dashboard"), ("q", "quit()", "Quit"),
("s", "switch_mode('settings')", "Settings"), # ("d", "switch_mode('dashboard')", "Dashboard"),
("h", "switch_mode('help')", "Help"), # ("s", "switch_mode('settings')", "Settings"),
# ("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("dashboard") self.switch_mode("warning")
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)
@ -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 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
for sourcePath in paths:
#sourcePath = paths[0]
#targetFilename = paths[1]
#if not os.path.isfile(sourcePath): if not os.path.isfile(sourcePath):
# raise click.ClickException(f"There is no file with path {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}") #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) #executeProcess(commandSequence2)
#click.echo('\nDONE\n')
#endTime = time.perf_counter()
#click.echo(f"Time elapsed {endTime - startTime}")
app = ModesApp(ctx.obj) app = ModesApp(ctx.obj)
app.run() 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()}")

Loading…
Cancel
Save