91 lines
2.1 KiB
Bash
Executable File
91 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
export YGGDRASIL="/srv/yggdrasil"
|
|
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 youtube-dl"
|
|
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;
|
|
fi
|
|
|
|
#Make sure we're in the Yggdrasil project.
|
|
if [ $(expr match "$PWD" "$YGGDRASIL") -ne $(expr length "$YGGDRASIL") ]; then
|
|
echo "Not in the Yggdrasil directory.";
|
|
exit;
|
|
fi
|
|
|
|
#unlock this directory
|
|
chmod ug+w "$PWD"
|
|
|
|
#Appropriately source the file
|
|
if [ $? -ne 0 ]; then
|
|
echo Couldn\'t unlock $PWD
|
|
exit
|
|
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
|
|
youtube-dl -o "$newname" "$path";
|
|
else
|
|
youtube-dl "$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
|
|
#Lock
|
|
chmod -R ug-w "$PWD"
|