hopefully usable

This commit is contained in:
Balakrishnan Balasubramanian 2022-08-08 13:23:49 -04:00
parent 469196c0fa
commit a4892609b9

56
down.sh
View File

@ -5,7 +5,6 @@
# curl # curl
mkdir -p ./{cache,state,Podcasts} mkdir -p ./{cache,state,Podcasts}
# rm -rf ./cache/*
YQ=~/bin/yq YQ=~/bin/yq
@ -13,22 +12,44 @@ yqf() {
$YQ "$1" config.yaml $YQ "$1" config.yaml
} }
dryrun() {
false
}
dryrun || rm -rf ./cache/*
make_fname() {
local name ftype title
ftype=$1; name=$2; title=$3
case $ftype in
"date")
echo "-o $name-$(date --iso-8601).mp3"
;;
"default")
echo "-O"
;;
"title")
sanitized=$(echo "$title" | sed 's/ */-/g' | tr -d -c 'A-Za-z-0-9\n' | grep -o '[^-].*' | cut -c-20)
echo "-o $name-${sanitized}.mp3"
;;
esac
}
export ALL_PROXY="socks5h://127.0.0.1:9050" export ALL_PROXY="socks5h://127.0.0.1:9050"
download() { download() {
local e name url limit mp3url local e name url limit mp3url fname ftype title
e=$1 e=$1
name=$(yqf "${e}.name") name=$(yqf "${e}.name");
url=$(yqf "${e}.url") url=$(yqf "${e}.url")
# limit=$(yqf "${e}.limit") limit=$(yqf "${e}.limit // 1")
limit=2
filter=$(yqf "${e}.filter // true") filter=$(yqf "${e}.filter // true")
ftype=$(yqf "${e}.filename_type // \"default\"")
local rss_path="cache/${name}.rss" local rss_path="cache/${name}.rss"
local downloads_path="state/${name}.downloads" local downloads_path="state/${name}.downloads"
false && curl -L -o "$rss_path" "$url" dryrun || curl -s -L -o "$rss_path" "$url"
#limit=$limit $YQ -p xml '.rss.channel.item[] | keys | .[] | select(. < env(limit)) | .[]' "$rss_path"
items=".rss.channel.item" items=".rss.channel.item"
ids=$($YQ -p xml "$items | .[] | select($filter) | path | .[-1]" "$rss_path" | ids=$($YQ -p xml "$items | .[] | select($filter) | path | .[-1]" "$rss_path" |
@ -36,11 +57,18 @@ download() {
for id in $ids for id in $ids
do do
echo "id is $id" title=$($YQ -p xml "$items.$id | (.title |= .[0]) | .title" "$rss_path")
#$YQ -p xml "$items.$id | (.title |= .[0]) | .title" "$rss_path"
mp3url=$($YQ -p xml "$items.$id | .enclosure.+url" "$rss_path") mp3url=$($YQ -p xml "$items.$id | .enclosure.+url" "$rss_path")
grep -q --fixed-strings "$mp3url" "$downloads_path" && continue grep -qF "$mp3url" "$downloads_path" && continue
echo "Downloading: $mp3url"
echo "Downloading: $title - $mp3url"
# mp3path=$(mktemp -p cache "${name}.XXXXXX.mp3")
dryrun && continue
cd cache || return
fname=$(curl -s -w "%{filename_effective}" -f -L $(make_fname "$ftype" "$name" "$title") "$mp3url")
cd ..
mv {cache,Podcasts}/"$fname"
echo "$mp3url" >> "$downloads_path" echo "$mp3url" >> "$downloads_path"
done done
} }
@ -48,8 +76,6 @@ download() {
entries=".entries" entries=".entries"
for id in $(yqf "$entries | .[] | path | .[-1]") for id in $(yqf "$entries | .[] | path | .[-1]")
do do
echo "============================ start ============================" download "${entries}.$id" &
download "${entries}.$id"
# exit
echo "============================ done ============================"
done done
wait