#!/bin/sh # # Given playlist URLs that could be parsed by youtube-dl generates entry via # youtube-dl. # sfeedify() { awk -F '\t' ' $1 == ".id" { id = $3 } $1 == ".uploader" { author = $3 } $1 == ".timestamp" { timestamp = $3 } $1 == ".title" { title = $3 } $1 == ".description" && $2 == "s" { content = $3 content_type = "plain" } $1 == ".webpage_url" { link = $3 } END { if (id) { print timestamp "\t" title "\t" link "\t" content "\t" content_type "\t" id "\t" author "\t" enclosure } } ' } # # Print usage messages and exit # usage() { echo "usage: $(basename $0) [-n number_of_items] ..." exit 1 } nitems=-1 while getopts n: f; do case $f in n) nitems=$OPTARG ;; \?) usage ;; esac done shift $((OPTIND - 1)) if [ $# -lt 1 ]; then usage fi for u in "$@"; do youtube-dl --playlist-end "${nitems}" -j "${u}" | while read -r line; do echo "${line}" | json2tsv | sfeedify done done