#!/usr/bin/env bash
# shellcheck disable=SC1004
# shellcheck disable=SC2016
+# shellcheck disable=SC2064
# shellcheck disable=SC2086
# shellcheck disable=SC2155
# Name: podl - podcast downloader with caching
# Version: 2021-10-22
-# Last version: https://git.code.sourcephile.fr/~julm/julm-nix/tree/main/item/nixpkgs/overlays/podl.sh
+# Latest version: https://git.sourcephile.fr/julm/julm-nix/tree/main/item/nixpkgs/overlays/podl.sh
# Synopsis:
# $ mkdir LaMéthodeScientifique 3Blue1Brown
# $ echo >LaMéthodeScientifique/.feed http://radiofrance-podcast.net/podcast09/rss_14312.xml
# it creates next to those ".feed" files;
# avoiding the cost of network activity when not necessary.
# Environment:
-# - $SKIP_DOWNLOAD: if set, skip the download command
+# - $PODL_SKIP_DOWNLOAD: if set, skip the download command
# but still register the entry in ".downloaded".
# Useful when adding the feed if you only want
# a few entries from the feed:
-# run SKIP_DOWNLOAD=set podl, then edit ".downloaded"
+# run PODL_SKIP_DOWNLOAD=set podl, then edit ".downloaded"
# to remove the entries you want, then run podl again.
# This trick does not work with ".page" downloads.
# - $YT: options passed to yt-dlp.
-# - $XTRACE: if set, enables set -x on the generated commands.
+# - $PODL_XTRACE: if set, enables set -x on the generated commands.
# Files:
# - ".yt-dlp": optional yt-dlp config,
# (looked up in parent directories).
case $found in
(*/.page)
yt-dlp $YT \
- ${SKIP_DOWNLOAD:+--skip-download} \
+ ${PODL_SKIP_DOWNLOAD:+--skip-download} \
--download-archive .downloaded \
--batch-file "$src"
;;
grep -qxF -e "url $url" -e "guid $guid" .downloaded || {
published=$(date +%Y-%m-%d -d "$published")
echo >&2 "$dst/$published - $title"
- if test ! "${SKIP_DOWNLOAD:+set}"
+ if test ! "${PODL_SKIP_DOWNLOAD:+set}"
then
yt-dlp $YT \
--output "$published - ${title//%/%%}.%(ext)s" \
grep -qxF "youtube $id" .downloaded || {
published=$(date +%Y-%m-%d -d "$published")
echo >&2 "$dst/$published - $title.$id"
- if test "${SKIP_DOWNLOAD:+set}"
+ if test "${PODL_SKIP_DOWNLOAD:+set}"
then
{ flock --exclusive 3
echo >&3 "youtube $id"
else
yt-dlp $YT \
--download-archive .downloaded \
- --output "$published - ${title//%/%%}.%(id)s.%(format_id)s.%(ext)s" \
+ --output "%(release_date>%Y-%m-%d,upload_date>%Y-%m-%d|$published)s - ${title//%/%%}.%(id)s.%(format_id)s.%(ext)s" \
"$url"
fi
}
';;
esac |
- "$SHELL" -seu${XTRACE:+x}
+ "$SHELL" -seu${PODL_XTRACE:+x}
+ rm -f '$file'
+ trap '' EXIT
)
done;;
esac