sync & torrent scripts
This commit is contained in:
1 parent
884ae1f841
commit
3e258c6afe
6 files changed
+75
-20
No files matched your search
+5
-2
@@ -10,7 +10,7 @@ from serverlibary import safe_rename,safe_delete
|
||||
VIDEO_EXTENSIONS = {".mpg", ".avi", ".mkv", ".mp4", ".m4v", ".srt"}
|
||||
|
||||
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"DUAL-", r"LostFilm", r"readnfo", r"BluRay",
|
||||
r"720p", r"1080p", r"WEB", r"AMZN", r"HDTV",
|
||||
@@ -23,7 +23,7 @@ UNWANTED_PATTERNS_PRE = [
|
||||
]
|
||||
|
||||
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 = [
|
||||
@@ -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"\.+", ".", base)
|
||||
base = re.sub(r" +", " ", base)
|
||||
base = re.sub(r" ", ".", base)
|
||||
|
||||
|
||||
base = base.strip(".")
|
||||
return base + ext
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ while [[ ${1:0:1} == - ]]; do
|
||||
usage;
|
||||
exit;
|
||||
};
|
||||
[[ $1 == -f ]] && {
|
||||
echo "Dest: /torrent/Films"
|
||||
STUFF="/torrent/Films/"
|
||||
shift 1
|
||||
continue
|
||||
};
|
||||
[[ $1 == -v ]] && {
|
||||
echo "Dest: Videos"
|
||||
STUFF="/data/Videos/"
|
||||
|
||||
@@ -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)
|
||||
@@ -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."
|
||||
@@ -14,6 +14,7 @@ PW_M="multimedia123"
|
||||
SYNC_MEDIA=0
|
||||
SYNC_RECIPIES=1
|
||||
SYNC_MEDIA_ONLY=0
|
||||
SYNC_ALINA=1
|
||||
SYNC_THEMES=0
|
||||
SILENT=true
|
||||
SERVER="https://someoneslinux.ddns.net"
|
||||
@@ -29,6 +30,11 @@ while [[ ${1:0:1} == - ]]; do
|
||||
shift 1;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -al ]] && {
|
||||
SYNC_ALINA=0;
|
||||
shift 1;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -m ]] && {
|
||||
SYNC_MEDIA=1;
|
||||
shift 1;
|
||||
@@ -70,6 +76,12 @@ else
|
||||
ret=$(( ret + $? ))
|
||||
#echo Return: $ret
|
||||
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
|
||||
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}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/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
|
||||
|
||||
/home/lucas/mqqt_venv/bin/python /home/lucas/scripts/serverhost/torrent_mqtt.py "$*"
|
||||
|
||||
Reference in new issue
Block a user