@@ -14,6 +14,7 @@ module.exports = {
14
14
items . forEach ( item => {
15
15
const prev = programs [ programs . length - 1 ]
16
16
const $item = cheerio . load ( item )
17
+ const episodeInfo = parseEP ( $item ) ;
17
18
let start = parseStart ( $item , date )
18
19
if ( ! start ) return
19
20
if ( prev ) {
@@ -26,6 +27,9 @@ module.exports = {
26
27
description : parseDescription ( $item ) ,
27
28
category : parseCategory ( $item ) ,
28
29
date : parseDate ( $item ) ,
30
+ ...episodeInfo ,
31
+ subTitles : parseSubtitle ( $item ) ,
32
+ previouslyShown : parsePreviously ( $item ) ,
29
33
start,
30
34
stop
31
35
} )
@@ -63,6 +67,32 @@ module.exports = {
63
67
function parseTitle ( $item ) {
64
68
return $item ( 'h3' ) . text ( ) . trim ( )
65
69
}
70
+ function parseEP ( $item ) {
71
+ const text = $item ( 'h6' ) . text ( ) . trim ( ) ;
72
+ const match = text . match ( / S e a s o n \s + ( \d + ) \s * • \s * E p i s o d e \s + ( \d + ) / i) ;
73
+
74
+ if ( ! match ) return { } ; // Return an empty object if no match, so properties are undefined later
75
+
76
+ const season = parseInt ( match [ 1 ] , 10 ) ;
77
+ const episode = parseInt ( match [ 2 ] , 10 ) ;
78
+
79
+ return { season, episode } ; // Return an object with season and episode
80
+ }
81
+
82
+ function parseSubtitle ( $item ) {
83
+ return $item ( 'h5' ) . text ( ) . trim ( )
84
+ }
85
+
86
+ function parsePreviously ( $item ) {
87
+ const h3Text = $item ( 'h3' ) . text ( ) . trim ( ) ;
88
+ const isNewShow = / N e w $ / . test ( h3Text ) ;
89
+
90
+ if ( isNewShow ) {
91
+ return null ;
92
+ } else {
93
+ return { } ;
94
+ }
95
+ }
66
96
67
97
function parseDescription ( $item ) {
68
98
return $item ( 'p' ) . text ( ) . trim ( )
0 commit comments