#!/bin/sh -e

inv_urls() {
  # shellcheck disable=SC2002
  cat subscription_manager | tr ">" "\n" | grep http | cut -d '"' -f8 \
    | cut -d "/" -f4- \
    | sed 's/feed\/channel\//https:\/\/www.youtube.com\/feeds\/videos.xml?channel_id=/g' >>~/urls_yt
}

piped_urls() {
  # shellcheck disable=SC2002
  cat subscriptions.json | tr "{" "\n" | cut -d '"' -f4 \
    | sed 's/channel\//feeds\/videos.xml?channel_id=/g' >>~/urls_yt
}

case "$1" in
  inv)
    inv_urls
    ;;
  piped)
    piped_urls
    ;;
  *)
    printf '%s\n' "$(basename "$0") [inv] [piped]"
    exit 0
    ;;
esac
