11import React , { useEffect , useRef , useState } from "react" ;
22import { useNavigate , useParams , useSearchParams } from "react-router-dom" ;
33import {
4+ getLibraryDir ,
45 getLibraryMeta ,
56 getPlayQueue ,
67 getServerPreferences ,
@@ -29,7 +30,11 @@ import {
2930 useTheme ,
3031} from "@mui/material" ;
3132import ReactPlayer from "react-player" ;
32- import { queryBuilder } from "../plex/QuickFunctions" ;
33+ import {
34+ getIncludeProps ,
35+ getXPlexProps ,
36+ queryBuilder ,
37+ } from "../plex/QuickFunctions" ;
3338import {
3439 ArrowBackIosNewRounded ,
3540 ArrowBackIosRounded ,
@@ -62,6 +67,32 @@ import { platformCache } from "../common/DesktopApp";
6267let SessionID = "" ;
6368export { 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+
6596function 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 (
0 commit comments