Skip to content

Commit 4f66452

Browse files
authored
Merge pull request #64 from Ipmake/dev
Version 1.3.2
2 parents 8d56534 + 3b84bde commit 4f66452

File tree

4 files changed

+70
-51
lines changed

4 files changed

+70
-51
lines changed

backend/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const proxy = httpProxy.createProxyServer({
5454
cookieDomainRewrite: (new URL(process.env.PLEX_SERVER as string)).hostname,
5555
changeOrigin: true,
5656
secure: false,
57+
followRedirects: true,
5758
});
5859

5960
proxy.on('error', (err, req, res) => {
@@ -496,6 +497,10 @@ app.use('/dynproxy/*', (req, res) => {
496497
const url = req.originalUrl.split('/dynproxy')[1];
497498
if (!url) return res.status(400).send('Bad request');
498499

500+
// strip cookies from the request
501+
req.headers.cookie = '';
502+
req.headers['x-forwarded-for'] = ((req.headers['x-forwarded-for'] || req.socket.remoteAddress || '') as string).replace("::ffff:", "");
503+
499504
proxy.web(req, res, { target: `${process.env.PLEX_SERVER}${url}` }, (err) => {
500505
console.error('Proxy error:', err);
501506
res.status(500).send('Proxy error');
@@ -504,7 +509,9 @@ app.use('/dynproxy/*', (req, res) => {
504509

505510
app.post('/proxy', (req, res) => {
506511
const { url, method, headers, data } = req.body;
507-
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
512+
const ip = ((req.headers['x-forwarded-for'] || req.socket.remoteAddress || '') as string).replace("::ffff:", "");
513+
514+
console.log(`[${new Date().toISOString()}] [PROXY] [${method}] ${url} from ${ip}`);
508515

509516
// the url must start with a / to prevent the server from making requests to external servers
510517
if (!url || !url.startsWith('/')) return res.status(400).send('Invalid URL');
@@ -523,7 +530,7 @@ app.post('/proxy', (req, res) => {
523530
'Accept': 'application/json',
524531
'Content-Type': 'application/json',
525532
'User-Agent': 'Mozilla/5.0',
526-
'X-Fowarded-For': ip,
533+
'X-Forwarded-For': ip,
527534
},
528535
data,
529536
...(process.env.DISABLE_TLS_VERIFY === "true" && {

frontend/package-lock.json

Lines changed: 3 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/pages/Watch.tsx

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useRef, useState } from "react";
22
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
33
import {
4+
getLibraryDir,
45
getLibraryMeta,
56
getPlayQueue,
67
getServerPreferences,
@@ -29,7 +30,11 @@ import {
2930
useTheme,
3031
} from "@mui/material";
3132
import ReactPlayer from "react-player";
32-
import { queryBuilder } from "../plex/QuickFunctions";
33+
import {
34+
getIncludeProps,
35+
getXPlexProps,
36+
queryBuilder,
37+
} from "../plex/QuickFunctions";
3338
import {
3439
ArrowBackIosNewRounded,
3540
ArrowBackIosRounded,
@@ -62,6 +67,32 @@ import { platformCache } from "../common/DesktopApp";
6267
let SessionID = "";
6368
export { SessionID };
6469

70+
const getUrl = (
71+
data: Plex.Metadata,
72+
quality: { bitrate?: number; auto?: boolean }
73+
) => {
74+
console.log("Metadata:", data);
75+
const bitrate = quality
76+
? quality.bitrate
77+
: parseInt(localStorage.getItem("quality") ?? "10000");
78+
if (bitrate === -1)
79+
return `${getBackendURL()}/dynproxy${
80+
data?.Media?.[0].Part[0].key
81+
}?${queryBuilder({
82+
...getXPlexProps(),
83+
})}`;
84+
85+
return `${getBackendURL()}/dynproxy/video/:/transcode/universal/start.${
86+
platformCache.isDesktop ? "m3u8" : "mpd"
87+
}?${queryBuilder({
88+
...getStreamProps(data.ratingKey as string, {
89+
...(quality.bitrate && {
90+
maxVideoBitrate: bitrate,
91+
}),
92+
}),
93+
})}`;
94+
};
95+
6596
function Watch() {
6697
const { itemID } = useParams<{ itemID: string }>();
6798
const [params] = useSearchParams();
@@ -121,12 +152,14 @@ function Watch() {
121152
});
122153

123154
let Metadata: Plex.Metadata | null = null;
124-
await getLibraryMeta(itemID).then((metadata) => {
125-
Metadata = metadata;
126-
if (["movie", "episode"].includes(metadata.type)) {
127-
setMetadata(metadata);
128-
if (metadata.type === "episode") {
129-
getLibraryMeta(metadata.grandparentRatingKey as string).then(
155+
await getLibraryDir(`/library/metadata/${itemID}`, {
156+
...getIncludeProps(),
157+
}).then((mediacontainer) => {
158+
Metadata = mediacontainer.Metadata?.[0] ?? null;
159+
if (["movie", "episode"].includes(Metadata?.type as string)) {
160+
setMetadata(Metadata);
161+
if (Metadata?.type === "episode") {
162+
getLibraryMeta(Metadata?.grandparentRatingKey as string).then(
130163
(show) => {
131164
setShowMetadata(show);
132165
}
@@ -152,15 +185,6 @@ function Watch() {
152185
};
153186

154187
const [url, setURL] = useState<string>("");
155-
const getUrl = `${getBackendURL()}/dynproxy/video/:/transcode/universal/start.${platformCache.isDesktop ? "m3u8" : "mpd"}?${queryBuilder({
156-
...getStreamProps(itemID as string, {
157-
...(quality.bitrate && {
158-
maxVideoBitrate: quality
159-
? quality.bitrate
160-
: parseInt(localStorage.getItem("quality") ?? "10000"),
161-
}),
162-
}),
163-
})}`;
164188

165189
const [showControls, setShowControls] = useState(true);
166190
useEffect(() => {
@@ -419,10 +443,10 @@ function Watch() {
419443
}
420444
}
421445

422-
console.log(`Setting URL: ${getUrl}`);
446+
console.log(`Setting URL: ${getUrl(metadata, quality)}`);
423447

424448
await loadMetadata(itemID);
425-
setURL(getUrl);
449+
setURL(getUrl(metadata, quality));
426450
setShowError(false);
427451
})();
428452
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1093,7 +1117,7 @@ function Watch() {
10931117
seekToAfterLoad.current = progress;
10941118
setURL("");
10951119
setTimeout(() => {
1096-
setURL(getUrl);
1120+
setURL(getUrl(metadata, quality));
10971121
}, 100);
10981122
}}
10991123
>
@@ -1186,7 +1210,7 @@ function Watch() {
11861210
seekToAfterLoad.current = progress;
11871211
setURL("");
11881212
setTimeout(() => {
1189-
setURL(getUrl);
1213+
setURL(getUrl(metadata, quality));
11901214
}, 100);
11911215
}}
11921216
>
@@ -1264,7 +1288,7 @@ function Watch() {
12641288
seekToAfterLoad.current = progress;
12651289
setURL("");
12661290
setTimeout(() => {
1267-
setURL(getUrl);
1291+
setURL(getUrl(metadata, quality));
12681292
}, 100);
12691293
}}
12701294
>
@@ -1332,7 +1356,7 @@ function Watch() {
13321356
seekToAfterLoad.current = progress;
13331357
setURL("");
13341358
setTimeout(() => {
1335-
setURL(getUrl);
1359+
setURL(getUrl(metadata, quality));
13361360
}, 100);
13371361
}}
13381362
>
@@ -1684,9 +1708,7 @@ function Watch() {
16841708
)
16851709
return "";
16861710
return getTranscodeImageURL(
1687-
`/library/parts/${
1688-
metadata.Media[0].Part[0].id
1689-
}/indexes/sd/${value}`,
1711+
`/library/parts/${metadata.Media[0].Part[0].id}/indexes/sd/${value}`,
16901712
240,
16911713
135
16921714
);
@@ -1941,9 +1963,6 @@ function Watch() {
19411963
}}
19421964
config={{
19431965
file: {
1944-
forceDisableHls: !platformCache.isDesktop,
1945-
forceHLS: platformCache.isDesktop,
1946-
forceDASH: !platformCache.isDesktop,
19471966
hlsVersion: "1.6.7",
19481967
dashVersion: "4.7.4",
19491968
attributes: {
@@ -2193,6 +2212,13 @@ export function getCurrentVideoLevels(
21932212
original?: boolean;
21942213
}[] = [];
21952214

2215+
// if (platformCache.isDesktop)
2216+
// levels.push({
2217+
// title: "Direct Play (Original)",
2218+
// bitrate: -1,
2219+
// extra: extraForOriginal,
2220+
// });
2221+
21962222
switch (resolution) {
21972223
case "720":
21982224
levels.push(

frontend/src/plex/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function getStreamProps(key: string, limitation: {
110110
audioBoost: 700,
111111
autoAdjustQuality: limitation.autoAdjustQuality ? 1 : 0,
112112
autoAdjustSubtitle: 0,
113-
directPlay: 0,
113+
directPlay: limitation.maxVideoBitrate === -1 ? 1 : 0,
114114
directStream: 1,
115115
directStreamAudio: 1,
116116
fastSeek: 1,
@@ -123,14 +123,14 @@ export function getStreamProps(key: string, limitation: {
123123
protocol: platformCache.isDesktop ? "hls" : "dash",
124124
addDebugOverlay: 0,
125125
subtitleSize: 100,
126-
subtitles: "burn",
126+
subtitles: limitation.maxVideoBitrate === -1 ? "sidecar" : "burn",
127127
"Accept-Language": "en",
128128
...getXPlexProps(),
129129
...(limitation.autoAdjustQuality && {
130130
autoAdjustQuality: limitation.autoAdjustQuality ? 1 : 0
131131
}),
132-
...(limitation.maxVideoBitrate && {
133-
maxVideoBitrate: limitation.maxVideoBitrate
132+
...(limitation.maxVideoBitrate && limitation.maxVideoBitrate !== -1 && {
133+
maxVideoBitrate: limitation.maxVideoBitrate,
134134
})
135135
}
136136
}

0 commit comments

Comments
 (0)