Skip to content

Commit

Permalink
apn mpd
Browse files Browse the repository at this point in the history
  • Loading branch information
nb557 committed Sep 17, 2024
1 parent 0cc3ebc commit eab799e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
9 changes: 7 additions & 2 deletions cloudflare_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
let body = "";
request.headers.forEach((value, key) => body += key + " = " + value + "\n");
body += "request_url" + " = " + request.url + "\n";
body += "worker_version = 1.06\n";
body += "worker_version = 1.07\n";
return new Response(body, corsHeaders);
}

Expand Down Expand Up @@ -76,7 +76,12 @@ export default {
api_pos += api.length;
api = "";
}
params.push(param.split("="));
pos = param.indexOf("=");
if (pos !== -1) {
params.push([param.substring(0, pos), param.substring(pos + 1)]);
} else {
params.push([param]);
}
} else {
next_param = false;
}
Expand Down
56 changes: 53 additions & 3 deletions deno_apn.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function handle(request, connInfo) {
body += "connInfo" + " = " + JSON.stringify(connInfo.remoteAddr) + "\n";
}
body += "request_url" + " = " + request.url + "\n";
body += "apn_version = 1.06\n";
body += "apn_version = 1.07\n";
return new Response(body, corsHeaders);
}

Expand Down Expand Up @@ -78,7 +78,12 @@ async function handle(request, connInfo) {
api_pos += api.length;
api = "";
}
params.push(param.split("="));
pos = param.indexOf("=");
if (pos !== -1) {
params.push([param.substring(0, pos), param.substring(pos + 1)]);
} else {
params.push([param]);
}
} else {
next_param = false;
}
Expand Down Expand Up @@ -176,7 +181,7 @@ async function handle(request, connInfo) {
if (apiUrl.hostname === "kinoplay.site" || apiUrl.hostname === "kinoplay1.site" || apiUrl.hostname === "kinoplay2.site") {
request.headers.set("Cookie", "invite=a246a3f46c82fe439a45c3dbbbb24ad5");
}
if (apiUrl.pathname.endsWith(".m3u8") || apiUrl.pathname.endsWith(".m3u") || apiUrl.pathname.endsWith(".M3U8") || apiUrl.pathname.endsWith(".M3U")) {
if (apiUrl.pathname.endsWith(".m3u8") || apiUrl.pathname.endsWith(".m3u") || apiUrl.pathname.endsWith(".M3U8") || apiUrl.pathname.endsWith(".M3U") || apiUrl.pathname.endsWith(".mpd") || apiUrl.pathname.endsWith(".MPD")) {
request.headers.delete("Range");
}
params.forEach(param => {
Expand Down Expand Up @@ -221,6 +226,13 @@ async function handle(request, connInfo) {
response.headers.set("Accept-Ranges", "none");
return new Response(body, response);
}
if (["application/dash+xml"].indexOf(ctype) !== -1) {
let body = edit_mpd(await response.text(), proxy, apiUrl, apiBase);
response.headers.delete("Content-Length");
response.headers.delete("Content-Range");
response.headers.set("Accept-Ranges", "none");
return new Response(body, response);
}
}

// Fix redirect URL
Expand Down Expand Up @@ -268,6 +280,44 @@ async function handle(request, connInfo) {
}
}

function unescapeXml(str) {
return str.replace(/<|>|&|'|"/g, function (c) {
switch (c) {
case "&lt;": return "<";
case "&gt;": return ">";
case "&amp;": return "&";
case "&apos;": return "'";
case "&quot;": return '"';
}
});
}

function escapeXml(str) {
return str.replace(/[<>&'"]/g, function (c) {
switch (c) {
case "<": return "&lt;";
case ">": return "&gt;";
case "&": return "&amp;";
case "'": return "&apos;";
case '"': return "&quot;";
}
});
}

function edit_mpd(mpd, proxy, url, base) {
try {
return mpd.replace(/<BaseURL>([^<]*)/g, (str, link) => {
link = link.trim();
if (link) {
return "<BaseURL>" + escapeXml(fixLink(unescapeXml(link), proxy, url, base));
}
return str;
});
} catch (err) {
return mpd;
}
}

async function handleOptions(request, connInfo) {
if (
request.headers.get("Origin") !== null &&
Expand Down
9 changes: 7 additions & 2 deletions deno_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function handle(request, connInfo) {
body += "connInfo" + " = " + JSON.stringify(connInfo.remoteAddr) + "\n";
}
body += "request_url" + " = " + request.url + "\n";
body += "worker_version = 1.06\n";
body += "worker_version = 1.07\n";
return new Response(body, corsHeaders);
}

Expand Down Expand Up @@ -78,7 +78,12 @@ async function handle(request, connInfo) {
api_pos += api.length;
api = "";
}
params.push(param.split("="));
pos = param.indexOf("=");
if (pos !== -1) {
params.push([param.substring(0, pos), param.substring(pos + 1)]);
} else {
params.push([param]);
}
} else {
next_param = false;
}
Expand Down

0 comments on commit eab799e

Please sign in to comment.