diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8b56eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +output +urls.txt +done.txt +processed diff --git a/.obsidian/app.json b/.obsidian/app.json deleted file mode 100644 index 8c13e56..0000000 --- a/.obsidian/app.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "alwaysUpdateLinks": true, - "showUnsupportedFiles": true -} \ No newline at end of file diff --git a/.obsidian/appearance.json b/.obsidian/appearance.json deleted file mode 100644 index 9e26dfe..0000000 --- a/.obsidian/appearance.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json deleted file mode 100644 index 0faa60d..0000000 --- a/.obsidian/core-plugins.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "file-explorer": true, - "global-search": true, - "switcher": true, - "graph": true, - "backlink": true, - "canvas": true, - "outgoing-link": true, - "tag-pane": true, - "footnotes": false, - "properties": false, - "page-preview": true, - "daily-notes": true, - "templates": true, - "note-composer": true, - "command-palette": true, - "slash-command": false, - "editor-status": true, - "bookmarks": true, - "markdown-importer": false, - "zk-prefixer": false, - "random-note": false, - "outline": true, - "word-count": true, - "slides": false, - "audio-recorder": false, - "workspaces": false, - "file-recovery": true, - "publish": false, - "sync": true, - "bases": true, - "webviewer": false -} \ No newline at end of file diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json deleted file mode 100644 index f89cd09..0000000 --- a/.obsidian/workspace.json +++ /dev/null @@ -1,274 +0,0 @@ -{ - "main": { - "id": "c14fb7788bb86e58", - "type": "split", - "children": [ - { - "id": "b277dc0ec57ac4e5", - "type": "tabs", - "children": [ - { - "id": "bd0227a0bc51fda3", - "type": "leaf", - "pinned": true, - "state": { - "type": "markdown", - "state": { - "file": "rename-nested-file-to-parent.md", - "mode": "source", - "source": false - }, - "pinned": true, - "icon": "lucide-file", - "title": "rename-nested-file-to-parent" - } - }, - { - "id": "aad5fb65253dfe6f", - "type": "leaf", - "pinned": true, - "state": { - "type": "markdown", - "state": { - "file": "metadata-stuff.md", - "mode": "source", - "source": false - }, - "pinned": true, - "icon": "lucide-file", - "title": "metadata-stuff" - } - }, - { - "id": "1edaeb936a995d2c", - "type": "leaf", - "pinned": true, - "state": { - "type": "markdown", - "state": { - "file": "move-file-into-dir-with-same-name.md", - "mode": "source", - "source": false - }, - "pinned": true, - "icon": "lucide-file", - "title": "move-file-into-dir-with-same-name" - } - }, - { - "id": "50fc2c454baeec28", - "type": "leaf", - "state": { - "type": "markdown", - "state": { - "file": "bring-files-up-one-dir.md", - "mode": "source", - "source": false - }, - "icon": "lucide-file", - "title": "bring-files-up-one-dir" - } - }, - { - "id": "4c3684fe958a6ed9", - "type": "leaf", - "state": { - "type": "markdown", - "state": { - "file": "bulk-move.md", - "mode": "source", - "source": false - }, - "icon": "lucide-file", - "title": "bulk-move" - } - }, - { - "id": "b527262a94efda07", - "type": "leaf", - "state": { - "type": "markdown", - "state": { - "file": "move-file-into-dir-with-same-name.md", - "mode": "source", - "source": false - }, - "icon": "lucide-file", - "title": "move-file-into-dir-with-same-name" - } - } - ], - "currentTab": 1 - } - ], - "direction": "vertical" - }, - "left": { - "id": "10ee71e8f52d892a", - "type": "split", - "children": [ - { - "id": "63a8cd2db9e08095", - "type": "tabs", - "children": [ - { - "id": "50dd7c7842ea0193", - "type": "leaf", - "state": { - "type": "file-explorer", - "state": { - "sortOrder": "alphabetical", - "autoReveal": false - }, - "icon": "lucide-folder-closed", - "title": "Files" - } - }, - { - "id": "96368e722c01fada", - "type": "leaf", - "state": { - "type": "search", - "state": { - "query": "", - "matchingCase": false, - "explainSearch": false, - "collapseAll": false, - "extraContext": false, - "sortOrder": "alphabetical" - }, - "icon": "lucide-search", - "title": "Search" - } - }, - { - "id": "ecb77e1599effc54", - "type": "leaf", - "state": { - "type": "bookmarks", - "state": {}, - "icon": "lucide-bookmark", - "title": "Bookmarks" - } - } - ] - } - ], - "direction": "horizontal", - "width": 300 - }, - "right": { - "id": "cf899824f83d0bec", - "type": "split", - "children": [ - { - "id": "5b1763d858d0e9ab", - "type": "tabs", - "children": [ - { - "id": "5a0c75072484915d", - "type": "leaf", - "state": { - "type": "backlink", - "state": { - "file": "metadata-stuff.md", - "collapseAll": false, - "extraContext": false, - "sortOrder": "alphabetical", - "showSearch": false, - "searchQuery": "", - "backlinkCollapsed": false, - "unlinkedCollapsed": true - }, - "icon": "links-coming-in", - "title": "Backlinks for metadata-stuff" - } - }, - { - "id": "85c23228c3824809", - "type": "leaf", - "state": { - "type": "outgoing-link", - "state": { - "linksCollapsed": false, - "unlinkedCollapsed": true - }, - "icon": "links-going-out", - "title": "Outgoing links" - } - }, - { - "id": "b58ae060bc33155e", - "type": "leaf", - "state": { - "type": "tag", - "state": { - "sortOrder": "frequency", - "useHierarchy": true, - "showSearch": false, - "searchQuery": "" - }, - "icon": "lucide-tags", - "title": "Tags" - } - }, - { - "id": "502c9508500b0f41", - "type": "leaf", - "state": { - "type": "outline", - "state": { - "followCursor": false, - "showSearch": false, - "searchQuery": "" - }, - "icon": "lucide-list", - "title": "Outline" - } - } - ] - } - ], - "direction": "horizontal", - "width": 300 - }, - "left-ribbon": { - "hiddenItems": { - "switcher:Open quick switcher": false, - "graph:Open graph view": false, - "canvas:Create new canvas": false, - "daily-notes:Open today's daily note": false, - "templates:Insert template": false, - "command-palette:Open command palette": false, - "bases:Create new base": false - } - }, - "active": "aad5fb65253dfe6f", - "lastOpenFiles": [ - "move-file-into-dir-with-same-name.md", - "metadata-stuff.md", - "bulk-move.md", - "find-short-videos.md", - "rename-nested-file-to-parent.md", - "bring-files-up-one-dir.md", - "remove-timestamps.md", - "ffmpeg.md", - "regex-stuff.md", - "add-prefix-to-file.md", - "usr-local-bin/setartist", - "usr-local-bin/getresauto", - "usr-local-bin/getres", - "usr-local-bin/cutto", - "usr-local-bin/cutfrom", - "usr-local-bin", - "remove-n-chars-from-name.md", - "remove-n-chars-from-name_handle-duplicates.md", - "recursively-extract-artist-from-filename.md", - "print-all-files-and-folders.md", - "print-all-files-and-folders-to-file.md", - "move-files-to-year-and-month-dirs.md", - "move-file-in-dir-with-same-name.md", - "filename-as-metadata-title.md", - "auto-fill-missing-artist-tags.md" - ] -} \ No newline at end of file diff --git a/auto-curler/auto-curler.sh b/auto-curler/auto-curler.sh new file mode 100755 index 0000000..7b56e21 --- /dev/null +++ b/auto-curler/auto-curler.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +if [ $# -eq 0 ]; then + echo "Usage: $0 file_with_urls.txt" + exit 1 +fi + +URL_FILE="$1" +OUTPUT_DIR="output" + +mkdir -p "$OUTPUT_DIR" + +while IFS= read -r url; do + if [ -z "$url" ]; then + continue + fi + + domain=$(echo "$url" | awk -F[/:] '{print $4}') + + filename=$(basename "$url") + + sub_dir="$OUTPUT_DIR/$domain" + full_path="${sub_dir}/${filename}" + + mkdir -p "$sub_dir" + + if [ ! -f "$full_path" ]; then + echo "Downloading $url..." + echo "Subdir $sub_dir" + + curl -o "$full_path" "$url" + + last_modified=$(curl -sI $url | grep -i Last-Modified | awk '{print substr($0, index($0,$2))}') + + echo "Modified: $last_modified" + touch -d "$last_modified" "$full_path" + + echo "---" + else + echo "Skipping $url; file already exists." + fi + + sleep 2 +done < "$URL_FILE" + +echo "Download complete." diff --git a/auto-curler/file-replicator.sh b/auto-curler/file-replicator.sh new file mode 100755 index 0000000..98a0181 --- /dev/null +++ b/auto-curler/file-replicator.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +SOURCE_DIR="output" +TARGET_DIR="target" + +replicate_structure() { + local source="$1" + local target="$2" + + for item in "$source"/*; do + if [ -d "$item" ]; then + local dir_name=$(basename "$item") + + mkdir -p "$target/$dir_name" + + replicate_structure "$item" "$target/$dir_name" + + elif [ -f "$item" ]; then + if [ -s "$item" ]; then + local file_name=$(basename "$item") + + touch "$target/$file_name" + fi + fi + done +} + +replicate_structure "$SOURCE_DIR" "$TARGET_DIR" + +echo "Replication complete from $SOURCE_DIR to $TARGET_DIR" diff --git a/backup-and-restore/fetch-and-execute.sh b/backup-and-restore/fetch-and-execute.sh new file mode 100644 index 0000000..0dbfd68 --- /dev/null +++ b/backup-and-restore/fetch-and-execute.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -euo pipefail + +fetch_and_execute() { + local script_name=$1 + shift # Shift the arguments so $@ contains the additional arguments to pass + local token_file=".gitea_token" + local gitea_user="user" + local gitea_repo="repo" + local gitea_domain="http://127.0.0.1:3333" + local gitea_access_token + + if [[ -f "$token_file" ]]; then + gitea_access_token=$(<"$token_file") + else + echo "Cannot find the Gitea token file. Ensure it exists at $token_file." + exit 1 + fi + + echo "Fetching and executing ${script_name}..." + + tmp_script="$(mktemp)" + + if curl -fSL --show-error --header "Authorization: token $gitea_access_token" \ + "${gitea_domain}/api/v1/repos/${gitea_user}/${gitea_repo}/raw/${script_name}" \ + -o "$tmp_script"; then + + chmod +x "$tmp_script" + + mkdir -p ./log/homelab + + logfile="./log/homelab/$(basename "$script_name").log" + + if "$tmp_script" "$@" 2>&1 | tee "$logfile"; then + echo "Execution of ${script_name} was successful." + else + echo "Failed to execute ${script_name}. Log saved to $logfile" + rm -f "$tmp_script" + exit 2 + fi + else + echo "Failed to download ${script_name}." + exit 1 + fi + + rm -f "$tmp_script" +} + + + +# How to use in other scripts: + +# path_to_fetch_script="fetch_and_execute.sh" +# source "$path_to_fetch_script" + +# fetch_and_execute "name_of_script_to_fetch_and_run.sh" arg1 arg2 arg3 diff --git a/backup-and-restore/ground-zero.sh b/backup-and-restore/ground-zero.sh new file mode 100644 index 0000000..928a874 --- /dev/null +++ b/backup-and-restore/ground-zero.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -euo pipefail + +umask 077 +cat < .gitea_token +REPLACE:gitea-token +EOF + +fetch() { + local script_name=$1 + local target=$2 + local token_file=".gitea_token" + local gitea_user="user" + local gitea_repo="repo" + local gitea_domain="http://127.0.0.1:3333" + local gitea_access_token + + if [[ -f "$token_file" ]]; then + gitea_access_token=$(<"$token_file") + else + echo "Cannot find the Gitea token file. Ensure it exists at $token_file." + exit 1 + fi + + echo "Fetching ${script_name}..." + + mkdir -p "$(dirname "$target")" + + if curl -fsSL \ + --header "Authorization: token $gitea_access_token" \ + "${gitea_domain}/api/v1/repos/${gitea_user}/${gitea_repo}/raw/${script_name}" \ + -o "$target"; then + + chmod +x "$target" + echo "Successfully fetched ${script_name} to ${target}." + + else + echo "Failed to fetch ${script_name} from ${gitea_repo}." + exit 2 + fi +} + +fetch "script/fetch_and_execute.sh" "/usr/local/lib/fetch-and-execute.sh" + +path_to_fetch_script="/usr/local/lib/fetch-and-execute.sh" +source "$path_to_fetch_script" + +#fetch_and_execute "script/vm-setup/machine_setup.sh" REPLACE:generic-dev-machine diff --git a/backup-and-restore/machine-setup/TEMPLATE-backup/backup-cronjob-sudo.sh b/backup-and-restore/machine-setup/TEMPLATE-backup/backup-cronjob-sudo.sh new file mode 100644 index 0000000..e225673 --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-backup/backup-cronjob-sudo.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] backup-cronjob-sudo" +echo + +sudo crontab -l > "root-crontab-backup.txt" + +echo +echo "[SCRIPT DONE] backup-cronjob-sudo" +echo +echo diff --git a/backup-and-restore/machine-setup/TEMPLATE-backup/backup-cronjob.sh b/backup-and-restore/machine-setup/TEMPLATE-backup/backup-cronjob.sh new file mode 100644 index 0000000..c1522ea --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-backup/backup-cronjob.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] backup-cronjob" +echo + +crontab -l > "crontab-backup.txt" + +echo +echo "[SCRIPT DONE] backup-cronjob" +echo +echo diff --git a/backup-and-restore/machine-setup/TEMPLATE-backup/rsync-docker-volumes-local.sh b/backup-and-restore/machine-setup/TEMPLATE-backup/rsync-docker-volumes-local.sh new file mode 100644 index 0000000..80d482b --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-backup/rsync-docker-volumes-local.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] rsync-docker-volumes-local" +echo + +BACKUP_DIR="/var/lib/docker/volumes/" +REMOTE_DIR="/path/to/backup/folder" + +rsync -avz --progress "$BACKUP_DIR" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR" + +echo +echo "[SCRIPT DONE] rsync-docker-volumes-local" +echo +echo diff --git a/backup-and-restore/machine-setup/TEMPLATE-backup/rsync-docker-volumes-ssh.sh b/backup-and-restore/machine-setup/TEMPLATE-backup/rsync-docker-volumes-ssh.sh new file mode 100644 index 0000000..ca7bcb7 --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-backup/rsync-docker-volumes-ssh.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] rsync-docker-volumes-ssh" +echo + +BACKUP_DIR="/var/lib/docker/volumes/" +REMOTE_USER="user" +REMOTE_HOST="127.0.0.1" +REMOTE_PORT="22" +REMOTE_DIR="/path/to/backup/folder" + +rsync -avz -e "ssh -i /home/user/.ssh/id_rsa -p $REMOTE_PORT" --progress "$BACKUP_DIR" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR" + +echo +echo "[SCRIPT DONE] rsync-docker-volumes-ssh" +echo +echo diff --git a/backup-and-restore/machine-setup/TEMPLATE-restore/configure-app-X.sh b/backup-and-restore/machine-setup/TEMPLATE-restore/configure-app-X.sh new file mode 100644 index 0000000..2eefc76 --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-restore/configure-app-X.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] configure-app-X" +echo + +mkdir app-name +cd app-name + +cat < /dev/null + +echo "[SCRIPT] Install Docker" + +sudo apt update +sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin + +echo "[SCRIPT] Install docker-compose" + +sudo curl -SL http://127.0.0.1/github/docker-compose/v2.27.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose + +echo "[SCRIPT] Add user to docker group" + +sudo usermod -aG docker ${USER} + +echo +echo "[SCRIPT DONE] configure-docker" +echo +echo diff --git a/backup-and-restore/machine-setup/TEMPLATE-restore/configure-fstab.sh b/backup-and-restore/machine-setup/TEMPLATE-restore/configure-fstab.sh new file mode 100644 index 0000000..58ff9ef --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-restore/configure-fstab.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] configure-fstab" +echo + +sudo mkdir /mnt/REPLACE:folder-name + +cat < /dev/null + +echo "[SCRIPT] Update package lists" + +sudo apt update + +echo "[SCRIPT] Install ungoogled-chromium" + +sudo apt-get install -y ungoogled-chromium + +echo +echo "[SCRIPT DONE] configure-ungoogled-chromium" +echo +echo diff --git a/backup-and-restore/machine-setup/TEMPLATE-restore/execute.sh b/backup-and-restore/machine-setup/TEMPLATE-restore/execute.sh new file mode 100644 index 0000000..fea1d9d --- /dev/null +++ b/backup-and-restore/machine-setup/TEMPLATE-restore/execute.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] execute" +echo + +path_to_fetch_script="/usr/local/lib/fetch_and_execute.sh" +source "$path_to_fetch_script" + +fetch_and_execute "script/vm-setup/machine/generic-dev-machine/restore/configure-apt-mirror.sh" + +echo +echo "[SCRIPT DONE] execute" +echo +echo diff --git a/backup-and-restore/machine-setup/machine-setup.sh b/backup-and-restore/machine-setup/machine-setup.sh new file mode 100644 index 0000000..0c87d5b --- /dev/null +++ b/backup-and-restore/machine-setup/machine-setup.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -euo pipefail + +echo +echo +echo "[SCRIPT START] machine-setup" +echo + +if [ -z "$1" ]; then + echo "Please provide a machine name as an argument. Usage: $0 " + exit 1 +fi + +MACHINE_NAME=$1 + +path_to_fetch_script="/usr/local/lib/fetch_and_execute.sh" +source "$path_to_fetch_script" + + + +case "$MACHINE_NAME" in + "generic-dev-machine") + fetch_and_execute "script/vm-setup/machine/generic-dev-machine/restore/execute.sh" + ;; + *) + echo "Unknown machine name. Please provide a valid one." + exit 2 + ;; +esac + +echo +echo "[SCRIPT DONE] machine-setup" +echo +echo diff --git a/backup-and-restore/machine-setup/machine/generic-dev-machine/restore/configure-packages.sh b/backup-and-restore/machine-setup/machine/generic-dev-machine/restore/configure-packages.sh new file mode 100755 index 0000000..dac6d45 --- /dev/null +++ b/backup-and-restore/machine-setup/machine/generic-dev-machine/restore/configure-packages.sh @@ -0,0 +1,14 @@ +echo +echo +echo "[SCRIPT START] configure-packages" +echo + +sudo apt update + +sudo apt install openssh-server +sudo apt install nfs-common + +echo +echo "[SCRIPT DONE] configure-packages" +echo +echo diff --git a/backup-and-restore/machine-setup/machine/generic-dev-machine/restore/execute.sh b/backup-and-restore/machine-setup/machine/generic-dev-machine/restore/execute.sh new file mode 100755 index 0000000..7a55e78 --- /dev/null +++ b/backup-and-restore/machine-setup/machine/generic-dev-machine/restore/execute.sh @@ -0,0 +1,14 @@ +echo +echo +echo "[SCRIPT START] execute" +echo + +path_to_fetch_script="/usr/local/lib/fetch_and_execute.sh" +source "$path_to_fetch_script" + +fetch_and_execute "script/vm-setup/machine/generic-dev-machine/restore/configure-packages.sh" + +echo +echo "[SCRIPT DONE] execute" +echo +echo diff --git a/backup-and-restore/overview.md b/backup-and-restore/overview.md new file mode 100644 index 0000000..65bfa4d --- /dev/null +++ b/backup-and-restore/overview.md @@ -0,0 +1,8 @@ +SETUP ON NEW MACHINE: +- Create "ground-zero.sh" +- Paste content +- Replace gitea token +- Replace machine name +- Make executable + +$ ./ground-zero.sh diff --git a/browser-snippets/a.src-grabber.js b/browser-snippets/a.src-grabber.js new file mode 100644 index 0000000..074f7ac --- /dev/null +++ b/browser-snippets/a.src-grabber.js @@ -0,0 +1,79 @@ +const id = 'collectedAHref'; +let collectedImgSrc = JSON.parse(localStorage.getItem(id)) || []; + +function collectInitialSrc(targetNode) { + const elems = targetNode.querySelectorAll('a[href]'); + + elems.forEach(elem => { + if (!collectedImgSrc.includes(elem.href)) { + collectedImgSrc.push(elem.href); + + localStorage.setItem(id, JSON.stringify(collectedImgSrc)); + console.log(`πŸ™„ Snagged an initial a.href: ${elem.href}`); + } + }); +} + +const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((addedNode) => { + if (addedNode.nodeType === Node.ELEMENT_NODE) { + const elems = addedNode.querySelectorAll('a[href]'); + + elems.forEach((elem) => { + if (!collectedImgSrc.includes(elem.href)) { + collectedImgSrc.push(elem.href); + + localStorage.setItem(id, JSON.stringify(collectedImgSrc)); + console.log(`πŸ™„ Added a.href: ${elem.href}`); + } + }); + } + }); + }); +}); + +function waitForElement(selector, callback) { + if (document.querySelector(selector) != null) { + console.log("πŸ’ β€πŸŒ Target acquired. Commencing operation collect-a.srcs."); + + callback(document.querySelector(selector)); + } else { + setTimeout(() => waitForElement(selector, callback), 500); + } +} + +collectInitialSrc(document.body); + +const config = { childList: true, subtree: true }; +observer.observe(document.body, config); + + + +function downloadData(data, fileName, type = 'text/plain') { + const blob = new Blob([data], { type }); + const url = URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = url; + link.download = fileName; + link.click(); + + URL.revokeObjectURL(url); +} + +function stopObservingAHref() { + observer.disconnect(); + console.log("πŸ’ β€πŸŒ I've ceased surveillance. Here's what I've collected in a.href:"); + + const data = JSON.parse(localStorage.getItem(id)).join('\n'); + + console.log(data); + downloadData(data, 'a-hrefs.txt'); +} + +function clearCollectedAHrefs() { + localStorage.removeItem(id); + collectedImgSrc = []; + console.log("πŸ’ β€πŸŒ Local storage cleared. The slate is wiped clean."); +} diff --git a/browser-snippets/auto-scroller.js b/browser-snippets/auto-scroller.js new file mode 100644 index 0000000..a22b7b4 --- /dev/null +++ b/browser-snippets/auto-scroller.js @@ -0,0 +1,28 @@ +const scrollSpeed = 3; +const scrollDelay = 20; + +let autoScrollInterval = null; + +function startAutoScroll(){ + if(autoScrollInterval) return; + + autoScrollInterval = setInterval(() => { + window.scrollBy(0, scrollSpeed); + + if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + /** Uncomment if you want to enable auto-stop on page end */ + //stopAutoScroll(); + //console.log("πŸ™„ Reached bottom of page."); + } + }, scrollDelay); + + console.log("πŸ’ β€πŸŒ Auto‑scroll engaged."); +} + +function stopAutoScroll(){ + clearInterval(autoScrollInterval); + autoScrollInterval = null; + console.log("πŸ’ β€πŸŒ Auto‑scroll disengaged."); +} + +startAutoScroll(); diff --git a/browser-snippets/grab-magnets.js b/browser-snippets/grab-magnets.js new file mode 100644 index 0000000..1582ce0 --- /dev/null +++ b/browser-snippets/grab-magnets.js @@ -0,0 +1,20 @@ +let magnets = [...document.querySelectorAll('a')].map(a => a.href).filter(href => href.startsWith('magnet:')).join('\n'); + +if (magnets.length > 0) { + let tempTextArea = document.createElement('textarea'); + tempTextArea.value = magnets; + document.body.appendChild(tempTextArea); + tempTextArea.select(); + + try { + let successful = document.execCommand('copy'); + let msg = successful ? 'Successfully copied to clipboard!' : 'Failed to copy to clipboard!'; + console.log(msg); + } catch (err) { + console.error('Fallback: Oops, unable to copy', err); + } + + document.body.removeChild(tempTextArea); +} else { + console.log('No magnet links found on this page.'); +} diff --git a/browser-snippets/href-collector__reddit.js b/browser-snippets/href-collector__reddit.js new file mode 100644 index 0000000..97b5145 --- /dev/null +++ b/browser-snippets/href-collector__reddit.js @@ -0,0 +1,76 @@ +let collectedHrefs = JSON.parse(localStorage.getItem('collectedHrefs')) || []; + +function collectInitialHrefs(targetNode) { + const links = targetNode.querySelectorAll('a[href]'); + links.forEach(link => { + if (!collectedHrefs.includes(link.href)) { + collectedHrefs.push(link.href); + + localStorage.setItem('collectedHrefs', JSON.stringify(collectedHrefs)); + console.log(`πŸ™„ Snagged an initial href: ${link.href}`); + } + }); +} + +const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((addedNode) => { + if (addedNode.nodeType === Node.ELEMENT_NODE) { + const links = addedNode.querySelectorAll('a[href]'); + links.forEach((link) => { + if (!collectedHrefs.includes(link.href)) { + collectedHrefs.push(link.href); + + localStorage.setItem('collectedHrefs', JSON.stringify(collectedHrefs)); + console.log(`πŸ™„ Added href: ${link.href}`); + } + }); + } + }); + }); +}); + +function waitForElement(selector, callback) { + if (document.querySelector(selector) != null) { + console.log("πŸ’ β€πŸŒ Target acquired. Commencing operation collect-hrefs."); + callback(document.querySelector(selector)); + } else { + setTimeout(() => waitForElement(selector, callback), 500); + } +} + +waitForElement(".main-container", (targetNode) => { + collectInitialHrefs(targetNode); + const config = { childList: true, subtree: true }; + observer.observe(targetNode, config); +}); + + + +function downloadData(data, fileName, type = 'text/plain') { + const blob = new Blob([data], { type }); + const url = URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = url; + link.download = fileName; + link.click(); + + URL.revokeObjectURL(url); +} + +function stopObserving() { + observer.disconnect(); + console.log("πŸ’ β€πŸŒ I've ceased surveillance. Here's what I've collected:"); + + const data = JSON.parse(localStorage.getItem('collectedHrefs')).join('\n'); + + console.log(data); + downloadData(data, 'hrefs__reddit.txt'); +} + +function clearCollectedHrefs() { + localStorage.removeItem('collectedHrefs'); + collectedHrefs = []; + console.log("πŸ’ β€πŸŒ Local storage cleared. The slate is wiped clean."); +} diff --git a/browser-snippets/img-auto-clicker.js b/browser-snippets/img-auto-clicker.js new file mode 100644 index 0000000..d2d57d6 --- /dev/null +++ b/browser-snippets/img-auto-clicker.js @@ -0,0 +1,31 @@ +const delay = 300; // ms between clicks +const thumbs = Array.from(document.querySelectorAll("img")); +let i = 0; + +console.log("πŸ’ β€πŸŒ Found " + thumbs.length + " images. Initiating click rampage."); + +const clicker = setInterval(() => { + if (i >= thumbs.length) { + clearInterval(clicker); + console.log("πŸ™„ Finished clicking everything."); + return; + } + + const img = thumbs[i]; + + try { + img.scrollIntoView({ block: "center" }); + + img.dispatchEvent(new MouseEvent("click", { + bubbles: true, + cancelable: true, + view: window + })); + + console.log("πŸ’ β€πŸŒ Clicked #" + i + " -> " + (img.src || "no-src")); + + } catch (e) {} + + i++; + +}, delay); diff --git a/browser-snippets/img.src-grabber.js b/browser-snippets/img.src-grabber.js new file mode 100644 index 0000000..e64d357 --- /dev/null +++ b/browser-snippets/img.src-grabber.js @@ -0,0 +1,79 @@ +const id = 'collectedImgSrc'; +let collectedImgSrc = JSON.parse(localStorage.getItem(id)) || []; + +function collectInitialSrc(targetNode) { + const elems = targetNode.querySelectorAll('img[src]'); + + elems.forEach(elem => { + if (!collectedImgSrc.includes(elem.src)) { + collectedImgSrc.push(elem.src); + + localStorage.setItem(id, JSON.stringify(collectedImgSrc)); + console.log(`πŸ™„ Snagged an initial img.src: ${elem.src}`); + } + }); +} + +const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((addedNode) => { + if (addedNode.nodeType === Node.ELEMENT_NODE) { + const elems = addedNode.querySelectorAll('img[src]'); + + elems.forEach((elem) => { + if (!collectedImgSrc.includes(elem.src)) { + collectedImgSrc.push(elem.src); + + localStorage.setItem(id, JSON.stringify(collectedImgSrc)); + console.log(`πŸ™„ Added img.src: ${elem.src}`); + } + }); + } + }); + }); +}); + +function waitForElement(selector, callback) { + if (document.querySelector(selector) != null) { + console.log("πŸ’ β€πŸŒ Target acquired. Commencing operation collect-hrefs."); + + callback(document.querySelector(selector)); + } else { + setTimeout(() => waitForElement(selector, callback), 500); + } +} + +collectInitialSrc(document.body); + +const config = { childList: true, subtree: true }; +observer.observe(document.body, config); + + + +function downloadData(data, fileName, type = 'text/plain') { + const blob = new Blob([data], { type }); + const url = URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = url; + link.download = fileName; + link.click(); + + URL.revokeObjectURL(url); +} + +function stopObservingImgSrc() { + observer.disconnect(); + console.log("πŸ’ β€πŸŒ I've ceased surveillance. Here's what I've collected in img.src:"); + + const data = JSON.parse(localStorage.getItem(id)).join('\n'); + + console.log(data); + downloadData(data, 'img-srcs.txt'); +} + +function clearCollectedImgSrcs() { + localStorage.removeItem(id); + collectedImgSrc = []; + console.log("πŸ’ β€πŸŒ Local storage cleared. The slate is wiped clean."); +} diff --git a/browser-snippets/img.src-grabber__yandex.js b/browser-snippets/img.src-grabber__yandex.js new file mode 100644 index 0000000..60ece69 --- /dev/null +++ b/browser-snippets/img.src-grabber__yandex.js @@ -0,0 +1,75 @@ +let collectedImgURL = JSON.parse(localStorage.getItem('collectedImgURL')) || []; + +function collectInitialHrefs(targetNode) { + const links = targetNode.querySelectorAll('a[href*="img_url"]'); + + links.forEach(link => { + if (!collectedImgURL.includes(link.href)) { + collectedImgURL.push(link.href); + + localStorage.setItem('collectedImgURL', JSON.stringify(collectedImgURL)); + console.log(`πŸ™„ Snagged an initial img url: ${link.href}`); + } + }); +} + +const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((addedNode) => { + if (addedNode.nodeType === Node.ELEMENT_NODE) { + const links = addedNode.querySelectorAll('a[href*="img_url"]'); + links.forEach((link) => { + if (!collectedImgURL.includes(link.href)) { + collectedImgURL.push(link.href); + + localStorage.setItem('collectedImgURL', JSON.stringify(collectedImgURL)); + console.log(`πŸ™„ Added href: ${link.href}`); + } + }); + } + }); + }); +}); + + + +function downloadData(data, fileName, type = 'text/plain') { + const blob = new Blob([data], { type }); + const url = URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = url; + link.download = fileName; + link.click(); + + URL.revokeObjectURL(url); +} + +function waitForElement(selector, callback) { + if (document.querySelector(selector) != null) { + console.log("πŸ’ β€πŸŒ Target acquired. Commencing operation collect-hrefs."); + callback(document.querySelector(selector)); + } else { + setTimeout(() => waitForElement(selector, callback), 500); + } +} + + collectInitialHrefs(document.body); + const config = { childList: true, subtree: true }; + observer.observe(document.body, config); + +function stopObserving() { + observer.disconnect(); + console.log("πŸ’ β€πŸŒ I've ceased surveillance. Here's what I've collected:"); + + const data = JSON.parse(localStorage.getItem('collectedImgURL')).join('\n'); + + console.log(data); + downloadData(data, 'images__yandex.txt'); +} + +function clearCollectedImgURL() { + localStorage.removeItem('collectedImgURL'); + collectedImgURL = []; + console.log("πŸ’ β€πŸŒ Local storage cleared. The slate is wiped clean."); +} diff --git a/browser-snippets/store-magnets.js b/browser-snippets/store-magnets.js new file mode 100644 index 0000000..e552ed5 --- /dev/null +++ b/browser-snippets/store-magnets.js @@ -0,0 +1,79 @@ +const MAGNET_STORAGE_KEY = 'nova_magnets'; + +function getStoredMagnets() { + const raw = localStorage.getItem(MAGNET_STORAGE_KEY); + + if (!raw) return []; + + try { + const parsed = JSON.parse(raw); + return Array.isArray(parsed) ? parsed : []; + } catch { + return []; + } +} + +function setStoredMagnets(magnets) { + const unique = Array.from(new Set(magnets)); + localStorage.setItem(MAGNET_STORAGE_KEY, JSON.stringify(unique)); +} + +(function collectMagnets() { + const pageMagnets = [...document.querySelectorAll('a')] + .map(a => a.href) + .filter(href => href && href.startsWith('magnet:')); + + if (pageMagnets.length === 0) { + console.log('No magnet links found on this page.'); + return; + } + + const stored = getStoredMagnets(); + const combined = stored.concat(pageMagnets); + + setStoredMagnets(combined); + + console.log(`Stored ${pageMagnets.length} new magnet(s). Total in storage: ${getStoredMagnets().length}`); +})(); + +async function copyStoredMagnetsToClipboard() { + const magnets = getStoredMagnets(); + if (magnets.length === 0) { + console.log('No stored magnets to copy.'); + return; + } + + const text = magnets.join('\n'); + + if (navigator.clipboard && navigator.clipboard.writeText) { + try { + await navigator.clipboard.writeText(text); + console.log('Successfully copied magnets to clipboard (navigator.clipboard).'); + return; + } catch (err) { + console.warn('navigator.clipboard failed, falling back to execCommand:', err); + } + } + + const tempTextArea = document.createElement('textarea'); + tempTextArea.value = text; + document.body.appendChild(tempTextArea); + tempTextArea.select(); + + try { + const successful = document.execCommand('copy'); + const msg = successful + ? 'Successfully copied magnets to clipboard (execCommand fallback).' + : 'Failed to copy magnets to clipboard (execCommand fallback).'; + console.log(msg); + } catch (err) { + console.error('Fallback: unable to copy magnets', err); + } finally { + document.body.removeChild(tempTextArea); + } +} + +function clearStoredMagnets() { + localStorage.removeItem(MAGNET_STORAGE_KEY); + console.log('Cleared stored magnets.'); +} diff --git a/manage-music/extract-artist-and-song.sh b/manage-music/extract-artist-and-song.sh new file mode 100755 index 0000000..b9518b9 --- /dev/null +++ b/manage-music/extract-artist-and-song.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +DRYRUN=0 +TARGET="." + +if [[ "${1:-}" == "--dry-run" ]]; then + DRYRUN=1 + TARGET="${2:-.}" +else + TARGET="${1:-.}" +fi + +LOGFILE="metadata_rename_log_$(date +%Y%m%d_%H%M%S).txt" +touch "$LOGFILE" + +command -v ffprobe >/dev/null || { + echo "ffprobe not found. Install ffmpeg." + exit 1 +} + +sanitize() { + sed -E ' + s/[\/:*?"<>|]//g; + s/[[:space:]]+/ /g; + s/^[[:space:]]+//; + s/[[:space:]]+$// + ' +} + +normalize_artists() { + tr ';' ',' | + sed -E ' + s/[[:space:]]*,[[:space:]]*/, /g + s/[[:space:]]*&[[:space:]]*/, /g + s/[[:space:]]+feat\.?[[:space:]]+/, /Ig + s/[[:space:]]+ft\.?[[:space:]]+/, /Ig + ' | + awk -F',' ' + { + out="" + for(i=1;i<=NF;i++){ + gsub(/^ +| +$/, "", $i) + if($i!=""){ + if(out==""){out=$i}else{out=out" & "$i} + } + } + print out + }' +} + +get_tag() { + local file=$1 + local tag=$2 + local val + + val=$(ffprobe -v error \ + -show_entries format_tags="$tag" \ + -of default=nokey=1:noprint_wrappers=1 \ + "$file" 2>/dev/null || true) + + printf '%s\n' "$val" | head -n1 +} + +dedupe_target() { + local path="$1" + + if [[ ! -e "$path" ]]; then + echo "$path" + return + fi + + local dir + dir="$(dirname "$path")" + + local base + base="$(basename "$path")" + + local name="${base%.*}" + local ext="${base##*.}" + + local n=1 + local candidate + + while true; do + candidate="$dir/$name.$n.$ext" + [[ -e "$candidate" ]] || break + ((n++)) + done + + echo "$candidate" +} + +for file in "$TARGET"/*; do + [[ -f "$file" ]] || continue + + base="$(basename "$file")" + ext="${base##*.}" + + artist="$(get_tag "$file" artist)" + artists="$(get_tag "$file" artists)" + album_artist="$(get_tag "$file" album_artist)" + title="$(get_tag "$file" title)" + + artist_combined="" + + if [[ -n "$artists" ]]; then + artist_combined="$artists" + elif [[ -n "$artist" ]]; then + artist_combined="$artist" + elif [[ -n "$album_artist" ]]; then + artist_combined="$album_artist" + fi + + if [[ -z "$artist_combined" && -z "$title" ]]; then + echo "Skipped non-extracted $file" + continue + fi + + artist_norm="$(echo "$artist_combined")" + title_norm="$(echo "$title")" + + if [[ -z "$artist_norm" ]]; then + newname="$title_norm.$ext" + elif [[ -z "$title_norm" ]]; then + newname="$artist_norm.$ext" + else + newname="$artist_norm - $title_norm.$ext" + fi + + target="$TARGET/$newname" + target="$(dedupe_target "$target")" + + if [[ "$file" == "$target" ]]; then + echo "Skipped unchanged $file" + + continue + fi + + if [[ "$DRYRUN" == "1" ]]; then + echo "DRY:" + echo " OLD: $file" + echo " NEW: $target" + echo + else + if [[ -e "$target" ]]; then + echo "SKIP (exists): $target" + continue + fi + + echo "Renaming" + echo " OLD: $file" + echo " NEW: $target" + echo + + mv "$file" "$target" + + echo "$file -> $target" >> "$LOGFILE" + fi + +done diff --git a/manage-music/group-by-artist.sh b/manage-music/group-by-artist.sh new file mode 100755 index 0000000..db92b78 --- /dev/null +++ b/manage-music/group-by-artist.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +set -euo pipefail + +DRYRUN=0 +TARGET="." + +if [[ "$1" == "--dry-run" ]]; then + DRYRUN=1 + TARGET="${2:-.}" +else + TARGET="${1:-.}" +fi + +LOGFILE="grouping_log_$(date +%Y%m%d_%H%M%S).txt" +touch "$LOGFILE" + +dedupe_target() { + local path="$1" + + if [[ ! -e "$path" ]]; then + echo "$path" + return + fi + + local dir + dir="$(dirname "$path")" + + local base + base="$(basename "$path")" + + local name="${base%.*}" + local ext="${base##*.}" + + local n=1 + local candidate + + while true; do + candidate="$dir/$name.$n.$ext" + [[ -e "$candidate" ]] || break + ((n++)) + done + + echo "$candidate" +} + +#find "$TARGET" -type f -maxdepth 1 | while IFS= read -r file; do +for file in "$TARGET"/*; do + [[ -f "$file" ]] || continue + + base="$(basename "$file")" + + # skip if no artist-title pattern + [[ "$base" != *" - "* ]] && continue + + artist="${base%% - *}" + + # remove "feat." / "ft." sections + artist="$(sed -E 's/[[:space:]]+(feat|ft)\.?[[:space:]].*$//I' <<< "$artist")" + + # split on common artist separators and keep first + artist="$(sed -E 's/[[:space:]]*(,|&| x | X u)[[:space:]]*.*$//' <<< "$artist")" + + # trim whitespace + artist="$(sed 's/^[[:space:]]*//;s/[[:space:]]*$//' <<< "$artist")" + + # lowercase + artist_lc="$(tr '[:upper:]' '[:lower:]' <<< "$artist")" + + target_dir="$TARGET/$artist_lc" + target="$target_dir/$base" + + # skip if artist extraction failed +[[ -z "$artist_lc" ]] && continue + +target="$(dedupe_target "$target")" + + if [[ "$target" != "$file" ]]; then + if [[ "$DRYRUN" == "1" ]]; then + echo "[DRY]" + echo " OLD: $file" + echo " NEW: $target" + echo + + #Super lean dry run debug mode to spot leftovers + #echo "$target_dir" + else + mkdir -p "$target_dir" + + echo "Renaming" + echo " OLD: $file" + echo " NEW: $target" + echo + + mv -n "$file" "$target" + + echo "$file -> $target" >> "$LOGFILE" + fi + fi +done diff --git a/manage-music/pre-process-filenames.sh b/manage-music/pre-process-filenames.sh new file mode 100755 index 0000000..2a22a77 --- /dev/null +++ b/manage-music/pre-process-filenames.sh @@ -0,0 +1,239 @@ +#!/usr/bin/env bash + +DRYRUN=0 +TARGET="." + +if [[ "$1" == "--dry-run" ]]; then + DRYRUN=1 + TARGET="${2:-.}" +else + TARGET="${1:-.}" +fi + +LOGFILE="rename_log_$(date +%Y%m%d_%H%M%S).txt" +touch "$LOGFILE" + +clean_name() { + local name="$1" + + # remove leading track numbers like "01 - ", "07 ", "003. " + name=$(echo "$name" | sed -E 's/^[0-9]{1,3}[[:space:]]*[-._][[:space:]]*//') + name=$(echo "$name" | sed -E 's/^[0-9]{1,3}[[:space:]]+//') + + # remove youtube ids + name=$(echo "$name" | sed -E 's/\[[A-Za-z0-9_-]{11}\]//g') + + # remove common youtube junk + name=$(echo "$name" | sed -E 's/\((official|official video|official music video|lyrics|lyric video|audio|visualizer|video)\)//ig') + name=$(echo "$name" | sed -E 's/\[lyric video\]//ig') + name=$(echo "$name" | sed -E 's/\(lyric video\)//ig') + name=$(echo "$name" | sed -E 's/\[(official|lyrics|audio|visualizer)\]//ig') + name=$(echo "$name" | sed -E 's/\[(official[^]]*)\]//ig') + name=$(echo "$name" | sed -E 's/\((official[^)]*)\)//ig') + name=$(echo "$name" | sed -E 's/[||][[:space:]]*official[^-]*//ig') + name=$(echo "$name" | sed -E 's/M.?V//ig') + name=$(echo "$name" | sed -E 's/\((music video)\)//ig') + name=$(echo "$name" | sed -E 's/\bOfficial( Music Video| Video| Audio)?\b//ig') + name=$(echo "$name" | sed -E 's/\[offizielles video\]//ig') + + # quality markers + name=$(echo "$name" | sed -E 's/\b(4k|1080p|720p|hq|hd)\b//ig') + + #remove director credits + name=$(echo "$name" | sed -E 's/\(directed by [^)]+\)//ig') + name=$(echo "$name" | sed -E 's/\(dir\.? by [^)]+\)//ig') + + #remove producer bracket + name=$(echo "$name" | sed -E 's/\[prod\.? [^]]+\]//ig') + name=$(echo "$name" | sed -E 's/\(prod\.? [^)]+\)//ig') + name=$(echo "$name" | sed -E 's/\(prod\.? by [^)]+\)//ig') + + # remove free download + name=$(echo "$name" | sed -E 's/\[free download\]//ig') + name=$(echo "$name" | sed -E 's/\(bass boost(ed)?\)//ig') + + #remove quoting + name=$(echo "$name" | sed -E "s/'([^']+)'/\1/g") + + #genres + name=$(echo "$name" | sed -E 's/^\[[^]]+\][[:space:]]*-?[[:space:]]*//') + name=$(echo "$name" | sed -E 's/\bDnB\b//ig') + name=$(echo "$name" | sed -E 's/\([A-Z ]{6,}\)//g') + name=$(echo "$name" | sed -E 's/\[(wave|phonk|liquid dubstep)[^]]*\]//ig') + name=$(echo "$name" | sed -E 's/\(tiktok\)//ig') + name=$(echo "$name" | sed -E 's/EP OUT NOW//ig') + name=$(echo "$name" | sed -E 's/VORBESTELLBAR//ig') + name=$(echo "$name" | sed -E 's/\+?.*beat by [^)]*\)//ig') + + # remove copy artifacts + name=$(echo "$name" | sed -E 's/\((copy|kopie)\)//ig') + name=$(echo "$name" | sed -E 's/\((copy|kopie) *[0-9]+\)//ig') + name=$(echo "$name" | sed -E 's/\([0-9]+\. *(copy|kopie)\)//ig') + name=$(echo "$name" | sed -E 's/\((weitere )?kopie\)//ig') + + # remove @prodby @mixtape like handles + name=$(echo "$name" | sed -E 's/_? *@[A-Za-z0-9_]+//g') + + # remove numbered duplicates like "(1)" "(2)" + name=$(echo "$name" | sed -E 's/\([0-9]+\)//g') + + # hashtags + name=$(echo "$name" | sed -E 's/#[A-Za-z0-9_]+//g') + + #labels + name=$(echo "$name" | sed -E 's/\((free|copyright free|no copyright music)\)//ig') + name=$(echo "$name" | sed -E 's/\[(copyright free|no copyright music)[^]]*\]//ig') + + # normalize separators + name=$(echo "$name" | sed -E 's/[–—]/-/g') + name=$(echo "$name" | sed -E 's/[|:]/-/g') + name=$(echo "$name" | sed -E 's/[::|]/-/g') + + # remove quotes + name=$(echo "$name" | sed -E 's/[\"β€œβ€β€˜β€™]//g') + + # clean weird punctuation leftovers + #name=$(echo "$name" | sed -E 's/[ ]+-[ ]+/-/g') + + # collapse whitespace + name=$(echo "$name" | sed -E 's/[[:space:]]+/ /g') + + # remove duplicate dashes + name=$(echo "$name" | sed -E 's/- -/-/g') + + # ensure single space around dashes + name=$(echo "$name" | sed -E 's/[[:space:]]*-[[:space:]]*/ - /g') + + #remove empty brackets + name=$(echo "$name" | sed -E 's/\(\s*\)//g') + name=$(echo "$name" | sed -E 's/\[\s*\]//g') + + #vertical bar garbage + name=$(echo "$name" | sed -E 's/[||]+/ - /g') + + # trailing dashes + name=$(echo "$name" | sed -E 's/[[:space:]]*-[[:space:]]*$//') + + # trim + name=$(echo "$name" | sed -E 's/^ *//; s/ *$//') + + + + # Specific removals + name=$(echo "$name" | sed -E 's/\[Monstercat Release\]//ig') + name=$(echo "$name" | sed -E 's/\[Monstercat[^]]*\]//ig') + name=$(echo "$name" | sed -E 's/\bNCS - Copyright Free Music\b//ig') + name=$(echo "$name" | sed -E 's/_ *League of Legends//ig') + name=$(echo "$name" | sed -E 's/\(wshh[^\)]*\)//ig') + name=$(echo "$name" | sed -E 's/\(WSHH[^\)]*//ig') + name=$(echo "$name" | sed -E 's/_ *Music Video *- *League of Legends//ig') + name=$(echo "$name" | sed -E 's/\(original soundtrack\)//ig') + name=$(echo "$name" | sed -E 's/\[NCS Release\]//ig') + + + + + + + + # normalize featuring keywords + name=$(echo "$name" | sed -E 's/\b(ft|ft\.|feat|feat\.|featuring)\b/feat./ig') + + # normalize separators inside features + name=$(echo "$name" | sed -E 's/feat\. ([^,-]+),/feat. \1 \&/g') + + # convert "(feat X)" "[feat X]" -> "feat. X" + name=$(echo "$name" | sed -E 's/[\(\[]\s*feat\.? ([^\)\]]+)[\)\]]/feat. \1/ig') + + # remove duplicate feat markers + name=$(echo "$name" | sed -E 's/feat\. feat\./feat./ig') + + # collapse multiple dots + name=$(echo "$name" | sed -E 's/feat\.+/feat./g') + + + + # convert [Remix] -> (Remix) + name=$(echo "$name" | sed -E 's/\[([^\]]*remix[^\]]*)\]/(\1)/ig') + + # normalize spacing + name=$(echo "$name" | sed -E 's/\(([^)]*remix)\)/(\1)/ig') + + # remove double brackets + name=$(echo "$name" | sed -E 's/\(\(([^)]*)\)\)/(\1)/g') + name=$(echo "$name" | sed -E 's/\[\s*\]//g') + + + echo "$name" +} + +clean_loop() { + local name="$1" + local prev="" + + for i in {1..3}; do + prev="$name" + name=$(clean_name "$name") + [[ "$name" == "$prev" ]] && break + done + + echo "$name" +} + +generate_unique() { + local filepath="$1" + local ext="${filepath##*.}" + local base="${filepath%.*}" + + local i=2 + local newpath="$filepath" + + while [[ -e "$newpath" ]]; do + newpath="${base}.${i}.${ext}" + ((i++)) + done + + echo "$newpath" +} + +find "$TARGET" -type f -print0 | while IFS= read -r -d '' file; do + + dir=$(dirname "$file") + base=$(basename "$file") + ext="${base##*.}" + name="${base%.*}" + + cleaned=$(clean_loop "$name") + + [[ -z "$cleaned" ]] && return + + proposed="$dir/$cleaned.$ext" + + if [[ "$proposed" != "$file" ]]; then + + final="$proposed" + + if [[ -e "$final" ]]; then + final=$(generate_unique "$proposed") + fi + + if [[ "$DRYRUN" == "1" ]]; then + echo "[DRY]" + echo " OLD: $base" + echo " NEW: $(basename "$final")" + echo + + #Super lean dry run debug mode to spot leftovers + #echo "$cleaned" + else + echo "Renaming" + echo " OLD: $base" + echo " NEW: $(basename "$final")" + echo + + mv -n "$file" "$final" + + echo "$file -> $final" >> "$LOGFILE" + fi + fi +done diff --git a/manage-music/print-embedded-youtube-source.sh b/manage-music/print-embedded-youtube-source.sh new file mode 100755 index 0000000..d9176ed --- /dev/null +++ b/manage-music/print-embedded-youtube-source.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +library="$1" + +for file in "$library"/*; do + [[ -f "$file" ]] || continue + + comment=$(ffprobe -v quiet -show_entries format_tags=comment \ + -of default=noprint_wrappers=1:nokey=1 "$file") + + if echo "$comment" | grep -Eiq "(youtube\.com|youtu\.be)"; then + echo "$comment" | grep -Eo "https?://(www\.)?(youtube\.com|youtu\.be)[^ ]+" + fi +done + diff --git a/manage-video/bitrate-shrinker/bitrate-shrinker.sh b/manage-video/bitrate-shrinker/bitrate-shrinker.sh new file mode 100644 index 0000000..54b7681 --- /dev/null +++ b/manage-video/bitrate-shrinker/bitrate-shrinker.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Directory containing the MP4 files +DIRECTORY="input" +OUTPUT_DIRECTORY="output" + +# Navigate to the directory +cd "$DIRECTORY" + +# Loop through all MP4 files in the directory +for FILE in *.mp4; do + # Skip if the file does not exist (e.g., when the glob matches no files) + [ -f "$FILE" ] || continue + + # Generate output file name with prefix + OUTPUT_FILE="$OUTPU_DIRECTORY/REDUCED_BITRATE $FILE" + + # Apply the ffmpeg command to reduce bitrate + ffmpeg -i "$FILE" -c:v libx264 -preset medium -b:v 2500k -pass 1 -an -f null /dev/null && \ + ffmpeg -i "$FILE" -c:v libx264 -preset medium -b:v 2500k -pass 2 -c:a aac -b:a 128k "$OUTPUT_FILE" +done diff --git a/manage-video/check-missing-targets/check-missing-targets.sh b/manage-video/check-missing-targets/check-missing-targets.sh new file mode 100755 index 0000000..658184a --- /dev/null +++ b/manage-video/check-missing-targets/check-missing-targets.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +LOGS_DIR="logs" +TARGET_DIR="target" + +# Loop through all log files +for log_file in "${LOGS_DIR}"/*.log; do + # Extract the base name without the log extension + base_name=$(basename "${log_file}" .log) + # Construct the name of the corresponding target file + target_file="${TARGET_DIR}/${base_name}.mp4" + + # Check if the target file exists + if [ ! -f "${target_file}" ]; then + echo "Missing target file for log: ${log_file}" + fi +done diff --git a/manage-video/collect-video-details/collect-video-details.sh b/manage-video/collect-video-details/collect-video-details.sh new file mode 100755 index 0000000..81dcb66 --- /dev/null +++ b/manage-video/collect-video-details/collect-video-details.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Output file +output_csv="file_details.csv" + +# CSV Header +echo "File Path,Resolution,Bitrate (kbps),Size (GB),Duration (Seconds)" > "$output_csv" + +# Find all mp4 files and count them +total_files=$(find . -type f -name "*.mp4" ! -name "video*" | wc -l) +current_file=0 + +# Find and process mp4 files +find . -type f -name "*.mp4" ! -name "video*" -print0 | while IFS= read -r -d '' file; do + # Increment current file counter + ((current_file++)) + + # Progress indicator + echo "$(date +"%Y-%m-%d %H:%M:%S"): Checking file $current_file/$total_files: $file" + + # Extract file details with ffprobe +details=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height,bit_rate -of csv=p=0 "$file") + +# Extract file duration with ffprobe + duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file") +duration=$(printf "%.0f\n" $(echo "$duration / 60" | bc -l)) + +# Read the details into an array +IFS=',' read -r width height bitrate <<< "$details" + +# Convert bitrate to kilobits per second (kbps) if it's not N/A +if [[ "$bitrate" != "N/A" ]]; then + bitrate=$(awk "BEGIN {printf \"%.2f\", $bitrate/1000}") # Convert to kbps +else + bitrate="Unknown" +fi + +# Calculate file size in GB TODO This seems to output MB for some strange reason +size=$(stat -c%s "$file" | awk '{ printf "%.3f", $1 / (1024^3) }') # Size in GB + +# Format resolution +resolution="${width}x${height}" + + + # Write details to CSV + echo "\"$file\",\"$resolution\",\"$bitrate\",\"$size\",\"$duration\"" >> "$output_csv" +done + +echo "Cataloging complete. Details saved in $output_csv" diff --git a/manage-video/find-low-res-videos/find-low-res-videos.sh b/manage-video/find-low-res-videos/find-low-res-videos.sh new file mode 100755 index 0000000..ae30bea --- /dev/null +++ b/manage-video/find-low-res-videos/find-low-res-videos.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +export MIN_RES_WIDTH=1300 +export MIN_RES_HEIGHT=800 + +SEARCH_DIR="/search/dir" +OUTPUT_DIR="." + +mkdir -p "$OUTPUT_DIR" + +export OUTPUT_FILE="$OUTPUT_DIR/low_res_videos.txt" +export OUTPUT_FILE_WITH_RESOLUTION="$OUTPUT_DIR/low_res_videos_with_res.txt" + +check_resolution() { + local file="$1" + + read width height < <(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "$file" | awk -F',' '{print $1, $2}') + + echo "Checking $width x $height for $file" + + if [[ $width -lt $MIN_RES_WIDTH || $height -lt $MIN_RES_HEIGHT ]]; then + echo "$file" >> "$OUTPUT_FILE" + echo "$width x $height | $file" >> "$OUTPUT_FILE_WITH_RESOLUTION" + fi +} + +export -f check_resolution + +find "$SEARCH_DIR" -type f \( -iname "*.mp4" -o -iname "*.avi" -o -iname "*.mkv" -o -iname "*.flv" -o -iname "*.mov" \) -exec bash -c 'check_resolution "$0"' {} \; + +if [[ -s "$OUTPUT_FILE" ]]; then + echo "Low-resolution video files have been written to $OUTPUT_FILE" +else + echo "No low-resolution video files found." +fi diff --git a/manage-video/find-low-res-videos/move-low-res-videos.sh b/manage-video/find-low-res-videos/move-low-res-videos.sh new file mode 100644 index 0000000..84adba0 --- /dev/null +++ b/manage-video/find-low-res-videos/move-low-res-videos.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +INPUT_FILE="low_res_videos.txt" +DESTINATION_DIR="/path/to/low-res" + +while read -r dir; do + echo "Moving $dir" + mv "$dir" "$DESTINATION_DIR" +done < "$INPUT_FILE" + +echo "All specified directories have been moved to '$DESTINATION_DIR'" diff --git a/manage-video/find-similar-folders/find-similar.sh b/manage-video/find-similar-folders/find-similar.sh new file mode 100755 index 0000000..790193f --- /dev/null +++ b/manage-video/find-similar-folders/find-similar.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +TOP_LEVEL_DIR="$1" +OUTPUT_FOLDER="./output" +UNSORTED_DIR_LIST="./unsorted_dir_list.txt" +THRESHOLD=55 + +mkdir -p "$OUTPUT_FOLDER" + +process_directory() { + local sorted_dir=$1 + local dir_name=$(basename "$sorted_dir") + + echo "--------------------------" + echo "Processing dir '${dir_name}' (${sorted_dir})" + + local output_file="${OUTPUT_FOLDER}/${dir_name}_similar_folders_detailed.txt" + local output_file_folder_name_only="${OUTPUT_FOLDER}/${dir_name}_similar_folders_folder_only.txt" + + > "$output_file" + > "$output_file_folder_name_only" + + while IFS= read -r -d '' sorted_folder_path; do + local sorted_name=$(basename "$sorted_folder_path") + echo "Checking '$sorted_name'" + + while IFS= read -r unsorted_name; do + local levenshtein_distance=$(awk -f levenshtein.awk "$sorted_name" "$unsorted_name") + local len_sorted=${#sorted_name} + local len_unsorted=${#unsorted_name} + local max_length=$((len_sorted > len_unsorted ? len_sorted : len_unsorted)) + local similarity=$((100 - (levenshtein_distance * 100 / max_length))) + + if [ "$similarity" -ge "$THRESHOLD" ]; then + echo "\"$sorted_name\" <- \"$unsorted_name\": $similarity%" + echo "\"$sorted_name\" <- \"$unsorted_name\": $similarity%" >> "$output_file" + echo "$unsorted_name" >> "$output_file_folder_name_only" + fi + done < "$UNSORTED_DIR_LIST" + done < <(find "$sorted_dir" -mindepth 1 -maxdepth 1 -type d -print0) + + echo "Similarity analysis for $sorted_dir complete. Results saved to $output_file and $output_file_folder_name_only." +} + +for subdir in "$TOP_LEVEL_DIR"/*/; do + if [ -d "$subdir" ]; then + process_directory "$subdir" + fi +done + +echo "All similarity analysis processes are complete." diff --git a/manage-video/find-similar-folders/levenshtein.awk b/manage-video/find-similar-folders/levenshtein.awk new file mode 100755 index 0000000..15f7d67 --- /dev/null +++ b/manage-video/find-similar-folders/levenshtein.awk @@ -0,0 +1,34 @@ +# levenshtein.awk +function levenshtein(a, b, len_a, len_b, cost, i, j, matrix) { + len_a = length(a); + len_b = length(b); + for (i = 0; i <= len_a; i++) + matrix[i, 0] = i; + for (j = 0; j <= len_b; j++) + matrix[0, j] = j; + + for (i = 1; i <= len_a; i++) { + for (j = 1; j <= len_b; j++) { + cost = (substr(a, i, 1) != substr(b, j, 1)); + matrix[i, j] = min(matrix[i-1, j] + 1, # deletion + matrix[i, j-1] + 1, # insertion + matrix[i-1, j-1] + cost); # substitution + } + } + return matrix[len_a, len_b]; +} + +function min(x, y, z) { + if (x < y && x < z) return x; + if (y < z) return y; + return z; +} + +BEGIN { + if (ARGC != 3) { + print "Usage: levenshtein.awk "; + exit 1; + } + print levenshtein(ARGV[1], ARGV[2]); + exit; +} diff --git a/manage-video/find-similar-folders/unsorted_dir_list.txt b/manage-video/find-similar-folders/unsorted_dir_list.txt new file mode 100644 index 0000000..e69de29 diff --git a/manage-video/poster-tagger/Noto_Emoji.zip b/manage-video/poster-tagger/Noto_Emoji.zip new file mode 100644 index 0000000..8f214be Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji.zip differ diff --git a/manage-video/poster-tagger/Noto_Emoji/NotoEmoji-VariableFont_wght.ttf b/manage-video/poster-tagger/Noto_Emoji/NotoEmoji-VariableFont_wght.ttf new file mode 100644 index 0000000..4c7d78e Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji/NotoEmoji-VariableFont_wght.ttf differ diff --git a/manage-video/poster-tagger/Noto_Emoji/OFL.txt b/manage-video/poster-tagger/Noto_Emoji/OFL.txt new file mode 100644 index 0000000..8f8e6f5 --- /dev/null +++ b/manage-video/poster-tagger/Noto_Emoji/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2013 Google LLC + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/manage-video/poster-tagger/Noto_Emoji/README.txt b/manage-video/poster-tagger/Noto_Emoji/README.txt new file mode 100644 index 0000000..0190d84 --- /dev/null +++ b/manage-video/poster-tagger/Noto_Emoji/README.txt @@ -0,0 +1,67 @@ +Noto Emoji Variable Font +======================== + +This download contains Noto Emoji as both a variable font and static fonts. + +Noto Emoji is a variable font with this axis: + wght + +This means all the styles are contained in a single file: + NotoEmoji-VariableFont_wght.ttf + +If your app fully supports variable fonts, you can now pick intermediate styles +that aren’t available as static fonts. Not all apps support variable fonts, and +in those cases you can use the static font files for Noto Emoji: + static/NotoEmoji-Light.ttf + static/NotoEmoji-Regular.ttf + static/NotoEmoji-Medium.ttf + static/NotoEmoji-SemiBold.ttf + static/NotoEmoji-Bold.ttf + +Get started +----------- + +1. Install the font files you want to use + +2. Use your app's font picker to view the font family and all the +available styles + +Learn more about variable fonts +------------------------------- + + https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts + https://variablefonts.typenetwork.com + https://medium.com/variable-fonts + +In desktop apps + + https://theblog.adobe.com/can-variable-fonts-illustrator-cc + https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts + +Online + + https://developers.google.com/fonts/docs/getting_started + https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide + https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts + +Installing fonts + + MacOS: https://support.apple.com/en-us/HT201749 + Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux + Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows + +Android Apps + + https://developers.google.com/fonts/docs/android + https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts + +License +------- +Please read the full license text (OFL.txt) to understand the permissions, +restrictions and requirements for usage, redistribution, and modification. + +You can use them in your products & projects – print or digital, +commercial or otherwise. + +This isn't legal advice, please consider consulting a lawyer and see the full +license for all details. diff --git a/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Bold.ttf b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Bold.ttf new file mode 100644 index 0000000..d574c00 Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Bold.ttf differ diff --git a/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Light.ttf b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Light.ttf new file mode 100644 index 0000000..86932b7 Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Light.ttf differ diff --git a/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Medium.ttf b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Medium.ttf new file mode 100644 index 0000000..9f16d8e Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Medium.ttf differ diff --git a/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Regular.ttf b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Regular.ttf new file mode 100644 index 0000000..b50618f Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-Regular.ttf differ diff --git a/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-SemiBold.ttf b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-SemiBold.ttf new file mode 100644 index 0000000..95c3e22 Binary files /dev/null and b/manage-video/poster-tagger/Noto_Emoji/static/NotoEmoji-SemiBold.ttf differ diff --git a/manage-video/poster-tagger/poster-tagger.sh b/manage-video/poster-tagger/poster-tagger.sh new file mode 100755 index 0000000..9febbff --- /dev/null +++ b/manage-video/poster-tagger/poster-tagger.sh @@ -0,0 +1,223 @@ +#!/usr/bin/env bash + +set -e + +MODE="$1" # auto | manual +SEARCH_ROOT="${2:-.}" +CORNER="${3:-nw}" # nw ne sw se + +FONT="./Noto_Emoji/static/NotoEmoji-Regular.ttf" +TMP="/tmp/jellyfin_tags_$" + +mkdir -p "$TMP" + +TAG_HEIGHT_RATIO=10 +OFFSET_RATIO=40 +PADDING_RATIO=3 + +declare -A TAG_COLOR +declare -A TAG_LABEL + +TAG_COLOR[HDR]="#f5c542" +TAG_COLOR[TRASH]="#dc3545" + +TAG_LABEL[HDR]="🌈 HDR" +TAG_LABEL[TRASH]="πŸ—‘ TRASH" + +cleanup() { +rm -rf "$TMP" +} + +trap cleanup EXIT + + +detect_hdr() { + +FILE="$1" + +ffprobe -v quiet \ +-select_streams v:0 \ +-show_entries stream=color_transfer \ +-of default=nw=1:nk=1 "$FILE" 2>/dev/null | +grep -Eq "smpte2084|arib-std-b67" && echo "HDR" + +} + + +make_tag_() { + +TEXT="$1" +COLOR="$2" +OUT="$3" + +convert \ + -font "$FONT" \ + -pointsize "$FONTSIZE" \ + -background "$COLOR" \ + -fill white \ + label:" $TEXT " \ + -gravity center \ + -alpha set \ + -channel A \ + -evaluate set 100% \ + -bordercolor "$COLOR" \ + -border "$PADDING" \ + "$OUT" + +} + +make_tag() { + +TEXT="$1" +COLOR="$2" +OUT="$3" + +convert -background none \ + -font "$FONT" \ + -pointsize "$FONTSIZE" \ + label:"$TEXT" \ + -bordercolor none -border "$PADDING" \ + \( +clone \ + -fill "$COLOR" \ + -draw "roundrectangle 0,0 %[fx:w],%[fx:h] $RADIUS,$RADIUS" \ + \) \ + -compose DstOver -composite \ + "$OUT" + +} + + +combine_tags() { + +OUT="$TMP/combined.png" + +convert "$@" +append "$OUT" + +echo "$OUT" + +} + + +find_video() { + +DIR="$1" + +find "$DIR" -maxdepth 1 -type f \ +\( -iname "*.mkv" -o -iname "*.mp4" -o -iname "*.m4v" \) | +head -n1 + +} + + +apply_tags() { + +IMG="$1" +shift + +TAGS=("$@") +[ "${#TAGS[@]}" -eq 0 ] && return + +WIDTH=$(identify -format "%w" "$IMG") + +TAGH=$((WIDTH / TAG_HEIGHT_RATIO)) +FONTSIZE=$((TAGH / 2)) +OFFSET=$((WIDTH / OFFSET_RATIO)) +PADDING=$((TAGH / PADDING_RATIO)) + +TAG_FILES=() + +for T in "${TAGS[@]}"; do + +OUT="$TMP/tag_$T.png" + +make_tag "${TAG_LABEL[$T]}" "${TAG_COLOR[$T]}" "$OUT" + +TAG_FILES+=("$OUT") + +done + +COMBINED=$(combine_tags "${TAG_FILES[@]}") + +BACKUP="${IMG}.bak" +cp "$IMG" "$BACKUP" + +convert "$IMG" \ +"$COMBINED" \ +-gravity "$CORNER" \ +-geometry +$OFFSET+$OFFSET \ +-composite \ +-quality 95 \ +"$IMG" + +echo "tagged: $IMG -> ${TAGS[*]}" + +} + + +process_auto() { + +find "$SEARCH_ROOT" -type f -iname "folder.jpg" | while read -r IMG; do + +DIR=$(dirname "$IMG") +VIDEO=$(find_video "$DIR") + +TAGS=() + +if [ -n "$VIDEO" ]; then + +HDR=$(detect_hdr "$VIDEO" || true) + +[ "$HDR" == "HDR" ] && TAGS+=("HDR") + +fi + +apply_tags "$IMG" "${TAGS[@]}" + +done + +} + + +process_manual() { + +IMG=$(find "$SEARCH_ROOT" -type f -iname "folder.jpg" | +fzf --preview 'convert {} -resize 300x jpg:- | display jpg:-') + +[ -z "$IMG" ] && exit + +DIR=$(dirname "$IMG") +VIDEO=$(find_video "$DIR") + +TAGS=() + +HDR=$(detect_hdr "$VIDEO" || true) + +[ "$HDR" == "HDR" ] && TAGS+=("HDR") + +SELECT=$(printf "TRASH\nnone" | +fzf --prompt="extra tag: ") + +[ "$SELECT" != "none" ] && TAGS+=("$SELECT") + +apply_tags "$IMG" "${TAGS[@]}" + +} + + +case "$MODE" in + +auto) +process_auto +;; + +manual) +process_manual +;; + +*) +echo "usage:" +echo "poster_tagger.sh auto [path] [nw|ne|sw|se]" +echo "poster_tagger.sh manual [path] [nw|ne|sw|se]" +;; + +esac diff --git a/manage-video/reencode/reencode_immich.sh b/manage-video/reencode/reencode_immich.sh new file mode 100755 index 0000000..1f111c9 --- /dev/null +++ b/manage-video/reencode/reencode_immich.sh @@ -0,0 +1,220 @@ +#!/bin/bash + +ROOT="${1:-.}" +LOG="reencode.log" +PROGRESS="reencode.progress" +FAILED="reencode.failed" +SAFE_DIR="${SAFE_DIR:-}" + +touch "$LOG" +touch "$PROGRESS" + +ts() { date '+%F %T'; } + +handler() { + echo "$(ts) INTERRUPTED by SIG$1 pid=$$ ppid=$PPID line=$LINENO cmd='$BASH_COMMAND'" + exit 1 +} + +trap 'handler INT' INT +trap 'handler TERM' TERM + +count=0 + +find "$ROOT" -type f \( \ + -iname "*.mp4" \ + ! -iname "*_delete" \ +\) -print0 | while IFS= read -r -d '' f; do + count=$((count+1)) + + echo "----------------" + echo "" + + if grep -Fxq "$f" "$PROGRESS"; then + echo "$(ts) [$count] SKIP file=$f reason=already_done" + continue + fi + + echo "$(ts) [$count] START file=$f" + + + + codec=$(ffprobe -v error -select_streams v:0 \ + -show_entries stream=codec_name \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + audio_codec=$(ffprobe -v error -select_streams a:0 \ + -show_entries stream=codec_name \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + sub_codec=$(ffprobe -v error -select_streams s:0 \ + -show_entries stream=codec_name \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + bitrate=$(ffprobe -v error -select_streams v:0 \ + -show_entries stream=bit_rate \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + video_streams=$(ffprobe -v error -select_streams v \ + -show_entries stream=index \ + -of csv=p=0 "$f" | wc -l) + + echo "$(ts) [$count] INFO Codecs: v=$codec a=$audio_codec s=$sub_codec bitrate=$bitrate video_streams=$video_streams" + + + + if [[ "$codec" == "hevc" || "$codec" == "av1" ]]; then + echo "$(ts) [$count] SKIP file=$f reason=codec_$codec" >> "$LOG" + echo "$(ts) [$count] SKIP file=$f reason=codec_$codec" + echo "$f" >> "$PROGRESS" + continue + fi + + + + container="mp4" + + case "$audio_codec" in + opus|vorbis|flac) + container="mkv" + ;; + esac + + case "$sub_codec" in + webvtt|ass|ssa) + container="mkv" + ;; + esac + + if (( video_streams > 1 )); then + container="mkv" + fi + + echo "$(ts) [$count] INFO Selected container: $container" + + + + if [[ -z "$bitrate" ]]; then + bitrate=0 + fi + + if (( bitrate > 20000000 )); then + crf=25 +elif (( bitrate > 10000000 )); then + crf=24 +elif (( bitrate > 5000000 )); then + crf=23 +else + crf=22 +fi + + orig_size=$(stat -c%s "$f") + + echo "$(ts) [$count] INFO CRF: $crf, Original Size: $orig_size" + + + + base="${f%.*}" + + if [[ -n "$SAFE_DIR" ]]; then + rel="${f#$ROOT/}" + out="$SAFE_DIR/${rel%.*}.reencode.tmp.$container" + mkdir -p "$(dirname "$out")" + else + out="${base}.reencode.tmp.$container" + fi + + + ffmpeg -nostdin -y -v error -stats \ + -i "$f" \ + -profile:v high \ + -level 4.1 \ + -map 0:v:0 \ + -map 0:a? \ + -map 0:s? \ + -map 0:v:2? \ + -c:v:0 libx264 \ + -c:v:1 copy \ + -c:a copy \ + -c:s copy \ + -c:t copy \ + -pix_fmt yuv420p \ + -crf "$crf" \ + -preset slow \ + -map_metadata 0 \ + -map_chapters 0 \ + -movflags use_metadata_tags+faststart \ + -disposition:v:1 attached_pic \ + -vsync vfr \ + -maxrate 10M \ + -bufsize 20M \ + "$out" + + + + ff_status=$? + + if [ $ff_status -ne 0 ]; then + echo "$(ts) [$count] FAIL encode exit=$ff_status file=$f" >> "$LOG" + echo "$(ts) [$count] FAIL encode exit=$ff_status file=$f" + echo "$f" >> "$FAILED" + rm -f "$out" + continue + fi + + if [[ ! -f "$out" ]]; then + echo "$(ts) [$count] FAIL empty_file file=$f" >> "$LOG" + echo "$(ts) [$count] FAIL empty_file file=$f" + echo "$f" >> "$FAILED" + continue + fi + + duration=$(ffprobe -v error -show_entries format=duration \ + -of default=noprint_wrappers=1:nokey=1 "$out") + + if [[ -z "$duration" || "$duration" == "0.000000" ]]; then + echo "$(ts) [$count] FAIL zero_duration file=$f" >> "$LOG" + echo "$(ts) [$count] FAIL zero_duration file=$f" + echo "$f" >> "$FAILED" + rm -f "$out" + continue + fi + + new_size=$(stat -c%s "$out") + + if (( new_size >= orig_size )); then + rm -f "$out" + echo "$(ts) [$count] SKIP larger orig=$orig_size new=$new_size bitrate=$bitrate crf=$crf file=$f" >> "$LOG" + echo "$(ts) [$count] SKIP larger orig=$orig_size new=$new_size bitrate=$bitrate crf=$crf file=$f" + echo "$f" >> "$PROGRESS" + continue + fi + + if [[ $? -eq 0 ]]; then + touch -r "$f" "$out" + + if [[ "$container" == "mp4" ]]; then + mv "$out" "$f" + + else + final="${base}.mkv" + mv "$out" "$final" + mv "$f" "${f}_delete" + fi + + echo "$f" >> "$PROGRESS" + + else + echo "$(ts) [$count] ERROR encoding failed for $f" + rm -f "$out" + fi + + reduction=$(( (orig_size - new_size) * 100 / orig_size )) + echo "$(ts) [$count] DONE file=$f reduction=${reduction}%" + echo "$(ts) [$count] OK orig=$orig_size new=$new_size bitrate=$bitrate crf=$crf reduction=${reduction}% file=$f" >> "$LOG" + + echo "$f" >> "$PROGRESS" +done + +echo "done" + diff --git a/manage-video/reencode/reencode_jellyfin.sh b/manage-video/reencode/reencode_jellyfin.sh new file mode 100755 index 0000000..678d341 --- /dev/null +++ b/manage-video/reencode/reencode_jellyfin.sh @@ -0,0 +1,213 @@ +#!/bin/bash + +ROOT="${1:-.}" +LOG="reencode.log" +PROGRESS="reencode.progress" +FAILED="reencode.failed" +SAFE_DIR="${SAFE_DIR:-}" + +touch "$LOG" +touch "$PROGRESS" + +ts() { date '+%F %T'; } + +handler() { + echo "$(ts) INTERRUPTED by SIG$1 pid=$$ ppid=$PPID line=$LINENO cmd='$BASH_COMMAND'" + exit 1 +} + +trap 'handler INT' INT +trap 'handler TERM' TERM + +count=0 + +find "$ROOT" -type f \( \ + -iname "*.mp4" \ + ! -iname "*_delete" \ +\) -print0 | while IFS= read -r -d '' f; do + count=$((count+1)) + + echo "----------------" + echo "" + + if grep -Fxq "$f" "$PROGRESS"; then + echo "$(ts) [$count] SKIP file=$f reason=already_done" + continue + fi + + echo "$(ts) [$count] START file=$f" + + + + codec=$(ffprobe -v error -select_streams v:0 \ + -show_entries stream=codec_name \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + audio_codec=$(ffprobe -v error -select_streams a:0 \ + -show_entries stream=codec_name \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + sub_codec=$(ffprobe -v error -select_streams s:0 \ + -show_entries stream=codec_name \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + bitrate=$(ffprobe -v error -select_streams v:0 \ + -show_entries stream=bit_rate \ + -of default=noprint_wrappers=1:nokey=1 "$f") + + video_streams=$(ffprobe -v error -select_streams v \ + -show_entries stream=index \ + -of csv=p=0 "$f" | wc -l) + + echo "$(ts) [$count] INFO Codecs: v=$codec a=$audio_codec s=$sub_codec bitrate=$bitrate video_streams=$video_streams" + + + + if [[ "$codec" == "hevc" || "$codec" == "av1" ]]; then + echo "$(ts) [$count] SKIP file=$f reason=codec_$codec" >> "$LOG" + echo "$(ts) [$count] SKIP file=$f reason=codec_$codec" + echo "$f" >> "$PROGRESS" + continue + fi + + + + container="mp4" + + case "$audio_codec" in + opus|vorbis|flac) + container="mkv" + ;; + esac + + case "$sub_codec" in + webvtt|ass|ssa) + container="mkv" + ;; + esac + + if (( video_streams > 1 )); then + container="mkv" + fi + + echo "$(ts) [$count] INFO Selected container: $container" + + + + if [[ -z "$bitrate" ]]; then + bitrate=0 + fi + + if (( bitrate > 15000000 )); then + crf=27 + else + crf=26 + fi + + orig_size=$(stat -c%s "$f") + + echo "$(ts) [$count] INFO CRF: $crf, Original Size: $orig_size" + + + + base="${f%.*}" + + if [[ -n "$SAFE_DIR" ]]; then + rel="${f#$ROOT/}" + out="$SAFE_DIR/${rel%.*}.reencode.tmp.$container" + mkdir -p "$(dirname "$out")" + else + out="${base}.reencode.tmp.$container" + fi + + + + ffmpeg -nostdin -y \ + -i "$f" \ + -x265-params log-level=error:aq-mode=3:qcomp=0.7:psy-rd=2.0:cutree=1:pools=12 \ + -map 0:v:0 \ + -map 0:v:2? \ + -map 0:a? \ + -map 0:s? \ + -c:v:0 libx265 \ + -c:v:1 copy \ + -c:a copy \ + -c:s copy \ + -c:t copy \ + -crf "$crf" \ + -preset slow \ + -map_metadata 0 \ + -map_chapters 0 \ + -movflags use_metadata_tags+faststart \ + -disposition:v:1 attached_pic \ + -fflags +bitexact \ + "$out" + + + + ff_status=$? + + if [ $ff_status -ne 0 ]; then + echo "$(ts) [$count] FAIL encode exit=$ff_status file=$f" >> "$LOG" + echo "$(ts) [$count] FAIL encode exit=$ff_status file=$f" + echo "$f" >> "$FAILED" + rm -f "$out" + continue + fi + + if [[ ! -f "$out" ]]; then + echo "$(ts) [$count] FAIL empty_file file=$f" >> "$LOG" + echo "$(ts) [$count] FAIL empty_file file=$f" + echo "$f" >> "$FAILED" + continue + fi + + duration=$(ffprobe -v error -show_entries format=duration \ + -of default=noprint_wrappers=1:nokey=1 "$out") + + if [[ -z "$duration" || "$duration" == "0.000000" ]]; then + echo "$(ts) [$count] FAIL zero_duration file=$f" >> "$LOG" + echo "$(ts) [$count] FAIL zero_duration file=$f" + echo "$f" >> "$FAILED" + rm -f "$out" + continue + fi + + new_size=$(stat -c%s "$out") + + if (( new_size >= orig_size )); then + rm -f "$out" + echo "$(ts) [$count] SKIP larger orig=$orig_size new=$new_size bitrate=$bitrate crf=$crf file=$f" >> "$LOG" + echo "$(ts) [$count] SKIP larger orig=$orig_size new=$new_size bitrate=$bitrate crf=$crf file=$f" + echo "$f" >> "$PROGRESS" + continue + fi + + if [[ $? -eq 0 ]]; then + touch -r "$f" "$out" + + if [[ "$container" == "mp4" ]]; then + mv "$out" "$f" + + else + final="${base}.mkv" + mv "$out" "$final" + mv "$f" "${f}_delete" + fi + + echo "$f" >> "$PROGRESS" + echo "$(ts) [$count] SUCCESS $f" + + else + echo "$(ts) [$count] ERROR encoding failed for $f" + rm -f "$out" + fi + + reduction=$(( (orig_size - new_size) * 100 / orig_size )) + echo "$(ts) [$count] DONE file=$f reduction=${reduction}%" + echo "$(ts) [$count] OK orig=$orig_size new=$new_size bitrate=$bitrate crf=$crf reduction=${reduction}% file=$f" >> "$LOG" + + echo "$f" >> "$PROGRESS" +done + +echo "done" diff --git a/manage-video/resolution-classifier/resolution-classifier.sh b/manage-video/resolution-classifier/resolution-classifier.sh new file mode 100755 index 0000000..0270eb5 --- /dev/null +++ b/manage-video/resolution-classifier/resolution-classifier.sh @@ -0,0 +1,162 @@ +#!/bin/bash + +IGNORED_FOLDERS=("backdrops" "samples" "extras" "featurettes") +VIDEO_EXTENSIONS=(mp4 mkv mov avi wmv m4v ts m2ts webm) +EXISTING_FILES="existing_target.txt" + +classify_resolution() { + local WIDTH="$1" + local HEIGHT="$2" + + local MAX=$((WIDTH > HEIGHT ? WIDTH : HEIGHT)) + + if ((MAX >= 3800)); then + echo " [2160p]" + elif ((MAX >= 1900)); then + echo " [1080p]" + elif ((MAX >= 1200)); then + echo " [720p]" + elif ((MAX >= 700)); then + echo " [480p]" + elif ((MAX >= 500)); then + echo " [360p]" + else + echo " [240p]" + fi +} + +strip_resolution_tag() { + echo "$1" | sed -E 's/ ?\[[0-9]{3,4}p\]//g' +} + +move_item() { + local SRC="$1" + local DST="$2" + + if [[ "$SRC" != "$DST" ]]; then + if [[ -e "$DST" ]]; then + echo "⚠️ Target already exists, skipping:" + echo " existing: $DST" + echo " incoming: $SRC" + echo "$SRC -> $DST" >>$EXISTING_FILES + continue + fi + + if $DRY_RUN; then + echo "[DRY RUN] Would rename:" + echo " $SRC" + echo " $DST" + else + echo "Renaming:" + echo " $SRC" + echo " $DST" + + mv "$SRC" "$DST" + fi + fi +} + +DRY_RUN=false + +if [[ "$1" == "--dry-run" || "$1" == "-n" ]]; then + DRY_RUN=true + echo "Running in DRY-RUN mode. No files will be renamed." +fi + +if ! $DRY_RUN; then + read -p "This will automatically classify and rename the resolution for all nested files in the current dir. Continue? [Y/n] " -n 1 -r + echo + + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Batch renaming cancelled by user." + exit 1 + fi +fi + +echo + +FIND_IGNORE_PARAMS=() +for FOLDER in "${IGNORED_FOLDERS[@]}"; do + FIND_IGNORE_PARAMS+=(-type d -name "$FOLDER" -o) +done +unset 'FIND_IGNORE_PARAMS[${#FIND_IGNORE_PARAMS[@]}-1]' + +EXT_ARGS=() +for EXT in "${VIDEO_EXTENSIONS[@]}"; do + EXT_ARGS+=(-iname "*.${EXT}" -o) +done +unset 'EXT_ARGS[${#EXT_ARGS[@]}-1]' + +find . \( "${FIND_IGNORE_PARAMS[@]}" \) -prune -o \ + -type f \ + -size +1M \ + ! -iname "*_delete" \ + \( "${EXT_ARGS[@]}" \) \ + -print0 | while IFS= read -r -d '' VIDEO_FILE; do + echo "-----------------------------" + + echo "Processing file: $VIDEO_FILE" + + RESOLUTION=$(ffprobe -v error \ +-select_streams v:0 \ +-show_entries stream=width,height \ +-of csv=p=0:s=x \ +"$VIDEO_FILE" | head -n1) + WIDTH=$(echo $RESOLUTION | cut -d'x' -f1) + HEIGHT=$(echo $RESOLUTION | cut -d'x' -f2) + +# echo "Resolution: $RESOLUTION (${WIDTH}x${HEIGHT})" + + if ((WIDTH < 100 || HEIGHT < 100)); then + echo "Invalid resolution detected (${WIDTH}x${HEIGHT}), skipping" + continue + fi + + CLASSIFICATION=$(classify_resolution "$WIDTH" "$HEIGHT") + +# echo "Resolution classification: $CLASSIFICATION" + + BASENAME=$(basename -- "$VIDEO_FILE") + DIRNAME=$(dirname -- "$VIDEO_FILE") + BASENAME_NO_EXT="${BASENAME%.*}" + BASE_CLEAN=$(strip_resolution_tag "$BASENAME_NO_EXT") + EXTENSION="${BASENAME##*.}" + + # detect cd suffix like -cd1, -cd2 etc (because Jellyfin absolutely requires those to be the last thing before the extension) + CD_SUFFIX="" + if [[ "$BASE_CLEAN" =~ (.*)(-(cd|disc|disk|part)[0-9]+)$ ]]; then + BASE_CLEAN="${BASH_REMATCH[1]}" + CD_SUFFIX="${BASH_REMATCH[2]}" + fi + + NEW_BASE="${BASE_CLEAN}${CLASSIFICATION}${CD_SUFFIX}" + NEW_FILENAME="${BASE_CLEAN}${CLASSIFICATION}${CD_SUFFIX}.${EXTENSION}" + + TARGET="$DIRNAME/$NEW_FILENAME" + + OLD_BASE="$BASENAME_NO_EXT" + OLD_TRICKPLAY="$DIRNAME/${OLD_BASE}.trickplay" + NEW_TRICKPLAY="$DIRNAME/${NEW_BASE}.trickplay" + +move_item "$VIDEO_FILE" "$TARGET" + +if [[ -d "$OLD_TRICKPLAY" ]]; then + echo + echo "[Trickplay] Matching trickplay folder detected" + move_item "$OLD_TRICKPLAY" "$NEW_TRICKPLAY" +else + VIDEO_COUNT=$(find "$DIRNAME" -maxdepth 1 -type f \( "${EXT_ARGS[@]}" \) | wc -l) + TRICKPLAY_COUNT=$(find "$DIRNAME" -maxdepth 1 -type d -name "*.trickplay" | wc -l) + + if [[ "$VIDEO_COUNT" -eq 1 && "$TRICKPLAY_COUNT" -eq 1 ]]; then + FOUND_TRICKPLAY=$(find "$DIRNAME" -maxdepth 1 -type d -name "*.trickplay") + + echo + echo "[Trickplay] Detected lone trickplay folder:" + echo " $FOUND_TRICKPLAY" + echo "[Trickplay] Assuming it belongs to this video" + + move_item "$FOUND_TRICKPLAY" "$NEW_TRICKPLAY" + fi +fi +done diff --git a/manage-video/video-clipper/auto-cover-editor.sh b/manage-video/video-clipper/auto-cover-editor.sh new file mode 100755 index 0000000..a72c290 --- /dev/null +++ b/manage-video/video-clipper/auto-cover-editor.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +set -e + +ROOT="${1:-.}" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LOG="$SCRIPT_DIR/deleted_poster_log.txt" + +touch "$LOG" + +find "$ROOT" -type f -name ".deleted" | while read -r DEL; do + + DIR="$(dirname "$DEL")" + + find "$DIR" -maxdepth 1 -type f \( \ + -iname "folder.jpg" -o \ + -iname "folder.png" -o \ + -iname "*-thumb*.jpg" -o \ + -iname "*-thumb*.png" -o \ + -iname "backdrop*.jpg" -o \ + -iname "backdrop*.png" \ + \) | while read -r IMG; do + + ABS=$(realpath "$IMG") + +grep -Fqx "$ABS" "$LOG" && echo "Skipping $ABS" && continue + + echo "Processing: $ABS" + + cp "$IMG" "$IMG.bak" + + WIDTH=$(identify -format "%w" "$IMG") + +BADGEW=$((WIDTH * 4 / 10)) +BADGEH=$((WIDTH * 12 / 100)) +RADIUS=$((BADGEH / 2)) +FONTSIZE=$((BADGEH / 2)) +OFFSET=$((WIDTH / 40)) + + convert "$IMG" \ + -modulate 60,5 -contrast -contrast \ + \( -size ${BADGEW}x${BADGEH} xc:none \ + -fill "rgba(0,0,0,0.35)" \ + -draw "roundrectangle 0,0 ${BADGEW},${BADGEH} ${RADIUS},${RADIUS}" \ + \) \ + -gravity northeast -geometry +$((OFFSET+4))+$((OFFSET+4)) -composite \ + \( -size ${BADGEW}x${BADGEH} xc:none \ + -fill "rgba(220,53,69,0.95)" \ + -draw "roundrectangle 0,0 ${BADGEW},${BADGEH} ${RADIUS},${RADIUS}" \ + -gravity center \ + -fill white \ + -font DejaVu-Sans-Bold \ + -pointsize ${FONTSIZE} \ + -annotate +0+0 "DELETED" \ + \) \ + -gravity northeast -geometry +${OFFSET}+${OFFSET} -composite \ + -quality 95 \ + "$IMG" + + echo "$ABS" >> "$LOG" + echo " -> marked + logged" + + done + +done diff --git a/manage-video/video-clipper/clip.sh b/manage-video/video-clipper/clip.sh new file mode 100755 index 0000000..d670f4b --- /dev/null +++ b/manage-video/video-clipper/clip.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +usage() { + echo "Usage: $0 [-bg] [-no-source-mv] start_timestamp end_timestamp" + echo "e.g., $0 00:42 01:37:18" + echo " $0 -bg 00:42 01:37:18 to run in background" +} + +background=false +move_source=true + +while [[ $# -gt 0 ]]; do + case "$1" in + -bg) + background=true + shift + ;; + -no-source-mv) + move_source=false + shift + ;; + -*) + echo "Unknown option: $1" + usage + exit 1 + ;; + *) + break + ;; + esac +done + +if [ "$#" -ne 2 ]; then + usage + exit 1 +fi + +START_CUT="$1" +END_CUT="$2" + +# Supported video extensions +VIDEO_EXTS=("mp4" "mkv" "mov" "avi" "webm" "m4v") + +shopt -s nullglob + +VIDEO_FILE="" +for ext in "${VIDEO_EXTS[@]}"; do + files=(*."$ext") + if [ ${#files[@]} -gt 0 ]; then + VIDEO_FILE="${files[0]}" + break + fi +done + +if [ -z "$VIDEO_FILE" ]; then + echo "No supported video files found in the current directory." + exit 1 +fi + +echo "Video File: ${VIDEO_FILE}" + +base="${VIDEO_FILE%.*}" +ext="${VIDEO_FILE##*.}" + +PROCESSED_DIR="processed" +OUTPUT_DIR="target/${base}" + +mkdir -p "${OUTPUT_DIR}" +mkdir -p "${PROCESSED_DIR}" + +max=0 +for f in "${OUTPUT_DIR}/${base}_"*.${ext}; do + num=${f##*_} + num=${num%.${ext}} + (( num > max )) && max=$num +done + +index=$(printf "%03d" $((max + 1))) +OUTPUT_FILE="${OUTPUT_DIR}/${base}_${index}.${ext}" + +SOURCE_PATH="${VIDEO_FILE}" + +if $move_source; then + mv "${VIDEO_FILE}" "${PROCESSED_DIR}/" + SOURCE_PATH="${PROCESSED_DIR}/${VIDEO_FILE}" +fi + +LOGS_DIR="logs" +mkdir -p "${LOGS_DIR}" +LOG_FILE="${LOGS_DIR}/${base}.log" + +export VIDEO_TAG="CLIP" + +if $background; then + echo "Processing ${VIDEO_FILE} in the background..." + nohup bash -c "VIDEO_TAG='${VIDEO_TAG}' ffmpeg -i '${SOURCE_PATH}' -ss '${START_CUT}' -to '${END_CUT}' -max_muxing_queue_size 102400 '${OUTPUT_FILE}'" >> "${LOG_FILE}" 2>&1 & + echo "Clip complete! Output is in ${OUTPUT_FILE}" + echo "Log file: ${LOG_FILE}" +else + VIDEO_TAG="${VIDEO_TAG}" ffmpeg -i "${SOURCE_PATH}" -ss "${START_CUT}" -to "${END_CUT}" -max_muxing_queue_size 102400 "${OUTPUT_FILE}" 2>&1 | tee "${LOG_FILE}" + echo "Clip complete! Output is in ${OUTPUT_FILE}" + echo "Log file: ${LOG_FILE}" +fi diff --git a/manage-video/video-clipper/frames.sh b/manage-video/video-clipper/frames.sh new file mode 100755 index 0000000..77da029 --- /dev/null +++ b/manage-video/video-clipper/frames.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Usage function to display help +usage() { + echo "Usage: $0 [-no-source-mv] timestamp" + echo "e.g., $0 01:37:18 23:59:59" +} + +# Check for the optional background flag +background=false +move_source=true + +if [[ "$1" == "-no-source-mv" ]]; then + move_source=false + shift +fi + +# Verify timestamp was provided +if [ "$#" -ne 2 ]; then + usage + exit 1 +fi + +# Find the first .mp4 file +shopt -s nullglob +mp4_files=(*.mp4) +VIDEO_FILE="${mp4_files[0]}" + +if [ -z "$VIDEO_FILE" ]; then + echo "No .mp4 files found in the current directory." + exit 1 +fi + +echo "Video File: ${VIDEO_FILE}" + +# Setting up directories +START_CUT="$1" +END_CUT="$2" +PROCESSED_DIR="processed" +OUTPUT_DIR="target" + +base="${VIDEO_FILE%.*}" +run=$(date +%Y%m%d_%H%M%S) +RUN_DIR="${OUTPUT_DIR}/${base}/${base} - ${run}" +OUTPUT_FILE="${RUN_DIR}/${base} - ${run} - %03d.png" + +# Create directories +mkdir -p "${RUN_DIR}" +mkdir -p "${PROCESSED_DIR}" + +# Move the source video to the "processed" directory +SOURCE_PATH="${VIDEO_FILE}" + +if $move_source; then + mv "${VIDEO_FILE}" "${PROCESSED_DIR}/" + SOURCE_PATH="${PROCESSED_DIR}/${VIDEO_FILE}" +fi + +LOGS_DIR="logs" +mkdir -p "${LOGS_DIR}" +LOG_FILE="${LOGS_DIR}/$(basename "${VIDEO_FILE}" .mp4).log" + +export VIDEO_TAG="SCREENSHOT" + +# Run ffmpeg command with output redirection to log file +if $background; then + echo "Processing ${VIDEO_FILE} in the background..." + nohup bash -c "VIDEO_TAG='${VIDEO_TAG}' ./ffmpeg -ss '${START_CUT}' -to '${END_CUT}' -i '${SOURCE_PATH}' -vf \"select='eq(pict_type,PICT_TYPE_I)'\" -vsync vfr '${OUTPUT_FILE}'" >> "${LOG_FILE}" 2>&1 & + + echo "Extracting screenshots complete! Output is in ${OUTPUT_FILE}" + echo "Log file: ${LOG_FILE}" +else + VIDEO_TAG="${VIDEO_TAG}" ./ffmpeg -ss "${START_CUT}" -to "${END_CUT}" -i "${SOURCE_PATH}" -vf "select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr "${OUTPUT_FILE}" 2>&1 | tee "${LOG_FILE}" + echo "Extracting screenshots complete! Output is in ${OUTPUT_FILE}" + echo "Log file: ${LOG_FILE}" +fi diff --git a/manage-video/video-clipper/media-cover-editor.sh b/manage-video/video-clipper/media-cover-editor.sh new file mode 100755 index 0000000..05ec2ad --- /dev/null +++ b/manage-video/video-clipper/media-cover-editor.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -e + +IMG=$(find . -type f -iname "folder.jpg" | fzf --preview 'convert {} -resize 200x - | display jpg:-' --prompt="Select poster to mark deleted: ") + +[ -z "$IMG" ] && exit 0 + +BACKUP="${IMG}.bak" +cp "$IMG" "$BACKUP" + + + +WIDTH=$(identify -format "%w" "$IMG") + +BADGEW=$((WIDTH / 3)) +BADGEH=$((WIDTH / 10)) +RADIUS=$((BADGEH / 2)) +FONTSIZE=$((BADGEH / 2)) +OFFSET=$((WIDTH / 40)) + +convert "$IMG" \ + \( -size ${BADGEW}x${BADGEH} xc:none \ + -fill "rgba(0,0,0,0.35)" \ + -draw "roundrectangle 0,0 ${BADGEW},${BADGEH} ${RADIUS},${RADIUS}" \ + \) \ + -gravity northeast -geometry +$((OFFSET+3))+$((OFFSET+3)) -composite \ + \( -size ${BADGEW}x${BADGEH} xc:none \ + -fill "rgba(220,53,69,0.95)" \ + -draw "roundrectangle 0,0 ${BADGEW},${BADGEH} ${RADIUS},${RADIUS}" \ + -gravity center \ + -fill white \ + -font DejaVu-Sans-Bold \ + -pointsize ${FONTSIZE} \ + -annotate +0+0 "DELETED" \ + \) \ + -gravity northeast -geometry +${OFFSET}+${OFFSET} -composite \ + -quality 95 \ + "$IMG" + +echo "Marked deleted: $IMG" +echo "Backup stored at: $BACKUP" diff --git a/manage-video/video-clipper/video-clipper.sh b/manage-video/video-clipper/video-clipper.sh new file mode 100755 index 0000000..f518364 --- /dev/null +++ b/manage-video/video-clipper/video-clipper.sh @@ -0,0 +1,254 @@ +#!/bin/bash + +CLIP_SCRIPT="./clip.sh" +FRAME_SCRIPT="./frames.sh" +QUEUE_FILE="/tmp/clip_queue.txt" + +> "$QUEUE_FILE" + +RED="\033[31m" +GREEN="\033[32m" +YELLOW="\033[33m" +BLUE="\033[34m" +CYAN="\033[36m" +NC="\033[0m" + +video="" +declare -a queue + +pick_video() { + #video=$(ls *.mp4 2>/dev/null | fzf --prompt="Select video > ") + video=$(find . -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.mkv" \) | fzf --prompt="Select video > ") + + if [[ -n "$video" ]]; then + echo "Selected: $video" + else + echo "No selection." + fi +} + +preview_timestamp() { + if [[ -z "$video" ]]; then + echo "No video selected" + return + fi + + ts="$1" + + mpv --quiet --hr-seek=yes --start="$ts" "$video" +} + +scrub_video() { + + if [[ -z "$video" ]]; then + echo "No video selected" + return + fi + + export SCRUB_QUEUE="$QUEUE_FILE" + + mpv --keep-open=yes \ + --pause \ + "$video" + + echo "" + echo "Importing marks..." + + while read -r line; do + queue+=("$line") + echo "queued $line" + done < "$QUEUE_FILE" +} + +show_queue() { + if [ ${#queue[@]} -eq 0 ]; then + echo -e "${YELLOW}(queue empty)${NC}" + return + fi + + i=1 + for job in "${queue[@]}"; do + type=$(echo "$job" | awk '{print $1}') + start=$(echo "$job" | awk '{print $2}') + end=$(echo "$job" | awk '{print $3}') + + if [[ "$type" == "c" ]]; then + label="CLIP" + color=$BLUE + else + label="FRAMES" + color=$CYAN + fi + + echo -e " $i. ${color}$label${NC} $start β†’ $end" + ((i++)) + done +} + +save_config() { + if [[ -z "$video" ]]; then + echo "No video selected" + return + fi + + name=$(basename "$video") + name="${name%.*}" + + dir="./target/$name" + mkdir -p "$dir" + + conf="$dir/video-clipper.conf" + + { + echo "video=$video" + echo "" + + echo "[jobs]" + for job in "${queue[@]}"; do + echo "$job" + done + } > "$conf" + + echo -e "${GREEN}Saved config:${NC} $conf" +} + +load_config() { + conf="$1" + + if [[ ! -f "$conf" ]]; then + echo "Config not found: $conf" + return + fi + + queue=() + video="" + mode="" + + > "$QUEUE_FILE" + + while IFS= read -r line; do + + [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue + + if [[ "$line" == "[jobs]" ]]; then + mode="jobs" + continue + fi + + if [[ "$line" == video=* ]]; then + video="${line#video=}" + continue + fi + + if [[ "$mode" == "jobs" ]]; then + queue+=("$line") + echo "$line" >> "$QUEUE_FILE" + fi + + done < "$conf" + + echo -e "${GREEN}Loaded config:${NC} $conf" + echo "video: $video" + echo "jobs: ${#queue[@]}" +} + +run_queue() { + if [ -z "$video" ]; then + echo -e "${RED}No video selected.${NC}" + return + fi + + save_config + + for job in "${queue[@]}"; do + type=$(echo "$job" | awk '{print $1}') + start=$(echo "$job" | awk '{print $2}') + end=$(echo "$job" | awk '{print $3}') + + echo -e "${GREEN}Running ${type} ${start} -> ${end}${NC}" + + if [[ "$type" == "c" ]]; then + $CLIP_SCRIPT -no-source-mv "$start" "$end" + else + $FRAME_SCRIPT -no-source-mv "$start" "$end" + fi + done + + queue=() + + > "$QUEUE_FILE" + + echo -e "${GREEN}Queue finished.${NC}" +} + + + +echo -e "${CYAN}FFmpeg Clip Console${NC}" +echo "commands: video, c, f, list, undo, go, quit" + +while true; do + read -e -p "> " cmd a b + + case "$cmd" in + + video) + pick_video + ;; + +p) + preview_timestamp "$a" + ;; + c) + queue+=("c $a $b") + echo -e "${BLUE}queued clip${NC} $a -> $b" + ;; + + f) + queue+=("f $a $b") + echo -e "${CYAN}queued frames${NC} $a -> $b" + ;; + + list) + show_queue + ;; + +del) + idx=$a + unset 'queue[$((idx-1))]' + queue=("${queue[@]}") + ;; + +scrub) + scrub_video + ;; + + undo) + unset 'queue[-1]' + echo "removed last job" + ;; + + go) + run_queue + ;; + + quit|exit) + break + ;; + +load) +conf=$(find ./target -type f -name "video-clipper.conf" \ +| fzf --prompt="Select config > " \ + --preview 'grep "^video=" {}') + +if [[ -n "$conf" ]]; then + load_config "$conf" + else + echo "No selection." + fi +;; + + *) + echo -e "${YELLOW}commands: video | scrub | p start | c start end | f start end | list | undo | go | quit${NC}" + ;; + esac +done diff --git a/manage-video/video-renamer/video-renamer.sh b/manage-video/video-renamer/video-renamer.sh new file mode 100755 index 0000000..d58c837 --- /dev/null +++ b/manage-video/video-renamer/video-renamer.sh @@ -0,0 +1,13 @@ +docker run --rm \ + --volume=./video-renamer:/mnt \ + jkwill87/mnamer \ + --language de \ + --no-guess \ + --no-overwrite \ + --movie-format "{name} ({year}){extension}" \ + --episode-format "{series} S{season:02}E{episode:02}{extension}" \ + --movie-directory "/mnt/movies/{name} ({year})" \ + --episode-directory "/mnt/shows/{series}" \ + -b \ + --test \ + /mnt diff --git a/manage-video/video-sniffer/video-sniffer.sh b/manage-video/video-sniffer/video-sniffer.sh new file mode 100755 index 0000000..0ad19d3 --- /dev/null +++ b/manage-video/video-sniffer/video-sniffer.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +set -euo pipefail + +video=$(find . -type f \( \ +-iname "*.mp4" -o \ +-iname "*.mkv" -o \ +-iname "*.webm" -o \ +-iname "*.mov" -o \ +-iname "*.avi" \ +\) | fzf --prompt="Select video: ") + +[ -z "${video:-}" ] && exit 0 + + + + +config="${video%.*}.jobs" + +echo +echo "Choose detection method:" +echo "1) freeze (almost identical frames)" +echo "2) motion (low motion using frame differences)" +echo "3) both" +read -rp "Selection: " mode + +case "$mode" in +1) method="freeze" ;; +2) method="motion" ;; +3) method="both" ;; +*) echo "Invalid choice"; exit 1 ;; +esac + +freeze_noise="" +freeze_dur="" +motion_amount="" +motion_thresh="" + +if [[ "$method" == "freeze" || "$method" == "both" ]]; then + read -rp "freeze noise threshold n (default 0.005): " freeze_noise + freeze_noise="${freeze_noise:-0.005}" + + read -rp "freeze minimum duration seconds d (default 2): " freeze_dur + freeze_dur="${freeze_dur:-2}" +fi + +if [[ "$method" == "motion" || "$method" == "both" ]]; then + read -rp "motion blackframe percent amount (default 98): " motion_amount + motion_amount="${motion_amount:-98}" + + read -rp "motion threshold (default 20): " motion_thresh + motion_thresh="${motion_thresh:-20}" +fi + +read -rp "merge gap tolerance seconds (default 3): " merge_gap +merge_gap="${merge_gap:-3}" + +read -rp "minimum segment length seconds (default 3): " min_len +min_len="${min_len:-3}" + +echo +echo "Video: $video" +echo "Method: $method" + +if [[ -f "$config" ]]; then + read -rp "Config exists ($config). Append run? [y/N]: " yn + [[ "$yn" =~ ^[Yy]$ ]] || exit 0 +fi + +tmp=$(mktemp) + +run_freeze () { +ffmpeg -hide_banner -i "$video" \ +-vf "freezedetect=n=${freeze_noise}:d=${freeze_dur}" \ +-f null - 2>&1 | \ +awk ' +/freeze_start/ {s=$NF} +/freeze_end/ {printf "%s %s\n", s, $NF} +' +} + +run_motion () { +ffmpeg -hide_banner -i "$video" \ +-vf "tblend=all_mode=difference,blackframe=amount=${motion_amount}:threshold=${motion_thresh}" \ +-f null - 2>&1 | \ +awk ' +/black_start/ {s=$NF} +/black_end/ {printf "%s %s\n", s, $NF} +' +} + +{ +if [[ "$method" == "freeze" ]]; then + run_freeze +elif [[ "$method" == "motion" ]]; then + run_motion +else + run_freeze + run_motion +fi +} | sort -n -k1 | awk -v gap="$merge_gap" -v minlen="$min_len" ' + +{ + start=$1 + end=$2 + + if (NR==1) { + cur_s=start + cur_e=end + next + } + + # overlapping or small gap + if (start <= cur_e + gap) { + if (end > cur_e) + cur_e=end + } + else { + if (cur_e-cur_s >= minlen) + printf "%f %f\n", cur_s, cur_e + cur_s=start + cur_e=end + } +} + +END { + if (NR>0 && cur_e-cur_s >= minlen) + printf "%f %f\n", cur_s, cur_e +} +' > "$tmp" + +if [[ ! -s "$tmp" ]]; then + rm -f "$tmp" + echo "No quiet scenes detected." + exit 0 +fi + +if [[ ! -f "$config" ]]; then + { + echo "video=$video" + echo + echo "[jobs]" + } > "$config" +fi + +{ +echo +echo "# run method=$method $(date)" +if [[ "$method" == "freeze" || "$method" == "both" ]]; then +echo "# freeze n=$freeze_noise d=$freeze_dur" +fi +if [[ "$method" == "motion" || "$method" == "both" ]]; then +echo "# motion amount=$motion_amount threshold=$motion_thresh" +fi + +awk '{printf "d %s %s\n",$1,$2}' +} < "$tmp" >> "$config" + +rm -f "$tmp" + +entries=$(grep -c '^d ' "$config" || true) + +if [[ "$entries" -eq 0 ]]; then + echo "No job entries created. Removing config." + rm -f "$config" +else + echo + echo "Jobs written to $config" + tail -n 10 "$config" +fi diff --git a/manage-video/video-splicer/README.md b/manage-video/video-splicer/README.md new file mode 100644 index 0000000..3c3dc95 --- /dev/null +++ b/manage-video/video-splicer/README.md @@ -0,0 +1,4 @@ +./video-splicer.sh good-video.mkv bad-video-but-good-audio.mkv out.mkv + +./video-splicer.sh --auto --done-dir finished/ --out-dir merged/ one.mkv two.mkv final.mkv +./video-splicer-wizard.sh --done-dir "./processed" diff --git a/manage-video/video-splicer/video-splicer-wizard.sh b/manage-video/video-splicer/video-splicer-wizard.sh new file mode 100755 index 0000000..19207db --- /dev/null +++ b/manage-video/video-splicer/video-splicer-wizard.sh @@ -0,0 +1,261 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +require() { + command -v "$1" >/dev/null || { + echo "Missing dependency: $1" + exit 1 + } +} + +strip_resolution_tag() { + echo "$1" | sed -E 's/ ?\[[0-9]{3,4}p\]//g' +} + + +require ffprobe +require jq + +SCAN_DIR="." +DONE_DIR="" +DRY_RUN=0 +MOVE_NON_GER=1 +MOVE_ALL=0 +ENGINE="./video-splicer.sh" +LOG_DIR="${LOG_DIR:-./logs}" + +while [[ $# -gt 0 ]]; do + case "$1" in + --scan) + SCAN_DIR="$2" + shift + ;; + --done-dir) + DONE_DIR="$2" + shift + ;; + --engine) + ENGINE="$2" + shift + ;; + --dry-run) + DRY_RUN=1 + ;; + --no-move-non-ger) + MOVE_NON_GER=0 + ;; + --move-all) + MOVE_ALL=1 + ;; + *) + echo "Unknown flag $1" + exit 1 + ;; + esac + shift +done + +mkdir -p "$LOG_DIR" +RUN_ID=$(date +"%Y%m%d_%H%M%S")_$RANDOM +LOG_FILE="$LOG_DIR/automerge_$RUN_ID.log" + +log() { + echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] $*" | tee -a "$LOG_FILE" +} + +log_json() { + jq -nc "$@" >> "$LOG_FILE" +} + +probe_json() { + ffprobe -v error -print_format json -show_streams "$1" +} + +has_german_audio() { + + local json="$1" + + count=$(echo "$json" | jq '[.streams[] + | select(.codec_type=="audio") + | select(.tags.language=="ger" or .tags.language=="deu")] | length') + + [[ "$count" -gt 0 ]] && echo 1 || echo 0 +} + +has_english_audio() { + + local json="$1" + + count=$(echo "$json" | jq '[.streams[] + | select(.codec_type=="audio") + | select(.tags.language=="eng")] | length') + + [[ "$count" -gt 0 ]] && echo 1 || echo 0 +} + +video_score() { + + local file="$1" + +RESOLUTION=$(ffprobe -v error \ +-select_streams v:0 \ +-show_entries stream=width,height \ +-of csv=p=0:s=x \ +"$file" | head -n1) + width=$(echo $RESOLUTION | cut -d'x' -f1) + height=$(echo $RESOLUTION | cut -d'x' -f2) + + score=$((width * height)) + + echo "$score" +} + +process_movie_dir() { + dir="$1" + + log "Scanning $dir" + + mapfile -t files < <(find "$dir" -maxdepth 1 -type f \( -iname "*.mkv" -o -iname "*.mp4" \)) + + if [[ ${#files[@]} -lt 2 ]]; then + log "Skipping $dir (need >=2 files)" + return + fi + + GER_FILES=() + NON_GER_FILES=() + + declare -A PROBE_CACHE + + for f in "${files[@]}"; do + log "Checking file $f" + + json=$(probe_json "$f") + PROBE_CACHE["$f"]="$json" + + ger=$(has_german_audio "$json") + + if [[ "$ger" -eq 1 ]]; then + GER_FILES+=("$f") + else + NON_GER_FILES+=("$f") + fi + + done + + if [[ ${#GER_FILES[@]} -eq 0 ]]; then + log "No German tracks detected. Skip." + return + fi + + if [[ ${#NON_GER_FILES[@]} -eq 0 ]]; then + log "All files already contain German audio. Likely resolution variants. Skip." + return + fi + + best_file="" + best_score=0 + + for f in "${NON_GER_FILES[@]}"; do + + score=$(video_score "$f") + + if ((score > best_score)); then + best_score="$score" + best_file="$f" + fi + + done + + if [[ -z "$best_file" ]]; then + log "No suitable primary source found" + return + fi + + inputs=("$best_file") + + for f in "${GER_FILES[@]}"; do + inputs+=("$f") + done + + base=$(basename "$best_file") + name="${base%.*}" + BASE_CLEAN=$(strip_resolution_tag "$name") + EXTENSION="${base##*.}" + OUT_FILE="$dir/${BASE_CLEAN}.${EXTENSION}" + + counter=1 +final_out="$OUT_FILE" + +while [[ -e "$final_out" ]]; do + final_out="$dir/${BASE_CLEAN}.${EXTENSION}.spliced${counter}" + ((counter++)) +done + +OUT_FILE="$final_out" + + log "Merge candidate detected" + log "Primary video: $best_file" + log "GER sources: ${GER_FILES[*]}" + log "Output: $OUT_FILE" + + log_json \ + --arg dir "$dir" \ + --arg primary "$best_file" \ + --argjson ger "$(printf '%s\n' "${GER_FILES[@]}" | jq -R . | jq -s .)" \ + '{ + event:"merge_candidate", + directory:$dir, + primary_source:$primary, + german_sources:$ger + }' + + if [[ "$DRY_RUN" -eq 1 ]]; then + log "DRY RUN: skipping merge" + return + fi + + cmd=("$ENGINE" --auto) + + for f in "${inputs[@]}"; do + cmd+=("$f") + done + + cmd+=("$OUT_FILE") + + log "Executing merge engine" + "${cmd[@]}" + + if [[ "$MOVE_NON_GER" -eq 1 && -n "$DONE_DIR" ]]; then + mkdir -p "$DONE_DIR" + mv "$best_file" "$DONE_DIR/" + log "Moved non-german source $best_file" + fi + + if [[ "$MOVE_ALL" -eq 1 && -n "$DONE_DIR" ]]; then + for f in "${GER_FILES[@]}"; do + mv "$f" "$DONE_DIR/" + done + fi + + log "Merge finished for $dir" +} + +export -f process_movie_dir +export -f probe_json +export -f has_german_audio +export -f has_english_audio +export -f video_score +export ENGINE DRY_RUN LOG_FILE DONE_DIR MOVE_NON_GER MOVE_ALL + +log "Starting automerge scan of $SCAN_DIR" + +#mapfile -t dirs < <(find "$SCAN_DIR" -type d) + +#for d in "${dirs[@]}"; do +# process_movie_dir "$d" +#done + +process_movie_dir "$SCAN_DIR" + +log "Scan complete" diff --git a/manage-video/video-splicer/video-splicer.sh b/manage-video/video-splicer/video-splicer.sh new file mode 100755 index 0000000..d50af4d --- /dev/null +++ b/manage-video/video-splicer/video-splicer.sh @@ -0,0 +1,348 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +require() { + command -v "$1" >/dev/null || { + echo "Missing dependency: $1" + exit 1 + } +} + +require ffmpeg +require ffprobe +require jq + +ARGS=() + +AUTO=0 +DONE_DIR="" +OUT_DIR="" + +while [[ $# -gt 0 ]]; do + case "$1" in + --auto) AUTO=1 ;; + --done-dir) + DONE_DIR="$2" + shift + ;; + --out-dir) + OUT_DIR="$2" + shift + ;; + *) ARGS+=("$1") ;; + esac + shift +done + +if [[ ${#ARGS[@]} -lt 2 ]]; then + echo "Usage: merge.sh input1 [input2 ...] output" + exit 1 +fi + +OUT="${ARGS[-1]}" +unset 'ARGS[-1]' +INPUT_FILES=("${ARGS[@]}") + +LOG_DIR="${LOG_DIR:-./logs}" +mkdir -p "$LOG_DIR" + +START_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +RUN_ID=$(date +"%Y%m%d_%H%M%S")_$RANDOM +LOG_FILE="$LOG_DIR/merge_$(basename "$OUT")_${RUN_ID}.log" + +log_json() { jq -nc "$@" >>"$LOG_FILE"; } +log() { echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] $*" | tee -a "$LOG_FILE"; } + +probe() { ffprobe -loglevel error -print_format json -show_streams "$1"; } + +declare -a INPUT_JSONS + +for f in "${INPUT_FILES[@]}"; do + INPUT_JSONS+=("$(probe "$f")") +done + +log "Starting merge run $RUN_ID" + +log_json \ + --arg time "$START_TIME" \ + --argjson sources "$(printf '%s\n' "${INPUT_FILES[@]}" | jq -R . | jq -s .)" \ + '{event:"sources_detected",timestamp:$time,sources:$sources}' + +declare -A STREAM_FILE +declare -A STREAM_INDEX +declare -A STREAM_TYPE +declare -A STREAM_CODEC +declare -A STREAM_LANG +declare -A STREAM_CHANNELS +declare -A STREAM_TITLE +declare -A STREAM_SCORE +declare -A STREAM_WIDTH +declare -A STREAM_HEIGHT + +ALL_STREAMS=() + +check_sources() { + + base="${INPUT_FILES[0]}" + + for cur in "${INPUT_FILES[@]:1}"; do + + echo + echo "==== SOURCE COMPAT CHECK ====" + + d1=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$base") + d2=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$cur") + + diff=$(awk -v a="$d1" -v b="$d2" 'BEGIN{print (a>b)?a-b:b-a}') + + printf "Duration base: %.3f\n" "$d1" + printf "Duration curr: %.3f\n" "$d2" + printf "Ξ” difference : %.3f\n" "$diff" + + fps1=$(ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of csv=p=0 "$base") + fps2=$(ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of csv=p=0 "$cur") + + echo "FPS base : $fps1" + echo "FPS curr : $fps2" + + risk=0 + + if [[ "$fps1" != "$fps2" ]]; then + echo "⚠ FPS mismatch" + risk=1 + fi + + awk_check=$(awk -v d="$diff" 'BEGIN{print (d>2)?1:0}') + if [[ "$awk_check" == 1 ]]; then + echo "⚠ Duration >2s" + risk=2 + fi + + if [[ $risk -eq 2 ]]; then + echo "❌ Sources incompatible" + exit 1 + elif [[ $risk -eq 1 ]]; then + read -rp "Potential risk detected. Continue? [y/N]: " ans + [[ "$ans" =~ ^[Yy]$ ]] || exit 1 + else + echo "βœ… Compatible" + fi + + done +} + +detect_commentary() { + shopt -s nocasematch + [[ "$1" =~ commentary ]] && echo 1 || echo 0 +} + +score_video() { + + codec=$1 + width=$2 + height=$3 + bitrate=$4 + + score=0 + + case "$codec" in + av1) score=100 ;; + hevc) score=90 ;; + h264) score=80 ;; + *) score=50 ;; + esac + + pixels=$((width * height)) + ((score += pixels / 500000)) + + [[ "$bitrate" != null ]] && ((score += bitrate / 1000000)) + + echo "$score" +} + +score_audio() { + + codec=$1 + lang=$2 + ch=$3 + commentary=$4 + + score=0 + + case "$lang" in + ger | deu) score=1000 ;; + eng) score=200 ;; + *) score=100 ;; + esac + + case "$codec" in + truehd) ((score += 100)) ;; + dts*) ((score += 90)) ;; + ac3) ((score += 70)) ;; + aac) ((score += 60)) ;; + *) ((score += 40)) ;; + esac + + ((score += ch * 5)) + + [[ "$commentary" == 1 ]] && ((score -= 150)) + + echo "$score" +} + +audio_sig() { + echo "${STREAM_CODEC[$1]}-${STREAM_LANG[$1]}-${STREAM_CHANNELS[$1]}-${STREAM_SCORE[$1]}" +} + +add_streams() { + + filetag="$1" + json="$2" + + mapfile -t rows < <(echo "$json" | jq -c '.streams[]') + + for row in "${rows[@]}"; do + + idx=$(jq -r '.index' <<<"$row") + type=$(jq -r '.codec_type' <<<"$row") + codec=$(jq -r '.codec_name' <<<"$row") + lang=$(jq -r '.tags.language // "unknown"' <<<"$row") + title=$(jq -r '.tags.title // ""' <<<"$row") + channels=$(jq -r '.channels // 0' <<<"$row") + width=$(jq -r '.width // 0' <<<"$row") + height=$(jq -r '.height // 0' <<<"$row") + bitrate=$(jq -r '.bit_rate // 0' <<<"$row") + + id="${filetag}:${idx}" + + STREAM_FILE[$id]=$filetag + STREAM_INDEX[$id]=$idx + STREAM_TYPE[$id]=$type + STREAM_CODEC[$id]=$codec + STREAM_LANG[$id]=$lang + STREAM_CHANNELS[$id]=$channels + STREAM_TITLE[$id]=$title + STREAM_WIDTH[$id]=$width + STREAM_HEIGHT[$id]=$height + + score=0 + + if [[ "$type" == video ]]; then + score=$(score_video "$codec" "$width" "$height" "$bitrate") + fi + + if [[ "$type" == audio ]]; then + comm=$(detect_commentary "$title") + score=$(score_audio "$codec" "$lang" "$channels" "$comm") + fi + + STREAM_SCORE[$id]=$score + ALL_STREAMS+=("$id") + + done +} + +check_sources + +declare -A TAG_TO_INPUT + +for i in "${!INPUT_FILES[@]}"; do + tag="f$i" + TAG_TO_INPUT[$tag]=$i + add_streams "$tag" "${INPUT_JSONS[$i]}" +done + +echo +echo "==== STREAM INVENTORY ====" + +for id in "${ALL_STREAMS[@]}"; do + if [[ ${STREAM_TYPE[$id]} == video ]]; then + echo "$id video ${STREAM_WIDTH[$id]}x${STREAM_HEIGHT[$id]} ${STREAM_CODEC[$id]} score=${STREAM_SCORE[$id]}" + else + echo "$id ${STREAM_TYPE[$id]} ${STREAM_LANG[$id]} ${STREAM_CODEC[$id]} score=${STREAM_SCORE[$id]}" + fi +done + +mapfile -t VIDEO < <(for s in "${ALL_STREAMS[@]}"; do [[ ${STREAM_TYPE[$s]} == video ]] && echo "$s ${STREAM_SCORE[$s]}"; done | sort -k2 -nr) +mapfile -t AUDIO < <(for s in "${ALL_STREAMS[@]}"; do [[ ${STREAM_TYPE[$s]} == audio ]] && echo "$s ${STREAM_SCORE[$s]}"; done | sort -k2 -nr) +mapfile -t SUBS < <(for s in "${ALL_STREAMS[@]}"; do [[ ${STREAM_TYPE[$s]} == subtitle ]] && echo "$s"; done) + +ORDER=() + +best_video=$(awk '{print $1}' <<<"${VIDEO[0]}") +ORDER+=("$best_video") + +declare -A AUDIO_SEEN + +for a in "${AUDIO[@]}"; do + id=$(awk '{print $1}' <<<"$a") + sig=$(audio_sig "$id") + if [[ -z "${AUDIO_SEEN[$sig]+x}" ]]; then + ORDER+=("$id") + AUDIO_SEEN[$sig]=1 + fi +done + +for s in "${SUBS[@]}"; do + ORDER+=($(awk '{print $1}' <<<"$s")) +done + +if [[ "$AUTO" -eq 1 ]]; then + ans=y +else + read -rp "Accept layout? [Y/n/edit]: " ans +fi + +MAP=() + +for s in "${ORDER[@]}"; do + tag="${STREAM_FILE[$s]}" + input_index="${TAG_TO_INPUT[$tag]}" + MAP+=(-map "${input_index}:${STREAM_INDEX[$s]}") +done + +TMP="${OUT}.tmp.mkv" + +INPUT_ARGS=() +for f in "${INPUT_FILES[@]}"; do + INPUT_ARGS+=(-i "$f") +done + +BUILD_LOG_B64=$(base64 -w0 "$LOG_FILE") + +FF_CMD=(ffmpeg "${INPUT_ARGS[@]}" + "${MAP[@]}" + -map_chapters 0 + -c copy + -metadata build_input_files="${INPUT_FILES[*]}" + -metadata building_log="$BUILD_LOG_B64" + -metadata build_time="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + -metadata build_stream_map="${MAP[*]}" + -stats -stats_period 1 + -reset_timestamps 1 + -fflags +genpts + -avoid_negative_ts make_zero + -max_interleave_delta 0 + "$TMP") + +log_json --arg cmd "${FF_CMD[*]}" '{event:"ffmpeg_command",command:$cmd}' + +"${FF_CMD[@]}" 2>&1 | tee -a "$LOG_FILE" + +FINAL_OUT="$OUT" + +if [[ -n "$OUT_DIR" ]]; then + mkdir -p "$OUT_DIR" + FINAL_OUT="$OUT_DIR/$(basename "$OUT")" +fi + +mv "$TMP" "$FINAL_OUT" + +echo "Created $FINAL_OUT" + +if [[ "$AUTO" -eq 1 && -n "$DONE_DIR" ]]; then + mkdir -p "$DONE_DIR/$(basename "$OUT")" + for f in "${INPUT_FILES[@]}"; do + mv "$f" "$DONE_DIR/$(basename "$OUT")/" + done +fi diff --git a/manage-video/video-wizard/0-auto-split-input.sh b/manage-video/video-wizard/0-auto-split-input.sh new file mode 100755 index 0000000..9be940a --- /dev/null +++ b/manage-video/video-wizard/0-auto-split-input.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +VIDEO_FOLDER="./0-auto-split-input" +ROWS=3 + +OUTPUT_DIR="./0-multi-input" + +mkdir -p "$OUTPUT_DIR" + +cd "$VIDEO_FOLDER" + +index=1 +files_per_row=$((($(ls | wc -l) + ROWS - 1) / ROWS)) + +for file in *.mp4 *.mov *.avi *.m4v; do + if [ ! -f "$file" ]; then + continue + fi + + folder_index=$(( (index - 1) / files_per_row )) + + mkdir -p "$OUTPUT_DIR/horizontal-$folder_index" + mv "$file" "$OUTPUT_DIR/horizontal-$folder_index/" + + ((index++)) +done diff --git a/manage-video/video-wizard/0-convert-gif.sh b/manage-video/video-wizard/0-convert-gif.sh new file mode 100755 index 0000000..cdabd8e --- /dev/null +++ b/manage-video/video-wizard/0-convert-gif.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +TARGET_DIR="./0-input" + +if [ ! -d "$TARGET_DIR" ]; then + echo "---->>>> Error: Directory '$TARGET_DIR' does not exist." + exit 1 +fi + +cd "$TARGET_DIR" + +for gif in *.gif; do + if [ -f "$gif" ]; then + mp4="${gif%.gif}.mp4" + if ffmpeg -hide_banner -loglevel error -i "$gif" -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "$mp4"; then + echo "---->>>> Converted $gif to $mp4 successfully." + rm "$gif" + else + echo "---->>>> Failed to convert $gif." + fi + fi +done diff --git a/manage-video/video-wizard/0-convert-images.sh b/manage-video/video-wizard/0-convert-images.sh new file mode 100755 index 0000000..5859b1f --- /dev/null +++ b/manage-video/video-wizard/0-convert-images.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +TARGET_DIR="./0-input" +DURATION=1 # seconds per image + +if [ ! -d "$TARGET_DIR" ]; then + echo "---->>>> Error: Directory '$TARGET_DIR' does not exist." + exit 1 +fi + +cd "$TARGET_DIR" + +for img in *.png *.jpg *.jpeg *.webp; do + if [ -f "$img" ]; then + mp4="${img%.*}.mp4" + + if ffmpeg -hide_banner -loglevel error \ + -loop 1 -i "$img" \ + -t $DURATION \ + -movflags faststart \ + -pix_fmt yuv420p \ + -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \ + "$mp4"; then + + echo "---->>>> Converted $img to $mp4 successfully." + rm "$img" + else + echo "---->>>> Failed to convert $img." + fi + fi +done diff --git a/manage-video/video-wizard/1-scale-to-height.sh b/manage-video/video-wizard/1-scale-to-height.sh new file mode 100755 index 0000000..7559496 --- /dev/null +++ b/manage-video/video-wizard/1-scale-to-height.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +COMMON_HEIGHT=$1 +INPUT_DIR="./0-input" +OUTPUT_DIR="./1-scaled" + +mkdir -p "$OUTPUT_DIR" + +for video_file in "$INPUT_DIR"/*.{mp4,mov,avi,m4v}; do + if [ -f "$video_file" ]; then + base_name=$(basename "$video_file") + output_file="$OUTPUT_DIR/$base_name" + + ffmpeg -y -i "$video_file" -vf "scale='ceil($COMMON_HEIGHT*a/2)*2:$COMMON_HEIGHT'" -c:a copy "$output_file" + + rm "$video_file" + + echo "---->>>> Scaled $video_file to have a height of $COMMON_HEIGHT pixels and even width." + fi +done + +echo "---->>>> All videos have been scaled to a common height of $COMMON_HEIGHT pixels with even widths." diff --git a/manage-video/video-wizard/1-scale-to-width.sh b/manage-video/video-wizard/1-scale-to-width.sh new file mode 100755 index 0000000..19110b8 --- /dev/null +++ b/manage-video/video-wizard/1-scale-to-width.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +COMMON_WIDTH=$1 +INPUT_DIR="./0-input" +OUTPUT_DIR="./1-scaled" + +mkdir -p "$OUTPUT_DIR" + +for video_file in "$INPUT_DIR"/*.{mp4,mov,avi,m4v}; do + if [ -f "$video_file" ]; then + base_name=$(basename "$video_file") + output_file="$OUTPUT_DIR/$base_name" + + ffmpeg -y -i "$video_file" -vf "scale=$COMMON_WIDTH:'ceil(ow/a/2)*2'" -c:a copy "$output_file" + + rm "$video_file" + + echo "---->>>> Scaled $video_file to have a width of $COMMON_WIDTH pixels and even height." + fi +done + +echo "---->>>> All videos have been scaled to a common width of $COMMON_WIDTH pixels with even heights." diff --git a/manage-video/video-wizard/2-loop.sh b/manage-video/video-wizard/2-loop.sh new file mode 100755 index 0000000..cddaecb --- /dev/null +++ b/manage-video/video-wizard/2-loop.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +DURATION=$1 +INPUT_DIR="./1-scaled" +OUTPUT_DIR="./2-looped" + +mkdir -p "$OUTPUT_DIR" + +for video_file in "$INPUT_DIR"/*; do + if [[ $video_file == *.mp4 ]] || [[ $video_file == *.mov ]] || [[ $video_file == *.avi ]] || [[ $video_file == *.m4v ]]; then + filename=$(basename -- "$video_file") + extension="${filename##*.}" + filename="${filename%.*}" + output_file="${OUTPUT_DIR}/${filename}.${extension}" + + ffmpeg -y -stream_loop -1 -i "$video_file" -c copy -t "$DURATION" -f mp4 -y "$output_file" + + rm "$video_file" + + echo "---->>>> Generated looped video: $output_file" + else + echo "---->>>> Skipping non-video file: $video_file" + fi +done + +echo "---->>>> All videos processed." diff --git a/manage-video/video-wizard/3-merge-horizontal.sh b/manage-video/video-wizard/3-merge-horizontal.sh new file mode 100755 index 0000000..2ba0cb3 --- /dev/null +++ b/manage-video/video-wizard/3-merge-horizontal.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +OUTPUT_FILE=$1 +INPUT_DIR="./2-looped" +OUTPUT_DIR="./3-output" + +mkdir -p $OUTPUT_DIR + +mapfile -t video_files < <( + find "$INPUT_DIR" -maxdepth 1 -type f \( \ + -iname "*.mp4" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.m4v" -o -iname "*.mkv" -o -iname "*.webm" \ + \) -printf "%f\n" | + sort -t. -k1,1V | + sed "s|^|$INPUT_DIR/|" +) + +if [ "${#video_files[@]}" -lt 2 ]; then + echo "Need at least two video files to concatenate." + exit 1 +fi + +echo "Found ${#video_files[@]} video files to concatenate." + +ffmpeg_cmd="ffmpeg -y" +filter_complex="" +input_count=0 + +for video_file in "${video_files[@]}"; do + if [[ -f $video_file ]]; then + ffmpeg_cmd+=" -i \"$video_file\"" + filter_complex+="[${input_count}:v:0] " + input_count=$((input_count+1)) + fi +done + +filter_complex+="hstack=inputs=$input_count [v]" +ffmpeg_cmd+=" -filter_complex \"$filter_complex\" -map \"[v]\" \"$OUTPUT_DIR/$OUTPUT_FILE\"" + +eval $ffmpeg_cmd + +if [ $? -eq 0 ]; then + echo "---->>>> Generated concatenated video: $OUTPUT_DIR/$OUTPUT_FILE" + + for video_file in "${video_files[@]}"; do + if [ -f "$video_file" ]; then + rm "$video_file" + echo "---->>>> Removed video file: $video_file" + fi + done +else + echo "---->>>> FFmpeg command failed. Video files have not been removed." +fi diff --git a/manage-video/video-wizard/3-merge-vertical.sh b/manage-video/video-wizard/3-merge-vertical.sh new file mode 100755 index 0000000..669c10b --- /dev/null +++ b/manage-video/video-wizard/3-merge-vertical.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +OUTPUT_FILE=$1 +INPUT_DIR="./2-looped" +OUTPUT_DIR="./3-output" + +mkdir -p "$OUTPUT_DIR" + +video_files=( "$INPUT_DIR"/*.{mp4,mov,avi,m4v} ) + +if [ "${#video_files[@]}" -lt 2 ]; then + echo "Need at least two video files to concatenate vertically." + exit 1 +fi + +echo "Found ${#video_files[@]} video files to concatenate vertically." + +ffmpeg_cmd="ffmpeg -y" +filter_complex="" + +input_count=0 + +for video_file in "${video_files[@]}"; do + if [[ -f $video_file ]]; then + ffmpeg_cmd+=" -i \"$video_file\"" + filter_complex+="[${input_count}:v:0] " + input_count=$((input_count+1)) + fi +done + +filter_complex+="vstack=inputs=$input_count [v]" +ffmpeg_cmd+=" -filter_complex \"$filter_complex\" -map \"[v]\" \"$OUTPUT_DIR/$OUTPUT_FILE\"" + +eval $ffmpeg_cmd + + + +if [ $? -eq 0 ]; then + echo "---->>>> Generated concatenated video: $OUTPUT_DIR/$OUTPUT_FILE" + + for video_file in "${video_files[@]}"; do + if [ -f "$video_file" ]; then + rm "$video_file" + echo "---->>>> Removed video file: $video_file" + fi + done +else + echo "---->>>> FFmpeg command failed. Video files have not been removed." +fi diff --git a/manage-video/video-wizard/4-move-to-input.sh b/manage-video/video-wizard/4-move-to-input.sh new file mode 100755 index 0000000..4b3cd30 --- /dev/null +++ b/manage-video/video-wizard/4-move-to-input.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +INPUT_DIR="./0-multi-input/vertical-0" +OUTPUT_DIR="./3-output" +largest_width=0 +largest_height=0 + +mkdir -p "$INPUT_DIR" + +for video_file in "$OUTPUT_DIR"/*.{mp4,mov,avi,m4v}; do + if [ -f "$video_file" ]; then + filename=$(basename "$video_file") + dimensions=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "$video_file") + width=$(echo "$dimensions" | cut -d ',' -f 1) + height=$(echo "$dimensions" | cut -d ',' -f 2) + + if [ "$width" -gt "$largest_width" ]; then + largest_width=$width + fi + if [ "$height" -gt "$largest_height" ]; then + largest_height=$height + fi + + mv "$video_file" "$INPUT_DIR/$filename" + fi +done + +echo "---->>>> Largest Width Found: $largest_width px" +echo "---->>>> Largest Height Found: $largest_height px" + +echo "---->>>> All video files have been moved from $OUTPUT_DIR to $INPUT_DIR." diff --git a/manage-video/video-wizard/5-metadata.sh b/manage-video/video-wizard/5-metadata.sh new file mode 100755 index 0000000..5106841 --- /dev/null +++ b/manage-video/video-wizard/5-metadata.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +VIDEO="$1" +DESC="$2" + +if [ -z "$VIDEO" ] || [ -z "$DESC" ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ ! -f "$VIDEO" ]; then + echo "Error: file '$VIDEO' not found." + exit 1 +fi + +TMP="${VIDEO%.*}_meta.${VIDEO##*.}" + +ffmpeg -hide_banner -loglevel error \ + -i "$VIDEO" \ + -map 0 \ + -c copy \ + -metadata description="$DESC" \ + -metadata comment="$DESC" \ + "$TMP" + +if [ $? -eq 0 ]; then + mv "$TMP" "$VIDEO" + echo "---->>>> Description added successfully." +else + echo "---->>>> Failed to write metadata." + rm -f "$TMP" +fi diff --git a/manage-video/video-wizard/README b/manage-video/video-wizard/README new file mode 100644 index 0000000..92855b4 --- /dev/null +++ b/manage-video/video-wizard/README @@ -0,0 +1,8 @@ +#How to do a multi row auto convert + +Row files into 0-multi-input separated into folders, optionally prefixed with index_ for particular order +define horizontal settings in run-full-wizard +run run-full-wizard +run 4-move-to-input +configure vertical in run-full-wizard +run run-full-wizard diff --git a/manage-video/video-wizard/run-full-wizard.sh b/manage-video/video-wizard/run-full-wizard.sh new file mode 100755 index 0000000..eba0bab --- /dev/null +++ b/manage-video/video-wizard/run-full-wizard.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +base_dir="./0-multi-input" +TARGET_INPUT="./0-input" +OUTPUT_DIR="./3-output" +DURATION_SECONDS=5 + +#Do horizontal +PROCESS_HORIZONTAL=true +PROCESS_VERTICAL=false +OUTPUT_NAME_HORIZONTAL="tom-lizard-waving.mp4" +HEIGHT=1920 + +#Then do vertical +#PROCESS_HORIZONTAL=false +#PROCESS_VERTICAL=true +OUTPUT_NAME_VERTICAL="tom-lizard-waving.mp4" +WIDTH=7000 + +# Optional description (leave empty to skip) +DESCRIPTION="" + + + + +process_horizontal() { + local dir=$1 + index=$2 + echo "---->>>> Processing horizontal directory: $dir" + + mv "$dir"/* "$TARGET_INPUT"/ + + ./0-convert-gif.sh + ./0-convert-images.sh + ./1-scale-to-height.sh $HEIGHT + ./2-loop.sh $DURATION_SECONDS + ./3-merge-horizontal.sh "${index}_${OUTPUT_NAME_HORIZONTAL}" +} + +process_vertical() { + local dir=$1 + index=$2 + echo "---->>>> Processing vertical directory: $dir" + + mv "$dir"/* "$TARGET_INPUT"/ + + ./0-convert-gif.sh + ./0-convert-images.sh + ./1-scale-to-width.sh $WIDTH + ./2-loop.sh $DURATION_SECONDS + ./3-merge-vertical.sh "${index}_${OUTPUT_NAME_VERTICAL}" +} + +post_horizontal() { + echo "---->>>> Running scripts after processing all horizontal directories..." + + ./4-move-to-input.sh +} + +post_vertical() { + echo "---->>>> Running scripts after processing all vertical directories..." +} + + + +if [ "$PROCESS_HORIZONTAL" = true ]; then +horizontal_index=0 +echo "---->>>> Processing all horizontal directories..." +for dir in "$base_dir"/horizontal*/; do + if [ -d "$dir" ] && [ -n "$(find "$dir" -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.m4v" \) -print -quit)" ]; then + process_horizontal "$dir" "$horizontal_index" + + fi + + ((horizontal_index++)) +done +fi + +# Call scripts after processing all horizontal directories +#post_horizontal + + + +if [ "$PROCESS_VERTICAL" = true ]; then +vertical_index=0 +echo "---->>>> Processing all vertical directories..." +for dir in "$base_dir"/vertical*/; do + if [ -d "$dir" ] && [ -n "$(find "$dir" -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.m4v" \) -print -quit)" ]; then + process_vertical "$dir" "$vertical_index" + + fi + + ((vertical_index++)) +done +fi + +# Call scripts after processing all vertical directories +#post_vertical + + + +if [ -n "$DESCRIPTION" ]; then + for vid in "$OUTPUT_DIR"/*.{mp4,mkv,mov,webm}; do + ./5-metadata.sh "$vid" "$DESCRIPTION" + done +fi + +echo "---->>>> All processing complete." diff --git a/add-prefix-to-file.md b/misc/add-prefix-to-file.md similarity index 100% rename from add-prefix-to-file.md rename to misc/add-prefix-to-file.md diff --git a/bring-files-up-one-dir.md b/misc/bring-files-up-one-dir.md similarity index 100% rename from bring-files-up-one-dir.md rename to misc/bring-files-up-one-dir.md diff --git a/bulk-move.md b/misc/bulk-move.md similarity index 100% rename from bulk-move.md rename to misc/bulk-move.md diff --git a/ffmpeg.md b/misc/ffmpeg.md similarity index 100% rename from ffmpeg.md rename to misc/ffmpeg.md diff --git a/find-short-videos.md b/misc/find-short-videos.md similarity index 100% rename from find-short-videos.md rename to misc/find-short-videos.md diff --git a/metadata-stuff.md b/misc/metadata-stuff.md similarity index 100% rename from metadata-stuff.md rename to misc/metadata-stuff.md diff --git a/move-file-into-dir-with-same-name.md b/misc/move-file-into-dir-with-same-name.md similarity index 100% rename from move-file-into-dir-with-same-name.md rename to misc/move-file-into-dir-with-same-name.md diff --git a/move-files-to-year-and-month-dirs.md b/misc/move-files-to-year-and-month-dirs.md similarity index 100% rename from move-files-to-year-and-month-dirs.md rename to misc/move-files-to-year-and-month-dirs.md diff --git a/misc/open-urls-from-file.sh b/misc/open-urls-from-file.sh new file mode 100755 index 0000000..620384b --- /dev/null +++ b/misc/open-urls-from-file.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Path to the text file containing URLs +url_file="open_urls.txt" + +# Check if the file with URLs exists +if [[ ! -f "$url_file" ]]; then + echo "File with URLs not found: $url_file" + exit 1 +fi + +# Iterate over lines in the file and open each URL +while IFS= read -r url; do + ungoogled-chromium --new-tab "$url" +done < "$url_file" + +echo "All URLs have been opened in new tabs." diff --git a/print-all-files-and-folders.md b/misc/print-all-files-and-folders.md similarity index 100% rename from print-all-files-and-folders.md rename to misc/print-all-files-and-folders.md diff --git a/recursively-extract-artist-from-filename.md b/misc/recursively-extract-artist-from-filename.md similarity index 100% rename from recursively-extract-artist-from-filename.md rename to misc/recursively-extract-artist-from-filename.md diff --git a/regex-stuff.md b/misc/regex-stuff.md similarity index 100% rename from regex-stuff.md rename to misc/regex-stuff.md diff --git a/remove-n-chars-from-name.md b/misc/remove-n-chars-from-name.md similarity index 100% rename from remove-n-chars-from-name.md rename to misc/remove-n-chars-from-name.md diff --git a/remove-timestamps.md b/misc/remove-timestamps.md similarity index 100% rename from remove-timestamps.md rename to misc/remove-timestamps.md diff --git a/rename-nested-file-to-parent.md b/misc/rename-nested-file-to-parent.md similarity index 100% rename from rename-nested-file-to-parent.md rename to misc/rename-nested-file-to-parent.md diff --git a/misc/yandex-extract-img-url.sh b/misc/yandex-extract-img-url.sh new file mode 100755 index 0000000..c0f8f2d --- /dev/null +++ b/misc/yandex-extract-img-url.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Validate input +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +input_file="$1" +output_file="$2" +error_file="error_urls.txt" + +# Loop through each URL, extract, decode, and save the 'img_url', with indexing +index=0 +while IFS= read -r line; do + # Increment our index counter + index=$((index+1)) + + # Extract the 'img_url' query parameter + extracted_url=$(echo "$line" | awk -F 'img_url=' '{print $2}' | cut -d'&' -f1 | python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read()));") + + # Save and print the results + if [ -n "$extracted_url" ]; then + echo "$index: $extracted_url" + echo "$extracted_url" >> "$output_file" + else + echo "$index: No 'img_url' found" + echo "$line" >> "$error_file" + fi +done < "$input_file" + diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/all-people-ids.csv b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/all-people-ids.csv new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/asset-ids.txt b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/asset-ids.txt new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/blacklist.txt b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/blacklist.txt new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/central_log.csv b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/central_log.csv new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/find-people-names.txt b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/find-people-names.txt new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-add-assets-to-albums_csv.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-add-assets-to-albums_csv.sh new file mode 100755 index 0000000..83c1aae --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-add-assets-to-albums_csv.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Replace with your actual API endpoint and API key +API_ENDPOINT="http://127.0.0.1:2283/api/albums/assets" +API_KEY="REPLACE" + +HTTP_METHOD="PUT" +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to make the API call +make_api_call() { + # Make sure we actually have CSV values + if [ -z "$1" ] || [ -z "$2" ]; then + echo "Please provide two comma-separated lists: the first for album UUIDs, the second for asset UUIDs." >&2 + return 1 # Exit with an error status + fi + + # Assign the arguments to named variables for clarity + local album_csv="$1" + local asset_csv="$2" + local json_array_albums="[" + local json_array_assets="[" + + # Read CSV for album UUIDs + OLD_IFS="$IFS" # Preserve the original field separator + IFS=',' # Comma becomes the new field separator + set -f # Disable globbing to deal with special characters safely + + # Loop over the album CSV and encase each item in quotes + for album_uuid in $album_csv; do + json_array_albums+=\"${album_uuid}\", + done + + # Loop over the asset CSV and encase each item in quotes + for asset_uuid in $asset_csv; do + json_array_assets+=\"${asset_uuid}\", + done + + set +f # Re-enable globbing + IFS="$OLD_IFS" # Restore the original field separator + + # Chop off those pesky trailing commas and close the JSON arrays + json_array_albums="${json_array_albums%,}]" + json_array_assets="${json_array_assets%,}]" + + # Now we've got a JSON structure + local data="{\"albumIds\":$json_array_albums,\"assetIds\":$json_array_assets}" + + # Use a temp file to capture the response + temp_file=$(mktemp) + http_status=$(curl -X "$HTTP_METHOD" \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data "$data" \ + "$API_ENDPOINT" -s -o "$temp_file" -w "%{http_code}") + + response_body=$(cat "$temp_file") + + # Check the response + if [ "$http_status" -eq 200 ]; then + echo "API call was successful! πŸš€" + + # Clean up after ourselves + rm -f "$temp_file" + else + echo "API call failed with status $http_status 🀭" + fi +} + +# Check for input argument +if [ $# -lt 2 ]; then + echo "Usage: $0 \"album1,album2,...\" \"asset1,asset2,...\"" >&2 + exit 1 +fi + +ALBUM_IDS=$1 +ASSET_IDS=$2 + +# Make the API call with the CSV input turned directly into a JSON payload +make_api_call "$ALBUM_IDS" "$ASSET_IDS" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-add-assets-to-albums_file.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-add-assets-to-albums_file.sh new file mode 100755 index 0000000..273978c --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-add-assets-to-albums_file.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Replace with your actual API endpoint and API key +API_ENDPOINT="http://127.0.0.1:2283/api/albums/assets" +API_KEY="REPLACE" +HTTP_METHOD="PUT" +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to make the API call +make_api_call() { + local album_csv="$1" + local asset_file="$2" + local json_array_albums="[" + local json_array_assets="[" + local temp_file=$(mktemp) + + # Check if asset file exists and is readable + if [ ! -r "$asset_file" ]; then + echo "Asset file does not exist or is not readable. πŸ€·β€β™‚οΈ" >&2 + return 1 # Exit with an error status + fi + + # Loop over the album CSV and encase each item in quotes + OLD_IFS="$IFS" # Preserve the original field separator + IFS=',' # Comma becomes the new field separator + + for album_uuid in $album_csv; do + json_array_albums+=\"${album_uuid}\", + done + + IFS="$OLD_IFS" # Restore the original field separator + json_array_albums="${json_array_albums%,}]" # Remove trailing comma + + # Read UUIDs from asset file and build json array + while IFS= read -r asset_uuid; do + json_array_assets+=\"${asset_uuid}\", + done < "$asset_file" + json_array_assets="${json_array_assets%,}]" # Remove trailing comma + + # Create the JSON payload + local data="{\"albumIds\":$json_array_albums,\"assetIds\":$json_array_assets}" + + # Make the API call and capture the HTTP status code + http_status=$(curl -X "$HTTP_METHOD" \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data "$data" \ + "$API_ENDPOINT" -s -o "$temp_file" -w "%{http_code}") + + # Output the response + response_body=$(cat "$temp_file") + if [ "$http_status" -eq 200 ]; then + echo "API call was successful! Asset IDs from '$asset_file' have been associated with albums '$album_csv'. πŸš€" + else + echo "API call failed with status $http_status. Here's the response: $response_body πŸ€”" + fi + + # Clean up + rm -f "$temp_file" +} + +# Check for input arguments +if [ $# -lt 2 ]; then + echo "Usage: $0 \"album1,album2,...\" /path/to/assetids.txt" >&2 + exit 1 +fi + +ALBUM_IDS=$1 +ASSET_FILE=$2 + +# Make the API call with the CSV input turned directly into a JSON payload +make_api_call "$ALBUM_IDS" "$ASSET_FILE" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-clear-album.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-clear-album.sh new file mode 100755 index 0000000..e5ac665 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-clear-album.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# Replace with your actual API endpoint and API key +API_ENDPOINT="http://127.0.0.1:2283/api/albums" +API_KEY="REPLACE" + +HTTP_METHOD="DELETE" +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to make the API call +make_api_call() { + # Make sure we actually have CSV values + if [ -z "$2" ]; then + echo "No album-id and CSV values provided. Please provide a comma-separated list of UUIDs." >&2 + return + fi + + # Create a JSON array from the CSV string + album_id="$1" + csv_values="$2" + json_array="[" + + OLD_IFS="$IFS" + IFS=',' # Comma is our new separator + # POSIX compliant way to split a string into an array + set -f # Disable globbing + set -- $csv_values + set +f # Enable globbing again + IFS="$OLD_IFS" # Restore IFS + + for i; do # Loop over positional parameters + json_array="$json_array\"$i\"," + done + + # Remove the trailing comma and close the array + json_array="${json_array%,}]" + + # Now we've got a JSON array + data="{\"ids\":$json_array}" + + # Use a temp file to capture the response + temp_file=$(mktemp) + http_status=$(curl -X "$HTTP_METHOD" \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data "$data" \ + "$API_ENDPOINT/${album_id}/assets" -s -o "$temp_file" -w "%{http_code}") + + response_body=$(cat "$temp_file") + + # Check the response + if [ "$http_status" -eq 200 ]; then + echo "API call was successful! πŸš€" + + # Clean up after ourselves + rm -f "$temp_file" + else + echo "API call failed with status $http_status 🀭" + fi +} + +# Check for input argument +if [ $# -lt 2 ]; then + echo "Usage: $0 \"album-id\" \"value1,value2,value3,...\"" >&2 + exit 1 +fi + +ALBUM_ID=$1 +CSV_INPUT=$2 + +# Make the API call with the CSV input turned directly into a JSON payload +make_api_call "$ALBUM_ID" "$CSV_INPUT" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-delete-assets.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-delete-assets.sh new file mode 100755 index 0000000..9f4b7c8 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-delete-assets.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# Replace with your actual API endpoint and API key +API_ENDPOINT="http://127.0.0.1:2283/api/assets" +API_KEY="REPLACE" + +HTTP_METHOD="DELETE" +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to make the API call +make_api_call() { + # Make sure we actually have CSV values + if [ -z "$1" ]; then + echo "Please provide a comma-separated list for album UUIDs." >&2 + return 1 # Exit with an error status + fi + + # Assign the arguments to named variables for clarity + local asset_csv="$1" + local json_array_assets="[" + + # Read CSV for album UUIDs + OLD_IFS="$IFS" # Preserve the original field separator + IFS=',' # Comma becomes the new field separator + set -f # Disable globbing to deal with special characters safely + + # Loop over the album CSV and encase each item in quotes + for asset_uuid in $asset_csv; do + json_array_assets+=\"${asset_uuid}\", + done + + set +f # Re-enable globbing + IFS="$OLD_IFS" # Restore the original field separator + + # Chop off those pesky trailing commas and close the JSON arrays + json_array_assets="${json_array_assets%,}]" + + # Now we've got a JSON structure + local data="{\"ids\":$json_array_assets}" + + # Use a temp file to capture the response + temp_file=$(mktemp) + http_status=$(curl -X "$HTTP_METHOD" \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data "$data" \ + "$API_ENDPOINT" -s -o "$temp_file" -w "%{http_code}") + + response_body=$(cat "$temp_file") + + # Check the response + if [ "$http_status" -eq 204 ]; then + echo "API call was successful! πŸš€" + + # Clean up after ourselves + rm -f "$temp_file" + else + echo "API call failed with status $http_status 🀭" + fi +} + +# Check for input argument +if [ $# -lt 1 ]; then + echo "Usage: $0 \"asset1,asset1,...\"" >&2 + exit 1 +fi + +ASSET_IDS=$1 + +# Make the API call with the CSV input turned directly into a JSON payload +make_api_call "$ASSET_IDS" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-album-asset-ids.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-album-asset-ids.sh new file mode 100755 index 0000000..2839bf6 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-album-asset-ids.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# Replace these with your actual API endpoint and credentials +API_ENDPOINT_BASE="http://127.0.0.1:2283/api/albums" +API_KEY="REPLACE" + +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to fetch asset IDs for a given album id +fetch_asset_ids() { + album_id=$1 + response=$(curl -X GET \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + "$API_ENDPOINT_BASE/$album_id" -s -o response.txt -w "%{http_code}") + + if [ "$response" -eq 200 ]; then + asset_ids=$(jq -r '.assets[].id' response.txt | paste -sd, -) + + if [ -n "$asset_ids" ]; then + echo "$asset_ids" + else + echo "No assets found for album ID $album_id." >&2 + exit 1 + fi + else + echo "API call failed with status $response. Response body:" >&2 + cat response.txt >&2 + exit 1 + fi + + # Clean up the response file + rm -f response.txt +} + +# Check for input argument +if [ $# -lt 1 ]; then + echo "Usage: $0 album_id" >&2 + exit 1 +fi + +ALBUM_ID=$1 + +# Get asset IDs as CSV +fetch_asset_ids "$ALBUM_ID" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-all-people.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-all-people.sh new file mode 100755 index 0000000..54b64f6 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-all-people.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +API_ENDPOINT_BASE="http://127.0.0.1:2283/api/people" +API_KEY="REPLACE" + +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +fetch_assets() { + page=$1 + response=$(curl -G \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data-urlencode "size=1000" \ + --data-urlencode "page=$page" \ + "$API_ENDPOINT_BASE" -s -o response.txt -w "%{http_code}") + + if [ "$response" -eq 200 ]; then + people_ids=$(jq -r '.people[] | .id' response.txt | paste -sd, -) + + if [ -n "$people_ids" ]; then + echo "$people_ids" + else + echo "No people found on page $page" >&2 + exit 1 + fi + else + echo "API call failed with status $response. Check out the mess:" >&2 + cat response.txt >&2 + exit 1 + fi + + # Clean up after the party's over + rm -f response.txt +} + + +N=150000 # Limit of asset IDs +X=123 # Maximum page number to fetch +counter=0 +page=1 # Start from page 1 +people_ids_csv="" + +OUTPUT_CSV="all-people-ids.csv" + +while (( counter < N )) && (( page <= X )); do + ids=$(fetch_assets $page) + + if [ -z "$ids" ]; then + break # If no IDs are returned, exit the loop + fi + + echo "${ids}," >> "$OUTPUT_CSV" + # Count the number of IDs fetched + ids_count=$(grep -o ',' <<< "$ids" | wc -l) + ((ids_count++)) # Add one because the last asset ID does not have a trailing comma + ((counter+=ids_count)) + + echo "Fetched $ids_count/$N people on page $page/$X" + + if (( counter >= N )); then + break # If we've hit or exceeded N, break the loop + fi + ((page++)) # Increment page number +done + diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-asset-filenames-csv.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-asset-filenames-csv.sh new file mode 100755 index 0000000..b9d0c9f --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-asset-filenames-csv.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Replace these with your actual API endpoint and credentials +API_ENDPOINT_BASE="http://127.0.0.1:2283/api/assets" +API_KEY="REPLACE" + +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to fetch the original filename for a given asset ID +fetch_original_filename() { + local asset_id=$1 + local response=$(curl -X GET \ + -H "$AUTH_HEADER" \ + "$API_ENDPOINT_BASE/$asset_id" -s -o response.txt -w "%{http_code}") + + if [ "$response" -eq 200 ]; then + local original_filename=$(jq -r '.originalFileName' response.txt) + echo "$original_filename" + else + echo "API call failed for asset ID $asset_id with status $response. Drama unfolds:" >&2 + cat response.txt >&2 + exit 1 + fi + + # Cleanup the stage after the show + rm -f response.txt +} + + + +#ASSET_ID_CSV="$1" + +# Check if the asset ID CSV string is provided +#if [ -z "$ASSET_ID_CSV" ]; then +# echo "Please provide a comma-separated list of asset IDs." >&2 +# exit 1 +#fi + +ASSET_ID_CSV=$1 + +# Convert CSV string into an array +IFS=',' read -r -a asset_ids < $ASSET_ID_CSV + +# Concatenate original filenames +original_filenames="" + +for asset_id in "${asset_ids[@]}"; do + original_filenames+="$(fetch_original_filename "$asset_id")"$'\n' +done + +# Curtain call! Here are the filenames. +echo "$original_filenames" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-asset-metadata.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-asset-metadata.sh new file mode 100755 index 0000000..1e86666 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-asset-metadata.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# Replace these with your actual API endpoint and credentials +API_ENDPOINT_BASE="http://127.0.0.1:2283/api/assets" +API_KEY="REPLACE" + +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to fetch asset IDs for a given album id +fetch_asset_metadata() { + asset_id=$1 + response=$(curl -X GET \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + "$API_ENDPOINT_BASE/$asset_id/metadata" -s -o response.txt -w "%{http_code}") + + if [ "$response" -eq 200 ]; then + cat response.txt + else + echo "API call failed with status $response. Response body:" >&2 + cat response.txt >&2 + exit 1 + fi + + # Clean up the response file + # rm -f response.txt +} + +# Check for input argument +if [ $# -lt 1 ]; then + echo "Usage: $0 asset_id" >&2 + exit 1 +fi + +ASSET_ID=$1 + +fetch_asset_metadata "$ASSET_ID" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-bucket.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-bucket.sh new file mode 100755 index 0000000..a7d372a --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-bucket.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +API_ENDPOINT_BASE="http://127.0.0.1:2283/api/timeline/bucket" +API_KEY="REPLACE" + +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +fetch_assets() { + person_id=$1 + time_bucket=$2 + response=$(curl -G \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data-urlencode "personId=$person_id" \ + --data-urlencode "timeBucket=$time_bucket" \ + "$API_ENDPOINT_BASE" -s -o response.txt -w "%{http_code}") + + if [ "$response" -eq 200 ]; then + asset_ids=$(jq -r '.id[]' response.txt | paste -sd, -) + + if [ -n "$asset_ids" ]; then + echo "$asset_ids" + else + echo "No assets found for person ID $person_id and time bucket $time_bucket." >&2 + exit 1 + fi + else + echo "API call failed with status $response. Check out the mess:" >&2 + cat response.txt >&2 + exit 1 + fi + + # Clean up after the party's over + rm -f response.txt +} + + +# Check for input argument +if [ $# -lt 2 ]; then + echo "Usage: $0 person_id time_bucket_csv" >&2 + exit 1 +fi + +PERSON_ID=$1 +TIME_BUCKET_CSV=$2 + +time_buckets=() +asset_ids_csv="" +N=500 +counter=0 + +# Convert the string to an array using a classic IFS (Internal Field Separator) and read loop +OIFS=$IFS +IFS=',' # Set comma as delimiter +# Read the string into an array as tokens separated by IFS +for time_bucket in $TIME_BUCKET_CSV; do + time_buckets+=("$time_bucket") +done +IFS=$OIFS # Reset IFS to its original value + +# Iterate over each time bucket and fetch assets +for time_bucket in "${time_buckets[@]}"; do + if (( counter < N )); then + assets=$(fetch_assets $PERSON_ID $time_bucket) + asset_ids_csv+="${assets}," + # Increment counter by the number of assets fetched + asset_count=$(grep -o ',' <<< "$assets" | wc -l) + ((asset_count++)) # add one because the last asset ID does not have a trailing comma + ((counter+=asset_count)) + else + break # Break the loop like you’re breaking out of Alcatraz + fi +done + +# Trim the trailing comma, because neatness counts +asset_ids_csv="${asset_ids_csv%,}" + +# Output the concatenated asset IDs with finesse +echo "$asset_ids_csv" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-buckets.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-buckets.sh new file mode 100755 index 0000000..cf530df --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-buckets.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Replace these with your actual API endpoint and credentials +API_ENDPOINT_BASE="http://127.0.0.1:2283/api/timeline/buckets" +API_KEY="REPLACE" + +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to fetch asset IDs for a given album id +fetch_asset_ids() { + person_id=$1 + response=$(curl -X GET \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + "$API_ENDPOINT_BASE?personId=$person_id" -s -o response.txt -w "%{http_code}") + + if [ "$response" -eq 200 ]; then + asset_ids=$(jq -r '.[].timeBucket' response.txt | paste -sd, -) + + if [ -n "$asset_ids" ]; then + echo "$asset_ids" + else + echo "No assets found for album ID $album_id." >&2 + exit 1 + fi + else + echo "API call failed with status $response. Response body:" >&2 + cat response.txt >&2 + exit 1 + fi + + # Clean up the response file + rm -f response.txt +} + +# Check for input argument +if [ $# -lt 1 ]; then + echo "Usage: $0 person_id" >&2 + exit 1 +fi + +PERSON_ID=$1 + +# Get asset IDs as CSV +fetch_asset_ids "$PERSON_ID" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-people-assets-names-pipeline-bulk.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-people-assets-names-pipeline-bulk.sh new file mode 100755 index 0000000..e80f0c5 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-people-assets-names-pipeline-bulk.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Check for the CSV of person IDs +if [ "$#" -ne 1 ]; then + echo "Usage: $0 [path_to_csv_of_person_ids]" >&2 + exit 1 +fi + +CSV_PATH="$1" + +# Make sure the CSV file exists +if [ ! -f "$CSV_PATH" ]; then + echo "CSV file not found!" + exit 1 +fi + +# Prepare your final CSV masterpiece +OUTPUT_CSV="sorted_names.csv" +counter=0 + +# Let's check if the file exists +if [ ! -f "$OUTPUT_CSV" ]; then + # It doesn't exist, so let's be all neat and formal and create a new file with a header + echo "person_id,first_name,second_name,other_top_words" > "$OUTPUT_CSV" +else + # The file exists, do a little celebration and move on to append without adding the header again + : # The no-op command because we don’t actually need to do anything here +fi + +# Start looping through that CSV +while IFS= read -r person_id; do + ((counter++)) + # Ignore empty lines + if [ -z "$person_id" ]; then + continue + fi + + echo "Grabbing Person $counter with ID $person_id" + + echo " Get Timeline Buckets" + + # The script assumes immich-get-buckets.sh and others output CSV format + TIME_BUCKETS_CSV=$(sh immich-get-buckets.sh "$person_id") + + echo " Get Assets in buckets" + + bash immich-get-bucket.sh "$person_id" "$TIME_BUCKETS_CSV" > asset-ids.txt + + echo " Get asset filenames" + + #bash immich-get-asset-filenames-csv.sh "$ASSET_IDS_CSV" > sort-names.txt + bash immich-get-asset-filenames-csv.sh asset-ids.txt > sort-names.txt + + echo " Sorting words" + + # Get the top words, assumes top 10 for example + mapfile -t top_words < <(./sort-words.sh sort-names.txt | awk '{print $2}' | head -n 10) + + # Process the words if we have at least one +if (( ${#top_words[@]} < 1 )); then + echo "⚠️ No names found for person ID: $person_id." + continue +fi + +first_name="${top_words[0]}" +first_name_capitalized="$(tr '[:lower:]' '[:upper:]' <<< ${first_name:0:1})${first_name:1}" + +# Only process the second name if it exists +if (( ${#top_words[@]} > 1 )); then + second_name="${top_words[1]}" + second_name_capitalized="$(tr '[:lower:]' '[:upper:]' <<< ${second_name:0:1})${second_name:1}" +else + second_name="" + second_name_capitalized="" +fi + + # Gather the rest of the words, if any + other_top_words="${top_words[*]:2}" + other_top_words_csv=$(echo "$other_top_words" | tr ' ' ',') + + echo " Add '$first_name_capitalized $second_name_capitalized'" + echo + + # Append to your CSV file + echo "http://127.0.0.1:2283/people/$person_id,$first_name_capitalized,$second_name_capitalized,\"$other_top_words_csv\"" >> "$OUTPUT_CSV" + +done < "$CSV_PATH" + +# Cue the applause +echo "All done! Check the sorted names in $OUTPUT_CSV" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-people-assets-names-pipeline.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-people-assets-names-pipeline.sh new file mode 100755 index 0000000..fc8c7ab --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-get-people-assets-names-pipeline.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Check for the person ID argument +if [ "$#" -ne 1 ]; then + echo "Usage: $0 [person_id]" >&2 + exit 1 +fi + +PERSON_ID="$1" + +# Call the immich-get-buckets script to retrieve the timeBuckets csv +TIME_BUCKETS_CSV=$(sh immich-get-buckets.sh "$PERSON_ID") + +# Sanity check - did we get the time buckets? +if [ -z "$TIME_BUCKETS_CSV" ]; then + echo "Failed to retrieve time buckets." + exit 1 +fi + +# Call the immich-get-assets script with the timeBuckets csv +ASSET_IDS_CSV=$(bash immich-get-bucket.sh "$PERSON_ID" "$TIME_BUCKETS_CSV") + +# Sanity check - did we get the asset IDs? +if [ -z "$ASSET_IDS_CSV" ]; then + echo "Failed to retrieve asset IDs." + exit 1 +fi + +ASSET_NAMES=$(bash immich-get-asset-filenames-csv.sh "$ASSET_IDS_CSV") + +# Ta-da! The output is here. +echo "$ASSET_NAMES" +echo "------" +echo -e "$ASSET_NAMES" | ./sort-words.sh diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-stack-images.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-stack-images.sh new file mode 100755 index 0000000..6c4c2b1 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-stack-images.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# Replace with your actual API endpoint and API key +API_ENDPOINT="http://127.0.0.1:2283/api/stacks" +API_KEY="REPLACE" + +HTTP_METHOD="POST" +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to make the API call +make_api_call() { + # Make sure we actually have CSV values + if [ -z "$1" ]; then + echo "No CSV values provided. Please provide a comma-separated list of UUIDs." >&2 + return + fi + + # Create a JSON array from the CSV string + csv_values="$1" + json_array="[" + + OLD_IFS="$IFS" + IFS=',' # Comma is our new separator + # POSIX compliant way to split a string into an array + set -f # Disable globbing + set -- $csv_values + set +f # Enable globbing again + IFS="$OLD_IFS" # Restore IFS + + for i; do # Loop over positional parameters + json_array="$json_array\"$i\"," + done + + # Remove the trailing comma and close the array + json_array="${json_array%,}]" + + # Now we've got a JSON array + data="{\"assetIds\":$json_array}" + + # Use a temp file to capture the response + temp_file=$(mktemp) + http_status=$(curl -X "$HTTP_METHOD" \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data "$data" \ + "$API_ENDPOINT" -s -o "$temp_file" -w "%{http_code}") + + response_body=$(cat "$temp_file") + + # Check the response + if [ "$http_status" -eq 201 ]; then + echo "API call was successful! πŸš€" + + # Clean up after ourselves + rm -f "$temp_file" + else + echo "API call failed with status $http_status 🀭" + fi +} + +# Check for input argument +if [ $# -lt 1 ]; then + echo "Usage: $0 \"value1,value2,value3,...\"" >&2 + exit 1 +fi + +CSV_INPUT=$1 + +# Make the API call with the CSV input turned directly into a JSON payload +make_api_call "$CSV_INPUT" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-update-assets.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-update-assets.sh new file mode 100755 index 0000000..3beb246 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/immich-update-assets.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# Replace with your actual API endpoint and API key +API_ENDPOINT="http://127.0.0.1:2283/api/assets" +API_KEY="REPLACE" + +HTTP_METHOD="PUT" +CONTENT_TYPE="Content-Type: application/json" +AUTH_HEADER="x-api-key: $API_KEY" + +# Function to make the API call +make_api_call() { + # Make sure we actually have CSV values + if [ -z "$1" ]; then + echo "No CSV values provided. Please provide a comma-separated list of UUIDs." >&2 + return + fi + + # Create a JSON array from the CSV string + description="$1" + csv_values="$2" + json_array="[" + + OLD_IFS="$IFS" + IFS=',' # Comma is our new separator + # POSIX compliant way to split a string into an array + set -f # Disable globbing + set -- $csv_values + set +f # Enable globbing again + IFS="$OLD_IFS" # Restore IFS + + for i; do # Loop over positional parameters + json_array="$json_array\"$i\"," + done + + # Remove the trailing comma and close the array + json_array="${json_array%,}]" + + # Now we've got a JSON array + data="{\"ids\":$json_array,\"description\":\"$description\"}" + + # Use a temp file to capture the response + temp_file=$(mktemp) + http_status=$(curl -X "$HTTP_METHOD" \ + -H "$CONTENT_TYPE" \ + -H "$AUTH_HEADER" \ + --data "$data" \ + "$API_ENDPOINT" -s -o "$temp_file" -w "%{http_code}") + + response_body=$(cat "$temp_file") + + # Check the response + if [ "$http_status" -eq 204 ]; then + echo "API call was successful! πŸš€" + + # Clean up after ourselves + rm -f "$temp_file" + else + echo "API call failed with status $http_status 🀭" + fi +} + +# Check for input argument +if [ $# -lt 2 ]; then + echo "Usage: $0 \"description\" \"value1,value2,value3,...\"" >&2 + exit 1 +fi + +DESCRIPTION=$1 +CSV_INPUT=$2 + +# Make the API call with the CSV input turned directly into a JSON payload +make_api_call "$DESCRIPTION" "$CSV_INPUT" diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/jellyfin-find-movie.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/jellyfin-find-movie.sh new file mode 100755 index 0000000..acc44e5 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/jellyfin-find-movie.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Endpoint and API Key Constants +JELLYFIN_SERVER="http://127.0.0.1:8096" +API_KEY="REPLACE" +USER_ID="REPLACE" + +# Input Variables +item_name=$1 + +# Check for required arguments +if [ -z "$item_name" ]; then + echo "Usage: $0 {item-name}" + exit 1 +fi + +encoded_item_name=$(jq -nr --arg name "$item_name" '$name|@uri') + +# Fetch the current item details +response=$(curl -s -o response.txt -w "%{http_code}" -X GET "${JELLYFIN_SERVER}/Users/${USER_ID}/Items?searchTerm=${encoded_item_name}&Recursive=true&limit=2&collectionType=movies" \ + -H "X-Emby-Token: ${API_KEY}") + +# Validate the response and the number of items +if [ "$response" -ne 200 ]; then + echo "Failed to retrieve items. HTTP status: $response" >&2 + exit 1 +fi + +# Parse the JSON to count items returned +items_count=$(jq '.TotalRecordCount' response.txt | paste -sd, -) + +# Check for the exact number of items +if [ "$items_count" -ne 1 ]; then + echo "Expected exactly one item, but found $items_count." >&2 +fi + +# Extract the item ID +item_id=$(jq -r '.Items[0].Id' response.txt | paste -sd, -) + +echo "$item_id" # Output the item ID + +rm response.txt # Clean up the response_body file + diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/jellyfin-immich-facial-recognition-pipeline.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/jellyfin-immich-facial-recognition-pipeline.sh new file mode 100755 index 0000000..4d1e25a --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/jellyfin-immich-facial-recognition-pipeline.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Define the central CSV file where the results will be stored +CENTRAL_CSV="central_log.csv" +SCRIPT_PATH="." + +counter=1 + +# Function to log the results to the central CSV +log_to_csv() { + local path="$1" + local movie_name="$2" + local asset_csv="$3" + local jellyfin_url="$4" + local error_msg="$5" + + echo "\"$path\",\"$movie_name\",\"$asset_csv\",\"$jellyfin_url\",\"$error_msg\"" >> "$CENTRAL_CSV" +} + +( + echo "Path,Movie Name,Asset CSV,Jellyfin URL,Error" > "$CENTRAL_CSV" + + # Traverse all folders and subfolders + #find . -type d \( -name "Youtube" -prune \) -o \( -type d -print \) | while read -r media_folder; do + find "/path" -type d | while read -r media_folder; do + echo "Processing media folder #$counter: $media_folder" + ((counter++)) + + cd "$media_folder" || { echo "Failed to enter $media_folder"; continue; } + + # Check for nested ".trickplay" folders and operate + find . -maxdepth 1 -name '*.trickplay' -type d | while read -r trickplay_folder; do + echo " - Trickplay Folder: $trickplay_folder" + echo " - Running immich upload" + + # Step 1: Execute Immich upload + immich upload --ignore "**/*.{mp4,avi,mkv}" --album-name "#TEMP - Stack 'em" --recursive "." + immich upload --ignore "**/*.{mp4,avi,mkv}" --album-name "#TEMP - Trickplay Facial Recognition" --recursive "." + + echo " - Waiting 3 seconds.." + + sleep 3 + + echo " - Running immich-get-album-asset-ids.sh" + + # Step 2: Get Asset IDs CSV from Immich + asset_csv=$(sh $SCRIPT_PATH/immich-get-album-asset-ids.sh "REPLACE") + + echo " - Running immich-stack-images.sh" + + # Step 3: Stack images + sh $SCRIPT_PATH/immich-stack-images.sh "$asset_csv" + + echo " - Running immich-clear-album.sh" + + # Step 4: Clear the album + sh $SCRIPT_PATH/immich-clear-album.sh "REPLACE" "$asset_csv" + + echo " - Running jellyfin-find-movie.sh" + + # Step 5: Find the Jellyfin movie and get the media ID + movie_name=$(basename "$trickplay_folder" .trickplay | sed -E "s/ \[[0-9]+p\]$//") + + echo " Movie Name: $movie_name" + + jellyfin_media_id=$(sh $SCRIPT_PATH/jellyfin-find-movie.sh "$movie_name") + + echo " - Running immich-update-assets.sh" + + # Step 6: Update Immich assets with the Jellyfin URL and movie folder path +full_path=$(realpath "$trickplay_folder") +description="http://127.0.0.1:8096/web/#/details?id=$jellyfin_media_id&serverId=REPLACE\n\nFull path: $full_path" +sh $SCRIPT_PATH/immich-update-assets.sh "$description" "$asset_csv" + + echo " - Add to logs" + + # Step 7: Log to central CSV + log_to_csv "$full_path" "$movie_name" "$asset_csv" "$jellyfin_url" + + echo " - DONE" + echo + echo + echo + done + + # Go back to the parent directory + cd - > /dev/null || { echo "Failed to go back to the parent directory from $media_folder"; continue; } + done +) 2>&1 | tee -a "script_log.txt" + diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/quarantine_assets_ids.txt b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/quarantine_assets_ids.txt new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/script_log.txt b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/script_log.txt new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sort-names.txt b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sort-names.txt new file mode 100644 index 0000000..e69de29 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sort-words.sh b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sort-words.sh new file mode 100755 index 0000000..17201d8 --- /dev/null +++ b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sort-words.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +FILE_PATH=$1 + +# Declare an array of unwelcome strings +declare -a blacklist=("" "") + +# Now accepting your strings of wisdom from the standard input. +cat "$FILE_PATH" | tr '[:upper:]' '[:lower:]' | tr -c '[:alnum:]' '\n' | +# Exorcise the blacklisted words from your midst. +grep -vFf <(printf "%s\n" "${blacklist[@]}") | +# Remove everything with less than 3 chars +grep -E "^[a-zA-Z].{2,}$" | +# Remove everything thats numbers only +grep -Ev "^[0-9]+$" | +# Sort the words like you're organizing some kind of lexical yard sale. +sort | +# Count occurrences like you're taking attendance at word school. +uniq -c | +# Sort them by popularity because it's a popularity contest for words. +sort -nr | +# Only let the top X through because we're exclusive like that. +head -n 10 diff --git a/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sorted_names.csv b/old-stupid-and-overcomplicated/jellyfin-immich-facial-recognition-pipeline/sorted_names.csv new file mode 100644 index 0000000..e69de29 diff --git a/usr-local-bin/cutfrom b/usr-local-bin/cutfrom deleted file mode 100644 index ca1f9bb..0000000 --- a/usr-local-bin/cutfrom +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 01:37:18" - exit 1 -fi - -VIDEO_FILE=$(ls *.mp4 | head -n 1) - -if [ -z "$VIDEO_FILE" ]; then - echo "No .mp4 files found in the current directory." - exit 1 -fi - -echo "Video File: ${VIDEO_FILE}" - -TIMESTAMP="$1" -OUTPUT_DIR="target" -OUTPUT_FILE="${OUTPUT_DIR}/${VIDEO_FILE}" - -mkdir -p "${OUTPUT_DIR}" - -ffmpeg -i "${VIDEO_FILE}" -ss "${TIMESTAMP}" -c copy -avoid_negative_ts 1 "${OUTPUT_FILE}" - -echo "Cut complete! Output is in ${OUTPUT_FILE}" diff --git a/usr-local-bin/cutto b/usr-local-bin/cutto deleted file mode 100644 index 6164bd1..0000000 --- a/usr-local-bin/cutto +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 01:37:18" - exit 1 -fi - -VIDEO_FILE=$(ls *.mp4 | head -n 1) - -if [ -z "$VIDEO_FILE" ]; then - echo "No .mp4 files found in the current directory." - exit 1 -fi - -echo "Video File: ${VIDEO_FILE}" - -TIMESTAMP="$1" -OUTPUT_DIR="target" -OUTPUT_FILE="${OUTPUT_DIR}/${VIDEO_FILE}" - -mkdir -p "${OUTPUT_DIR}" - -ffmpeg -i "${VIDEO_FILE}" -to "${TIMESTAMP}" -c copy -map 0 "${OUTPUT_FILE}" - -echo "Cut complete! Output is in ${OUTPUT_FILE}" diff --git a/usr-local-bin/getres b/usr-local-bin/getres deleted file mode 100644 index 40a4825..0000000 --- a/usr-local-bin/getres +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 video_file" - exit 1 -fi - -VIDEO_FILE="$1" - -RESOLUTION=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$VIDEO_FILE") - -HEIGHT=$(echo $RESOLUTION | cut -d'x' -f2) - -classify_resolution() { - local HEIGHT="$1" - - # Classify based on height - if (( HEIGHT >= 4320 )); then - echo "4320p" - elif (( HEIGHT >= 2160 )); then - echo "2160p" - elif (( HEIGHT >= 1080 )); then - echo "1080p" - elif (( HEIGHT >= 720 )); then - echo "720p" - elif (( HEIGHT >= 480 )); then - echo "480p" - elif (( HEIGHT >= 360 )); then - echo "360p" - elif (( HEIGHT >= 240 )); then - echo "240p" - else - echo "Unknown resolution" - fi -} - -CLASSIFICATION=$(classify_resolution "$HEIGHT") - -echo "Resolution: $RESOLUTION" -echo "Resolution classification: $CLASSIFICATION" - -BASENAME=$(basename "$VIDEO_FILE") -BASENAME_NO_EXT="${BASENAME%.*}" -EXTENSION="${BASENAME##*.}" -NEW_FILENAME="${BASENAME_NO_EXT} [${CLASSIFICATION}].${EXTENSION}" - -echo "Renaming '$VIDEO_FILE' to '$NEW_FILENAME'" - -mv "$VIDEO_FILE" "$NEW_FILENAME" diff --git a/usr-local-bin/getresauto b/usr-local-bin/getresauto deleted file mode 100644 index 82b5441..0000000 --- a/usr-local-bin/getresauto +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -classify_resolution() { - local HEIGHT="$1" - - case "$HEIGHT" in - [7-9]*|6[4-9]*) - echo "4320p" - ;; - [3-5]*|21[6-9]*|2[2-9]*) - echo "2160p" - ;; - 1[0-8]*|19[0-7]*) - echo "1080p" - ;; - [8-9]*|7[0-1]*) - echo "720p" - ;; - 4[8-9]*|[5-6]*) - echo "480p" - ;; - 3[6-9]*) - echo "360p" - ;; - 2[4-9]*) - echo "240p" - ;; - *) - echo "Unknown" - ;; - esac -} - -read -p "This will automatically classify and rename the resolution for all nested files in the current dir. Continue? [Y/n] " -n 1 -r -echo - -if [[ $REPLY =~ ^[Yy]$ ]]; then - find . -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.wmv" \) -print0 | while IFS= read -r -d '' VIDEO_FILE; do - - echo "-----------------------------" - echo "Processing file: $VIDEO_FILE" - - RESOLUTION=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 -i "$VIDEO_FILE") - HEIGHT=$(echo $RESOLUTION | cut -d'x' -f2) - CLASSIFICATION=$(classify_resolution "$HEIGHT") - - echo "Resolution: $RESOLUTION" - echo "Resolution classification: $CLASSIFICATION" - - BASENAME=$(basename -- "$VIDEO_FILE") - DIRNAME=$(dirname -- "$VIDEO_FILE") - BASENAME_NO_EXT="${BASENAME%.*}" - EXTENSION="${BASENAME##*.}" - NEW_FILENAME="${BASENAME_NO_EXT} [${CLASSIFICATION}].${EXTENSION}" - - echo -e "Renaming: $VIDEO_FILE -> $DIRNAME/$NEW_FILENAME" - - mv "$VIDEO_FILE" "$DIRNAME/$NEW_FILENAME" - done -else - echo "Batch renaming cancelled by user." -fi diff --git a/usr-local-bin/setartist b/usr-local-bin/setartist deleted file mode 100644 index 14df535..0000000 --- a/usr-local-bin/setartist +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 'Artist Name'" - exit 1 -fi - -ARTIST_NAME="$1" -VIDEO_FILE=$(ls *.mp4 | head -n 1) - -if [ -z "$VIDEO_FILE" ]; then - echo "No .mp4 files found in the current directory." - exit 1 -fi - -echo "Video File: ${VIDEO_FILE}" - - -# Check if a file was found -if [ -z "$VIDEO_FILE" ]; then - echo "No .mp4 files found in the current directory." - exit 1 -fi - -# Set the artist metadata using ffmpeg -ffmpeg -i "$VIDEO_FILE" -c copy -metadata artist="$ARTIST_NAME" "temp_$VIDEO_FILE" && mv "temp_$VIDEO_FILE" "$VIDEO_FILE" - -echo "Artist metadata set to '$ARTIST_NAME' for file: $VIDEO_FILE"