TV News example




Shortcut : https://www.icloud.com/shortcuts/418a36693e514eb99b062b4dc2649451

videoFinder script :

// credits to @memalign creator of original DPDL shortcut. https://www.icloud.com/shortcuts/6b904d0393ef4bc797489692203545dd

// cleaned & updated by @sjshaiks. 


let url = args.shortcutParameter;
let wv = new WebView()
await wv.loadURL(url)
let js = `
var plainHTMLVideoSourceResults = new Array();
function addPlainHTMLVideoSourceResult(res) {
//console.log("Inside addPlainHTMLVideoSourceResult function " );
    if (plainHTMLVideoSourceResults.indexOf(res) < 0) {
        plainHTMLVideoSourceResults.push(res);
    }
}

function updateVideoResultTable(showEmpty) {
    collectCurlCommandsForDocument(document, 'video');
    recursivelyInspectIFrames(document);
}

function recursivelyInspectIFrames(doc) {
var iframes = doc.getElementsByTagName('iframe'); 
for (var i = 0; i < iframes.length; i++) {
        var iframe = iframes.item(i);
        var iframeDocument = iframe.contentDocument;
        //console.log("iframeDocument : " + iframeDocument);
        if (iframeDocument) {
            collectCurlCommandsForDocument(iframeDocument, 'video');
            recursivelyInspectIFrames(iframeDocument);
        } else {
            console.log("Found cross-origin iframe which might contain a video: " + iframe.src);
        }
    }
}

function collectCurlCommandsForDocument(doc, tagName) {
//console.log("Inside collectCurlCommandsForDocument function " );
var vids = doc.getElementsByTagName(tagName);
// vids is an HTMLCollection
for (var i = 0; i < vids.length; i++) { 
	var videoSrc = vids.item(i).src;
		if (!videoSrc) {
			var potentialSources = vids.item(i).getElementsByTagName('source');
			if (potentialSources && potentialSources.item(0)) {
				videoSrc = potentialSources.item(0).src;
			}
		}
		console.log("Video url: " + videoSrc);
		if (videoSrc) {
			addPlainHTMLVideoSourceResult(videoSrc);
		}
	}
}

updateVideoResultTable(false);

setTimeout(function() {
    updateVideoResultTable(true);
}, 10000);
let vidString = plainHTMLVideoSourceResults[0];
vidString;
`

let vidTemp = await wv.evaluateJavaScript(js);
//log(vidTemp);

let stream_url = encodeURI(vidTemp)
Script.setShortcutOutput(stream_url);
Script.complete();

hls_player script:

   // updated by @sjshaiks. contributed by jtokash 
    var url = args.shortcutParameter;
    let html = `
    <html><body>
    <style>
    body {
      margin: 0;
      padding 0;
      background: black;
    }
    .vid {
      width: 100%;
      height: 100%;
    }
    </style>
    <video src="${url}" autoplay controls></video>
    </html></body>
    `
    WebView.loadHTML(html, null, new Size(0, 202))
1 Like

Thanks!! Works like a charm on my phone.

On iPad, the Scriptable box at the end is completely black, with no audio. I’ve tried CNN, BBC and MSNBC so far. I used quick look to verify that the streaming URL is correct. Still investigating.

I didn’t test on iPad. Please test this stand alone shortcut.
https://www.icloud.com/shortcuts/c8be74c6e3c84001b19f7b81bb847e12

@slmkdp, that also failed with a black box on iPad Pro 11" iOS 13.3.

I think it’s something funky with hls.js. For what it’s worth I suggest not leveraging the hls.js library and instead doing one of the following (which are working perfectly on iPad and iPhone):

  • In the shortcut, load the resulting m3u8 url in Safari with the Open action, or
  • Replace the hls_player script with one that just populates an HTML5 video tag directly <video src="${url}" autoplay controls></video>

Given that Shortcuts and Scriptable are both iOS-only, I’m not sure what the benefit of using hls.js is.

1 Like

Thanks for the suggestions. You are right hls.js is not needed for iOS when hls format is supported natively.
Updated the hls script with your contributions.

Only BBC, Aljazeera, and Weather Channel are working for me. I’m on an iPhone XS, iOS 13.3. Looks like the m3u8 feeds are working; but, the others are not.

Also, there’s a small typo in Bloomberg in the Shortcut.

The links in the shortcut are for only demo purpose. You can google for sites that has live streams playable on iOS and edit the shortcuts with site URLs or direct .m3u8 links.

1 Like

Hiya, thanks for such a fun script. Just wanted to share a shortcut to which I added a bit more examples :stuck_out_tongue_winking_eye: https://www.icloud.com/shortcuts/c60916100bf24e2daaadd58a3f5d861a

1 Like

Updated shortcut

More channels can be found at https://ustvgo.tv/