-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateytsubs
executable file
·36 lines (31 loc) · 1.09 KB
/
updateytsubs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /bin/bash
# Run this in cron
# First parameter is path your subscription_manager file downloadable from
# Youtube https://www.youtube.com/subscription_manager (Bottom of the page)
# It updates ~/.youtubesubs
# test network connectivity
ping -q -w 1 -c 1 youtube.com > /dev/null || exit 1
# test that the file given as a parameter is atleast somewhat correct
if [ "$(grep 'opml' $1 | wc -l)" -eq 0 ]; then
echo "invalid parameter"
exit 1
fi
fetched="$(cat $1 \
| sed -e 's/\"/\n/g' -e 's/;//g' \
| grep https \
| sed -e 's/^/curl -s /' | sh \
| grep -A 16 "<entry>" \
| grep "<name>\|<title>\|<yt:videoId>\|<published>" \
| paste - - - - \
| sed \
-e "s/\(.*\)<published>\(.*\)<\/published>\(.*\)/\1\3\t\2/" \
-e "s/\(.*\)<name>\(.*\)<\/name>\(.*\)/\1\3\t\2/" \
-e "s/\(.*\)<title>\(.*\)<\/title>\(.*\)/\1\3\t\2/" \
-e "s/\(.*\)<yt:videoId>\(.*\)<\/yt:videoId>\(.*\)/\1\3\t\2/" \
-e "s/^\s*//" \
-e 's/\"/"/g' -e 's/\&/\&/g' \
)"
combined="$(echo -e "$fetched" | cat - ~/.youtubesubs \
| sort -t$'\t' -u -k4,4 \
| sort -rn)"
echo "$combined" > ~/.youtubesubs