#!/bin/bash
declare -i start
declare -i n
declare -i end
path="/data/data/com.termux/files/home/storage/music/youtube/1dl/"
clear #clear screen
n=0 #set counter to 0
start=${2} #get the 2nd and 3rd parameter from user
[ $((start)) == 0 ] && read -p "download from:" start
end=${3}
[ $((end)) == 0 ] && read -p "download end to:" end
echo $(date) | awk '{printf $4}'
echo " ====== download from #$((start)) and end to $((end))"
echo -e downloading ......
now=$SECONDS
while read data
do
n=n+1
if [ $((n%2)) == 1 ]; then
id=$data
array=(`yt-dlp --get-description $id`)
descript=${array[*]}
else
title=${data/ \[$id\]/}
#get title but remove id
ext="${title##*.}" #get ext
title=${title/.$ext/}
#remove ext from title
if [ $ext == "webm" ]; then
yt-dlp -f bestaudio $id --throttled-rate 100K --buffer-size 5120k --http-chunk-size 10M --no-part -o - | ffmpeg -loglevel debug -y -i - -codec copy -f ogg -ignore_unknown -metadata title="$title" -metadata description="$descript" "$path$title".ogg && ( echo $(date) | awk '{printf $4}'; echo " #$((n/2+start-1)) $title.ogg was downloaded" )
else
yt-dlp -f bestaudio -i $id --throttled-rate 100K --embed-thumbnail --add-metadata --buffer-size 5120k --http-chunk-size 10M -o "$path$title".m4a && ( echo $(date) | awk '{printf $4}'; echo " #$((n/2-1+start)) $title.m4a was downloaded" )
fi
fi
done < <(yt-dlp -s -f bestaudio --get-id --get-filename -i --playlist-start $((start)) --playlist-end $((end)) ${1})
echo spent $(( SECONDS - now )) seconds
exit 0
嵌入 thumbnail 後檔案看起來就像下圖一樣