convert heic functional script w docker

add docker for new magic version on ubuntu 24
This commit is contained in:
Lucas Serverhost authored and Lucas Vivohost committed 2026-09-14 12:43:38 +02:00
1 parent 14c7e69172
commit f27c172a73
4 files changed
+168 -62

No files matched your search

+68 -23
View File
@@ -18,16 +18,35 @@ convert_one() {
echo "Converting: $src" echo "Converting: $src"
# Convert HEIC -> JPEG # Convert HEIC -> JPEG
if ! magick "$src" \ if command -v magick >/dev/null 2>&1; then
if ! magick "$src" \
-auto-orient \
-quality 100 \
-sampling-factor 4:4:4 \
"jpg:$tmp"; then
echo "ERROR: local conversion failed: $src"
rm -f "$tmp"
return 1
fi
else
if ! docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$PWD:/work" \
-w /work \
--entrypoint magick \
dpokidov/imagemagick \
"$src" \
-auto-orient \ -auto-orient \
-quality 100 \ -quality 100 \
-sampling-factor 4:4:4 \ -sampling-factor 4:4:4 \
"jpg:$tmp"; then "jpg:$tmp"; then
echo "ERROR: conversion failed: $src" echo "ERROR: docker conversion failed: $src"
rm -f "$tmp" rm -f "$tmp"
return 1 return 1
fi
fi fi
if [[ ! -s "$tmp" ]]; then if [[ ! -s "$tmp" ]]; then
echo "ERROR: output JPEG is empty: $tmp" echo "ERROR: output JPEG is empty: $tmp"
rm -f "$tmp" rm -f "$tmp"
@@ -76,20 +95,20 @@ convert_mov() {
echo "Converting: $src" echo "Converting: $src"
# MOV -> MP4, keep video/audio, drop unsupported data streams # MOV -> MP4, keep video/audio, drop unsupported data streams
if ! ffmpeg \ if ! ffmpeg \
-hide_banner \ -hide_banner \
-loglevel error \ -loglevel error \
-i "$src" \ -i "$src" \
-map 0:0 \ -map 0:0 \
-map 0:1 \ -map 0:1 \
-map_metadata 0 \ -map_metadata 0 \
-c copy \ -c copy \
-movflags use_metadata_tags+faststart \ -movflags use_metadata_tags+faststart \
"$tmp"; then "$tmp"; then
echo "ERROR: conversion failed: $src" echo "ERROR: conversion failed: $src"
rm -f "$tmp" rm -f "$tmp"
return 1 return 1
fi fi
if [[ ! -s "$tmp" ]]; then if [[ ! -s "$tmp" ]]; then
echo "ERROR: output MP4 is empty: $tmp" echo "ERROR: output MP4 is empty: $tmp"
@@ -140,17 +159,43 @@ process_file() {
} }
HOSTNAME_EXPECTED="serverhost"
SOURCE_DIR="/torrent/alina/Dropfolder"
TARGET_DIR="/torrent/camera"
# If running on serverhost, perform initial sync
if [[ "$(hostname)" == "$HOSTNAME_EXPECTED" ]]; then
/home/lucas/scripts/serverhost/syncNC.sh -d -c
cd "$SOURCE_DIR" || exit 1
fi
if [[ $# -gt 0 ]]; then if [[ $# -gt 0 ]]; then
process_file "$1" process_file "$1"
else else
shopt -s nullglob
files=( *.heic *.mov ) files=( *.heic *.mov )
if [[ ${#files[@]} -eq 0 ]]; then if [[ ${#files[@]} -eq 0 ]]; then
echo "No HEIC or MOV files found." echo "No HEIC or MOV files found."
exit 0 else
for f in "${files[@]}"; do
process_file "$f"
done
fi fi
fi
for f in "${files[@]}"; do # Run sync again if on serverhost
process_file "$f" if [[ "$(hostname)" == "$HOSTNAME_EXPECTED" ]]; then
shopt -s nullglob
for ext in jpg mp4; do
files=("$SOURCE_DIR"/*."$ext")
if ((${#files[@]})); then
mv -n "${files[@]}" "$TARGET_DIR"/
fi
done done
fi shopt -u nullglob
/home/lucas/scripts/serverhost/syncNC.sh -d -c
fi
+53 -16
View File
@@ -100,30 +100,65 @@ def local_safe_rename(src_path, new_filename):
def get_exif_creation_datetime(filepath): def get_exif_creation_datetime(filepath):
"""Try to extract creation datetime from image EXIF metadata""" """Try to extract creation datetime from image EXIF metadata"""
try: try:
if 'heic' in filepath.lower(): if filepath.lower().endswith((".mp4", ".mov", ".m4v")):
# WhatsApp videos: use filesystem modification time
heif_file = open_heif(filepath) if "WA" in os.path.basename(filepath):
img = Image.fromarray(heif_file.data) return datetime.datetime.fromtimestamp(
exif = img.getexif() os.path.getmtime(filepath)
)
for tag_id, value in exif.items():
print(tag_id, value) tags = ["CreateDate", "MediaCreateDate", "TrackCreateDate"]
result = subprocess.run(
[
"exiftool",
"-j",
"-CreateDate",
"-MediaCreateDate",
"-TrackCreateDate",
filepath,
],
capture_output=True,
text=True,
check=True,
)
metadata = json.loads(result.stdout)[0]
for tag in tags:
if metadata.get(tag):
return datetime.datetime.strptime(
metadata[tag],
"%Y:%m:%d %H:%M:%S"
)
# Fallback: use filesystem modification time
return datetime.datetime.fromtimestamp(
os.path.getmtime(filepath)
)
else: else:
with Image.open(filepath) as img: with Image.open(filepath) as img:
exif = img._getexif() exif = img._getexif()
if not exif: if not exif:
print("Exif failed") print("Exif failed")
return None return None
# Map tag ids to tag names tag_label = {
tag_label = {ExifTags.TAGS.get(k): v for k, v in exif.items() if k in ExifTags.TAGS} ExifTags.TAGS.get(k): v
for k, v in exif.items()
if k in ExifTags.TAGS
}
for tag in EXIF_DATE_TAGS: for tag in EXIF_DATE_TAGS:
print(tag) print(tag)
if tag in tag_label: if tag in tag_label:
print(tag) print(tag)
# EXIF date format: 'YYYY:MM:DD HH:MM:SS' return datetime.datetime.strptime(
return datetime.datetime.strptime(tag_label[tag], '%Y:%m:%d %H:%M:%S') tag_label[tag],
'%Y:%m:%d %H:%M:%S'
)
except Exception as e: except Exception as e:
print(f"Exif Error {e}") print(f"Exif Error {e}")
@@ -141,13 +176,15 @@ def get_manufacturer(file_path):
# Parse JSON output # Parse JSON output
metadata = json.loads(result.stdout)[0] metadata = json.loads(result.stdout)[0]
# Extract Author tag and remove spaces # Extract Author tag and remove spaces
author = metadata.get("Author", "") author = metadata.get("Author", "")
if author == "": if author == "":
author = metadata.get("AndroidManufacturer", "") author = metadata.get("AndroidManufacturer", "")
if author == "":
author = metadata.get("Model", "")
if author == "":
author = "NoAuthor"
author_no_spaces = author.replace(" ", "") author_no_spaces = author.replace(" ", "")
return author_no_spaces return author_no_spaces
def process_images(folder): def process_images(folder):
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
PW=$(cat /home/lucas/.PW) PW=$(cat /home/lucas/.PW)
FOLDER=/torrent/Camera FOLDER=/torrent/camera
SERVER="https://someoneslinux.ddns.net" SERVER="https://someoneslinux.ddns.net"
nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera ${FOLDER} ${SERVER} 1>/dev/null 2>&1 nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera ${FOLDER} ${SERVER} 1>/dev/null 2>&1
export PYTHONPATH=/home/lucas/scripts export PYTHONPATH=/home/lucas/scripts
+46 -22
View File
@@ -11,11 +11,14 @@ ret=0
count=20 count=20
PW=$(cat /home/lucas/.PW) PW=$(cat /home/lucas/.PW)
PW_M="multimedia123" PW_M="multimedia123"
SYNC_MEDIA=0 SYNC_MEDIA=1
SYNC_RECIPIES=1 SYNC_RECIPIES=1
SYNC_MEDIA_ONLY=0
SYNC_ALINA=1 SYNC_ALINA=1
SYNC_THEMES=0 SYNC_ALINA_DROP=1
SYNC_THEMES=1
SYNC_WALLPAPER=1
SYNC_CAMERA=1
SYNC_SERVER=0
SILENT=true SILENT=true
SERVER="https://someoneslinux.ddns.net" SERVER="https://someoneslinux.ddns.net"
while [[ ${1:0:1} == - ]]; do while [[ ${1:0:1} == - ]]; do
@@ -26,7 +29,18 @@ while [[ ${1:0:1} == - ]]; do
continue; continue;
}; };
[[ $1 == -o ]] && { [[ $1 == -o ]] && {
SYNC_MEDIA_ONLY=1; SYNC_SERVER=1;
SYNC_WALLPAPER=1
shift 1;
continue;
};
[[ $1 == -d ]] && {
SYNC_ALINA_DROP=0;
shift 1;
continue;
};
[[ $1 == -c ]] && {
SYNC_CAMERA=0;
shift 1; shift 1;
continue; continue;
}; };
@@ -36,25 +50,24 @@ while [[ ${1:0:1} == - ]]; do
continue; continue;
}; };
[[ $1 == -m ]] && { [[ $1 == -m ]] && {
SYNC_MEDIA=1; SYNC_MEDIA=0;
shift 1; shift 1;
continue; continue;
}; };
[[ $1 == -t ]] && { [[ $1 == -t ]] && {
SYNC_THEMES=1; SYNC_THEMES=0;
shift 1; shift 1;
continue; continue;
}; };
[[ $1 == -del ]] && {
[[ $1 == -del ]] && { if [ -f /tmp/nextcloud_sync ]; then
if [ -f /tmp/nextcloud_sync ]; then rm /tmp/nextcloud_sync
rm /tmp/nextcloud_sync echo "File removed"
echo "File removed" fi
fi shift 1;
shift 1; continue;
continue;
}; };
echo "Parameter $1 discarded" echo "Parameter $1 discarded"
shift 1; shift 1;
done done
@@ -64,18 +77,24 @@ else
echo "Sync Nextcloud" echo "Sync Nextcloud"
while true; do while true; do
ret=0 ret=0
if [ ${SYNC_MEDIA} -eq 1 ];then if [ ${SYNC_MEDIA} -eq 0 ];then
echo "Sync Multmedia" echo "Sync Multmedia"
run_cmd sudo /home/lucas/scripts/serverhost/tvbitch_user_cmd.sh nextcloudcmd --logdebug --trust --user multimedia --password ${PW_M} --path Filme/New /torrent/multimedia/Filme/New ${SERVER} run_cmd sudo /home/lucas/scripts/serverhost/tvbitch_user_cmd.sh nextcloudcmd --logdebug --trust --user multimedia --password ${PW_M} --path Filme/New /torrent/multimedia/Filme/New ${SERVER}
ret=$(( ret + $? )) ret=$(( ret + $? ))
#echo Return: $ret #echo Return: $ret
fi fi
if [[ ${SYNC_THEMES} -eq 1 ]] && [[ ${SYNC_MEDIA_ONLY} -eq 0 ]]; then if [[ ${SYNC_THEMES} -eq 0 ]] && [[ ${SYNC_MEDIA_ONLY} -eq 0 ]]; then
echo "Sync Themes" echo "Sync Themes"
run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Projekte/Handy/ThemeProject/SolarSystemTheme /home/lucas/Documents/Dokumente/Projekte/Handy/ThemeProject/SolarSystemTheme ${SERVER} run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Projekte/Handy/ThemeProject/SolarSystemTheme /home/lucas/Documents/Dokumente/Projekte/Handy/ThemeProject/SolarSystemTheme ${SERVER}
ret=$(( ret + $? )) ret=$(( ret + $? ))
#echo Return: $ret #echo Return: $ret
fi fi
if [[ ${SYNC_ALINA_DROP} -eq 0 ]];then
echo "Sync Alina Share"
run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Alina\ Share/ /torrent/alina ${SERVER}
ret=$(( ret + $? ))
#echo Return: $ret
fi
if [[ ${SYNC_ALINA} -eq 0 ]];then if [[ ${SYNC_ALINA} -eq 0 ]];then
echo "Sync Alina" echo "Sync Alina"
run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Shared/Alina/Wachstum /home/lucas/Documents/Dokumente/Shared/Alina/Wachstum ${SERVER} run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Shared/Alina/Wachstum /home/lucas/Documents/Dokumente/Shared/Alina/Wachstum ${SERVER}
@@ -88,14 +107,19 @@ else
ret=$(( ret + $? )) ret=$(( ret + $? ))
#echo Return: $ret #echo Return: $ret
fi fi
if [[ "$1" != "-W" ]] && [[ ${SYNC_MEDIA_ONLY} -eq 0 ]];then if [[ ${SYNC_CAMERA} -eq 0 ]];then
echo "Sync Camera"
nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera /torrent/camera ${SERVER} 1>/dev/null 2>&1
ret=$(( ret + $? ))
#echo Return: $ret
fi
if [[ ${SYNC_SERVER} -eq 0 ]];then
echo "Sync Server" echo "Sync Server"
# echo "nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Projekte/Server /home/lucas/Documents/Dokumente/Projekte/Server ${SERVER}"
run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Projekte/Server /home/lucas/Documents/Dokumente/Projekte/Server ${SERVER} run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Projekte/Server /home/lucas/Documents/Dokumente/Projekte/Server ${SERVER}
ret=$(( ret + $? )) ret=$(( ret + $? ))
#echo Return: $ret #echo Return: $ret
fi fi
if [[ ${SYNC_MEDIA_ONLY} -eq 0 ]]; then if [[ ${SYNC_WALLPAPER} -eq 0 ]]; then
echo "Sync Wallpaper" echo "Sync Wallpaper"
run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Media/Stuff/Wallpaper /torrent/WallpaperChanger ${SERVER} run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Media/Stuff/Wallpaper /torrent/WallpaperChanger ${SERVER}
ret=$(( ret + $? )) ret=$(( ret + $? ))