-
Notifications
You must be signed in to change notification settings - Fork 1
/
techtv.sh
executable file
·86 lines (71 loc) · 1.92 KB
/
techtv.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
DLORIGINALS=true
DLBASIC=true
TESTMODE=false
while getopts ":tob" opt; do
case $opt in
t)
echo "Test mode. No video files will be downloaded."
TESTMODE=true
;;
o)
echo "Only original files will be processed."
DLBASIC=false
;;
b)
echo "Only basic MP4 files will be processed."
DLORIGINALS=false
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $(($OPTIND - 1))
RSSFILE=$1
if [ -z "$RSSFILE" ] ; then
echo "TechTV downloader requires an RSS video listing for your collection."
echo "For example: ./techtv.sh videos.rss"
exit 1
fi
URLS=`grep -o '<link>.*</link>' $RSSFILE | sed 's/<[^>]*>//g' | sed '/http:\/\/techtv.mit.edu\/collections/d'`
ORIGINALS=0
BASICS=0
while read -r SOURCEURL; do
SOURCE=`curl -s $SOURCEURL`
EXTENSION=${SOURCE#*download.source\" class=\"i-download\">}
EXTENSION=${EXTENSION%%</a>*}
if [ ${#EXTENSION} -ne 3 ]; then
if [ "$DLBASIC" = false ] ; then
continue
fi
VIDPATH=${SOURCE%/download.mp4*}
VIDPATH=${VIDPATH##*<a href=\"}
VIDPATH=http://techtv.mit.edu$VIDPATH/download.mp4
EXTENSION=mp4
(( BASICS += 1 ))
else
if [ "$DLORIGINALS" = false ] ; then
continue
fi
VIDPATH=${SOURCE%/download.source*}
VIDPATH=${VIDPATH##*<a href=\"}
VIDPATH=http://techtv.mit.edu$VIDPATH/download.source
(( ORIGINALS += 1 ))
fi
TITLE=`echo $SOURCE | sed -n 's:.*<title>MIT TechTV – \(.*\)</title>.*:\1:p'`
TITLE=`echo $TITLE | sed -e 's/[[:space:]]*$//'`
FILENAME=${TITLE//['<>:\|']/_}.$EXTENSION
echo "Processing $VIDPATH to $FILENAME"
if [ "$TESTMODE" = false ] ; then
curl -L -s -o "$FILENAME" "$VIDPATH"
fi
done <<< "$URLS"
echo "All done!"
echo "$ORIGINALS original files processed"
echo "$BASICS basic MP4 files processed"