Skip to content

Instantly share code, notes, and snippets.

@Rafaeltheraven
Created December 14, 2022 11:23
Show Gist options
  • Save Rafaeltheraven/79063fa59fe6d374636df29214532a82 to your computer and use it in GitHub Desktop.
Save Rafaeltheraven/79063fa59fe6d374636df29214532a82 to your computer and use it in GitHub Desktop.
Open in VLC button for all platforms
const parseRegex = /.*%0A.*%0A(https%3A%2F%2F(.*))/;
function iOS() { // We have to do this in JS because Apple sucks cock
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
// iPad on iOS 13 detection
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
function android() {
return navigator.userAgent.toLowerCase().indexOf("android") > -1;
}
function setVLCiOS() {
vlcs = document.getElementsByClassName('vlc');
for (var i = 0; i < vlcs.length; i++) {
vlc = vlcs[i];
stream_url = decodeURIComponent(extractURL(vlc.href)[1]); // With https://
vlc.setAttribute('href','vlc://' + stream_url);
vlc.removeAttribute('download');
}
}
function setVLCAndroid() {
vlcs = document.getElementsByClassName('vlc');
for (var i = 0; i < vlcs.length; i++) {
vlc = vlcs[i];
stream_url = decodeURIComponent(extractURL(vlc.href)[2]); // Without https://
vlc.setAttribute('href', 'intent://' + stream_url + '#Intent;scheme=https;type=video/*;end')
vlc.removeAttribute('download');
}
}
function extractURL(text) {
return text.match(parseRegex);
}
window.onload = function() {
ios = iOS();
if (ios === true) {
setVLCiOS();
} else if (android() === true) {
setVLCAndroid();
}
};
// $file = Filename
// $endpoint = The actual endpoint on which the file is hosted
$txt = "#EXTM3U\n#EXTINF:-1," . $file . "\n" . $endpoint;
echo "<a href='data:application/x-mpegurl;charset=utf-8,".rawurlencode($txt)."' download='".$file.".m3u8' class='vlc'> Open in VLC </a>";
@Rafaeltheraven
Copy link
Author

"Open in VLC" on desktops just means creating an m3u file, so you can also open in, for example, MPV. I think on Android you can also just open with any other player. For iOS, I think this only works with specifically the VLC app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment