Created
December 14, 2022 11:23
-
-
Save Rafaeltheraven/79063fa59fe6d374636df29214532a82 to your computer and use it in GitHub Desktop.
Open in VLC button for all platforms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $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>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"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.