#!/bin/sh
# Requires sfeed (https://git.codemadness.org/sfeed/)
# configured with youtube feeds, and Peertube cli tools:
# https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/tools.md

peertubetoolsdir=$HOME/PeerTube
peertubepass=$(pass show peertube | head -n 1)
peertubeuser=$(pass show peertube | grep user: | awk '{print $2}')

exitdir="$(pwd)"
sfeed_update
sfeed_plain $HOME/.sfeed/feeds/* | awk '{print $NF}' > $HOME/.sfeed/newfeeds.txt

cd $peertubetoolsdir
cat $HOME/.sfeed/feeds.txt $HOME/.sfeed/newfeeds.txt | sort | uniq -u | xargs -r -n 1 node dist/server/tools/peertube-import-videos.js -u https://tube.midov.pl -U "$peertubeuser" --password "$peertubepass"  -t

mv $HOME/.sfeed/newfeeds.txt $HOME/.sfeed/feeds.txt

cd $exitdir
