1 /*****************************************************************************
2 * rss.c : rss/atom feed display video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Atom : http://www.ietf.org/rfc/rfc4287.txt
26 * RSS : http://www.rssboard.org/rss-specification
27 *****************************************************************************/
29 /*****************************************************************************
31 *****************************************************************************/
32 #include <stdlib.h> /* malloc(), free() */
38 #include "vlc_filter.h"
39 #include "vlc_block.h"
42 #include "vlc_block.h"
43 #include "vlc_stream.h"
47 #include "vlc_image.h"
49 /*****************************************************************************
51 *****************************************************************************/
52 static int CreateFilter ( vlc_object_t * );
53 static void DestroyFilter( vlc_object_t * );
54 static subpicture_t *Filter( filter_t *, mtime_t );
56 static int FetchRSS( filter_t * );
57 static void FreeRSS( filter_t * );
59 static int pi_color_values[] = { 0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,
60 0x00FFFFFF, 0x00800000, 0x00FF0000, 0x00FF00FF, 0x00FFFF00,
61 0x00808000, 0x00008000, 0x00008080, 0x0000FF00, 0x00800080,
62 0x00000080, 0x000000FF, 0x0000FFFF};
63 static char *ppsz_color_descriptions[] = { N_("Default"), N_("Black"),
64 N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"), N_("Red"),
65 N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"),
66 N_("Teal"), N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"),
69 /*****************************************************************************
70 * filter_sys_t: rss filter descriptor
71 *****************************************************************************/
76 char *psz_description;
83 char *psz_description;
89 struct rss_item_t *p_items;
97 int i_xoff, i_yoff; /* offsets for the display string in the video window */
98 int i_pos; /* permit relative positioning (top, bottom, left, right, center) */
102 char *psz_marquee; /* marquee string */
104 text_style_t *p_style; /* font control */
110 struct rss_feed_t *p_feeds;
113 time_t t_last_update;
121 #define MSG_TEXT N_("RSS/Atom feed URLs")
122 #define MSG_LONGTEXT N_("RSS/Atom feed '|' (pipe) seperated URLs")
123 #define SPEED_TEXT N_("RSS/Atom feed speed")
124 #define SPEED_LONGTEXT N_("RSS/Atom feed speed (bigger is slower)")
125 #define LENGTH_TEXT N_("RSS/Atom feed max number of chars displayed")
126 #define LENGTH_LONGTEXT N_("RSS/Atom feed max number of chars displayed")
127 #define TTL_TEXT N_("Number of seconds between each forced refresh of the feeds")
128 #define TTL_LONGTEXT N_("Number of seconds between each forced refresh of the feeds. If 0, the feeds will never be updated.")
129 #define IMAGE_TEXT N_("Display feed images if available")
130 #define IMAGE_LONGTEXT N_("Display feed images if available")
132 #define POSX_TEXT N_("X offset, from left")
133 #define POSX_LONGTEXT N_("X offset, from the left screen edge" )
134 #define POSY_TEXT N_("Y offset, from the top")
135 #define POSY_LONGTEXT N_("Y offset, down from the top" )
136 #define OPACITY_TEXT N_("Opacity")
137 #define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of " \
138 "overlay text. 0 = transparent, 255 = totally opaque. " )
139 #define SIZE_TEXT N_("Font size, pixels")
140 #define SIZE_LONGTEXT N_("Specify the font size, in pixels, " \
141 "with -1 = use freetype-fontsize" )
143 #define COLOR_TEXT N_("Text Default Color")
144 #define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, hexadecimal. " \
145 "#000000 = all colors off, " \
146 "0xFF0000 = just Red, 0xFFFFFF = all color on [White]" )
148 #define POS_TEXT N_("Marquee position")
149 #define POS_LONGTEXT N_( \
150 "You can enforce the marquee position on the video " \
151 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
152 "also use combinations of these values by adding them).")
154 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
155 static char *ppsz_pos_descriptions[] =
156 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
157 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
159 /*****************************************************************************
161 *****************************************************************************/
163 set_capability( "sub filter", 0 );
164 set_shortname( "RSS / Atom" );
165 set_callbacks( CreateFilter, DestroyFilter );
166 set_category( CAT_VIDEO );
167 set_subcategory( SUBCAT_VIDEO_SUBPIC );
168 add_string( "rss-urls", "rss", NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );
170 set_section( N_("Position"), NULL );
171 add_integer( "rss-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
172 add_integer( "rss-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
173 add_integer( "rss-position", 5, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
174 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
176 set_section( N_("Font"), NULL );
177 /* 5 sets the default to top [1] left [4] */
178 add_integer_with_range( "rss-opacity", 255, 0, 255, NULL,
179 OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
180 add_integer( "rss-color", 0xFFFFFF, NULL, COLOR_TEXT, COLOR_LONGTEXT,
182 change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
183 add_integer( "rss-size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );
185 set_section( N_("Misc"), NULL );
186 add_integer( "rss-speed", 100000, NULL, SPEED_TEXT, SPEED_LONGTEXT,
188 add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT,
190 add_integer( "rss-ttl", 1800, NULL, TTL_TEXT, TTL_LONGTEXT, VLC_FALSE );
191 add_bool( "rss-images", 1, NULL, IMAGE_TEXT, IMAGE_LONGTEXT, VLC_FALSE );
193 set_description( _("RSS and Atom feed display") );
194 add_shortcut( "rss" );
195 add_shortcut( "atom" );
198 /*****************************************************************************
199 * CreateFilter: allocates RSS video filter
200 *****************************************************************************/
201 static int CreateFilter( vlc_object_t *p_this )
203 filter_t *p_filter = (filter_t *)p_this;
207 /* Allocate structure */
208 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
211 msg_Err( p_filter, "out of memory" );
215 vlc_mutex_init( p_filter, &p_sys->lock );
216 vlc_mutex_lock( &p_sys->lock );
218 p_sys->psz_urls = var_CreateGetString( p_filter, "rss-urls" );
219 p_sys->i_cur_feed = 0;
220 p_sys->i_cur_item = 0;
221 p_sys->i_cur_char = 0;
223 p_sys->p_feeds = NULL;
224 p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" );
225 p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" );
226 p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, "rss-ttl" ) );
227 p_sys->b_images = var_CreateGetBool( p_filter, "rss-images" );
228 p_sys->psz_marquee = (char *)malloc( p_sys->i_length );
230 p_sys->p_style = malloc( sizeof( text_style_t ));
231 memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ));
233 p_sys->i_xoff = var_CreateGetInteger( p_filter, "rss-x" );
234 p_sys->i_yoff = var_CreateGetInteger( p_filter, "rss-y" );
235 p_sys->i_pos = var_CreateGetInteger( p_filter, "rss-position" );
236 p_sys->p_style->i_font_alpha = 255 - var_CreateGetInteger( p_filter, "rss-opacity" );
237 p_sys->p_style->i_font_color = var_CreateGetInteger( p_filter, "rss-color" );
238 p_sys->p_style->i_font_size = var_CreateGetInteger( p_filter, "rss-size" );
240 if( p_sys->b_images == VLC_TRUE && p_sys->p_style->i_font_size == -1 )
242 msg_Warn( p_filter, "rrs-size wasn't specified. Feed images will thus be displayed without being resized" );
245 if( FetchRSS( p_filter ) )
247 msg_Err( p_filter, "failed while fetching RSS ... too bad" );
248 vlc_mutex_unlock( &p_sys->lock );
251 p_sys->t_last_update = time( NULL );
253 if( p_sys->i_feeds == 0 )
255 vlc_mutex_unlock( &p_sys->lock );
258 for( i_feed=0; i_feed < p_sys->i_feeds; i_feed ++ )
259 if( p_sys->p_feeds[i_feed].i_items == 0 )
261 vlc_mutex_unlock( &p_sys->lock );
266 p_filter->pf_sub_filter = Filter;
267 p_sys->last_date = (mtime_t)0;
269 vlc_mutex_unlock( &p_sys->lock );
273 /*****************************************************************************
274 * DestroyFilter: destroy RSS video filter
275 *****************************************************************************/
276 static void DestroyFilter( vlc_object_t *p_this )
278 filter_t *p_filter = (filter_t *)p_this;
279 filter_sys_t *p_sys = p_filter->p_sys;
281 vlc_mutex_lock( &p_sys->lock );
283 if( p_sys->p_style ) free( p_sys->p_style );
284 if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
285 free( p_sys->psz_urls );
287 vlc_mutex_unlock( &p_sys->lock );
288 vlc_mutex_destroy( &p_sys->lock );
291 /* Delete the RSS variables */
292 var_Destroy( p_filter, "rss-urls" );
293 var_Destroy( p_filter, "rss-speed" );
294 var_Destroy( p_filter, "rss-length" );
295 var_Destroy( p_filter, "rss-ttl" );
296 var_Destroy( p_filter, "rss-images" );
297 var_Destroy( p_filter, "rss-x" );
298 var_Destroy( p_filter, "rss-y" );
299 var_Destroy( p_filter, "rss-position" );
300 var_Destroy( p_filter, "rss-color");
301 var_Destroy( p_filter, "rss-opacity");
302 var_Destroy( p_filter, "rss-size");
305 /****************************************************************************
306 * Filter: the whole thing
307 ****************************************************************************
308 * This function outputs subpictures at regular time intervals.
309 ****************************************************************************/
310 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
312 filter_sys_t *p_sys = p_filter->p_sys;
314 video_format_t fmt = {0};
316 subpicture_region_t *p_region;
320 struct rss_feed_t *p_feed;
322 vlc_mutex_lock( &p_sys->lock );
325 + ( p_sys->i_cur_char == 0 && p_sys->i_cur_item == 0 ? 5 : 1 )
326 /* ( ... ? 5 : 1 ) means "wait more for the 1st char" */
327 * p_sys->i_speed > date )
329 vlc_mutex_unlock( &p_sys->lock );
333 /* Do we need to update the feeds ? */
335 && time( NULL ) > p_sys->t_last_update + (time_t)p_sys->i_ttl )
337 msg_Dbg( p_filter, "Forcing update of all the RSS feeds" );
338 if( FetchRSS( p_filter ) )
340 msg_Err( p_filter, "failed while fetching RSS ... too bad" );
341 vlc_mutex_unlock( &p_sys->lock );
342 return NULL; /* FIXME : we most likely messed up all the data,
343 * so we might need to do something about it */
345 p_sys->t_last_update = time( NULL );
348 p_sys->last_date = date;
350 if( p_sys->p_feeds[p_sys->i_cur_feed].p_items[p_sys->i_cur_item].psz_title[p_sys->i_cur_char] == 0 )
352 p_sys->i_cur_char = 0;
354 if( p_sys->i_cur_item >= p_sys->p_feeds[p_sys->i_cur_feed].i_items )
356 p_sys->i_cur_item = 0;
357 p_sys->i_cur_feed = (p_sys->i_cur_feed + 1)%p_sys->i_feeds;
361 p_spu = p_filter->pf_sub_buffer_new( p_filter );
364 vlc_mutex_unlock( &p_sys->lock );
368 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
370 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
371 if( !p_spu->p_region )
373 p_filter->pf_sub_buffer_del( p_filter, p_spu );
374 vlc_mutex_unlock( &p_sys->lock );
378 /* Generate the string that will be displayed. This string is supposed to
379 be p_sys->i_length characters long. */
380 i_item = p_sys->i_cur_item;
381 i_feed = p_sys->i_cur_feed;
382 p_feed = &p_sys->p_feeds[p_sys->i_cur_feed];
386 /* Don't display the feed's title if we have an image */
387 snprintf( p_sys->psz_marquee, p_sys->i_length, "%s",
388 p_sys->p_feeds[i_feed].p_items[i_item].psz_title
389 +p_sys->i_cur_char );
393 snprintf( p_sys->psz_marquee, p_sys->i_length, "%s : %s",
394 p_sys->p_feeds[i_feed].psz_title,
395 p_sys->p_feeds[i_feed].p_items[i_item].psz_title
396 +p_sys->i_cur_char );
399 while( strlen( p_sys->psz_marquee ) < (unsigned int)p_sys->i_length )
402 if( i_item == p_sys->p_feeds[i_feed].i_items ) break;
403 snprintf( strchr( p_sys->psz_marquee, 0 ),
404 p_sys->i_length - strlen( p_sys->psz_marquee ),
406 p_sys->p_feeds[i_feed].p_items[i_item].psz_title );
409 /* Calls to snprintf might split multibyte UTF8 chars ...
410 * which freetype doesn't like. */
412 char *a = strdup( p_sys->psz_marquee );
414 char *b = p_sys->psz_marquee;
415 EnsureUTF8( p_sys->psz_marquee );
416 /* we want to use ' ' instead of '?' for erroneous chars */
419 if( *b != *a ) *b = ' ';
425 p_spu->p_region->psz_text = strdup(p_sys->psz_marquee);
426 p_spu->i_start = date;
428 p_spu->b_ephemer = VLC_TRUE;
430 /* where to locate the string: */
431 if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
432 { /* set to one of the 9 relative locations */
433 p_spu->i_flags = p_sys->i_pos;
436 p_spu->b_absolute = VLC_FALSE;
439 { /* set to an absolute xy, referenced to upper left corner */
440 p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
441 p_spu->i_x = p_sys->i_xoff;
442 p_spu->i_y = p_sys->i_yoff;
443 p_spu->b_absolute = VLC_TRUE;
447 p_spu->p_region->p_style = p_sys->p_style;
451 /* Display the feed's image */
452 picture_t *p_pic = p_feed->p_pic;
453 video_format_t fmt_out = {0};
455 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
456 fmt_out.i_aspect = VOUT_ASPECT_FACTOR;
457 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
459 fmt_out.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
461 fmt_out.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
463 p_region = p_spu->pf_create_region( VLC_OBJECT( p_filter ), &fmt_out );
466 msg_Err( p_filter, "cannot allocate SPU region" );
470 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
471 p_spu->p_region->p_next = p_region;
474 /* Offset text to display right next to the image */
475 p_spu->p_region->i_x = p_pic->p[Y_PLANE].i_visible_pitch;
478 vlc_mutex_unlock( &p_sys->lock );
482 /****************************************************************************
483 * RSS related functions
484 ****************************************************************************
485 * You should always lock the p_filter mutex before using any of these
487 ***************************************************************************/
489 #undef LoadImage /* do not conflict with Win32 API */
491 /****************************************************************************
492 * download and resize image located at psz_url
493 ***************************************************************************/
494 picture_t *LoadImage( filter_t *p_filter, const char *psz_url )
496 filter_sys_t *p_sys = p_filter->p_sys;
498 video_format_t fmt_in={0}, fmt_out={0};
499 picture_t *p_orig, *p_pic=NULL;
500 image_handler_t *p_handler = image_HandlerCreate( p_filter );
504 psz_local = ToLocale( psz_url );
505 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
506 p_orig = image_ReadUrl( p_handler, psz_local, &fmt_in, &fmt_out );
507 LocaleFree( psz_local );
511 msg_Warn( p_filter, "Unable to read image %s", psz_url );
513 else if( p_sys->p_style->i_font_size > 0 )
516 fmt_in.i_chroma = VLC_FOURCC('Y','U','V','A');
517 fmt_in.i_height = p_orig->p[Y_PLANE].i_visible_lines;
518 fmt_in.i_width = p_orig->p[Y_PLANE].i_visible_pitch;
519 fmt_out.i_width = p_orig->p[Y_PLANE].i_visible_pitch
520 *p_sys->p_style->i_font_size/p_orig->p[Y_PLANE].i_visible_lines;
521 fmt_out.i_height = p_sys->p_style->i_font_size;
523 p_pic = image_Convert( p_handler, p_orig, &fmt_in, &fmt_out );
524 p_orig->pf_release( p_orig );
527 msg_Warn( p_filter, "Error while converting %s", psz_url );
535 image_HandlerDelete( p_handler );
540 /****************************************************************************
541 * remove all ' ' '\t' '\n' '\r' characters from the begining and end of the
543 ***************************************************************************/
544 char *removeWhiteChars( char *psz_src )
546 char *psz_src2 = strdup( psz_src );
547 char *psz_clean = strdup( psz_src2 );
550 while( ( *psz_clean == ' ' || *psz_clean == '\t'
551 || *psz_clean == '\n' || *psz_clean == '\r' )
552 && *psz_clean != '\0' )
556 i = strlen( psz_clean );
558 ( psz_clean[i] == ' ' || psz_clean[i] == '\t'
559 || psz_clean[i] == '\n' || psz_clean[i] == '\r' ) );
560 psz_clean[i+1] = '\0';
561 psz_clean2 = strdup( psz_clean );
566 /****************************************************************************
567 * FetchRSS (or Atom) feeds
568 ***************************************************************************/
569 static int FetchRSS( filter_t *p_filter)
571 filter_sys_t *p_sys = p_filter->p_sys;
573 stream_t *p_stream = NULL;
575 xml_reader_t *p_xml_reader = NULL;
577 char *psz_eltname = NULL;
578 char *psz_eltvalue = NULL;
579 char *psz_feed = NULL;
580 char *psz_buffer = NULL;
581 char *psz_buffer_2 = NULL;
585 vlc_bool_t b_is_item;
586 vlc_bool_t b_is_image;
592 while( p_sys->psz_urls[i_int] != 0 )
593 if( p_sys->psz_urls[i_int++] == '|' )
595 p_sys->p_feeds = (struct rss_feed_t *)malloc( p_sys->i_feeds
596 * sizeof( struct rss_feed_t ) );
598 p_xml = xml_Create( p_filter );
601 msg_Err( p_filter, "Failed to open XML parser" );
605 psz_buffer = strdup( p_sys->psz_urls );
606 psz_buffer_2 = psz_buffer; /* keep track so we can free it */
607 for( i_feed = 0; i_feed < p_sys->i_feeds; i_feed++ )
609 struct rss_feed_t *p_feed = p_sys->p_feeds+i_feed;
611 if( psz_buffer == NULL ) break;
612 if( psz_buffer[0] == 0 ) psz_buffer++;
613 psz_feed = psz_buffer;
614 psz_buffer = strchr( psz_buffer, '|' );
615 if( psz_buffer != NULL ) psz_buffer[0] = 0;
617 p_feed->psz_title = NULL;
618 p_feed->psz_description = NULL;
619 p_feed->psz_link = NULL;
620 p_feed->psz_image = NULL;
621 p_feed->p_pic = NULL;
623 p_feed->p_items = NULL;
625 msg_Dbg( p_filter, "Opening %s RSS/Atom feed ...", psz_feed );
627 p_stream = stream_UrlNew( p_filter, psz_feed );
630 msg_Err( p_filter, "Failed to open %s for reading", psz_feed );
634 p_xml_reader = xml_ReaderCreate( p_xml, p_stream );
637 msg_Err( p_filter, "Failed to open %s for parsing", psz_feed );
642 b_is_item = VLC_FALSE;
643 b_is_image = VLC_FALSE;
645 while( xml_ReaderRead( p_xml_reader ) == 1 )
647 switch( xml_ReaderNodeType( p_xml_reader ) )
653 case XML_READER_STARTELEM:
659 psz_eltname = xml_ReaderName( p_xml_reader );
665 msg_Dbg( p_filter, "element name : %s", psz_eltname );
667 if( !strcmp( psz_eltname, "item" ) /* rss */
668 || !strcmp( psz_eltname, "entry" ) ) /* atom */
670 b_is_item = VLC_TRUE;
672 p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) );
673 p_feed->p_items[p_feed->i_items-1].psz_title = NULL;
674 p_feed->p_items[p_feed->i_items-1].psz_description
676 p_feed->p_items[p_feed->i_items-1].psz_link = NULL;
678 else if( !strcmp( psz_eltname, "image" ) ) /* rss */
680 b_is_image = VLC_TRUE;
682 else if( !strcmp( psz_eltname, "link" ) ) /* atom */
684 char *psz_href = NULL;
685 char *psz_rel = NULL;
686 while( xml_ReaderNextAttr( p_xml_reader )
689 char *psz_name = xml_ReaderName( p_xml_reader );
690 char *psz_value = xml_ReaderValue( p_xml_reader );
691 if( !strcmp( psz_name, "rel" ) )
695 else if( !strcmp( psz_name, "href" ) )
697 psz_href = psz_value;
705 if( psz_rel && psz_href )
707 if( !strcmp( psz_rel, "alternate" )
708 && b_is_item == VLC_FALSE
709 && b_is_image == VLC_FALSE
710 && !p_feed->psz_link )
712 p_feed->psz_link = psz_href;
714 /* this isn't in the rfc but i found some ... */
715 else if( ( !strcmp( psz_rel, "logo" )
716 || !strcmp( psz_rel, "icon" ) )
717 && b_is_item == VLC_FALSE
718 && b_is_image == VLC_FALSE
719 && !p_feed->psz_image )
721 p_feed->psz_image = psz_href;
730 if( psz_href ) free( psz_href );
732 if( psz_rel ) free( psz_rel );
736 case XML_READER_ENDELEM:
742 psz_eltname = xml_ReaderName( p_xml_reader );
748 msg_Dbg( p_filter, "element end : %s", psz_eltname );
750 if( !strcmp( psz_eltname, "item" ) /* rss */
751 || !strcmp( psz_eltname, "entry" ) ) /* atom */
753 b_is_item = VLC_FALSE;
756 else if( !strcmp( psz_eltname, "image" ) ) /* rss */
758 b_is_image = VLC_FALSE;
764 case XML_READER_TEXT:
765 if( !psz_eltname ) break;
766 psz_eltvalue = xml_ReaderValue( p_xml_reader );
774 psz_clean = removeWhiteChars( psz_eltvalue );
775 free( psz_eltvalue ); psz_eltvalue = psz_clean;
778 msg_Dbg( p_filter, " text : <%s>", psz_eltvalue );
780 if( b_is_item == VLC_TRUE )
782 struct rss_item_t *p_item;
783 p_item = p_feed->p_items+i_item;
784 if( !strcmp( psz_eltname, "title" ) /* rss/atom */
785 && !p_item->psz_title )
787 p_item->psz_title = psz_eltvalue;
789 else if( !strcmp( psz_eltname, "link" ) /* rss */
790 && !p_item->psz_link )
792 p_item->psz_link = psz_eltvalue;
794 else if((!strcmp( psz_eltname, "description" ) /* rss */
795 || !strcmp( psz_eltname, "summary" ) ) /* atom */
796 && !p_item->psz_description )
798 p_item->psz_description = psz_eltvalue;
802 free( psz_eltvalue );
806 else if( b_is_image == VLC_TRUE )
808 if( !strcmp( psz_eltname, "url" ) /* rss */
809 && !p_feed->psz_image )
811 p_feed->psz_image = psz_eltvalue;
815 free( psz_eltvalue );
821 if( !strcmp( psz_eltname, "title" ) /* rss/atom */
822 && !p_feed->psz_title )
824 p_feed->psz_title = psz_eltvalue;
826 else if( !strcmp( psz_eltname, "link" ) /* rss */
827 && !p_feed->psz_link )
829 p_feed->psz_link = psz_eltvalue;
831 else if((!strcmp( psz_eltname, "description" ) /* rss */
832 || !strcmp( psz_eltname, "subtitle" ) ) /* atom */
833 && !p_feed->psz_description )
835 p_feed->psz_description = psz_eltvalue;
837 else if( ( !strcmp( psz_eltname, "logo" ) /* atom */
838 || !strcmp( psz_eltname, "icon" ) ) /* atom */
839 && !p_feed->psz_image )
841 p_feed->psz_image = psz_eltvalue;
845 free( psz_eltvalue );
853 if( p_sys->b_images == VLC_TRUE
854 && p_feed->psz_image && !p_feed->p_pic )
856 p_feed->p_pic = LoadImage( p_filter, p_feed->psz_image );
859 if( p_xml_reader && p_xml ) xml_ReaderDelete( p_xml, p_xml_reader );
860 if( p_stream ) stream_Delete( p_stream );
861 msg_Dbg( p_filter, "Done with %s RSS/Atom feed.", psz_feed );
863 free( psz_buffer_2 );
864 if( p_xml ) xml_Delete( p_xml );
869 /****************************************************************************
871 ***************************************************************************/
872 static void FreeRSS( filter_t *p_filter)
874 filter_sys_t *p_sys = p_filter->p_sys;
876 struct rss_item_t *p_item;
877 struct rss_feed_t *p_feed;
882 for( i_feed = 0; i_feed < p_sys->i_feeds; i_feed++ )
884 p_feed = p_sys->p_feeds+i_feed;
885 for( i_item = 0; i_item < p_feed->i_items; i_item++ )
887 p_item = p_feed->p_items+i_item;
888 free( p_item->psz_title );
889 free( p_item->psz_link );
890 free( p_item->psz_description );
892 free( p_feed->p_items );
893 free( p_feed->psz_title);
894 free( p_feed->psz_link );
895 free( p_feed->psz_description );
896 free( p_feed->psz_image );
897 if( p_feed->p_pic != NULL )
898 p_feed->p_pic->pf_release( p_feed->p_pic );
900 free( p_sys->p_feeds );