Jay Taylor's notes
back to listing indexHow to use VLC to watch m3u8 playlist at URL with custom HTTP referrer and user agent · GitHub
[web search]
Original source (gist.github.com)
Clipped on: 2024-09-17
(function (xhr) {
var XHR = XMLHttpRequest.prototype
var open = XHR.open
XHR.open = function (method, url) {
this._method = method
this._url = url
if ((arguments[0] == "GET") && ((arguments[1].indexOf(".mp4") > 0) || (arguments[1].indexOf(".m3u8") > 0)))
console.log("open: url:", url)
return open.apply(this, arguments)
}
})(XMLHttpRequest)
And to tie it all together, here's a bookmarklet that will construct and download a playlist.m3u8
file that can be opened in VLC.
(() => { const XHR = XMLHttpRequest.prototype; const open = XHR.open; let done = false; XHR.open = function (...args) { const [method, url] = args; this._method = method; this._url = url; if ( done === false && method === 'GET' && ['.mp4', '.m3u8'].some(type => new URL(url).pathname.endsWith(type)) ) { done = true; const playlist = [ '#EXTM3U', `#EXTVLCOPT:http-referrer=${location.toString()}`, '#EXTVLCOPT:http-user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0', url, ].join('n'); const link = document.createElement('a'); link.setAttribute('download', 'playlist.m3u8'); link.setAttribute('href', `data:application/vnd.apple.mpegurl;base64,${btoa(playlist)}`); link.click(); } return open.apply(this, args); }; })();
The yt-dlp generic extractor will be able to handle this and more. If you have both yt-dlp and mpv installed then you can often just do mpv $video_page_url
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment