2020-12-26 15:30:55 +01:00
|
|
|
#!/bin/bash
|
2020-07-04 14:23:27 +02:00
|
|
|
#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
|
2020-12-15 13:42:59 +01:00
|
|
|
BLACKLIST=$XDG_VIDEOS_DIR/.blacklist
|
2020-07-04 14:23:27 +02:00
|
|
|
|
|
|
|
# Required to display notifications if run as a cronjob:
|
2020-10-04 15:44:42 +02:00
|
|
|
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
|
2020-07-04 14:23:27 +02:00
|
|
|
export DISPLAY=:0.0
|
|
|
|
|
2021-01-01 17:25:13 +01:00
|
|
|
APIKEY="$(pass show Misc/Youtube\ Data\ API\ v3 | head -n1 )"
|
|
|
|
|
2020-12-26 14:04:07 +01:00
|
|
|
if [ $(pgrep -c ripper) -gt 1 ]; then
|
|
|
|
echo "Ripper already running, exiting new instance..."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2020-07-04 14:23:27 +02:00
|
|
|
echo "Scanning for new Videos to download"
|
2021-01-01 17:25:13 +01:00
|
|
|
echo "Scanning on Youtube:"
|
|
|
|
IDs="$( grep 'youtube' "$CHANNELSFILE" | grep 'channel' | sed 's/https:\/\/www\.youtube\.com\/channel\///')"
|
|
|
|
not_correctly_formatted="$(grep 'youtube' "$CHANNELSFILE" | grep -v 'channel')"
|
|
|
|
if [ "$( echo "$not_correctly_formatted" | wc -l )" -gt 0 ]; then
|
|
|
|
echo Please fix the following channel urls to be scannable:
|
|
|
|
echo "$not_correctly_formatted"
|
|
|
|
echo "They need to be in the 'https://www.youtube.com/channel/...' format"
|
|
|
|
fi
|
|
|
|
for channel_id in $IDs; do
|
|
|
|
echo "ID: $channel_id"
|
|
|
|
curl -s "https://www.googleapis.com/youtube/v3/search?key=$APIKEY&channelId=$channel_id&part=snippet,id&order=date&maxResults=500" | jq '."items" | .[] | .id."videoId"' | tr -d '"' | sed 's/^/https:\/\/www\.youtube\.com\/watch\?v=/' | grep -vf "$BLACKLIST" >> /tmp/todownload$$
|
|
|
|
done
|
2020-12-26 14:04:07 +01:00
|
|
|
grep 'youtube' "$DLARCHIVE" | sed 's/youtube /https:\/\/www\.youtube\.com\/watch?v=/' > /tmp/alreadydownloaded$$
|
2020-07-04 14:23:27 +02:00
|
|
|
|
2021-01-01 17:25:13 +01:00
|
|
|
echo "Scanning on Bitchute..."
|
|
|
|
grep 'bitchute' "$CHANNELSFILE" | xargs -L1 lynx --dump --nonumbers -listonly | grep 'bitchute\.com\/video' | sort -u | grep -vf "$BLACKLIST" >> /tmp/todownload$$
|
2020-12-26 14:04:07 +01:00
|
|
|
grep 'bitchute' "$DLARCHIVE" | sed 's/bitchute /https:\/\/www\.bitchute\.com\/video\//' >> /tmp/alreadydownloaded$$
|
2020-07-04 14:23:27 +02:00
|
|
|
|
2020-12-26 15:30:55 +01:00
|
|
|
grep -vf /tmp/alreadydownloaded$$ /tmp/todownload$$ | sort -u > /tmp/new_videos$$
|
|
|
|
number=$(wc -l /tmp/new_videos$$ | cut -d ' ' -f 1 )
|
2020-07-04 14:23:27 +02:00
|
|
|
if [ $number -gt 0 ]; then
|
2020-12-26 14:04:07 +01:00
|
|
|
[ $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."
|
2020-12-25 21:54:03 +01:00
|
|
|
if [ "$number" -lt 10 ];then
|
2021-01-01 17:25:13 +01:00
|
|
|
youtube-dl --get-filename -o "'%(uploader)s' '%(title)s'" -a /tmp/new_videos$$ | xargs -L1 notify-send
|
2020-12-25 21:54:03 +01:00
|
|
|
fi
|
2020-12-26 14:04:07 +01:00
|
|
|
rm -f /tmp/alreadydownloaded$$ /tmp/todownload$$
|
2021-01-01 17:25:13 +01:00
|
|
|
youtube-dl --hls-prefer-native -i --download-archive $DLARCHIVE -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$$
|
2020-12-26 14:04:07 +01:00
|
|
|
rm -f /tmp/new_videos$$
|
2020-07-04 14:23:27 +02:00
|
|
|
notify-send "Channel Ripper" "Finished downloading"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $number -eq 0 ]; then
|
2021-01-01 17:25:13 +01:00
|
|
|
echo "No new videos"
|
2020-07-04 14:23:27 +02:00
|
|
|
fi
|