hopefully usable
This commit is contained in:
parent
469196c0fa
commit
a4892609b9
56
down.sh
56
down.sh
@ -5,7 +5,6 @@
|
||||
# curl
|
||||
|
||||
mkdir -p ./{cache,state,Podcasts}
|
||||
# rm -rf ./cache/*
|
||||
|
||||
YQ=~/bin/yq
|
||||
|
||||
@ -13,22 +12,44 @@ yqf() {
|
||||
$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"
|
||||
|
||||
download() {
|
||||
local e name url limit mp3url
|
||||
local e name url limit mp3url fname ftype title
|
||||
e=$1
|
||||
name=$(yqf "${e}.name")
|
||||
name=$(yqf "${e}.name");
|
||||
url=$(yqf "${e}.url")
|
||||
# limit=$(yqf "${e}.limit")
|
||||
limit=2
|
||||
limit=$(yqf "${e}.limit // 1")
|
||||
filter=$(yqf "${e}.filter // true")
|
||||
ftype=$(yqf "${e}.filename_type // \"default\"")
|
||||
|
||||
local rss_path="cache/${name}.rss"
|
||||
local downloads_path="state/${name}.downloads"
|
||||
|
||||
false && curl -L -o "$rss_path" "$url"
|
||||
#limit=$limit $YQ -p xml '.rss.channel.item[] | keys | .[] | select(. < env(limit)) | .[]' "$rss_path"
|
||||
dryrun || curl -s -L -o "$rss_path" "$url"
|
||||
items=".rss.channel.item"
|
||||
|
||||
ids=$($YQ -p xml "$items | .[] | select($filter) | path | .[-1]" "$rss_path" |
|
||||
@ -36,11 +57,18 @@ download() {
|
||||
|
||||
for id in $ids
|
||||
do
|
||||
echo "id is $id"
|
||||
#$YQ -p xml "$items.$id | (.title |= .[0]) | .title" "$rss_path"
|
||||
title=$($YQ -p xml "$items.$id | (.title |= .[0]) | .title" "$rss_path")
|
||||
mp3url=$($YQ -p xml "$items.$id | .enclosure.+url" "$rss_path")
|
||||
grep -q --fixed-strings "$mp3url" "$downloads_path" && continue
|
||||
echo "Downloading: $mp3url"
|
||||
grep -qF "$mp3url" "$downloads_path" && continue
|
||||
|
||||
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"
|
||||
done
|
||||
}
|
||||
@ -48,8 +76,6 @@ download() {
|
||||
entries=".entries"
|
||||
for id in $(yqf "$entries | .[] | path | .[-1]")
|
||||
do
|
||||
echo "============================ start ============================"
|
||||
download "${entries}.$id"
|
||||
# exit
|
||||
echo "============================ done ============================"
|
||||
download "${entries}.$id" &
|
||||
done
|
||||
wait
|
||||
|
Loading…
Reference in New Issue
Block a user