@@ -5,7 +5,8 @@ import { useRouter } from "next/navigation";
55import LoadingOverlay from "@/components/LoadingOverlay" ;
66import { useAppContext } from "@/context/AppContext" ;
77import { playerPathForMedia , softReplaceUrl } from "@/lib/playerNavigation" ;
8- import { isDirectMediaURL , isYoutubeURL } from "@/utils" ;
8+ import { ensureYouTubeLinkMeta } from "@/lib/youtubeOembed" ;
9+ import { getYouTubeId , isDirectMediaURL , isYoutubeURL } from "@/utils" ;
910
1011/**
1112 * Deep-link / rewrite entry for /player and /watch.
@@ -21,25 +22,31 @@ export default function PlayerRouteBridge({ url }: { url?: string }) {
2122 if ( started . current ) return ;
2223 started . current = true ;
2324
24- if ( url && ( isDirectMediaURL ( url ) || isYoutubeURL ( url ) ) ) {
25- // syncUrl false — router.replace("/") would stomp a soft /watch path.
26- openPlayer ( { url, expand : true , syncUrl : false } ) ;
27- router . replace ( "/" ) ;
28- // Re-apply shareable URL after Next lands on Home.
29- const path = playerPathForMedia ( url , null ) ;
30- requestAnimationFrame ( ( ) => softReplaceUrl ( path ) ) ;
31- return ;
32- }
25+ void ( async ( ) => {
26+ if ( url && ( isDirectMediaURL ( url ) || isYoutubeURL ( url ) ) ) {
27+ if ( isYoutubeURL ( url ) ) {
28+ const id = getYouTubeId ( url ) ;
29+ if ( id ) await ensureYouTubeLinkMeta ( id ) ;
30+ }
31+ // syncUrl false — router.replace("/") would stomp a soft /watch path.
32+ openPlayer ( { url, expand : true , syncUrl : false } ) ;
33+ router . replace ( "/" ) ;
34+ // Re-apply shareable URL after Next lands on Home.
35+ const path = playerPathForMedia ( url , null ) ;
36+ requestAnimationFrame ( ( ) => softReplaceUrl ( path ) ) ;
37+ return ;
38+ }
3339
34- if ( media ) {
35- openPlayer ( { media, expand : true , syncUrl : false } ) ;
36- const path = playerPathForMedia ( null , media ) ;
37- router . replace ( "/" ) ;
38- requestAnimationFrame ( ( ) => softReplaceUrl ( path ) ) ;
39- return ;
40- }
40+ if ( media ) {
41+ openPlayer ( { media, expand : true , syncUrl : false } ) ;
42+ const path = playerPathForMedia ( null , media ) ;
43+ router . replace ( "/" ) ;
44+ requestAnimationFrame ( ( ) => softReplaceUrl ( path ) ) ;
45+ return ;
46+ }
4147
42- router . replace ( "/" ) ;
48+ router . replace ( "/" ) ;
49+ } ) ( ) ;
4350 } , [ url , openPlayer , router , media ] ) ;
4451
4552 return (
0 commit comments