@@ -27,6 +27,70 @@ export const __clearCaches = (): void => {
2727 seriesCache . clear ( ) ;
2828} ;
2929
30+ export type BuildSourcesOptions = {
31+ season ?: string ;
32+ episode ?: string ;
33+ preferredServer ?: '1' | '2' ;
34+ } ;
35+
36+ /**
37+ * Builds canonical URL for a movie/series.
38+ * @param {string } appUrl - Base application URL
39+ * @param {string } id - IMDB ID of the movie/show
40+ * @param {string } type - Type of content ('movie' or 'series')
41+ * @param {string } [season] - Season number (for series)
42+ * @param {string } [episode] - Episode number (for series)
43+ * @returns {string } Canonical URL for the content
44+ */
45+ const buildCanonical = (
46+ appUrl : string ,
47+ id : string ,
48+ type : string ,
49+ season ?: string ,
50+ episode ?: string
51+ ) => {
52+ return season && episode
53+ ? `${ appUrl } /view/${ id } /${ type } /${ season } /${ episode } `
54+ : `${ appUrl } /view/${ id } /${ type } ` ;
55+ } ;
56+
57+ /**
58+ * Builds video source URLs for movie/series iframe embedding.
59+ * @param {string } id - IMDB ID of the movie/show
60+ * @param {'movie' | 'series' } kind - Type of content ('movie' or 'series')
61+ * @param {string } [season] - Season number (required for series)
62+ * @param {string } [episode] - Episode number (required for series)
63+ * @returns {Object } Object containing source URLs and current server
64+ */
65+ const buildSources = (
66+ id : string ,
67+ kind : 'movie' | 'series' ,
68+ options : BuildSourcesOptions = { }
69+ ) => {
70+ const { season, episode, preferredServer} = options ;
71+
72+ if ( kind === 'series' ) {
73+ const seasonParam = season ?? '' ;
74+ const episodeParam = episode ?? '' ;
75+ const server1Src = `https://${ appConfig . VIDSRC_DOMAIN } /embed/tv?imdb=${ id } &season=${ seasonParam } &episode=${ episodeParam } ` ;
76+ const multiDomain = Boolean ( appConfig . MULTI_DOMAIN ) ;
77+ const server2Src = multiDomain
78+ ? `https://${ appConfig . MULTI_DOMAIN } /?video_id=${ id } &s=${ seasonParam } &e=${ episodeParam } `
79+ : '' ;
80+ const useSecond = Boolean ( server2Src ) && preferredServer !== '1' ;
81+ const currentServer = useSecond ? '2' : '1' ;
82+ const iframeSrc = currentServer === '2' && server2Src ? server2Src : server1Src ;
83+ return { server1Src, server2Src, iframeSrc, currentServer} ;
84+ }
85+
86+ const multiDomain = Boolean ( appConfig . MULTI_DOMAIN ) ;
87+ const server1Src = `https://${ appConfig . VIDSRC_DOMAIN } /embed/movie/${ id } ` ;
88+ const server2Src = multiDomain ? `https://${ appConfig . MULTI_DOMAIN } /?video_id=${ id } ` : '' ;
89+ const useSecond = Boolean ( server2Src ) && preferredServer !== '1' ;
90+ const currentServer = useSecond ? '2' : '1' ;
91+ const iframeSrc = currentServer === '2' && server2Src ? server2Src : server1Src ;
92+ return { server1Src, server2Src, iframeSrc, currentServer} ;
93+ } ;
3094
3195/**
3296 * Constructs parameters object for OMDB API requests.
@@ -176,71 +240,6 @@ const getSeriesDetail = async (id: string, season: number): Promise<SeriesDetail
176240 } ;
177241} ;
178242
179- /**
180- * Builds canonical URL for a movie/series.
181- * @param {string } appUrl - Base application URL
182- * @param {string } id - IMDB ID of the movie/show
183- * @param {string } type - Type of content ('movie' or 'series')
184- * @param {string } [season] - Season number (for series)
185- * @param {string } [episode] - Episode number (for series)
186- * @returns {string } Canonical URL for the content
187- */
188- const buildCanonical = (
189- appUrl : string ,
190- id : string ,
191- type : string ,
192- season ?: string ,
193- episode ?: string
194- ) => {
195- return season && episode
196- ? `${ appUrl } /view/${ id } /${ type } /${ season } /${ episode } `
197- : `${ appUrl } /view/${ id } /${ type } ` ;
198- } ;
199-
200- /**
201- * Builds video source URLs for movie/series iframe embedding.
202- * @param {string } id - IMDB ID of the movie/show
203- * @param {'movie' | 'series' } kind - Type of content ('movie' or 'series')
204- * @param {string } [season] - Season number (required for series)
205- * @param {string } [episode] - Episode number (required for series)
206- * @returns {Object } Object containing source URLs and current server
207- */
208- export type BuildSourcesOptions = {
209- season ?: string ;
210- episode ?: string ;
211- preferredServer ?: '1' | '2' ;
212- } ;
213-
214- const buildSources = (
215- id : string ,
216- kind : 'movie' | 'series' ,
217- options : BuildSourcesOptions = { }
218- ) => {
219- const { season, episode, preferredServer} = options ;
220-
221- if ( kind === 'series' ) {
222- const seasonParam = season ?? '' ;
223- const episodeParam = episode ?? '' ;
224- const server1Src = `https://${ appConfig . VIDSRC_DOMAIN } /embed/tv?imdb=${ id } &season=${ seasonParam } &episode=${ episodeParam } ` ;
225- const multiDomain = Boolean ( appConfig . MULTI_DOMAIN ) ;
226- const server2Src = multiDomain
227- ? `https://${ appConfig . MULTI_DOMAIN } /?video_id=${ id } &s=${ seasonParam } &e=${ episodeParam } `
228- : '' ;
229- const useSecond = Boolean ( server2Src ) && preferredServer !== '1' ;
230- const currentServer = useSecond ? '2' : '1' ;
231- const iframeSrc = currentServer === '2' && server2Src ? server2Src : server1Src ;
232- return { server1Src, server2Src, iframeSrc, currentServer} ;
233- }
234-
235- const multiDomain = Boolean ( appConfig . MULTI_DOMAIN ) ;
236- const server1Src = `https://${ appConfig . VIDSRC_DOMAIN } /embed/movie/${ id } ` ;
237- const server2Src = multiDomain ? `https://${ appConfig . MULTI_DOMAIN } /?video_id=${ id } ` : '' ;
238- const useSecond = Boolean ( server2Src ) && preferredServer !== '1' ;
239- const currentServer = useSecond ? '2' : '1' ;
240- const iframeSrc = currentServer === '2' && server2Src ? server2Src : server1Src ;
241- return { server1Src, server2Src, iframeSrc, currentServer} ;
242- } ;
243-
244243/**
245244 * Gets resume redirect URL for a series based on last watched episode.
246245 * @param {string } userId - User ID
0 commit comments