dotfiles/.local/bin/tools/ripper
2020-12-26 14:04:07 +01:00

44 lines
2.2 KiB
Bash
Executable File

#!/bin/zsh
#needed if run as cronjob
export XDG_VIDEOS_DIR=$HOME/vids
DLARCHIVE=$XDG_VIDEOS_DIR/.downloaded
DLLOC=$XDG_VIDEOS_DIR
CHANNELSFILE=$XDG_VIDEOS_DIR/.channels
BLACKLIST=$XDG_VIDEOS_DIR/.blacklist
# Required to display notifications if run as a cronjob:
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
export DISPLAY=:0.0
if [ $(pgrep -c ripper) -gt 1 ]; then
echo "Ripper already running, exiting new instance..."
exit
fi
range="now-40years"
echo "Scanning for new Videos to download"
grep 'youtube' "$CHANNELSFILE" | xargs -L1 lynx --dump --listonly --nonumbers | grep 'videos.xml' | xargs lynx --dump | grep -oE 'yt:video:[^\s\t ]{11,15}' | perl -pe 's/^yt:video:([^ \t\s]*)$/https:\/\/www\.youtube\.com\/watch\?v=\1/' | grep -vf "$BLACKLIST" > /tmp/todownload$$
grep 'youtube' "$DLARCHIVE" | sed 's/youtube /https:\/\/www\.youtube\.com\/watch?v=/' > /tmp/alreadydownloaded$$
grep 'bitchute' "$CHANNELSFILE" | xargs -L1 lynx --dump --nonumbers -listonly $1 | grep 'bitchute\.com\/video' | sort -u | grep -vf "$BLACKLIST" >> /tmp/todownload$$
grep 'bitchute' "$DLARCHIVE" | sed 's/bitchute /https:\/\/www\.bitchute\.com\/video\//' >> /tmp/alreadydownloaded$$
number=$(grep -vf /tmp/alreadydownloaded$$ /tmp/todownload$$ | sort -u | wc -l)
if [ $number -gt 0 ]; then
[ $number -gt 1 ] && plural="s"
notify-send "Channel Ripper" "$number new video$plural available for download, downloading now."
echo "$number new video$plural for download available, downloading now."
if [ "$number" -lt 10 ];then
grep -vf /tmp/alreadydownloaded$$ /tmp/todownload$$ | sort -u | xargs -L1 youtube-dl --get-filename -o "'%(uploader)s' '%(title)s'" $1 | xargs -L1 notify-send
fi
grep -vf /tmp/alreadydownloaded$$ /tmp/todownload$$ | sort -u > /tmp/new_videos$$
rm -f /tmp/alreadydownloaded$$ /tmp/todownload$$
youtube-dl --hls-prefer-native -i --download-archive $DLARCHIVE --dateafter $range -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' --add-metadata -o "$DLLOC/%(uploader)s/%(upload_date)s-%(title)s.%(ext)s" -a /tmp/new_videos$$
rm -f /tmp/new_videos$$
notify-send "Channel Ripper" "Finished downloading"
fi
if [ $number -eq 0 ]; then
echo "No new Videos"
fi