From 4f0629ae70200939db3ce25129b893c1781ab16e Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 23 Mar 2013 19:02:10 +0100 Subject: [PATCH] Stream list on Rai.it homepage too --- raitv.user.js | 103 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 18 deletions(-) diff --git a/raitv.user.js b/raitv.user.js index 83d515a..5169914 100644 --- a/raitv.user.js +++ b/raitv.user.js @@ -42,6 +42,7 @@ return srctag(urls[fmt], 'video', (fmt == 'std' ? null : fmt)); } + // create a link element for one of the page-wide media streams function H5a(fmt) { if (urls[fmt]) { var a = document.createElement('a'); @@ -53,9 +54,56 @@ return null } + // create a link element for a raw URL + function H5aRaw(name, url) { + if (url) { + var a = document.createElement('a'); + a.href = url; + a.innerHTML = name.toUpperCase(); + a.style='font-weight:bold;margin-left:1em;color:red'; + return a; + } + return null + } + + var streamlist = document.createElement("li"); + + // reset stream list: this is used in the playTg and playAudio + // functions to reset the stream list when changing stream, + function slReset() { + streamlist.innerHTML = 'Stream/Download:'; + } + // and of course once at the beginning of it all 8-) + slReset(); + var sch = document.getElementById("silverlightControlHost"); if (sch) { + // debug console.log(urls); + + // find place to append the stream list to + // if possible, look for an existing ul in what is likely to be the top + // otherwise, create an ul and put it either in a miniLink if available, + // or the top otherwise + // TODO use some smarter mechanism + var pp = sch.parentNode.parentNode.previousElementSibling; + var specs = pp.getElementsByTagName('ul'); + if (!specs || !specs[0]) { + specs = document.createElement('ul'); + specs.className = 'Specifiche'; + var mid = document.getElementById('Notizie'); + if (mid) { + mid = mid.lastElementChild; + mid.insertBefore(specs, mid.firstElementChild); + } else { + pp.appendChild(specs); + } + } else { + specs = specs[0]; + } + specs.appendChild(streamlist); + console.log(streamlist, 'appended'); + // if we are on a page that defines the videourl* metas, go straight to creating // the video element if (urls.std) { @@ -68,26 +116,11 @@ "

Sorry, no supported video format found :-(

"; console.log(sch, 'hacked'); - var list = document.createElement("li"); - list.id = 'mediaurl'; - list.innerHTML = 'Stream/Download:'; for (var fmt in urls) { var a = H5a(fmt); if (a) - list.appendChild(a); + streamlist.appendChild(a); } - // find place to append the list to: - var pp = sch.parentNode.parentNode.previousElementSibling; - var specs = pp.getElementsByTagName('ul'); - if (!specs || !specs[0]) { - specs = document.createElement('ul'); - specs.className = 'Specifiche'; - pp.appendChild(specs); - } else { - specs = specs[0]; - } - specs.appendChild(list); - console.log(list, 'enumerated and appended'); return; // done } @@ -99,21 +132,45 @@ ggP = dataP.getDate() + "-"; mmP = dataP.getMonth() + 1 + "-"; aaaaP = 1900 + dataP.getYear(); + // stop loading any current audio/video if (sch.firstChild && sch.firstChild.src) { console.log('stopping current A/V'); sch.firstChild.src = ''; } + + // re-create the video player sch.innerHTML = ""; + + // re-create stream list + slReset(); + // oh we would like to indicate the media type somehow, + // but it seems to be somewhat random. Not even a HEAD + // on the URL works reliably all the time + var a = H5aRaw('1', h264); + if (a) + streamlist.appendChild(a); + if (androidUrl != h264) { + a = H5aRaw('2', androidUrl); + if (a) + streamlist.appendChild(a); + } + if ((video != androidUrl) && (video != h264)) { + a = H5aRaw('3', video); + if (a) + streamlist.appendChild(a); + } + setNielsen(location.href + '&video=' + liveTg + '&data=' + ggP + mmP + aaaaP + '', true); console.log('playTg', liveTg, video, h264, androidUrl) } console.log('playTg hacked'); } + if (window.playAudio) { window.playAudio = function (grrEdizione, mediaUrl, mediatype) { var dataP = new Date(); @@ -121,14 +178,24 @@ ggP = dataP.getDate() + "-"; mmP = dataP.getMonth() + 1 + "-"; aaaaP = 1900 + dataP.getYear(); + // stop loading any current audio/video if (sch.firstChild && sch.firstChild.src) { console.log('stopping current A/V'); sch.firstChild.src = ''; } + + // re-create the audio player sch.innerHTML = ""; + "

Sorry, no supported audio format found :-(

"; + + // re-create stream list + slReset(); + var a = H5aRaw(mediatype ? mediatype : '(???)', mediaUrl); + if (a) + streamlist.appendChild(a); + setNielsen(location.href + '&audio=' + grrEdizione + '&data=' + ggP + mmP + aaaaP + '', true); console.log('playAudio', grrEdizione, mediaUrl, mediatype); } -- 2.32.0.93.g670b81a890