diff options
Diffstat (limited to 'fetch.sh')
| -rwxr-xr-x | fetch.sh | 37 |
1 files changed, 20 insertions, 17 deletions
@@ -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 |
