38 lines
1.3 KiB
Python
Executable file
38 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Final
|
|
|
|
source: Final = Path(sys.argv[1])
|
|
dest: Final = Path(sys.argv[2])
|
|
|
|
def find_source_jpg(dest_name: Path) -> Path:
|
|
ext_list = ['.jpg', '.jpeg', '.JPG', '.JPEG']
|
|
for ext in ext_list:
|
|
res = (Path(source) / relative_path / (dest_name + ext))
|
|
if os.path.exists(dest_file_path):
|
|
return res
|
|
raise RuntimeError('No original found', dest_name)
|
|
|
|
for dest_root, dirs, files in os.walk(dest):
|
|
for name in files:
|
|
dest_name, dest_ext = os.path.splitext(name)
|
|
if dest_ext.lower() != '.jxl':
|
|
continue
|
|
dest_file_path = (Path(dest_root) / (dest_name + '.jpg'))
|
|
print('scanning for ', dest_file_path, '\n')
|
|
if os.path.exists(dest_file_path): # both .jxl and jpg exist
|
|
print(dest_file_path, ' already exists\n')
|
|
continue
|
|
relative_path = os.path.relpath(dest_root, dest)
|
|
print('relapath ', relative_path, '\n')
|
|
src_file_path = find_source_jpg(dest_name)
|
|
shutil.copy2(src_file_path, dest_file_path)
|
|
print('restored ', dest_file_path, ' from ', src_file_path, '\n')
|
|
#dest_jxl = (Path(dest_root) / (dest_name + '.jxl'))
|
|
#os.remove(dest_jxl)
|
|
#print('deleted ', dest_jxl, '\n')
|