Fix vidmoly.to

This commit is contained in:
bytedream 2024-12-15 17:31:13 +01:00
parent e522916585
commit fd3eda9c61
5 changed files with 36 additions and 19 deletions

View File

@ -80,7 +80,7 @@ The best way to install the extension are the official browser extension stores:
## 📜 Supported websites
| Site | Firefox & Firefox for Android | Chrome & Chromium based |
|-----------------------------------------------------------------------| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [dropload.io](https://dropload.io) | ✔ | ✔ |
| [doodstream.com](doodstream.com) / [dood.pm](https://dood.pm) | ✔️ | ⚠ (redirect probably required) |
| [filemoon.to](https://filemoon.to) | ✔ | ✔ |
@ -93,7 +93,7 @@ The best way to install the extension are the official browser extension stores:
| [streamzz.to](https://streamzz.to) / [streamz.ws](https://streamz.ws) | ✔ | ✔ |
| [supervideo.tv](https://supervideo.tv) | ✔ | ✔ |
| [upstream.to](https://upstream.to) | ✔ | ✔ |
| [vidmoly.me](https://vidmoly.me) | ✔ | ✔ |
| [vidmoly.to](https://vidmoly.me) | ✔ | ✔ |
| [vidoza.net](https://vidoza.net) | ⚠ (doesn't always work the first time, retrying/reloading the page one or two times fixes it) | ⚠ (doesn't always work the first time, retrying/reloading the page one or two times fixes it) |
| [voe.sx](https://voe.sx) | ✔ | ❌ (redirect always required) |
| [vupload.com](https://vupload.com) | ✔ | ✔ |

View File

@ -1,23 +1,23 @@
import './shared';
import type { Match } from '~/lib/match';
import { Redirect, storageDelete, storageGet } from '~/lib/settings';
import { Redirect, UrlReferer } from '~/lib/settings';
import { getMatch } from '~/lib/match';
chrome.webRequest.onBeforeSendHeaders.addListener(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
async (details) => {
const referer: { domain: string } | undefined = await storageGet('referer');
if (referer === undefined) return;
const referer = await UrlReferer.get(new URL(details.url).hostname);
if (!referer) return;
await UrlReferer.delete(new URL(details.url).hostname);
details.requestHeaders!.push({
name: 'Referer',
value: `https://${referer.domain}/`
value: `https://${referer}/`
});
await storageDelete('referer');
return { requestHeaders: details.requestHeaders };
},
{ urls: ['<all_urls>'], types: ['xmlhttprequest'] },

View File

@ -1,17 +1,23 @@
import { matches } from '~/lib/match';
import Hls from 'hls.js';
import { storageSet } from '~/lib/settings';
import { UrlReferer } from '~/lib/settings';
async function playNative(url: string, domain: string, videoElem: HTMLVideoElement) {
await UrlReferer.set(new URL(url).hostname, domain);
async function playNative(url: string, videoElem: HTMLVideoElement) {
videoElem.src = url;
}
async function playHls(url: string, videoElem: HTMLVideoElement) {
async function playHls(url: string, domain: string, videoElem: HTMLVideoElement) {
if (videoElem.canPlayType('application/vnd.apple.mpegurl')) {
videoElem.src = url;
} else if (Hls.isSupported()) {
const hls = new Hls({
enableWorker: false
enableWorker: false,
xhrSetup: async (xhr: XMLHttpRequest, url: string) => {
await UrlReferer.set(new URL(url).hostname, domain);
xhr.open('GET', url);
}
});
hls.loadSource(url);
hls.attachMedia(videoElem);
@ -32,11 +38,9 @@ export async function play(videoElem: HTMLVideoElement) {
}
document.title = `Stream Bypass (${domain})`;
await storageSet('referer', { domain: domain });
if (new URL(url).pathname.endsWith('.m3u8')) {
await playHls(url, videoElem);
await playHls(url, domain, videoElem);
} else {
await playNative(url, videoElem);
await playNative(url, domain, videoElem);
}
}

View File

@ -225,6 +225,7 @@ export const Vidmoly: Match = {
id: 'vidmoly',
domains: ['vidmoly.me', 'vidmoly.to'],
regex: [/(?<=file:").+\.m3u8/gm],
replace: true,
match: async (match: RegExpMatchArray) => {
return match[0];

View File

@ -58,6 +58,18 @@ export const TmpHost = {
}
};
export const UrlReferer = {
get: async (url: string): Promise<string | null> => {
return (await storageGet(`urlReferer.${url}`)) || null;
},
set: async (url: string, referer: string) => {
await storageSet(`urlReferer.${url}`, referer);
},
delete: async (url: string) => {
await storageDelete(`urlReferer.${url}`);
}
};
export const Other = {
getFf2mpv: async () => {
return await storageGet('other.ff2mpv', false);
@ -67,7 +79,7 @@ export const Other = {
}
};
export async function storageGet<T>(key: string, defaultValue?: T): Promise<T | undefined> {
async function storageGet<T>(key: string, defaultValue?: T): Promise<T | undefined> {
let resolve: (value: T | undefined) => void;
const promise = new Promise<T | undefined>((r) => (resolve = r));
@ -79,7 +91,7 @@ export async function storageGet<T>(key: string, defaultValue?: T): Promise<T |
return promise;
}
export async function storageSet<T>(key: string, value: T) {
async function storageSet<T>(key: string, value: T) {
let resolve: () => void;
const promise = new Promise<void>((r) => (resolve = r));
@ -91,7 +103,7 @@ export async function storageSet<T>(key: string, value: T) {
return promise;
}
export async function storageDelete(key: string) {
async function storageDelete(key: string) {
let resolve: () => void;
const promise = new Promise<void>((r) => (resolve = r));