3 // @description Turn RaiTV silverlight objects into video tags
4 // @namespace http://oblomov.myopenid.com
5 // @include http://rai.tv/*
6 // @include http://rai.it/*
7 // @include http://www.rai.tv/*
8 // @include http://www.rai.it/*
9 // @author Giuseppe "Oblomov" Bilotta
10 // @version 20130322.2255
15 function getURL(name) {
16 var list = document.getElementsByName(name) ;
17 if (list && list[0]) {
18 return list[0].content;
20 var altname = name.toUpperCase().replace('VIDEO','video');
21 console.log(name, altname);
22 console.log(window[name], window[altname]);
23 return window[altname];
28 std: getURL('videourl'),
29 mp4: getURL('videourl_mp4'),
30 wmv: getURL('videourl_wmv'),
31 h264: getURL('videourl_h264'),
32 m3u8: getURL('videourl_m3u8'),
35 function srctag(url, av, fmt) {
38 return '<source src="' + url + '" ' + (fmt ? 'type="' + av + '/' + fmt + '" ' : '') + '/>'
41 function H5video(fmt) {
42 return srctag(urls[fmt], 'video', (fmt == 'std' ? null : fmt));
47 var a = document.createElement('a');
49 a.innerHTML = fmt.toUpperCase();
50 a.style='font-weight:bold;margin-left:1em;color:white';
56 var sch = document.getElementById("silverlightControlHost");
59 // if we are on a page that defines the videourl* metas, go straight to creating
62 // prevent other JS with messing with this element further
63 sch.id = 'html5mediaHost';
64 sch.innerHTML = "<video style='width:100%; height:100%' controls>" +
65 H5video('mp4') + H5video('wmv') +
66 H5video('h264') + H5video('m3u8') +
68 "<h3>Sorry, no supported video format found :-(</h3></video>";
69 console.log(sch, 'hacked');
71 var list = document.createElement("li");
73 list.innerHTML = '<span>Stream/Download:</span>';
74 for (var fmt in urls) {
79 // find place to append the list to:
80 var pp = sch.parentNode.parentNode.previousElementSibling;
81 var specs = pp.getElementsByTagName('ul');
82 if (!specs || !specs[0]) {
83 specs = document.createElement('ul');
84 specs.className = 'Specifiche';
85 pp.appendChild(specs);
89 specs.appendChild(list);
90 console.log(list, 'enumerated and appended');
94 // hack the play* JS functions
96 window.playTg = function (liveTg, video, h264, androidUrl) {
97 var dataP = new Date();
99 ggP = dataP.getDate() + "-";
100 mmP = dataP.getMonth() + 1 + "-";
101 aaaaP = 1900 + dataP.getYear();
102 // stop loading any current audio/video
103 if (sch.firstChild && sch.firstChild.src) {
104 console.log('stopping current A/V');
105 sch.firstChild.src = '';
107 sch.innerHTML = "<video width='258' height='195' controls autoplay>" +
108 srctag(h264, 'video', 'h264') +
109 srctag(androidUrl, 'video') +
110 srctag(video, 'video') +
111 "<h3>Sorry, no supported video format found :-(</h3></video>";
112 setNielsen(location.href + '&video=' + liveTg + '&data=' + ggP + mmP + aaaaP + '', true);
113 console.log('playTg', liveTg, video, h264, androidUrl)
115 console.log('playTg hacked');
117 if (window.playAudio) {
118 window.playAudio = function (grrEdizione, mediaUrl, mediatype) {
119 var dataP = new Date();
121 ggP = dataP.getDate() + "-";
122 mmP = dataP.getMonth() + 1 + "-";
123 aaaaP = 1900 + dataP.getYear();
124 // stop loading any current audio/video
125 if (sch.firstChild && sch.firstChild.src) {
126 console.log('stopping current A/V');
127 sch.firstChild.src = '';
129 sch.innerHTML = "<audio width='258' height='35' controls autoplay>" +
130 srctag(mediaUrl, 'audio') +
131 "<h3>Sorry, no supported audio format found :-(</h3></audio>";
132 setNielsen(location.href + '&audio=' + grrEdizione + '&data=' + ggP + mmP + aaaaP + '', true);
133 console.log('playAudio', grrEdizione, mediaUrl, mediatype);
135 console.log('playAudio hacked');