@@ -84,6 +84,24 @@ export const getMovieId = (el: HTMLElement): number => {
8484 return parseIdFromUrl ( url ) ;
8585} ;
8686
87+ export const getSerieasAndSeasonTitle = ( el : HTMLElement ) : { seriesName : string ; seasonName : string | null } => {
88+ const titleElement = el . querySelector ( 'h1' ) ;
89+ if ( ! titleElement ) {
90+ return { seriesName : null , seasonName : null } ;
91+ }
92+
93+ const fullText = titleElement . innerText . trim ( ) ;
94+
95+ // Check if there's a series part indicated by ' - '
96+ if ( fullText . includes ( ' - ' ) ) {
97+ const [ seriesName , seasonName ] = fullText . split ( ' - ' ) . map ( part => part . trim ( ) ) ;
98+ return { seriesName, seasonName } ;
99+ }
100+
101+ // If no series part found, return just the name
102+ return { seriesName : fullText , seasonName : null } ;
103+ } ;
104+
87105export const getMovieTitle = ( el : HTMLElement ) : string => {
88106 return el . querySelector ( 'h1' ) . innerText . split ( `(` ) [ 0 ] . trim ( ) ;
89107} ;
@@ -243,7 +261,7 @@ const parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {
243261 ) ;
244262} ;
245263
246- export const getSeasonsOrEpisodes = ( el : HTMLElement ) : CSFDSeason [ ] | null => {
264+ export const getSeasonsOrEpisodes = ( el : HTMLElement , serie ?: { id : number ; title : string ; } ) : CSFDSeason [ ] | null => {
247265 const childrenList = el . querySelector ( '.film-episodes-list' ) ;
248266 if ( ! childrenList ) return null ;
249267
@@ -263,20 +281,45 @@ export const getSeasonsOrEpisodes = (el: HTMLElement): CSFDSeason[] | null => {
263281 } ) ;
264282}
265283
266- export const getParent = ( el : HTMLElement ) : CSFDParent | null => {
284+ export const getEpisodeCode = ( el : HTMLElement ) : string | null => {
285+ const filmHeaderName = el . querySelector ( '.film-header-name h1' ) ;
286+ if ( ! filmHeaderName ) return null ;
287+
288+ const text = filmHeaderName . textContent ?. trim ( ) || '' ;
289+ const match = text . match ( / \( ( [ ^ ) ] + ) \) / ) ;
290+ const code = match ? match [ 1 ] : null ;
291+
292+ return code ;
293+ }
294+
295+ export const detectSeasonOrEpisodeListType = ( el : HTMLElement ) => {
296+ const headerText = el . querySelector ( '.box-header h3' ) ?. innerText . trim ( ) ?? '' ;
297+
298+ if ( headerText . includes ( 'Série' ) ) return 'seasons' ;
299+ if ( headerText . startsWith ( 'Epizody' ) ) return 'episodes' ;
300+ return null ;
301+ }
302+
303+ export const getSeasonorEpisodeParent = ( el : HTMLElement , serie ?: { id : number ; name : string ; } ) : CSFDParent | null => {
267304 const parents = el . querySelectorAll ( '.film-header h2 a' ) ;
268- if ( parents . length === 0 ) return null ;
305+ if ( parents . length === 0 ) {
306+ if ( ! serie ) return null ;
307+ return { series : serie , season : null } ;
308+ }
269309
270310 const [ parentSeries , parentSeason ] = parents ;
271311
272- return {
273- series : {
274- id : parseIdFromUrl ( parentSeries ?. getAttribute ( 'href' ) || '' ) , name : parentSeries ?. textContent ?. trim ( ) || null
275- } ,
276- season : {
277- id : parseIdFromUrl ( parentSeason ?. getAttribute ( 'href' ) || '' ) , name : parentSeason ?. textContent ?. trim ( ) || null
278- }
279- } ;
312+ const seriesId = parseIdFromUrl ( parentSeries ?. getAttribute ( 'href' ) ) ;
313+ const seasonId = parseIdFromUrl ( parentSeason ?. getAttribute ( 'href' ) ) ;
314+ const seriesName = parentSeries ?. textContent ?. trim ( ) || null ;
315+ const seasonName = parentSeason ?. textContent ?. trim ( ) || null ;
316+
317+ const series = seriesId && seriesName ? { id : seriesId , name : seriesName } : null ;
318+ const season = seasonId && seasonName ? { id : seasonId , name : seasonName } : null ;
319+
320+ if ( ! series && ! season ) return null ;
321+
322+ return { series, season } ;
280323}
281324
282325export const getMovieGroup = ( el : HTMLElement , group : CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak ) : CSFDMovieCreator [ ] => {
0 commit comments