Got it working.
This commit is contained in:
commit
dac055634c
65
download-yt-feeds.sh
Executable file
65
download-yt-feeds.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/bin/zsh
|
||||
# Download YouTube-feeds like they are podcasts.
|
||||
# Error codes:
|
||||
# 1 = Could not read file or directory.
|
||||
# 2 = Configuration option not set.
|
||||
|
||||
function die()
|
||||
{
|
||||
[[ -n "${2}" ]] && echo "Error: ${2}" >&2
|
||||
exit ${1}
|
||||
}
|
||||
|
||||
# Return path of configuration directory.
|
||||
function get_config_path()
|
||||
{
|
||||
local path
|
||||
if [[ -n "${XDG_CONFIG_HOME}" ]]; then
|
||||
path="${XDG_CONFIG_HOME}/download-yt-feeds"
|
||||
else
|
||||
path="${HOME}/.config/download-yt-feeds"
|
||||
fi
|
||||
|
||||
[[ -d "${path}" ]] || mkdir -p "${path}"
|
||||
[[ -r "${path}" ]] || die 1 "${path} is not readable."
|
||||
echo "${path}"
|
||||
}
|
||||
|
||||
# Return URLs of YouTube-feeds in feedlist.
|
||||
# All lines that don't start with "http" are ignored.
|
||||
function read_feedlist()
|
||||
{
|
||||
local feed_path="$(get_config_path)/feedlist"
|
||||
[[ -r "${feed_path}" ]] || die 1 "${feed_path} is not readable."
|
||||
|
||||
local -a entries
|
||||
while read line; do
|
||||
if [[ "${line}" =~ "^http" ]]; then
|
||||
local -a entry=("${(@s/ /)line}")
|
||||
entries+=(${entry[1]})
|
||||
fi
|
||||
done <"${feed_path}"
|
||||
|
||||
print -r -- ${(qq)entries}
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
local config_path="$(get_config_path)/config"
|
||||
[[ -r "${config_path}" ]] || die 1 "${config_path} is not readable."
|
||||
|
||||
source "${config_path}"
|
||||
[[ -z "${download_dir}" ]] && die 2 "download_dir not specified."
|
||||
[[ -z "${keep_for_days}" ]] && die 2 "keep_for_days not specified."
|
||||
|
||||
local -a feedlist=("${(@Q)${(z)$(read_feedlist)}}")
|
||||
for feed in ${feedlist}; do
|
||||
youtube-dl \
|
||||
--download-archive "$(get_config_path)/downloaded" \
|
||||
--dateafter "now-${keep_for_days}days" \
|
||||
--output "${download_dir}/%(title)s.%(ext)s" \
|
||||
"${feed}"
|
||||
done
|
||||
}
|
||||
|
||||
main
|
Loading…
x
Reference in New Issue
Block a user