#!/usr/bin/env sh

metadir=~/.cache/ytfeedget/meta
outdir=~/videos
finaldir=~/Video

mkdir -p $metadir
mkdir -p $outdir

while IFS= read -r line || [ -n "$line" ]; do
  printf '%s\n' "$line"
  yt-dlp -I 1:10 --download-archive "$metadir/$line.txt" --dateafter now-3days --force-write-archive -o "$outdir/%(uploader)s/%(upload_date)s - %(title)s.%(ext)s" "youtube.com/@$line"
  #yt-dlp --max-downloads 10 --download-archive "$metadir/$line.txt" --dateafter now-3days --force-write-archive -o "$outdir/%(uploader)s/%(upload_date)s - %(title)s.%(ext)s" "youtube.com/@$line"
  #yt-dlp --download-archive "$metadir/$line.txt" --dateafter now-3days --force-write-archive --match-filter 'original_url!*=/shorts/ & url!*=/shorts/' -o "./$outdir/%(uploader)s/%(upload_date)s - %(title)s.%(ext)s" "youtube.com/@$line"
done < ~/.config/ytfeedget/ytchannels

rm $finaldir/*
find $outdir -type f -exec ln -s {} $finaldir \; 


outdir=~/audio

mkdir -p $metadir
mkdir -p $outdir

while IFS= read -r line || [ -n "$line" ]; do
  printf '%s\n' "$line"

  f1=$(echo "$line" | cut -d "|" -f1)
  f2=$(echo "$line" | cut -d "|" -f2)

  mkdir -p "$outdir/$f1"
  poddl "$f2" -r -t 1 -o "$outdir/$f1"

done < ~/.config/ytfeedget/audiorss
