Added native m3u8 / hls streaming

This commit is contained in:
bytedream 2021-10-23 00:13:53 +02:00
parent 2e13586ebb
commit 9929c48761
6 changed files with 53 additions and 2 deletions

View File

@ -35,6 +35,13 @@ def write_manifest():
for content_script in manifest['content_scripts']:
content_script['matches'] = [f'*://{match}/*' for match in matches]
domains = []
for match in matches:
toplevel = match.split('.')[-1]
if toplevel not in domains:
domains.append(toplevel)
manifest['content_security_policy'] = f"script-src 'self' blob: https://cdn.jsdelivr.net {' '.join(f'*.{toplevel}' for toplevel in domains)}; object-src 'self'"
json.dump(manifest, open('src/manifest.json', 'w'), indent=2)

View File

@ -28,11 +28,13 @@ chrome.storage.local.get(['all', 'disabled'], function (result) {
if (regex === null) {
location.assign(document.body.innerHTML)
} else {
location.assign(hasSuffix(re[0], 'm3u8') ? `https://bharadwajpro.github.io/m3u8-player/player/#${re[0]}`: re[0])
// @ts-ignore
location.assign(hasSuffix(re[0], 'm3u8') ? chrome.runtime.getURL(`res/hls.html#${re[0]}`) : re[0])
}
} else {
matchClass.match(re).then(function (path) {
location.assign(hasSuffix(path, 'm3u8') ? `https://bharadwajpro.github.io/m3u8-player/player/#${path}`: path)
// @ts-ignore
location.assign(hasSuffix(path, 'm3u8') ? chrome.runtime.getURL(`res/hls.html#${path}`) : path)
})
}
}

View File

@ -15,6 +15,7 @@
"all_frames": true,
"matches": [
"*://evoload.io/*",
"*://mcloud.to/*",
"*://mixdrop.co/*",
"*://streamtape.com/*",
"*://streamzz.to/*",
@ -35,6 +36,7 @@
"permissions": [
"storage"
],
"content_security_policy": "script-src 'self' blob: https://cdn.jsdelivr.net *.io *.to *.co *.com *.me *.net *.st *.sx; object-src 'self'",
"browser_action": {
"default_icon": "icons/stream-bypass.png",
"default_title": "Stream Bypass",

14
src/res/hls.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--I haven't found out how to include scripts from third party websites, if even possible. PRs are always welcome-->
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<link rel="stylesheet" href="/res/hls.css">
<title>m3u8</title>
</head>
<body style="margin: 0">
<video id="video" style="width: 100%; height: 100%"></video>
<p id="not-supported" hidden>Filed to play m3u8 video. Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues">here</a></p>
<script src="/res/hls.js"></script>
</body>
</html>

6
src/res/hls.sass Normal file
View File

@ -0,0 +1,6 @@
html, body, video
height: 100%
width: 100%
video
margin: auto

20
src/res/hls.ts Normal file
View File

@ -0,0 +1,20 @@
function loadHls() {
let url = window.location.hash.substring(1)
let video = document.getElementById('video') as HTMLVideoElement;
video.controls = true
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url
// @ts-ignore
} else if (Hls.isSupported()) {
// @ts-ignore
let hls = new Hls()
hls.loadSource(url)
hls.attachMedia(video)
} else {
// shows a message if hls is not supported
document.getElementById('not-supported').hidden = false
}
}
loadHls()