Skip to content

Commit

Permalink
Fix muted segments not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
besuper committed Nov 20, 2022
1 parent 0769bb7 commit d239210
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion firefox-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TwitchNoSub",
"version": "0.6",
"version": "0.6.1",
"description": "Show sub only VOD on Twitch",
"manifest_version": 2,
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TwitchNoSub",
"version": "0.6",
"version": "0.6.1",
"description": "Show sub only VOD on Twitch",
"manifest_version": 3,
"icons": {
Expand Down
34 changes: 10 additions & 24 deletions src/patched-amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const oldFetch = self.fetch;
self.fetch = async function (url, opt) {
let response = await oldFetch(url, opt);

// Patch playlist from unmuted to muted segments
if (url.includes("cloudfront") && url.includes(".m3u8")) {
const body = await response.text();

return new Response(body.replace(/-unmuted/g, "-muted"), { status: 200 });
}

if (url.startsWith("https://usher.ttvnw.net/vod/")) {
if (response.status != 200) {
const vodId = url.split("https://usher.ttvnw.net/vod/")[1].split(".m3u8")[0];
Expand All @@ -37,9 +44,6 @@ self.fetch = async function (url, opt) {
});
}

// Muted segement are not supported for now
const isMuted = data.muted_segments != undefined && data.muted_segments.length > 0;

let resolutions = data.resolutions;

let sorted_dict = Object.keys(resolutions);
Expand Down Expand Up @@ -68,14 +72,8 @@ self.fetch = async function (url, opt) {
switch (data.broadcast_type) {
case "highlight":
for ([resKey, resValue] of Object.entries(resolutions)) {
let link = `https://${domain}/${vodSpecialID}/${resKey}/highlight-${vodId}.m3u8`;

/*if (isMuted) {
link = await patchUnmutedPlaylist(`https://${domain}/${vodSpecialID}/${resKey}/`, link, vodSpecialID, resKey);
}*/

sources_.push({
src: link,
src: `https://${domain}/${vodSpecialID}/${resKey}/highlight-${vodId}.m3u8`,
quality: resKey,
resolution: resValue,
fps: Math.ceil(data.fps[resKey]),
Expand All @@ -86,14 +84,8 @@ self.fetch = async function (url, opt) {
break;
case "upload":
for ([resKey, resValue] of Object.entries(resolutions)) {
let link = `https://${domain}/${data.channel.name}/${vodId}/${vodSpecialID}/${resKey}/index-dvr.m3u8`;

/*if (isMuted) {
link = await patchUnmutedPlaylist(`https://${domain}/${data.channel.name}/${vodId}/${vodSpecialID}/${resKey}/`, link, vodSpecialID, resKey);
}*/

sources_.push({
src: link,
src: `https://${domain}/${data.channel.name}/${vodId}/${vodSpecialID}/${resKey}/index-dvr.m3u8`,
quality: resKey,
resolution: resValue,
fps: Math.ceil(data.fps[resKey]),
Expand All @@ -104,14 +96,8 @@ self.fetch = async function (url, opt) {
break;
default:
for ([resKey, resValue] of Object.entries(resolutions)) {
let link = `https://${domain}/${vodSpecialID}/${resKey}/index-dvr.m3u8`;

/*if (isMuted) {
link = await patchUnmutedPlaylist(`https://${domain}/${vodSpecialID}/${resKey}/`, link, vodSpecialID, resKey);
}*/

sources_.push({
src: link,
src: `https://${domain}/${vodSpecialID}/${resKey}/index-dvr.m3u8`,
quality: resKey,
resolution: resValue,
fps: Math.ceil(data.fps[resKey]),
Expand Down

0 comments on commit d239210

Please sign in to comment.