Switch FileBow to English and present the app in the public README
This commit is contained in:
1 parent
2b897267d1
commit
84164251e3
36 files changed
+346
-280
No files matched your search
+22
-22
@@ -28,7 +28,7 @@ def emit(data):
|
||||
def bounded(value, default, low, high):
|
||||
try: result = float(value)
|
||||
except (TypeError, ValueError): result = default
|
||||
if not math.isfinite(result): raise ValueError('Ungültiger Zahlenwert.')
|
||||
if not math.isfinite(result): raise ValueError('Invalid numeric value.')
|
||||
return max(low, min(high, result))
|
||||
|
||||
def ext(file): return Path(file).suffix.lower().lstrip('.')
|
||||
@@ -39,7 +39,7 @@ def execute(args):
|
||||
encoding='utf-8', errors='replace', creationflags=0x08000000 if os.name == 'nt' else 0)
|
||||
if result.returncode:
|
||||
detail = result.stderr.strip().splitlines()
|
||||
raise RuntimeError('\n'.join(detail[-4:]) or 'Die Datei konnte nicht verarbeitet werden.')
|
||||
raise RuntimeError('\n'.join(detail[-4:]) or 'The file could not be processed.')
|
||||
return result.stdout
|
||||
def media(args):
|
||||
execute([ffmpeg(), '-hide_banner','-loglevel','error','-nostdin','-protocol_whitelist','file,pipe,data,crypto','-y', *args])
|
||||
@@ -56,7 +56,7 @@ def probe(file):
|
||||
def reader(file, password=None):
|
||||
pdf = PdfReader(file)
|
||||
if pdf.is_encrypted and not pdf.decrypt(password or ''):
|
||||
raise ValueError('Die PDF ist geschützt. Bitte zuerst das Passwort entfernen.')
|
||||
raise ValueError('This PDF is encrypted. Remove its password first.')
|
||||
return pdf
|
||||
|
||||
def save_output(source, suffix, writer, name=None):
|
||||
@@ -64,13 +64,13 @@ def save_output(source, suffix, writer, name=None):
|
||||
source = Path(source)
|
||||
stem = str(name or f'{source.stem} - FileBow').strip()
|
||||
if not stem or stem in {'.','..'} or re.search(r'[<>:"/\\|?*\x00-\x1f]',stem) or stem.endswith(('.', ' ')):
|
||||
raise ValueError('Der Dateiname enthält ungültige Zeichen.')
|
||||
if re.match(r'^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)',stem,re.I): raise ValueError('Dieser Dateiname ist unter Windows reserviert.')
|
||||
raise ValueError('The filename contains invalid characters.')
|
||||
if re.match(r'^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)',stem,re.I): raise ValueError('This filename is reserved by Windows.')
|
||||
with tempfile.TemporaryDirectory(prefix='.filebow-'+os.environ.get('FILEBOW_JOB_ID','local')+'-',dir=source.parent) as folder:
|
||||
emit({'type':'stage','directory':folder})
|
||||
staged = Path(folder) / ('result.'+suffix)
|
||||
extra = writer(staged) or {}
|
||||
if not staged.is_file() or not staged.stat().st_size: raise RuntimeError('Es wurde keine Ergebnisdatei erzeugt.')
|
||||
if not staged.is_file() or not staged.stat().st_size: raise RuntimeError('No output file was created.')
|
||||
for index in range(100000):
|
||||
target = source.parent / f'{stem}{f" ({index})" if index else ""}.{suffix}'
|
||||
try:
|
||||
@@ -79,7 +79,7 @@ def save_output(source, suffix, writer, name=None):
|
||||
else: os.link(staged,target); staged.unlink()
|
||||
return {'ok':True,'input':str(source),'output':str(target),'size':target.stat().st_size,**extra}
|
||||
except FileExistsError: continue
|
||||
raise RuntimeError('Kein freier Dateiname verfügbar.')
|
||||
raise RuntimeError('No available output filename.')
|
||||
|
||||
def image_load(file):
|
||||
with Image.open(file) as image:
|
||||
@@ -135,7 +135,7 @@ def text_read(file):
|
||||
from posixpath import normpath,join,dirname
|
||||
pages=[normpath(join(dirname(opf),manifest[x.attrib['idref']])) for x in package.iter() if x.tag.endswith('itemref')]
|
||||
return '\n\n'.join(BeautifulSoup(archive.read(page),'html.parser').get_text('\n') for page in pages)
|
||||
if kind in {'doc','ppt'}: raise ValueError('Bitte dieses Dokument zuerst als DOCX bzw. PPTX speichern.')
|
||||
if kind in {'doc','ppt'}: raise ValueError('Save this document as DOCX or PPTX first.')
|
||||
raw=Path(file).read_bytes()
|
||||
if raw.startswith((b'\xff\xfe',b'\xfe\xff')): return raw.decode('utf-16')
|
||||
try: text=raw.decode('utf-8-sig')
|
||||
@@ -160,19 +160,19 @@ def text_write(text,out,target):
|
||||
pdf.add_page()
|
||||
pdf.multi_cell(0,5,text.replace('\t',' '),new_x='LMARGIN',new_y='NEXT')
|
||||
pdf.output(str(out)); return
|
||||
raise ValueError('Nicht unterstütztes Dokumentformat.')
|
||||
raise ValueError('Unsupported document format.')
|
||||
|
||||
def video_args(target, options=None, bitrate=None):
|
||||
options=options or {}
|
||||
if target == 'webm': return ['-c:v','libvpx-vp9','-b:v',str(bitrate or 0),'-crf',str(int(bounded(options.get('crf'),32,10,50))),'-c:a','libopus','-b:a','128k']
|
||||
if target == 'mp4': return ['-c:v','libopenh264','-b:v',str(bitrate or 2500000),'-pix_fmt','yuv420p','-c:a','aac','-b:a','128k','-movflags','+faststart']
|
||||
if target == 'gif': return ['-an','-vf','fps=12,scale=640:-1:flags=lanczos,split[a][b];[a]palettegen[p];[b][p]paletteuse']
|
||||
raise ValueError('Nicht unterstütztes Videoformat.')
|
||||
raise ValueError('Unsupported video format.')
|
||||
def audio_args(target, bitrate='192k'):
|
||||
choices={'mp3':['-c:a','libmp3lame','-b:a',bitrate],'wav':['-c:a','pcm_s16le'],
|
||||
'm4a':['-c:a','aac','-b:a',bitrate],'flac':['-c:a','flac'],
|
||||
'ogg':['-c:a','libvorbis','-b:a',bitrate]}
|
||||
if target not in choices: raise ValueError('Nicht unterstütztes Audioformat.')
|
||||
if target not in choices: raise ValueError('Unsupported audio format.')
|
||||
return ['-vn',*choices[target]]
|
||||
|
||||
def convert(file,target,options):
|
||||
@@ -182,7 +182,7 @@ def convert(file,target,options):
|
||||
image=image_load(file)
|
||||
if target=='pdf': image.convert('RGB').save(out,'PDF',resolution=150)
|
||||
elif target in FORMATS: image_write(image,out,target,int(bounded(options.get('quality'),85,1,100)))
|
||||
else: raise ValueError('Nicht unterstütztes Bildformat.')
|
||||
else: raise ValueError('Unsupported image format.')
|
||||
elif kind in VIDEO:
|
||||
args=['-i',file]
|
||||
if target=='mp4': args += ['-vf','pad=ceil(iw/2)*2:ceil(ih/2)*2']
|
||||
@@ -228,7 +228,7 @@ def compress(file,options,estimate=False):
|
||||
for page in pdf.pages: page.compress_content_streams()
|
||||
pdf.compress_identical_objects(remove_duplicates=True,remove_unreferenced=True)
|
||||
pdf.write(out)
|
||||
else: raise ValueError('Diese Datei lässt sich nicht komprimieren.')
|
||||
else: raise ValueError('This file cannot be compressed.')
|
||||
return {'targetMet':not limit or out.stat().st_size<=limit}
|
||||
if estimate:
|
||||
original=Path(file).stat().st_size
|
||||
@@ -263,14 +263,14 @@ def edit(file,options):
|
||||
image=image.crop((x,y,x+w,y+h))
|
||||
if width or height:
|
||||
w=width or max(1,round(image.width*height/image.height)); h=height or max(1,round(image.height*width/image.width))
|
||||
if w*h > 100000000: raise ValueError('Die Zielgröße darf höchstens 100 Megapixel betragen.')
|
||||
if w*h > 100000000: raise ValueError('The output image cannot exceed 100 megapixels.')
|
||||
image=image.resize((w,h),Image.Resampling.LANCZOS)
|
||||
if angle: image=image.rotate(-angle,expand=True)
|
||||
if options.get('flipH'): image=ImageOps.mirror(image)
|
||||
if options.get('flipV'): image=ImageOps.flip(image)
|
||||
image_write(image,out,suffix)
|
||||
else:
|
||||
if not width and not height: raise ValueError('Bitte Breite oder Höhe angeben.')
|
||||
if not width and not height: raise ValueError('Enter a width or height.')
|
||||
media(['-i',file,'-vf',f'scale={width or -2}:{height or -2},pad=ceil(iw/2)*2:ceil(ih/2)*2',*video_args('mp4'),out])
|
||||
return save_output(file,suffix,writer,options.get('outputName'))
|
||||
|
||||
@@ -283,7 +283,7 @@ def metadata(file,options):
|
||||
if '/Metadata' in pdf._root_object: del pdf._root_object['/Metadata']
|
||||
pdf.write(out)
|
||||
elif kind in VIDEO|AUDIO: media(['-i',file,'-map','0','-map_metadata','-1','-map_chapters','-1','-c','copy',out])
|
||||
else: raise ValueError('Dieses Format wird nicht unterstützt.')
|
||||
else: raise ValueError('This format is not supported.')
|
||||
return save_output(file,kind,writer,options.get('outputName'))
|
||||
|
||||
def combined(files,target,options):
|
||||
@@ -297,7 +297,7 @@ def combined(files,target,options):
|
||||
images[0].save(out,'PDF',save_all=True,append_images=images[1:],resolution=150)
|
||||
for image in images: image.close()
|
||||
else: text_write('\n\n'.join(text_read(f) for f in files),out,target)
|
||||
return save_output(files[0],target,writer,options.get('outputName') or 'Zusammengefügt')
|
||||
return save_output(files[0],target,writer,options.get('outputName') or 'Combined')
|
||||
|
||||
def dispatch(file,op,target,options):
|
||||
if op=='convert': return convert(file,target,options)
|
||||
@@ -307,7 +307,7 @@ def dispatch(file,op,target,options):
|
||||
if op=='strip-metadata': return metadata(file,options)
|
||||
if op=='pdf-password':
|
||||
password=options.get('password')
|
||||
if not isinstance(password,str) or not password: raise ValueError('Bitte ein Passwort eingeben.')
|
||||
if not isinstance(password,str) or not password: raise ValueError('Enter a password.')
|
||||
def write(out):
|
||||
pdf=PdfWriter(clone_from=reader(file,password))
|
||||
if options.get('mode')=='add': pdf.encrypt(password,algorithm='AES-256')
|
||||
@@ -325,13 +325,13 @@ def dispatch(file,op,target,options):
|
||||
return {'ok':True,'input':file,'width':original[0],'height':original[1],
|
||||
'dataUrl':'data:image/png;base64,'+base64.b64encode(buffer.getvalue()).decode('ascii')}
|
||||
return {'ok':True,'input':file,**probe(file)}
|
||||
raise ValueError('Unbekannter Auftrag.')
|
||||
raise ValueError('Unknown operation.')
|
||||
|
||||
def run_job(job):
|
||||
files=job.get('files'); op=job.get('op'); target=str(job.get('target') or '').lower(); options=job.get('options') or {}
|
||||
if not isinstance(files,list) or not files or len(files)>1000: raise ValueError('Bitte 1 bis 1000 Dateien auswählen.')
|
||||
if not isinstance(files,list) or not files or len(files)>1000: raise ValueError('Select between 1 and 1,000 files.')
|
||||
files=[str(Path(f).resolve(strict=True)) for f in files]
|
||||
if not all(Path(f).is_file() for f in files): raise ValueError('Ordner werden nicht unterstützt.')
|
||||
if not all(Path(f).is_file() for f in files): raise ValueError('Folders are not supported.')
|
||||
results=[]
|
||||
if op in {'zip','combine','merge','image-to-pdf'}:
|
||||
if op=='zip':
|
||||
@@ -343,7 +343,7 @@ def run_job(job):
|
||||
while name.casefold() in names:
|
||||
name=f'{Path(file).stem} ({counter}){Path(file).suffix}'; counter+=1
|
||||
names.add(name.casefold()); z.write(file,name)
|
||||
results=[save_output(files[0],'zip',archive,options.get('outputName') or 'Archiv')]
|
||||
results=[save_output(files[0],'zip',archive,options.get('outputName') or 'Archive')]
|
||||
else: results=[combined(files,'pdf' if op in {'merge','image-to-pdf'} else target,options)]
|
||||
emit({'type':'progress','done':len(files),'total':len(files),'file':files[-1]})
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user