@@ -33,15 +33,11 @@ function fetchUrl(url, callback) {
33
33
} ) ;
34
34
}
35
35
36
+ // Modification 1: dans la fonction cleanXML
36
37
function cleanXML ( xml ) {
37
- // On utilise le 'match' pour avoir accès au tag complet pour le debugging si nécessaire
38
- console . log ( 'Cleaning XML...' ) ;
39
- return xml . replace ( / < ( \/ ? ) i t u n e s : ( [ ^ > ] + ) > / g, function ( match , slash , rest ) {
40
- console . log ( 'Found iTunes tag:' , match ) ;
41
- const cleaned = '<' + slash + rest + '>' ;
42
- console . log ( 'Cleaned to:' , cleaned ) ;
43
- return cleaned ;
44
- } ) ;
38
+ let cleanedXml = xml ;
39
+ cleanedXml = cleanedXml . replace ( / < ( \/ ? ) ( d c | i t u n e s ) : ( [ ^ > ] + ) > / g, '<$1$3>' ) ;
40
+ return cleanedXml ;
45
41
}
46
42
47
43
function extractImageFromDescription ( description ) {
@@ -113,25 +109,27 @@ module.exports = {
113
109
throw new Error ( 'Invalid RSS format' ) ;
114
110
}
115
111
116
- const rss = { item : [ ] } ;
112
+ const feed = { } ;
113
+ const response = { status : 'ok' , feed : feed , items : [ ] } ;
117
114
118
115
// Gestion enrichie des images principales
119
116
const mainimage = list . image ?. [ 0 ] ?. href ?. [ 0 ] ||
120
117
list . image ?. [ 0 ] ?. url ?. [ 0 ] ||
121
118
list [ 'media:thumbnail' ] ?. [ 0 ] ?. url ?. [ 0 ] ;
122
119
123
120
if ( mainimage ) {
124
- rss . image = { href : mainimage } ;
121
+ feed . image = mainimage ;
125
122
}
126
123
127
124
// Informations de base du channel
128
- rss . title = list . title ?. [ 0 ] || '' ;
129
- rss . description = list . description ?. [ 0 ] || '' ;
130
- rss . url = list . link ?. [ 0 ] || '' ;
131
- rss . author = list . author ?. [ 0 ] || '' ;
132
- rss . playlistURL = list . link ?. [ 0 ] || '' ;
133
- rss . language = list . language ?. [ 0 ] || '' ;
134
- rss . lastBuildDate = list . lastBuildDate ?. [ 0 ] || '' ;
125
+ feed . title = list . title ?. [ 0 ] || '' ;
126
+ feed . description = list . description ?. [ 0 ] || '' ;
127
+ feed . link = list . link ?. [ 0 ] || '' ;
128
+ feed . url = feed . link ; // Garder url comme alias de link
129
+ feed . author = list . author ?. [ 0 ] || '' ;
130
+ feed . playlistURL = list . link ?. [ 0 ] || '' ;
131
+ feed . language = list . language ?. [ 0 ] || '' ;
132
+ feed . lastBuildDate = list . lastBuildDate ?. [ 0 ] || '' ;
135
133
136
134
const parsedItems = [ ] ;
137
135
if ( list . item ) {
@@ -145,7 +143,7 @@ module.exports = {
145
143
title : val . title ?. [ 0 ] || '' ,
146
144
description : val . description ?. [ 0 ] || '' ,
147
145
group : val . category ?. [ 0 ] || '' ,
148
- author : val . author ?. [ 0 ] || list . author ?. [ 0 ] || '' ,
146
+ author : val . creator ?. [ 0 ] || val . author ?. [ 0 ] || list . author ?. [ 0 ] || '' , // Notez l'ordre : creator en premier
149
147
pubDate : val . pubDate ?. [ 0 ] || ''
150
148
} ;
151
149
@@ -164,7 +162,7 @@ module.exports = {
164
162
}
165
163
166
164
// Gestion enrichie des images (comme dans votre PHP)
167
- obj . thumb_square =
165
+ obj . thumbnail =
168
166
val . image ?. [ 0 ] ?. href ?. [ 0 ] || // Direct image
169
167
val [ 'media:thumbnail' ] ?. [ 0 ] ?. url ?. [ 0 ] || // Media thumbnail
170
168
val [ 'media:content' ] ?. [ 0 ] ?. [ 'media:thumbnail' ] ?. [ 0 ] ?. url ?. [ 0 ] || // Nested media thumbnail
@@ -180,30 +178,24 @@ module.exports = {
180
178
} ) ;
181
179
}
182
180
183
- return {
184
- title : rss . title ,
185
- description : rss . description ,
186
- url : rss . url ,
187
- author : rss . author ,
188
- image : rss . image ,
189
- language : rss . language ,
190
- lastBuildDate : rss . lastBuildDate ,
191
- item : parsedItems
192
- } ;
181
+ response . items = parsedItems ;
182
+ return response ;
183
+
193
184
} ,
194
185
195
186
parseAtom : function ( json ) {
196
187
const feed = json . feed ;
197
- const rss = { item : [ ] } ;
188
+ const response = { status : 'ok' , feed : { } , items : [ ] } ;
198
189
199
190
if ( feed . title ) {
200
- rss . title = feed . title [ 0 ] ;
191
+ response . feed . title = feed . title [ 0 ] ;
201
192
}
202
193
if ( feed . subtitle ) {
203
- rss . description = feed . subtitle [ 0 ] ;
194
+ response . feed . description = feed . subtitle [ 0 ] ;
204
195
}
205
196
if ( feed . link ) {
206
- rss . url = feed . link [ 0 ] . href || feed . link [ 0 ] ;
197
+ response . feed . link = feed . link [ 0 ] . href || feed . link [ 0 ] ;
198
+ response . feed . url = response . feed . link ;
207
199
}
208
200
209
201
if ( feed . entry ) {
@@ -228,11 +220,11 @@ module.exports = {
228
220
}
229
221
230
222
console . log ( 'Parsed Atom entry:' , obj ) ;
231
- rss . item . push ( obj ) ;
223
+ response . items . push ( obj ) ;
232
224
} ) ;
233
225
}
234
226
235
- return rss ;
227
+ return response ;
236
228
} ,
237
229
238
230
read : function ( url , callback ) {
0 commit comments