Commit 0e82702d authored by Antoine Cellerier's avatar Antoine Cellerier

* add --rss-ttl parmeter so the feeds can be updated

 * URL list seperator now is | (pipe)
 * fixes
parent f04ce3cc
...@@ -95,23 +95,27 @@ struct filter_sys_t ...@@ -95,23 +95,27 @@ struct filter_sys_t
mtime_t last_date; mtime_t last_date;
//vlc_bool_t b_need_update;
char *psz_urls; char *psz_urls;
int i_feeds; int i_feeds;
struct rss_feed_t *p_feeds; struct rss_feed_t *p_feeds;
int i_ttl;
time_t t_last_update;
int i_cur_feed; int i_cur_feed;
int i_cur_item; int i_cur_item;
int i_cur_char; int i_cur_char;
}; };
#define MSG_TEXT N_("RSS feed URLs") #define MSG_TEXT N_("RSS feed URLs")
#define MSG_LONGTEXT N_("RSS feed comma seperated URLs") #define MSG_LONGTEXT N_("RSS feed '|' (pipe) seperated URLs")
#define SPEED_TEXT N_("RSS feed speed") #define SPEED_TEXT N_("RSS feed speed")
#define SPEED_LONGTEXT N_("RSS feed speed (bigger is slower)") #define SPEED_LONGTEXT N_("RSS feed speed (bigger is slower)")
#define LENGTH_TEXT N_("RSS feed max number of chars displayed") #define LENGTH_TEXT N_("RSS feed max number of chars displayed")
#define LENGTH_LONGTEXT N_("RSS feed max number of chars displayed") #define LENGTH_LONGTEXT N_("RSS feed max number of chars displayed")
#define TTL_TEXT N_("Number of seconds between each forced refresh of the feeds")
#define TTL_LONGTEXT N_("Number of seconds between each forced refresh of the feeds")
#define POSX_TEXT N_("X offset, from left") #define POSX_TEXT N_("X offset, from left")
#define POSX_LONGTEXT N_("X offset, from the left screen edge" ) #define POSX_LONGTEXT N_("X offset, from the left screen edge" )
...@@ -170,6 +174,7 @@ vlc_module_begin(); ...@@ -170,6 +174,7 @@ vlc_module_begin();
VLC_FALSE ); VLC_FALSE );
add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT, add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT,
VLC_FALSE ); VLC_FALSE );
add_integer( "rss-ttl", 900, NULL, TTL_TEXT, TTL_LONGTEXT, VLC_FALSE );
set_description( _("RSS feed display sub filter") ); set_description( _("RSS feed display sub filter") );
add_shortcut( "rss" ); add_shortcut( "rss" );
...@@ -203,6 +208,7 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -203,6 +208,7 @@ static int CreateFilter( vlc_object_t *p_this )
p_sys->p_feeds = NULL; p_sys->p_feeds = NULL;
p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" ); p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" );
p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" ); p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" );
p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, "rss-ttl" ) );
p_sys->psz_marquee = (char *)malloc( p_sys->i_length ); p_sys->psz_marquee = (char *)malloc( p_sys->i_length );
p_sys->i_xoff = var_CreateGetInteger( p_filter, "rss-x" ); p_sys->i_xoff = var_CreateGetInteger( p_filter, "rss-x" );
...@@ -219,6 +225,7 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -219,6 +225,7 @@ static int CreateFilter( vlc_object_t *p_this )
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_sys->t_last_update = time( NULL );
if( p_sys->i_feeds == 0 ) if( p_sys->i_feeds == 0 )
{ {
...@@ -261,6 +268,7 @@ static void DestroyFilter( vlc_object_t *p_this ) ...@@ -261,6 +268,7 @@ static void DestroyFilter( vlc_object_t *p_this )
var_Destroy( p_filter, "rss-urls" ); var_Destroy( p_filter, "rss-urls" );
var_Destroy( p_filter, "rss-speed" ); var_Destroy( p_filter, "rss-speed" );
var_Destroy( p_filter, "rss-length" ); var_Destroy( p_filter, "rss-length" );
var_Destroy( p_filter, "rss-ttl" );
var_Destroy( p_filter, "rss-x" ); var_Destroy( p_filter, "rss-x" );
var_Destroy( p_filter, "rss-y" ); var_Destroy( p_filter, "rss-y" );
var_Destroy( p_filter, "rss-position" ); var_Destroy( p_filter, "rss-position" );
...@@ -284,13 +292,29 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -284,13 +292,29 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
/* wait more for the 1st char */ if( p_sys->last_date
if( p_sys->last_date + ( p_sys->i_cur_char == 0 && p_sys->i_cur_item == 0 ? 5 : 1 ) * p_sys->i_speed > date ) + ( p_sys->i_cur_char == 0 && p_sys->i_cur_item == 0 ? 5 : 1 )
/* ( ... ? 5 : 1 ) means "wait more for the 1st char" */
* p_sys->i_speed > date )
{ {
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return NULL; return NULL;
} }
/* Do we need to update the feeds ? */
if( time( NULL ) > p_sys->t_last_update + (time_t)p_sys->i_ttl )
{
msg_Dbg( p_filter, "Forcing update of all the RSS feeds" );
if( FetchRSS( p_filter ) )
{
msg_Err( p_filter, "failed while fetching RSS ... too bad" );
vlc_mutex_unlock( &p_sys->lock );
return NULL; /* FIXME : we most likely messed up all the data,
* so we might need to do something about it */
}
p_sys->t_last_update = time( NULL );
}
p_sys->last_date = date; p_sys->last_date = date;
p_sys->i_cur_char++; p_sys->i_cur_char++;
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 ) 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 )
...@@ -398,7 +422,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -398,7 +422,7 @@ static int FetchRSS( filter_t *p_filter)
p_sys->i_feeds = 1; p_sys->i_feeds = 1;
i_int = 0; i_int = 0;
while( p_sys->psz_urls[i_int] != 0 ) while( p_sys->psz_urls[i_int] != 0 )
if( p_sys->psz_urls[i_int++] == ',' ) if( p_sys->psz_urls[i_int++] == '|' )
p_sys->i_feeds++; p_sys->i_feeds++;
p_sys->p_feeds = (struct rss_feed_t *)malloc( p_sys->i_feeds p_sys->p_feeds = (struct rss_feed_t *)malloc( p_sys->i_feeds
* sizeof( struct rss_feed_t ) ); * sizeof( struct rss_feed_t ) );
...@@ -419,7 +443,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -419,7 +443,7 @@ static int FetchRSS( filter_t *p_filter)
if( psz_buffer == NULL ) break; if( psz_buffer == NULL ) break;
if( psz_buffer[0] == 0 ) psz_buffer++; if( psz_buffer[0] == 0 ) psz_buffer++;
psz_feed = psz_buffer; psz_feed = psz_buffer;
psz_buffer = strchr( psz_buffer, ',' ); psz_buffer = strchr( psz_buffer, '|' );
if( psz_buffer != NULL ) psz_buffer[0] = 0; if( psz_buffer != NULL ) psz_buffer[0] = 0;
p_feed->psz_title = NULL; p_feed->psz_title = NULL;
...@@ -456,35 +480,52 @@ static int FetchRSS( filter_t *p_filter) ...@@ -456,35 +480,52 @@ static int FetchRSS( filter_t *p_filter)
return 1; return 1;
case XML_READER_STARTELEM: case XML_READER_STARTELEM:
if( psz_eltname ) free( psz_eltname ); if( psz_eltname )
{
free( psz_eltname );
psz_eltname = NULL;
}
psz_eltname = xml_ReaderName( p_xml_reader ); psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname ) if( !psz_eltname )
{ {
return 1; return 1;
} }
# ifdef RSS_DEBUG
msg_Dbg( p_filter, "element name : %s", psz_eltname ); msg_Dbg( p_filter, "element name : %s", psz_eltname );
# endif
if( !strcmp( psz_eltname, "item" ) ) if( !strcmp( psz_eltname, "item" ) )
{ {
i_is_item = VLC_TRUE; i_is_item = VLC_TRUE;
p_feed->i_items++; p_feed->i_items++;
p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) ); p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) );
p_feed->p_items[p_feed->i_items-1].psz_title = NULL;
p_feed->p_items[p_feed->i_items-1].psz_description
= NULL;
p_feed->p_items[p_feed->i_items-1].psz_link = NULL;
} }
break; break;
case XML_READER_ENDELEM: case XML_READER_ENDELEM:
if( psz_eltname ) free( psz_eltname ); if( psz_eltname )
{
free( psz_eltname );
psz_eltname = NULL;
}
psz_eltname = xml_ReaderName( p_xml_reader ); psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname ) if( !psz_eltname )
{ {
return 1; return 1;
} }
# ifdef RSS_DEBUG
msg_Dbg( p_filter, "element end : %s", psz_eltname ); msg_Dbg( p_filter, "element end : %s", psz_eltname );
# endif
if( !strcmp( psz_eltname, "item" ) ) if( !strcmp( psz_eltname, "item" ) )
{ {
i_is_item = VLC_FALSE; i_is_item = VLC_FALSE;
i_item++; i_item++;
} }
free( psz_eltname ); psz_eltname = NULL; free( psz_eltname );
psz_eltname = NULL;
break; break;
case XML_READER_TEXT: case XML_READER_TEXT:
...@@ -493,7 +534,9 @@ static int FetchRSS( filter_t *p_filter) ...@@ -493,7 +534,9 @@ static int FetchRSS( filter_t *p_filter)
{ {
return 1; return 1;
} }
# ifdef RSS_DEBUG
msg_Dbg( p_filter, " text : %s", psz_eltvalue ); msg_Dbg( p_filter, " text : %s", psz_eltvalue );
# endif
if( i_is_item == VLC_FALSE ) if( i_is_item == VLC_FALSE )
{ {
if( !strcmp( psz_eltname, "title" ) ) if( !strcmp( psz_eltname, "title" ) )
...@@ -511,6 +554,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -511,6 +554,7 @@ static int FetchRSS( filter_t *p_filter)
else else
{ {
free( psz_eltvalue ); free( psz_eltvalue );
psz_eltvalue = NULL;
} }
} }
else else
...@@ -532,6 +576,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -532,6 +576,7 @@ static int FetchRSS( filter_t *p_filter)
else else
{ {
free( psz_eltvalue ); free( psz_eltvalue );
psz_eltvalue = NULL;
} }
} }
break; break;
...@@ -540,6 +585,7 @@ static int FetchRSS( filter_t *p_filter) ...@@ -540,6 +585,7 @@ static int FetchRSS( filter_t *p_filter)
if( p_xml_reader && p_xml ) xml_ReaderDelete( p_xml, p_xml_reader ); if( p_xml_reader && p_xml ) xml_ReaderDelete( p_xml, p_xml_reader );
if( p_stream ) stream_Delete( p_stream ); if( p_stream ) stream_Delete( p_stream );
msg_Dbg( p_filter, "Done with %s RSS feed.", psz_feed );
} }
free( psz_buffer_2 ); free( psz_buffer_2 );
if( p_xml ) xml_Delete( p_xml ); if( p_xml ) xml_Delete( p_xml );
...@@ -560,21 +606,28 @@ static void FreeRSS( filter_t *p_filter) ...@@ -560,21 +606,28 @@ static void FreeRSS( filter_t *p_filter)
int i_feed; int i_feed;
int i_item; int i_item;
fprintf( stderr, "freeing ...\n" );
for( i_feed = 0; i_feed < p_sys->i_feeds; i_feed++ ) for( i_feed = 0; i_feed < p_sys->i_feeds; i_feed++ )
{ {
fprintf( stderr, "i_feed = %d\n", i_feed );
p_feed = p_sys->p_feeds+i_feed; p_feed = p_sys->p_feeds+i_feed;
for( i_item = 0; i_item < p_feed->i_items; i_item++ ) for( i_item = 0; i_item < p_feed->i_items; i_item++ )
{ {
fprintf( stderr, "i_feed = %d, i_item = %d\n", i_feed, i_item );
p_item = p_feed->p_items+i_item; p_item = p_feed->p_items+i_item;
free( p_item->psz_title ); free( p_item->psz_title );
free( p_item->psz_link ); free( p_item->psz_link );
fprintf( stderr, "psz_description : %p %s \n", p_item->psz_description, p_item->psz_description);
free( p_item->psz_description ); free( p_item->psz_description );
fprintf( stderr, "i_item done\n");
} }
free( p_feed->p_items ); free( p_feed->p_items );
free( p_feed->psz_title); free( p_feed->psz_title);
free( p_feed->psz_link ); free( p_feed->psz_link );
free( p_feed->psz_description ); free( p_feed->psz_description );
fprintf( stderr, "i_feed done\n");
} }
free( p_sys->p_feeds ); free( p_sys->p_feeds );
p_sys->i_feeds = 0; p_sys->i_feeds = 0;
fprintf( stderr, "done freeing.\n" );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment