commit f6eece32d0ee290bee6e4530fe36a1bd3942f946
parent fa3c41bf5d6834c622bc598d41601ab19ea60385
Author: regexghost <dev@regexghost.com>
Date: Thu, 28 May 2026 16:37:48 +0100
new terminal scripts I forgot to push
Diffstat:
5 files changed, 165 insertions(+), 0 deletions(-)
diff --git a/terminal-scripts/am-extract.sh b/terminal-scripts/am-extract.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+read -p "Enter artist name: " artist
+
+results="$(curl -s "https://itunes.apple.com/search?term=${artist}&entity=musicArtist" | jq -r '.results[] | "\(.artistName) - \(.artistId)"' | nl)"
+
+echo "$results"
+
+read -p "Which one?: " selection
+
+selectedArtistID="$(echo "$results" | sed -n "${selection}p" | sed 's/.* - //g')"
+
+albums="$(curl -s "https://itunes.apple.com/lookup?id=${selectedArtistID}&entity=album" | jq -r '.results[] | "\(.collectionName) - \(.collectionId)"' | nl)"
+
+echo "$albums"
+
+read -p "Which album?: " selection
+
+selectedAlbumID="$(echo "$albums" | sed -n "${selection}p" | sed 's/.* - //g')"
+
+echo "$selectedAlbumID"
+
+albumInfo="$(curl -s "https://itunes.apple.com/lookup?id=${selectedAlbumID}&entity=song" | jq -r '.results[] | "\(.trackName) - \(.artistName) - \(.collectionName)"')"
+echo "$albumInfo"
diff --git a/terminal-scripts/download-vids.sh b/terminal-scripts/download-vids.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+LOC="${HOME}/Videos/YouTube"
+targetDir="${LOC}/toDownload"
+
+[ -d "$targetDir/done" ] || mkdir "$targetDir/done"
+
+quality_options_videos="bestvideo[height<=480][vcodec=vp9]+bestaudio[acodec=opus]/bestvideo[height<=480]+bestaudio"
+quality_options_shorts="bestvideo[width<=480][vcodec=vp9]+bestaudio[acodec=opus]/bestvideo[width<=480]+bestaudio"
+filename_options="%(channel)s - %(title)s.%(ext)s"
+
+if [ "$1" = "s" ]; then
+ targetDir="${targetDir}/Shorts"
+elif [ "$1" = "v" ]; then
+ targetDir="${targetDir}/Videos"
+fi
+
+i=1
+while read -r info_file; do
+ [ "$info_file" = "" ] && echo "No videos queued" && exit
+ video_name_channel="$(cat "$info_file" | head -n 2 | tac | awk '{print}' ORS=' - ' | sed 's/..$//g')"
+ echo "${i}: ${video_name_channel}"
+ i=$((i+1))
+done <<EOF
+$(find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort)
+EOF
+
+read -p "Select videos to download (e.g. 1 2 3): " toDownload
+
+[ -f /tmp/to_download ] && rm /tmp/to_download
+
+for i in $toDownload; do
+ path="$(find "$targetDir/Shorts" "$targetDir/Videos" -type f | sort | sed -n "${i}p")"
+ echo "$path" >> /tmp/to_download
+done
+
+while read -r path; do
+ id="$(basename "$path" | sed 's/.txt//g')"
+ if echo "$path" | grep -q Shorts; then
+ yt-dlp -o "$filename_options" -f "$quality_options_shorts" -P "$LOC/Shorts" -- "$id"
+ else
+ yt-dlp -o "$filename_options" -f "$quality_options_videos" -P "$LOC/Videos" -- "$id"
+ fi
+ if [ "$?" = "0" ]; then
+ mv "$path" "$targetDir/done"
+ fi
+done <<EOF
+$(cat /tmp/to_download)
+EOF
+
+[ -f /tmp/to_download ] && rm /tmp/to_download
diff --git a/terminal-scripts/tag-music.py b/terminal-scripts/tag-music.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+import music_tag
+from os.path import expanduser
+import os
+import json
+import sys
+import requests
+
+home = expanduser("~")
+xdg_data_home = os.environ["XDG_DATA_HOME"]
+xdg_cache_home = os.environ["XDG_CACHE_HOME"]
+art_file = xdg_cache_home + "/art.jpg"
+
+inputFile = sys.argv[1]
+genre = sys.argv[2]
+albumArt = sys.argv[3]
+
+cleanName = inputFile.replace(" - Topic", "")
+
+split = cleanName.replace(".m4a", "").split(" -- ")
+
+artist = split[1]
+title = split[0]
+album = split[2]
+
+file = music_tag.load_file(inputFile)
+file["title"] = title
+file["artist"] = artist
+file["album"] = album
+file["genre"] = genre
+
+r = requests.get(albumArt)
+with open(art_file, "wb")as out:
+ out.write(r.content)
+
+with open(art_file, "rb") as img:
+ file["artwork"] = img.read()
+
+file.save()
+
+metadata = xdg_data_home + "/regexghost/script-data/songs-metadata.csv"
+f = open(metadata, "a")
+f.write(inputFile.replace(" -- ", " - ") + "|" + title + "|" + artist + "|" + album + "|" + albumArt + "|" + genre + "\n")
+f.close()
+
+
diff --git a/terminal-scripts/tag-song.sh b/terminal-scripts/tag-song.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+genre="$1"
+appleMusicID="$2"
+shift
+shift
+
+searchLink="https://itunes.apple.com/lookup?id=${appleMusicID}&entity=song"
+json="$(curl "$searchLink")"
+if [[ "$(echo "$json" | jq .results[0].collectionName)" == "null" ]]; then
+ echo null
+ searchLink="https://itunes.apple.com/lookup?id=${appleMusicID}&entity=album"
+ json="$(curl "$searchLink")"
+fi
+
+art="$(echo "$json" | jq -r .results[0].artworkUrl100 | sed 's/100x100bb/1500x1500/g')"
+if [ "$art" = "null" ]; then
+ art="$(echo "$json" | jq -r .results[1].artworkUrl100 | sed 's/100x100bb/1500x1500/g')"
+fi
+
+echo $art
+for arg; do
+ "$HOME/.local/share/regexghost/.venv/bin/python3" "${XDG_DATA_HOME}/regexghost/terminal/tag-music.py" "$arg" "$genre" "$art"
+ rm -f "$XDG_CACHE_HOME/art.jpg"
+done
diff --git a/terminal-scripts/yt-data.sh b/terminal-scripts/yt-data.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Get basic data for a YouTube video
+
+url="$1"
+TEMP_FILE=/tmp/yt-data.html
+
+curl -s "$url" > "$TEMP_FILE"
+
+title="$(cat "$TEMP_FILE" | sed -nE 's/.*videoDescriptionHeaderRenderer":\{"title":\{"runs":\[\{"text":"([^}]*)"\}.*/\1/p')"
+channel="$(cat "$TEMP_FILE" | sed -nE 's/.*ownerProfileUrl[^@]*@([^"]*).*/\1/p' | head -n 1)"
+description="$(cat "$TEMP_FILE" | sed -nE 's/.*videoDescriptionHeaderRenderer":\{"title":\{"runs":\[\{"text":"([^}]*).*/\1/p' | sed -nE 's/([^\]*)(\\n|").*/\1/p')"..
+release_date="$(cat "$TEMP_FILE" | sed -nE 's/.*publishDate":\{"simpleText":"([^"]*)".*/\1/p')"
+
+echo "$title"
+echo "$channel"
+echo "$description"
+echo "$release_date"