@@ -20,6 +20,24 @@ export const getMovieId = (el: HTMLElement): number => {
2020 return parseIdFromUrl ( url ) ;
2121} ;
2222
23+ export const getSerieasAndSeasonTitle = ( el : HTMLElement ) : { seriesName : string ; seasonName : string | null } => {
24+ const titleElement = el . querySelector ( 'h1' ) ;
25+ if ( ! titleElement ) {
26+ return { seriesName : null , seasonName : null } ;
27+ }
28+
29+ const fullText = titleElement . innerText . trim ( ) ;
30+
31+ // Check if there's a series part indicated by ' - '
32+ if ( fullText . includes ( ' - ' ) ) {
33+ const [ seriesName , seasonName ] = fullText . split ( ' - ' ) . map ( part => part . trim ( ) ) ;
34+ return { seriesName, seasonName } ;
35+ }
36+
37+ // If no series part found, return just the name
38+ return { seriesName : fullText , seasonName : null } ;
39+ } ;
40+
2341export const getMovieTitle = ( el : HTMLElement ) : string => {
2442 return el . querySelector ( 'h1' ) . innerText . split ( `(` ) [ 0 ] . trim ( ) ;
2543} ;
@@ -179,7 +197,7 @@ const parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {
179197 ) ;
180198} ;
181199
182- export const getSeasonsOrEpisodes = ( el : HTMLElement ) : CSFDSeason [ ] | null => {
200+ export const getSeasonsOrEpisodes = ( el : HTMLElement , serie ?: { id : number ; title : string ; } ) : CSFDSeason [ ] | null => {
183201 const childrenList = el . querySelector ( '.film-episodes-list' ) ;
184202 if ( ! childrenList ) return null ;
185203
@@ -199,20 +217,45 @@ export const getSeasonsOrEpisodes = (el: HTMLElement): CSFDSeason[] | null => {
199217 } ) ;
200218}
201219
202- export const getParent = ( el : HTMLElement ) : CSFDParent | null => {
220+ export const getEpisodeCode = ( el : HTMLElement ) : string | null => {
221+ const filmHeaderName = el . querySelector ( '.film-header-name h1' ) ;
222+ if ( ! filmHeaderName ) return null ;
223+
224+ const text = filmHeaderName . textContent ?. trim ( ) || '' ;
225+ const match = text . match ( / \( ( [ ^ ) ] + ) \) / ) ;
226+ const code = match ? match [ 1 ] : null ;
227+
228+ return code ;
229+ }
230+
231+ export const detectSeasonOrEpisodeListType = ( el : HTMLElement ) => {
232+ const headerText = el . querySelector ( '.box-header h3' ) ?. innerText . trim ( ) ?? '' ;
233+
234+ if ( headerText . includes ( 'Série' ) ) return 'seasons' ;
235+ if ( headerText . startsWith ( 'Epizody' ) ) return 'episodes' ;
236+ return null ;
237+ }
238+
239+ export const getSeasonorEpisodeParent = ( el : HTMLElement , serie ?: { id : number ; name : string ; } ) : CSFDParent | null => {
203240 const parents = el . querySelectorAll ( '.film-header h2 a' ) ;
204- if ( parents . length === 0 ) return null ;
241+ if ( parents . length === 0 ) {
242+ if ( ! serie ) return null ;
243+ return { series : serie , season : null } ;
244+ }
205245
206246 const [ parentSeries , parentSeason ] = parents ;
207247
208- return {
209- series : {
210- id : parseIdFromUrl ( parentSeries ?. getAttribute ( 'href' ) || '' ) , name : parentSeries ?. textContent ?. trim ( ) || null
211- } ,
212- season : {
213- id : parseIdFromUrl ( parentSeason ?. getAttribute ( 'href' ) || '' ) , name : parentSeason ?. textContent ?. trim ( ) || null
214- }
215- } ;
248+ const seriesId = parseIdFromUrl ( parentSeries ?. getAttribute ( 'href' ) ) ;
249+ const seasonId = parseIdFromUrl ( parentSeason ?. getAttribute ( 'href' ) ) ;
250+ const seriesName = parentSeries ?. textContent ?. trim ( ) || null ;
251+ const seasonName = parentSeason ?. textContent ?. trim ( ) || null ;
252+
253+ const series = seriesId && seriesName ? { id : seriesId , name : seriesName } : null ;
254+ const season = seasonId && seasonName ? { id : seasonId , name : seasonName } : null ;
255+
256+ if ( ! series && ! season ) return null ;
257+
258+ return { series, season } ;
216259}
217260
218261export const getMovieGroup = ( el : HTMLElement , group : CSFDCreatorGroups ) : CSFDMovieCreator [ ] => {
0 commit comments