rtvnoord_video - randomcrap - random crap programs of varying quality
HTML git clone git://git.codemadness.org/randomcrap
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
rtvnoord_video (1009B)
---
1 #!/bin/sh
2 # get direct RTVNoord video from a page or URL.
3
4 url="$1"
5
6 if test "$url" = ""; then
7 echo "usage: $0 <URL>" >&2
8 exit 1
9 fi
10
11 # strip prefix for matching.
12 matchurl="${url#*://}"
13 matchurl="${matchurl#www.}"
14
15 # ID is in URL.
16 case "$matchurl" in
17 rtvnoord.nl/video/*)
18 id="${matchurl##*/video/}"
19 id="${id%%/*}"
20 jsonurl="https://rtvnoord.bbvms.com/p/regiogroei_noord_web_videoplayer/c/sourceid_string:${id}.json"
21 ;;
22 rtvnoord.nl/*)
23 # try to get video ID from page.
24 id=$(hurl "$url" | sed -nE 's@.*"sourceid_string:([0-9]+)".*@\1@p' | sed 1q)
25 jsonurl="https://rtvnoord.bbvms.com/p/regiogroei_noord_web_videoplayer/c/sourceid_string:${id}.json"
26 ;;
27 esac
28
29 if test "$id" = ""; then
30 echo "No video ID found" >&2
31 exit 1
32 fi
33
34 tmpf=$(mktemp)
35 hurl "$jsonurl" > "$tmpf"
36
37 json2tsv < "$tmpf" | \
38 LC_ALL=C awk '
39 BEGIN {
40 FS = OFS = "\t";
41 }
42 $1 == ".publicationData.defaultMediaAssetPath" {
43 baseurl = $3;
44 }
45 $3 ~ /\.mp4$/ {
46 urls[x++] = $3;
47 }
48 END {
49 for (x in urls) {
50 print baseurl urls[x];
51 }
52 }'
53
54 rm -f "$tmpf"