TV News example
Play SJTV Shortcut
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:
//source : https://github.com/video-dev/hls.js
// 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))
0 comments:
Post a Comment