some cleanup

This commit is contained in:
Balakrishnan Balasubramanian 2023-01-09 20:46:08 -05:00
parent 013d5ed60d
commit 70d3372bf3
2 changed files with 6 additions and 13 deletions

View File

@ -12,12 +12,6 @@ yqf() {
$YQ "$1" config.yaml $YQ "$1" config.yaml
} }
dryrun() {
false
}
dryrun || rm -rf ./cache/*
make_fname() { make_fname() {
local name ftype title local name ftype title
ftype=$1; name=$2; title=$3 ftype=$1; name=$2; title=$3
@ -47,7 +41,7 @@ download() {
local rss_path="cache/${name}.rss" local rss_path="cache/${name}.rss"
local downloads_path="state/${name}.downloads" local downloads_path="state/${name}.downloads"
dryrun || curl -s -L -o "$rss_path" "$url" curl -s -L -o "$rss_path" "$url"
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" |
@ -56,12 +50,10 @@ download() {
for id in $ids for id in $ids
do do
title=$($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") mp3url=$($YQ -p xml "$items.$id | .enclosure.+@url" "$rss_path")
grep -qF "$mp3url" "$downloads_path" && continue grep -qF "$mp3url" "$downloads_path" && continue
echo "Downloading: $title - $mp3url" echo "Downloading: $title - $mp3url"
# mp3path=$(mktemp -p cache "${name}.XXXXXX.mp3")
dryrun && continue
cd cache || return cd cache || return
read -ra title_options < <(make_fname "$ftype" "$name" "$title") read -ra title_options < <(make_fname "$ftype" "$name" "$title")
fname=$(curl -s -w "%{filename_effective}" -f -L "${title_options[@]}" "$mp3url") fname=$(curl -s -w "%{filename_effective}" -f -L "${title_options[@]}" "$mp3url")

View File

@ -2,6 +2,7 @@ $schema: http://json-schema.org/draft/2020-12/schema
type: object type: object
properties: properties:
entries: entries:
description: Array of feeds to download
type: array type: array
items: items:
type: object type: object
@ -15,20 +16,20 @@ properties:
limit: limit:
type: integer type: integer
description: Number of entries to download description: Number of entries to download
default: 1
filename_type: filename_type:
type: string type: string
description: Decides how the files are named description: Decides how the files are named
default: default
enum: enum:
- default - default
- title - title
- date - date
filter: filter:
type: string type: string
default: "true"
description: yq filter expression description: yq filter expression
foobar: hello world
required: required:
- filename_type
- limit
- name - name
- url - url
required: required: