sync & torrent scripts

This commit is contained in:
Lucas Faber authored and Lucas Vivohost committed 2026-09-14 09:20:47 +02:00
1 parent 884ae1f841
commit 3e258c6afe
6 files changed
+64 -9

No files matched your search

+5 -2
View File
@@ -10,7 +10,7 @@ from serverlibary import safe_rename,safe_delete
VIDEO_EXTENSIONS = {".mpg", ".avi", ".mkv", ".mp4", ".m4v", ".srt"} VIDEO_EXTENSIONS = {".mpg", ".avi", ".mkv", ".mp4", ".m4v", ".srt"}
UNWANTED_PATTERNS_POST = [ UNWANTED_PATTERNS_POST = [
r"TV\ Series", r"[a-z]264", r"10bit", r"\[.*?\]", r"MULTi", r"TV\ Series", r"[a-z]264", r"10bit", r"\[.*?\]",
r"320kbps", r"AC3", r"NF\.WEB", r"bdrip", r"RERIP", r"320kbps", r"AC3", r"NF\.WEB", r"bdrip", r"RERIP",
r"DUAL-", r"LostFilm", r"readnfo", r"BluRay", r"DUAL-", r"LostFilm", r"readnfo", r"BluRay",
r"720p", r"1080p", r"WEB", r"AMZN", r"HDTV", r"720p", r"1080p", r"WEB", r"AMZN", r"HDTV",
@@ -23,7 +23,7 @@ UNWANTED_PATTERNS_PRE = [
] ]
GARBAGE_PATTERNS = [ GARBAGE_PATTERNS = [
r"Downloaded From.*", r"www\.YTS.*", r".*\.nfo", r"YTSY.*", r"RARBG.*", r".*YIFY.*\.jpg", f"Torrent Downloaded From.*txt", "Screens" r"Downloaded From.*", r"www\.YTS.*", r"YTS.*txt", r"YTS.*jp*g" , r".*\.nfo", r"YTSY.*", r"RARBG.*", r".*YIFY.*\.jpg", f"Torrent Downloaded From.*txt", "Screens"
] ]
DAMAGE_PATTERNS = [ DAMAGE_PATTERNS = [
@@ -67,6 +67,9 @@ def clean_name(name: Path, search=None, replace=None):
base = re.sub(r'[^A-Za-z0-9)]+$', '', base) base = re.sub(r'[^A-Za-z0-9)]+$', '', base)
base = re.sub(r"\.+", ".", base) base = re.sub(r"\.+", ".", base)
base = re.sub(r" +", " ", base) base = re.sub(r" +", " ", base)
base = re.sub(r" ", ".", base)
base = base.strip(".") base = base.strip(".")
return base + ext return base + ext
+6
View File
@@ -19,6 +19,12 @@ while [[ ${1:0:1} == - ]]; do
usage; usage;
exit; exit;
}; };
[[ $1 == -f ]] && {
echo "Dest: /torrent/Films"
STUFF="/torrent/Films/"
shift 1
continue
};
[[ $1 == -v ]] && { [[ $1 == -v ]] && {
echo "Dest: Videos" echo "Dest: Videos"
STUFF="/data/Videos/" STUFF="/data/Videos/"
+19 -6
View File
@@ -4,17 +4,17 @@ import random
import datetime import datetime
import sys import sys
from PIL import Image, ExifTags from PIL import Image, ExifTags
from pillow_heif import open_heif
import subprocess import subprocess
import json import json
from serverlibary import safe_rename from serverlibary import safe_rename
from pathlib import Path from pathlib import Path
# Folder to scan # Folder to scan
folder_path = '.' folder_path = '.'
# Supported image and video extensions # Supported image and video extensions
video_extensions = { video_extensions = {
'.mp4', '.mov', '.avi', '.mkv', '.hevc' '.mp4', '.mov', '.avi', '.mkv', '.hevc', '.mov',
} }
img_extensions = { img_extensions = {
'.jpg', '.jpeg', '.png', '.heic', '.webp', '.jpg', '.jpeg', '.png', '.heic', '.webp',
@@ -100,19 +100,33 @@ 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():
heif_file = open_heif(filepath)
img = Image.fromarray(heif_file.data)
exif = img.getexif()
for tag_id, value in exif.items():
print(tag_id, value)
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")
return None return None
# Map tag ids to tag names # Map tag ids to tag names
tag_label = {ExifTags.TAGS.get(k): v for k, v in exif.items() if k in ExifTags.TAGS} tag_label = {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)
if tag in tag_label: if tag in tag_label:
print(tag)
# EXIF date format: 'YYYY:MM:DD HH:MM:SS' # EXIF date format: 'YYYY:MM:DD HH:MM:SS'
return datetime.datetime.strptime(tag_label[tag], '%Y:%m:%d %H:%M:%S') return datetime.datetime.strptime(tag_label[tag], '%Y:%m:%d %H:%M:%S')
except Exception as e: except Exception as e:
print(f"Exif Error {e}")
pass pass
return None return None
@@ -178,9 +192,7 @@ def process_images(folder):
# Now continue with your existing logic on normalized fname # Now continue with your existing logic on normalized fname
if correct_format_re.match(fname): if correct_format_re.match(fname):
if videoManufacturer != "" and file_prefix == "VID": if videoManufacturer != "" and file_prefix == "VID":
if videoManufacturer in fname: if videoManufacturer not in fname:
pass
else:
basename, _ = os.path.splitext(fname) basename, _ = os.path.splitext(fname)
new_fname = f"{basename}{videoManufacturer}{ext}" new_fname = f"{basename}{videoManufacturer}{ext}"
safe_rename(Path(fpath),folder / new_fname) 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}" new_fname = f"{file_prefix}_{dt.strftime('%Y%m%d_%H%M%S')}{videoManufacturer}{ext}"
safe_rename(Path(fpath),folder / new_fname) safe_rename(Path(fpath),folder / new_fname)
continue continue
else:
print(f"[Fail] Creation Date for {fpath} not found")
# 4. Fallback: keep original name, add _RX_<random> (only if not already added) # 4. Fallback: keep original name, add _RX_<random> (only if not already added)
if '_RX_' in fname: if '_RX_' in fname:
print(f"[SKIP] {fname} already has fallback name.") print(f"[SKIP] {fname} already has fallback name.")
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail
SOURCE1="/nextcloud/nextcloud-data/lucas/files/Media/Audiobooks/Englisch/"
DEST1="/nextcloud/audiobooks-englisch/"
SOURCE2="/nextcloud/nextcloud-data/lucas/files/Media/Music/Musik/"
DEST2="/nextcloud/navidrome/music/"
SOURCE3="/nextcloud/nextcloud-data/lucas/files/Media/Music/Playlists/Nextcloud/"
DEST3="/nextcloud/navidrome/music/playlists/Nextcloud/"
SOURCE4="/nextcloud/nextcloud-data/lucas/files/Media/Audiobooks/Deutsch/"
DEST4="/nextcloud/audiobooks-deutsch/"
SOURCE5="/nextcloud/nextcloud-data/lucas/files/Media/Audiobooks/Kinderbücher/"
DEST5="/nextcloud/audiobooks-kinder/"
echo "Syncing audiobooks..."
rsync -avh --delete "$SOURCE1" "$DEST1"
rsync -avh --delete "$SOURCE2" "$DEST2" --exclude="playlists"
rsync -avh --delete "$SOURCE3" "$DEST3" --mkpath
rsync -avh --delete "$SOURCE4" "$DEST4"
rsync -avh --delete "$SOURCE5" "$DEST5"
echo "Done."
+12
View File
@@ -14,6 +14,7 @@ PW_M="multimedia123"
SYNC_MEDIA=0 SYNC_MEDIA=0
SYNC_RECIPIES=1 SYNC_RECIPIES=1
SYNC_MEDIA_ONLY=0 SYNC_MEDIA_ONLY=0
SYNC_ALINA=1
SYNC_THEMES=0 SYNC_THEMES=0
SILENT=true SILENT=true
SERVER="https://someoneslinux.ddns.net" SERVER="https://someoneslinux.ddns.net"
@@ -29,6 +30,11 @@ while [[ ${1:0:1} == - ]]; do
shift 1; shift 1;
continue; continue;
}; };
[[ $1 == -al ]] && {
SYNC_ALINA=0;
shift 1;
continue;
};
[[ $1 == -m ]] && { [[ $1 == -m ]] && {
SYNC_MEDIA=1; SYNC_MEDIA=1;
shift 1; shift 1;
@@ -70,6 +76,12 @@ else
ret=$(( ret + $? )) ret=$(( ret + $? ))
#echo Return: $ret #echo Return: $ret
fi fi
if [[ ${SYNC_ALINA} -eq 0 ]];then
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}
ret=$(( ret + $? ))
#echo Return: $ret
fi
if [[ ${SYNC_RECIPIES} -eq 0 ]];then if [[ ${SYNC_RECIPIES} -eq 0 ]];then
echo "Sync Recipies" echo "Sync Recipies"
run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Shared/Diverses/Kochbuch/RecepiesLucas /home/lucas/Documents/Dokumente/Shared/Diverses/Kochbuch/RecepiesLucas ${SERVER} run_cmd nextcloudcmd --trust --user lucas --password ${PW} --path Dokumente/Dokumente/Shared/Diverses/Kochbuch/RecepiesLucas /home/lucas/Documents/Dokumente/Shared/Diverses/Kochbuch/RecepiesLucas ${SERVER}
+1 -1
View File
@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
deluge-console "connect 127.0.0.1:58846; rm $1 -c" 2>/dev/null #deluge-console "connect 127.0.0.1:58846; rm $1 -c" 2>/dev/null
echo "$@" >> /home/lucas/.LOG/log_torrentlog.txt echo "$@" >> /home/lucas/.LOG/log_torrentlog.txt
/home/lucas/mqqt_venv/bin/python /home/lucas/scripts/serverhost/torrent_mqtt.py "$*" /home/lucas/mqqt_venv/bin/python /home/lucas/scripts/serverhost/torrent_mqtt.py "$*"