sync & torrent scripts
This commit is contained in:
1 parent
884ae1f841
commit
3e258c6afe
6 files changed
+75
-20
No files matched your search
@@ -4,17 +4,17 @@ import random
|
||||
import datetime
|
||||
import sys
|
||||
from PIL import Image, ExifTags
|
||||
from pillow_heif import open_heif
|
||||
import subprocess
|
||||
import json
|
||||
from serverlibary import safe_rename
|
||||
from pathlib import Path
|
||||
|
||||
# Folder to scan
|
||||
folder_path = '.'
|
||||
# Supported image and video extensions
|
||||
|
||||
video_extensions = {
|
||||
'.mp4', '.mov', '.avi', '.mkv', '.hevc'
|
||||
'.mp4', '.mov', '.avi', '.mkv', '.hevc', '.mov',
|
||||
}
|
||||
img_extensions = {
|
||||
'.jpg', '.jpeg', '.png', '.heic', '.webp',
|
||||
@@ -100,19 +100,33 @@ def local_safe_rename(src_path, new_filename):
|
||||
def get_exif_creation_datetime(filepath):
|
||||
"""Try to extract creation datetime from image EXIF metadata"""
|
||||
try:
|
||||
with Image.open(filepath) as img:
|
||||
exif = img._getexif()
|
||||
if not exif:
|
||||
return None
|
||||
if 'heic' in filepath.lower():
|
||||
|
||||
# Map tag ids to tag names
|
||||
tag_label = {ExifTags.TAGS.get(k): v for k, v in exif.items() if k in ExifTags.TAGS}
|
||||
heif_file = open_heif(filepath)
|
||||
img = Image.fromarray(heif_file.data)
|
||||
exif = img.getexif()
|
||||
|
||||
for tag in EXIF_DATE_TAGS:
|
||||
if tag in tag_label:
|
||||
# EXIF date format: 'YYYY:MM:DD HH:MM:SS'
|
||||
return datetime.datetime.strptime(tag_label[tag], '%Y:%m:%d %H:%M:%S')
|
||||
for tag_id, value in exif.items():
|
||||
print(tag_id, value)
|
||||
else:
|
||||
with Image.open(filepath) as img:
|
||||
exif = img._getexif()
|
||||
if not exif:
|
||||
print("Exif failed")
|
||||
return None
|
||||
|
||||
# Map tag ids to tag names
|
||||
tag_label = {ExifTags.TAGS.get(k): v for k, v in exif.items() if k in ExifTags.TAGS}
|
||||
|
||||
for tag in EXIF_DATE_TAGS:
|
||||
print(tag)
|
||||
if tag in tag_label:
|
||||
print(tag)
|
||||
# EXIF date format: 'YYYY:MM:DD HH:MM:SS'
|
||||
return datetime.datetime.strptime(tag_label[tag], '%Y:%m:%d %H:%M:%S')
|
||||
except Exception as e:
|
||||
print(f"Exif Error {e}")
|
||||
|
||||
pass
|
||||
return None
|
||||
|
||||
@@ -178,9 +192,7 @@ def process_images(folder):
|
||||
# Now continue with your existing logic on normalized fname
|
||||
if correct_format_re.match(fname):
|
||||
if videoManufacturer != "" and file_prefix == "VID":
|
||||
if videoManufacturer in fname:
|
||||
pass
|
||||
else:
|
||||
if videoManufacturer not in fname:
|
||||
basename, _ = os.path.splitext(fname)
|
||||
new_fname = f"{basename}{videoManufacturer}{ext}"
|
||||
safe_rename(Path(fpath),folder / new_fname)
|
||||
@@ -213,7 +225,8 @@ def process_images(folder):
|
||||
new_fname = f"{file_prefix}_{dt.strftime('%Y%m%d_%H%M%S')}{videoManufacturer}{ext}"
|
||||
safe_rename(Path(fpath),folder / new_fname)
|
||||
continue
|
||||
|
||||
else:
|
||||
print(f"[Fail] Creation Date for {fpath} not found")
|
||||
# 4. Fallback: keep original name, add _RX_<random> (only if not already added)
|
||||
if '_RX_' in fname:
|
||||
print(f"[SKIP] {fname} already has fallback name.")
|
||||
@@ -237,4 +250,4 @@ if __name__ == '__main__':
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Processing images in: {os.path.abspath(folder_path)}\n")
|
||||
process_images(folder_path)
|
||||
process_images(folder_path)
|
||||
Reference in new issue
Block a user