This commit is contained in:
2025-10-21 14:04:09 -05:00
parent 4df485af5d
commit 571455802b
11 changed files with 186 additions and 144 deletions

View File

@@ -1,23 +1,109 @@
#!/bin/bash
source /opt/aninix/Uniglot/Bash/header
function ygdl() {
### Download a file
# param path: path to make
# param newname (optional): output location
if [ "$newname" != "" ]; then
wget -O "$newname" "$path";
else
wget "$path";
fi
}
function ygyt() {
### Cache from YouTube
# param path: YouTube URI
# param newname: output location
if [ `echo "$path" | grep -c '/watch?v='` -eq 1 ]; then
path="$(echo "$path" | cut -f 1 -d '&')"
fi
if [ "$newname" != "" ]; then
yt-dlp -o "$newname" "$path";
else
yt-dlp "$path";
fi
}
function ygmp3() {
uri="$path"
if [ "$newname" != "" ]; then
ygmkdir "$newname"
cd "$newname"
fi
if [ `echo "$uri" | grep -c '/watch?v='` -eq 1 ]; then
uri="$(echo "$uri" | cut -f 1 -d '&')"
fi
youtube-mp3 "$uri";
yggdrasil-set-music-data *.mp3
}
function ygcache() {
### Cache files
# param path: path to move
# param newname (option): somewhere other than $PWD to move
# param exec: what to use
if [ -n "$1" ]; then
exec="$1"
fi
if [ "$newname" != "" ]; then
$exec "$path" ./"$newname"
else
$exec "$path" .
fi
}
function ygmkdir() {
### Make a directory
# path: directory to make
if [ -n "$1" ]; then
path="$1"
fi
if [ -d "$path" ]; then
infoheader "Directory '$path' already existed."
else
mkdir -p "$path"
chmod u+w "$path"
fi
}
function usage() {
### Usage
# param retcode: what to return
if [ -z "$1" ]; then
retcode=0;
else
retcode=$1;
fi
cat << EOM
AniNIX/Yggdrasil Bash API
Syntax: yggdrasil-get {dl|yt|mp3|cp|mv|mkdir} PATH [new file name in $PWD]
Option:
-- dl: Use wget
-- yt: Use yt-dlp
-- mp3: Use youtube-mp3
-- cp: Copy the file here.
-- mv: Move the file here.
-- mkdir: Make a folder
EOM
exit $retcode
}
### Main
export YGGDRASIL="/home/yggdrasil"
if [ "$1" == '-v' ]; then
set -x
shift
fi
option="$1"
path="$2"
newname="$3"
#Offer help
if [ "$option" == "" ] || [ "$option" == "-h" ] || [ "$option" == "--help" ] || [ "$path" == "" ] || [ $(echo $newname | grep -c '/') -ne 0 ]; then
echo "AniNIX::Yggdrasil Bash API"
echo 'Syntax: yggdrasil-get {dl|yt|mp3|sol|cp|mv} PATH [new file name in $PWD]'
echo "Option:"
echo "-- dl: Use wget"
echo "-- yt: Use yt-dlp"
echo "-- mp3: Use youtube-mp3"
echo "-- sol: Use solarmovie-vodlocker-dl"
echo "-- cp: Copy the file here."
echo "-- mv: Move the file here."
echo "-- mkdir: Make a folder"
exit;
if [ "$option" == "" ] || [ "$option" == "-h" ] || [ "$option" == "--help" ] || [ "$path" == "" ]; then
usage 0;
fi
#Make sure we're in the Yggdrasil project.
@@ -29,62 +115,21 @@ fi
#unlock this directory
chmod ug+w "$PWD"
#Appropriately source the file
if [ $? -ne 0 ]; then
echo Couldn\'t unlock $PWD
exit
exit 1
fi
if [ "$option" == "dl" ]; then
if [ "$newname" != "" ]; then
wget -O "$newname" "$path";
else
wget "$path";
fi
fi
if [ "$option" == "yt" ]; then
if [ `echo "$path" | grep -c '/watch?v='` -eq 1 ]; then
path="$(echo "$path" | cut -f 1 -d '&')"
fi
if [ "$newname" != "" ]; then
yt-dlp -o "$newname" "$path";
else
yt-dlp "$path";
fi
fi
if [ "$option" == "mp3" ]; then
if [ "$newname" != "" ]; then
echo "Renaming not available."
fi
if [ `echo "$path" | grep -c '/watch?v='` -eq 1 ]; then
path="$(echo "$path" | cut -f 1 -d '&')"
fi
youtube-mp3 "$path";
yggdrasil-set-music-data *.mp3
fi
if [ "$option" == "sol" ]; then
if [ "$newname" != "" ]; then
solarmovie-vodlocker-dl "$path" "$newname"
else
echo "Need a name."
fi
fi
if [ "$option" == "cp" ]; then
if [ "$newname" != "" ]; then
cp "$path" ./"$newname"
else
cp "$path" .
fi
fi
if [ "$option" == "mv" ]; then
if [ "$newname" != "" ]; then
mv "$path" ./"$newname"
else
mv "$path" .
fi
fi
if [[ "$option" == "mkdir" && "$path" != "" ]]; then
mkdir -p "$path"
fi
# Functional loop
case "$option" in
dl) ygdl ;;
yt) ygyt ;;
mp3) ygmp3 ;;
cp) ygcache cp ;;
mv) ygcache mv ;;
mkdir) ygmkdir ;;
*) usage 1 ;;
esac
#Lock
chmod -R ug-w "$PWD"