Make paths configurable

This commit is contained in:
Balakrishnan Balasubramanian 2023-02-14 23:19:52 -05:00
parent 55072ef2a7
commit a02a9d6e56
2 changed files with 53 additions and 11 deletions

View File

@ -1,15 +1,18 @@
#!/usr/bin/bash
#Dependencies:
# yq
# yq https://github.com/mikefarah/yq
# curl
mkdir -p ./{cache,state,Podcasts}
YQ=yq
CONFIG=${1:-./config.yaml}
CACHE_DIR=./cache
STATE_DIR=./state
PODCASTS_DIR=./podcasts
yqf() {
$YQ "$1" config.yaml
$YQ "$1" "$CONFIG"
}
make_fname() {
@ -38,8 +41,8 @@ download() {
filter=$(yqf "${e}.filter // true")
ftype=$(yqf "${e}.filename_type // \"default\"")
local rss_path="cache/${name}.rss"
local downloads_path="state/${name}.downloads"
local rss_path="$CACHE_DIR/${name}.rss"
local downloads_path="$STATE_DIR/${name}.downloads"
curl -s -L -o "$rss_path" "$url"
items=".rss.channel.item"
@ -54,12 +57,12 @@ download() {
grep -qF "$mp3url" "$downloads_path" && continue
echo "Downloading: $title - $mp3url"
cd cache || return
pushd "$CACHE_DIR" || return
read -ra title_options < <(make_fname "$ftype" "$name" "$title")
fname=$(curl -s -w "%{filename_effective}" -f -L "${title_options[@]}" "$mp3url")
cd ..
popd || return
mv {cache,Podcasts}/"$fname"
mv "$CACHE_DIR/$fname" "$PODCASTS_DIR"
echo "$mp3url" >> "$downloads_path"
done
}
@ -74,6 +77,22 @@ set_proxy() {
set_proxy
set_directories() {
local base_dir cache_dir state_dir podcasts_dir
base_dir="$(yqf '.base_dir // ""')"
cache_dir="$(yqf '.cache_dir // ""')"
state_dir="$(yqf '.state_dir // ""')"
podcasts_dir="$(yqf '.podcasts_dir // ""')"
base_dir=${base_dir:-.}
CACHE_DIR=${cache_dir:-$base_dir/cache}
STATE_DIR=${state_dir:-$base_dir/state}
PODCASTS_DIR=${podcasts_dir:-$base_dir/podcasts}
}
set_directories
mkdir -p "$CACHE_DIR" "$STATE_DIR" "$PODCASTS_DIR"
entries=".entries"
for id in $(yqf "$entries | .[] | path | .[-1]")
do

View File

@ -1,6 +1,25 @@
$schema: http://json-schema.org/draft/2020-12/schema
type: object
properties:
proxy:
description: Proxy for curl. No proxy by default
type: string
base_dir:
description: Base directory for content
type: string
default: .
cache_dir:
description: Directory in which files are kept while downloading
type: string
default: <base_dir>/cache
state_dir:
description: Directory where downloaded urls are recorded to avoid re-downloading
type: string
default: <base_dir>/state
podcasts_dir:
description: Directory of the actual downloaded episodes
type: string
default: <base_dir>/podcasts
entries:
description: Array of feeds to download
type: array
@ -9,7 +28,7 @@ properties:
properties:
name:
type: string
description: Name of the feed
description: Name of the feed. Used as filenames. Avoid spaces or special characters
url:
type: string
description: Rss feed url of the podcast
@ -19,7 +38,11 @@ properties:
default: 1
filename_type:
type: string
description: Decides how the files are named
description: |
Decides how the files are named
default -> curl decides the filename (see curl's -O flag)
title -> Feed entries' title sanitized to remove special characters and spaces replaced with -
date -> feedname-<date>.<ext> e.g. linuxunplugged-2023-02-14.mp3
default: default
enum:
- default