aboutsummaryrefslogtreecommitdiff
path: root/fetch.sh
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-05-24 01:25:07 -0500
committericeyrazor <iceyrazor@mailfence.com>2026-05-24 01:25:07 -0500
commitd4e34ad096cfc15b9c537463dd3c08becc5dc84e (patch)
tree5f5a90c64a4cc07898f5a6579538fb985b5686fb /fetch.sh
parent431ffd2edf3d52bbe8b7999dbd4f771d236fa065 (diff)
posix shell changes
removed ls | grep fixed miss spelled word
Diffstat (limited to 'fetch.sh')
-rwxr-xr-xfetch.sh37
1 files changed, 20 insertions, 17 deletions
diff --git a/fetch.sh b/fetch.sh
index d7a7e61..446e150 100755
--- a/fetch.sh
+++ b/fetch.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# arg1 is the url and arg2 is the playlist name
# if arg1 is not defined. just fetch thumbnails
@@ -7,13 +7,14 @@
# yt-dlp --get-filename -o "insert into ytlist values('%(title)s','%(channel)s','%(id)s','shorts','');" "https://www.youtube.com/playlist?list=PLwpvCCyacwS9Us6F1_UUUre1Py9p4ex4J" 2> out2.txt #| sed "s/'/''/g" #| sqlite3 ./youtube_stuffs.db
-cd "$(dirname "$0")"
+cd "$(dirname "$0")" || exit
file="./download.txt"
+emptyvar=""
-[ "$3" == "t" ] && Cookies="--cookies cookies.txt"
+[ "$3" = "t" ] && Cookies="--cookies cookies.txt"
if [ "$1" ]; then
- [ -z "$2" ] && echo playlist not defined. continue? && read -p "continue? (press any key)"
+ [ -z "$2" ] && echo playlist not defined. continue? && printf "continue? (press any key)" && read -r emptyvar
yt-dlp $Cookies --get-filename -o "%(title)s----%(id)s----%(channel)s" "$1" > "$file" 2> download_err.txt
printf "\n\n"
@@ -23,16 +24,17 @@ if [ "$1" ]; then
printf -- "insert into ytlist values('%s','%s','')" "$(head -n $i $file | tail -n 1 | sed "s/'/''/g" | sed "s/----/','/g" )" "$2"
printf "\n"
printf -- "insert into ytlist values('%s','%s','')" "$(head -n $i $file | tail -n 1 | sed "s/'/''/g" | sed "s/----/','/g" )" "$2" | sqlite3 ./youtube_stuffs.db
- printf "insert: $i\n"
- ((i=$i+1))
- if (( $i >= $max + 1 )); then
+ printf "insert: %s\n" "%i"
+ i=$((i+1))
+ if [ $i -gt $max ]; then
break
fi
done
echo ----PLAYLIST DONE
- read -p "continue? (Y,n)" input
- [ "$input" == "n" ] && exit 1;
- [ "$input" == "N" ] && exit 1;
+ printf "continue? (Y,n)"
+ read -r input
+ [ "$input" = "n" ] && exit 1;
+ [ "$input" = "N" ] && exit 1;
fi
@@ -41,19 +43,20 @@ i=1
max=$(( $(sqlite3 ./youtube_stuffs.db 'select rowid from ytlist order by rowid desc limit 1;') ))
while :; do
urlid="$(sqlite3 ./youtube_stuffs.db 'select id from ytlist where rowid='$i';')"
- if [ -z "$(ls -l thumbnails | grep ".$urlid")" ]; then
- printf "$i::$urlid\n"
+
+ if [ "$urlid" ] && [ ! -e "./thumbnails/$urlid."* ]; then
+ printf "%s::%s\n" "$i" "$urlid"
thumbnailurl="$(yt-dlp $Cookies --get-thumbnail "https://youtube.com/watch?v=$urlid" 2>> thumberr.txt)"
- if [ ! "$thumbnailurl" == "" ]; then
- ext="$(printf "$thumbnailurl" | sed 's/.*\.//g' | sed 's/?.*//')"
+ if [ ! "$thumbnailurl" = "" ]; then
+ ext="$(printf -- "%s" "$thumbnailurl" | sed 's/.*\.//g' | sed 's/?.*//')"
wget "$thumbnailurl" -O "thumbnails/$urlid.$ext"
else
- echo could not download thumbnail $urlid
+ printf "could not download thumbnail %s\n" "$urlid"
fi
fi
- ((i=$i+1))
- if (( $i >= $max + 1 )); then
+ i=$((i+1))
+ if [ $i -gt $max ]; then
break
fi
done