#!/bin/sh
#Title: Puppy Download Manager
#Purpose: Learn gtkdialog and bash, make something bigger than Pwsget
#Licence: GPL3
#Author: puppy_apprentice (so far, contributions and errors correction appreciate and welcome)
[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog
TMPDIR=/tmp/gtkdialog/examples/"`basename $0`"
mkdir -p "$TMPDIR"
export TMPDIR
export download_list=`cat /root/download_list`
DOWNPLACE="$DEST"
funcClear() {
echo -n "" > "$TMPDIR"/inputfile1
}
export -f funcClear
funcClear
echo -e "\nApplication directory: $PWD\nDownloads directory: $DEST\n" > "$TMPDIR"/info
funcStart_() {
echo cat "$TMPDIR"/info
}
export -f funcStart_
funchelp() {
echo "testtttt" > "$LINKS1"
}
export -f funchelp
funcdowndir() {
echo "$DEST" > "$TMPDIR"/info
}
export -f funcdowndir
funcAddFromClip() {
if [ -s "$TMPDIR"/inputfile1 ]
then
echo -e -n "\n$(xclip -o)" >> "$TMPDIR"/inputfile1
else
echo -n "$(xclip -o)" >> "$TMPDIR"/inputfile1
fi
}
export -f funcAddFromClip
funcAddFromLink() {
if [ -s "$TMPDIR"/inputfile1 ]
then
echo -e -n "$LINKS1" >> "$TMPDIR"/inputfile1
else
echo -n "$LINKS1" >> "$TMPDIR"/inputfile1
fi
}
export -f funcAddFromLink
funcLoadFromFile() {
cat "$PWD/download_list" > "$TMPDIR"/inputfile1
}
export -f funcLoadFromFile
funcPrepareFile() {
cat "$PWD/download_list" | tr -d '||' > "$TMPDIR"/temp
cat "$TMPDIR"/temp > download_list
}
export -f funcPrepareFile
funcRemoveSelItem() {
echo -n "$(grep -vx "$1" "$TMPDIR"/inputfile1)" > "$TMPDIR"/temp
cat "$TMPDIR"/temp > "$TMPDIR"/inputfile1
}
export -f funcRemoveSelItem
funcMoveItemUp() {
echo "$1" > "$TMPDIR"/temp
echo -n "$(grep -vx "$1" "$TMPDIR"/inputfile1)" >> "$TMPDIR"/temp
cat "$TMPDIR"/temp > "$TMPDIR"/inputfile1
}
export -f funcMoveItemUp
funcMoveItemDown() {
echo -n "$(grep -vx "$1" "$TMPDIR"/inputfile1)" > "$TMPDIR"/temp
echo -en "\n$1" >> "$TMPDIR"/temp
cat "$TMPDIR"/temp > "$TMPDIR"/inputfile1
}
export -f funcMoveItemDown
funcStart_aria2() {
if [ "$1" ]
then
echo aria2 --disable-ipv6 "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo aria2 -i "$PWD/download_list" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_aria2
funcStart_aria2c() {
if [ "$1" ]
then
echo aria2c --disable-ipv6 "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo aria2c -i "$PWD/download_list" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_aria2c
funcStart_axel() {
if [ "$1" ]
then
echo axel --alternate "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
cat "$PWD/download_list" | xargs -d '\n' -l1 echo axel -a & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_axel
funcStart_curl() {
if [ "$1" ]
then
echo curl -L -O -C - "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
cat "$PWD/download_list" | xargs -d '\n' -l1 echo curl -L -O -C - & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_curl
funcStart_youtube_dl_video() {
if [ "$1" ]
then
echo youtube-dl "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo youtube-dl -a "$PWD/download_list" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_youtube_dl_video
funcStart_youtube_dl_mp3() {
if [ "$1" ]
then
echo youtube-dl -ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output '%\(title\)s.%\(ext\)s' "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo youtube-dl -ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output '%\(title\)s.%\(ext\)s' "'$download_list'" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_youtube_dl_mp3
funcStart_youtube_dl_playlist_mp3() {
if [ "$1" ]
then
echo youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output '%\(title\)s.%\(ext\)s' --yes-playlist "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output '%\(title\)s.%\(ext\)s' --yes-playlist "'$download_list'" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_youtube_dl_playlist_mp3
funcStart_youtube_dl_playlist_video() {
if [ "$1" ]
then
echo youtube-dl -i -f mp4 --yes-playlist "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo youtube-dl -i -f mp4 --yes-playlist "'$download_list'" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_youtube_dl_playlist_video
funcStart_wget() {
if [ "$1" ]
then
echo wget -c "$1" & PID=$!
echo $(( PID + 1 )) > pid
else
echo wget -c -i "'$download_list'" & PID=$!
echo $(( PID + 1 )) > pid
fi
}
export -f funcStart_wget
funcStop() {
PID="$(cat pid)"
kill -INT "$PID" &
}
export -f funcStop
downloaders="
youtube-dl
aria2
aria2c
axel
curl
wget
"
funcComboAddItems() {
for item in $downloaders
do
if [ -e "$(which $item)" ]
then
if [ "$item" == "youtube-dl" ]
then
echo "- "youtube_dl_video"
"
echo "- "youtube_dl_mp3"
"
echo "- "youtube_dl_playlist_mp3"
"
echo "- "youtube_dl_playlist_video"
"
else
echo "- "$item"
"
fi
fi
done
}
MAIN_DIALOG='
LINKS1
260
300
LIST1
400
'"$TMPDIR"'/inputfile1
DEST
COMBOBOX
'"`funcComboAddItems`"'
10
vte0
funcStart_"$COMBOBOX" "$LIST1"
echo "vte0=$vte0 - Default child-exited signal"
echo "vte0=$vte0 - Resetting and re-executing command"
clear:vte0
echo "vte0=$vte0 - New PID"
echo "vte0=$vte0 - show signal"
'
export MAIN_DIALOG
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --space-expand=true --space-fill=true --program=MAIN_DIALOG ;;
esac