| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
#ifdef HAVE_CONFIG_H |
|---|
| 31 |
# include "config.h" |
|---|
| 32 |
#endif |
|---|
| 33 |
|
|---|
| 34 |
#include <vlc_common.h> |
|---|
| 35 |
#include <vlc_demux.h> |
|---|
| 36 |
|
|---|
| 37 |
#include <ctype.h> |
|---|
| 38 |
#include <vlc_charset.h> |
|---|
| 39 |
#include "playlist.h" |
|---|
| 40 |
#include "vlc_meta.h" |
|---|
| 41 |
|
|---|
| 42 |
struct demux_sys_t |
|---|
| 43 |
{ |
|---|
| 44 |
char *psz_prefix; |
|---|
| 45 |
char *psz_data; |
|---|
| 46 |
int64_t i_data_len; |
|---|
| 47 |
bool b_utf8; |
|---|
| 48 |
bool b_skip_ads; |
|---|
| 49 |
}; |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
static int Demux( demux_t *p_demux); |
|---|
| 55 |
static int Control( demux_t *p_demux, int i_query, va_list args ); |
|---|
| 56 |
|
|---|
| 57 |
static int StoreString( demux_t *p_demux, char **ppsz_string, |
|---|
| 58 |
const char *psz_source_start, |
|---|
| 59 |
const char *psz_source_end ) |
|---|
| 60 |
{ |
|---|
| 61 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 62 |
unsigned len = psz_source_end - psz_source_start; |
|---|
| 63 |
|
|---|
| 64 |
free( *ppsz_string ); |
|---|
| 65 |
|
|---|
| 66 |
char *buf = *ppsz_string = malloc ((len * (1 + !p_sys->b_utf8)) + 1); |
|---|
| 67 |
if (buf == NULL) |
|---|
| 68 |
return VLC_ENOMEM; |
|---|
| 69 |
|
|---|
| 70 |
if( p_sys->b_utf8 ) |
|---|
| 71 |
{ |
|---|
| 72 |
memcpy (buf, psz_source_start, len); |
|---|
| 73 |
(*ppsz_string)[len] = '\0'; |
|---|
| 74 |
EnsureUTF8 (*ppsz_string); |
|---|
| 75 |
} |
|---|
| 76 |
else |
|---|
| 77 |
{ |
|---|
| 78 |
|
|---|
| 79 |
for (unsigned i = 0; i < len; i++) |
|---|
| 80 |
{ |
|---|
| 81 |
unsigned char c = psz_source_start[i]; |
|---|
| 82 |
if (c & 0x80) |
|---|
| 83 |
{ |
|---|
| 84 |
*buf++ = 0xc0 | (c >> 6); |
|---|
| 85 |
*buf++ = 0x80 | (c & 0x3f); |
|---|
| 86 |
} |
|---|
| 87 |
else |
|---|
| 88 |
*buf++ = c; |
|---|
| 89 |
} |
|---|
| 90 |
*buf++ = '\0'; |
|---|
| 91 |
|
|---|
| 92 |
buf = *ppsz_string = realloc (*ppsz_string, buf - *ppsz_string); |
|---|
| 93 |
} |
|---|
| 94 |
return VLC_SUCCESS; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
static char *SkipBlanks(char *s, size_t i_strlen ) |
|---|
| 98 |
{ |
|---|
| 99 |
while( i_strlen > 0 ) { |
|---|
| 100 |
switch( *s ) |
|---|
| 101 |
{ |
|---|
| 102 |
case ' ': |
|---|
| 103 |
case '\t': |
|---|
| 104 |
case '\r': |
|---|
| 105 |
case '\n': |
|---|
| 106 |
--i_strlen; |
|---|
| 107 |
++s; |
|---|
| 108 |
break; |
|---|
| 109 |
default: |
|---|
| 110 |
i_strlen = 0; |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
return s; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
static int ParseTime(char *s, size_t i_strlen) |
|---|
| 117 |
{ |
|---|
| 118 |
|
|---|
| 119 |
int result = 0; |
|---|
| 120 |
int val; |
|---|
| 121 |
const char *end = s + i_strlen; |
|---|
| 122 |
|
|---|
| 123 |
s = SkipBlanks(s, i_strlen); |
|---|
| 124 |
|
|---|
| 125 |
val = 0; |
|---|
| 126 |
while( (s < end) && isdigit(*s) ) |
|---|
| 127 |
{ |
|---|
| 128 |
int newval = val*10 + (*s - '0'); |
|---|
| 129 |
if( newval < val ) |
|---|
| 130 |
{ |
|---|
| 131 |
|
|---|
| 132 |
val = 0; |
|---|
| 133 |
break; |
|---|
| 134 |
} |
|---|
| 135 |
val = newval; |
|---|
| 136 |
++s; |
|---|
| 137 |
} |
|---|
| 138 |
result = val; |
|---|
| 139 |
s = SkipBlanks(s, end-s); |
|---|
| 140 |
if( *s == ':' ) |
|---|
| 141 |
{ |
|---|
| 142 |
++s; |
|---|
| 143 |
s = SkipBlanks(s, end-s); |
|---|
| 144 |
result = result * 60; |
|---|
| 145 |
val = 0; |
|---|
| 146 |
while( (s < end) && isdigit(*s) ) |
|---|
| 147 |
{ |
|---|
| 148 |
int newval = val*10 + (*s - '0'); |
|---|
| 149 |
if( newval < val ) |
|---|
| 150 |
{ |
|---|
| 151 |
|
|---|
| 152 |
val = 0; |
|---|
| 153 |
break; |
|---|
| 154 |
} |
|---|
| 155 |
val = newval; |
|---|
| 156 |
++s; |
|---|
| 157 |
} |
|---|
| 158 |
result += val; |
|---|
| 159 |
s = SkipBlanks(s, end-s); |
|---|
| 160 |
if( *s == ':' ) |
|---|
| 161 |
{ |
|---|
| 162 |
++s; |
|---|
| 163 |
s = SkipBlanks(s, end-s); |
|---|
| 164 |
result = result * 60; |
|---|
| 165 |
val = 0; |
|---|
| 166 |
while( (s < end) && isdigit(*s) ) |
|---|
| 167 |
{ |
|---|
| 168 |
int newval = val*10 + (*s - '0'); |
|---|
| 169 |
if( newval < val ) |
|---|
| 170 |
{ |
|---|
| 171 |
|
|---|
| 172 |
val = 0; |
|---|
| 173 |
break; |
|---|
| 174 |
} |
|---|
| 175 |
val = newval; |
|---|
| 176 |
++s; |
|---|
| 177 |
} |
|---|
| 178 |
result += val; |
|---|
| 179 |
|
|---|
| 180 |
} |
|---|
| 181 |
} |
|---|
| 182 |
return result; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
int Import_ASX( vlc_object_t *p_this ) |
|---|
| 189 |
{ |
|---|
| 190 |
demux_t *p_demux = (demux_t *)p_this; |
|---|
| 191 |
const uint8_t *p_peek; |
|---|
| 192 |
CHECK_PEEK( p_peek, 10 ); |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
p_peek = (uint8_t *)SkipBlanks((char *)p_peek, 6); |
|---|
| 196 |
|
|---|
| 197 |
if( POKE( p_peek, "<asx", 4 ) || demux_IsPathExtension( p_demux, ".asx" ) || |
|---|
| 198 |
demux_IsPathExtension( p_demux, ".wax" ) || demux_IsPathExtension( p_demux, ".wvx" ) || |
|---|
| 199 |
demux_IsForced( p_demux, "asx-open" ) ) |
|---|
| 200 |
{ |
|---|
| 201 |
; |
|---|
| 202 |
} |
|---|
| 203 |
else |
|---|
| 204 |
return VLC_EGENERIC; |
|---|
| 205 |
|
|---|
| 206 |
STANDARD_DEMUX_INIT_MSG( "found valid ASX playlist" ); |
|---|
| 207 |
p_demux->p_sys->psz_prefix = FindPrefix( p_demux ); |
|---|
| 208 |
p_demux->p_sys->psz_data = NULL; |
|---|
| 209 |
p_demux->p_sys->i_data_len = -1; |
|---|
| 210 |
p_demux->p_sys->b_utf8 = false; |
|---|
| 211 |
p_demux->p_sys->b_skip_ads = config_GetInt( p_demux, "playlist-skip-ads" ); |
|---|
| 212 |
|
|---|
| 213 |
return VLC_SUCCESS; |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
void Close_ASX( vlc_object_t *p_this ) |
|---|
| 220 |
{ |
|---|
| 221 |
demux_t *p_demux = (demux_t *)p_this; |
|---|
| 222 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 223 |
|
|---|
| 224 |
free( p_sys->psz_prefix ); |
|---|
| 225 |
free( p_sys->psz_data ); |
|---|
| 226 |
free( p_sys ); |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
static int Demux( demux_t *p_demux ) |
|---|
| 230 |
{ |
|---|
| 231 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 232 |
char *psz_parse = NULL; |
|---|
| 233 |
char *psz_backup = NULL; |
|---|
| 234 |
bool b_entry = false; |
|---|
| 235 |
INIT_PLAYLIST_STUFF; |
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
if( p_sys->i_data_len < 0 ) |
|---|
| 239 |
{ |
|---|
| 240 |
int64_t i_pos = 0; |
|---|
| 241 |
p_sys->i_data_len = stream_Size( p_demux->s ) +1; |
|---|
| 242 |
if( p_sys->i_data_len <= 0 && p_sys->i_data_len < 16384 ) p_sys->i_data_len = 1024; |
|---|
| 243 |
p_sys->psz_data = malloc( p_sys->i_data_len * sizeof(char) +1); |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
for( ;; ) |
|---|
| 247 |
{ |
|---|
| 248 |
int i_read = stream_Read( p_demux->s, &p_sys->psz_data[i_pos], p_sys->i_data_len - i_pos ); |
|---|
| 249 |
p_sys->psz_data[i_pos + i_read] = '\0'; |
|---|
| 250 |
|
|---|
| 251 |
if( i_read < p_sys->i_data_len - i_pos ) break; |
|---|
| 252 |
|
|---|
| 253 |
i_pos += i_read; |
|---|
| 254 |
p_sys->i_data_len += 1024; |
|---|
| 255 |
p_sys->psz_data = realloc( p_sys->psz_data, p_sys->i_data_len * sizeof( char * ) +1 ); |
|---|
| 256 |
} |
|---|
| 257 |
if( p_sys->i_data_len <= 0 ) return -1; |
|---|
| 258 |
} |
|---|
| 259 |
|
|---|
| 260 |
psz_parse = p_sys->psz_data; |
|---|
| 261 |
|
|---|
| 262 |
if( ( psz_parse = strcasestr( psz_parse, "<ASX" ) ) ) |
|---|
| 263 |
{ |
|---|
| 264 |
|
|---|
| 265 |
char *psz_string = NULL; |
|---|
| 266 |
int i_strlen = 0; |
|---|
| 267 |
|
|---|
| 268 |
char *psz_base_asx = NULL; |
|---|
| 269 |
char *psz_title_asx = NULL; |
|---|
| 270 |
char *psz_artist_asx = NULL; |
|---|
| 271 |
char *psz_copyright_asx = NULL; |
|---|
| 272 |
char *psz_moreinfo_asx = NULL; |
|---|
| 273 |
char *psz_abstract_asx = NULL; |
|---|
| 274 |
|
|---|
| 275 |
char *psz_base_entry = NULL; |
|---|
| 276 |
char *psz_title_entry = NULL; |
|---|
| 277 |
char *psz_artist_entry = NULL; |
|---|
| 278 |
char *psz_copyright_entry = NULL; |
|---|
| 279 |
char *psz_moreinfo_entry = NULL; |
|---|
| 280 |
char *psz_abstract_entry = NULL; |
|---|
| 281 |
int i_entry_count = 0; |
|---|
| 282 |
bool b_skip_entry = false; |
|---|
| 283 |
|
|---|
| 284 |
char *psz_href = NULL; |
|---|
| 285 |
int i_starttime = 0; |
|---|
| 286 |
int i_duration = 0; |
|---|
| 287 |
|
|---|
| 288 |
psz_parse = strcasestr( psz_parse, ">" ); |
|---|
| 289 |
|
|---|
| 290 |
while( psz_parse && ( psz_parse = strcasestr( psz_parse, "<" ) ) ) |
|---|
| 291 |
{ |
|---|
| 292 |
if( !strncasecmp( psz_parse, "<!--", 4 ) ) |
|---|
| 293 |
{ |
|---|
| 294 |
|
|---|
| 295 |
if( ( psz_parse = strcasestr( psz_parse, "-->" ) ) ) |
|---|
| 296 |
psz_parse+=3; |
|---|
| 297 |
else continue; |
|---|
| 298 |
} |
|---|
| 299 |
else if( !strncasecmp( psz_parse, "<PARAM ", 7 ) ) |
|---|
| 300 |
{ |
|---|
| 301 |
bool b_encoding_flag = false; |
|---|
| 302 |
psz_parse = SkipBlanks(psz_parse+7, (unsigned)-1); |
|---|
| 303 |
if( !strncasecmp( psz_parse, "name", 4 ) ) |
|---|
| 304 |
{ |
|---|
| 305 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 306 |
{ |
|---|
| 307 |
psz_backup = ++psz_parse; |
|---|
| 308 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 309 |
{ |
|---|
| 310 |
i_strlen = psz_parse-psz_backup; |
|---|
| 311 |
if( i_strlen < 1 ) continue; |
|---|
| 312 |
msg_Dbg( p_demux, "param name strlen: %d", i_strlen); |
|---|
| 313 |
psz_string = malloc( i_strlen *sizeof( char ) +1); |
|---|
| 314 |
memcpy( psz_string, psz_backup, i_strlen ); |
|---|
| 315 |
psz_string[i_strlen] = '\0'; |
|---|
| 316 |
msg_Dbg( p_demux, "param name: %s", psz_string); |
|---|
| 317 |
b_encoding_flag = !strcasecmp( psz_string, "encoding" ); |
|---|
| 318 |
free( psz_string ); |
|---|
| 319 |
} |
|---|
| 320 |
else continue; |
|---|
| 321 |
} |
|---|
| 322 |
else continue; |
|---|
| 323 |
} |
|---|
| 324 |
psz_parse++; |
|---|
| 325 |
if( !strncasecmp( psz_parse, "value", 5 ) ) |
|---|
| 326 |
{ |
|---|
| 327 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 328 |
{ |
|---|
| 329 |
psz_backup = ++psz_parse; |
|---|
| 330 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 331 |
{ |
|---|
| 332 |
i_strlen = psz_parse-psz_backup; |
|---|
| 333 |
if( i_strlen < 1 ) continue; |
|---|
| 334 |
msg_Dbg( p_demux, "param value strlen: %d", i_strlen); |
|---|
| 335 |
psz_string = malloc( i_strlen *sizeof( char ) +1); |
|---|
| 336 |
memcpy( psz_string, psz_backup, i_strlen ); |
|---|
| 337 |
psz_string[i_strlen] = '\0'; |
|---|
| 338 |
msg_Dbg( p_demux, "param value: %s", psz_string); |
|---|
| 339 |
if( b_encoding_flag && !strcasecmp( psz_string, "utf-8" ) ) p_sys->b_utf8 = true; |
|---|
| 340 |
free( psz_string ); |
|---|
| 341 |
} |
|---|
| 342 |
else continue; |
|---|
| 343 |
} |
|---|
| 344 |
else continue; |
|---|
| 345 |
} |
|---|
| 346 |
if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) ) |
|---|
| 347 |
psz_parse += 2; |
|---|
| 348 |
else continue; |
|---|
| 349 |
} |
|---|
| 350 |
else if( !strncasecmp( psz_parse, "<BANNER", 7 ) ) |
|---|
| 351 |
{ |
|---|
| 352 |
|
|---|
| 353 |
if( ( psz_parse = strcasestr( psz_parse, "</BANNER>" ) ) ) |
|---|
| 354 |
psz_parse += 9; |
|---|
| 355 |
else continue; |
|---|
| 356 |
} |
|---|
| 357 |
else if( !strncasecmp( psz_parse, "<PREVIEWDURATION", 16 ) || |
|---|
| 358 |
!strncasecmp( psz_parse, "<LOGURL", 7 ) || |
|---|
| 359 |
!strncasecmp( psz_parse, "<Skin", 5 ) ) |
|---|
| 360 |
{ |
|---|
| 361 |
|
|---|
| 362 |
if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) ) |
|---|
| 363 |
psz_parse += 2; |
|---|
| 364 |
else continue; |
|---|
| 365 |
} |
|---|
| 366 |
else if( !strncasecmp( psz_parse, "<BASE ", 6 ) ) |
|---|
| 367 |
{ |
|---|
| 368 |
psz_parse = SkipBlanks(psz_parse+6, (unsigned)-1); |
|---|
| 369 |
if( !strncasecmp( psz_parse, "HREF", 4 ) ) |
|---|
| 370 |
{ |
|---|
| 371 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 372 |
{ |
|---|
| 373 |
psz_backup = ++psz_parse; |
|---|
| 374 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 375 |
{ |
|---|
| 376 |
StoreString( p_demux, (b_entry ? &psz_base_entry : &psz_base_asx), psz_backup, psz_parse ); |
|---|
| 377 |
} |
|---|
| 378 |
else continue; |
|---|
| 379 |
} |
|---|
| 380 |
else continue; |
|---|
| 381 |
} |
|---|
| 382 |
if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) ) |
|---|
| 383 |
psz_parse += 2; |
|---|
| 384 |
else continue; |
|---|
| 385 |
} |
|---|
| 386 |
else if( !strncasecmp( psz_parse, "<TITLE>", 7 ) ) |
|---|
| 387 |
{ |
|---|
| 388 |
psz_backup = psz_parse+=7; |
|---|
| 389 |
if( ( psz_parse = strcasestr( psz_parse, "</TITLE>" ) ) ) |
|---|
| 390 |
{ |
|---|
| 391 |
StoreString( p_demux, (b_entry ? &psz_title_entry : &psz_title_asx), psz_backup, psz_parse ); |
|---|
| 392 |
psz_parse += 8; |
|---|
| 393 |
} |
|---|
| 394 |
else continue; |
|---|
| 395 |
} |
|---|
| 396 |
else if( !strncasecmp( psz_parse, "<Author>", 8 ) ) |
|---|
| 397 |
{ |
|---|
| 398 |
psz_backup = psz_parse+=8; |
|---|
| 399 |
if( ( psz_parse = strcasestr( psz_parse, "</Author>" ) ) ) |
|---|
| 400 |
{ |
|---|
| 401 |
StoreString( p_demux, (b_entry ? &psz_artist_entry : &psz_artist_asx), psz_backup, psz_parse ); |
|---|
| 402 |
psz_parse += 9; |
|---|
| 403 |
} |
|---|
| 404 |
else continue; |
|---|
| 405 |
} |
|---|
| 406 |
else if( !strncasecmp( psz_parse, "<Copyright", 10 ) ) |
|---|
| 407 |
{ |
|---|
| 408 |
psz_backup = psz_parse+=11; |
|---|
| 409 |
if( ( psz_parse = strcasestr( psz_parse, "</Copyright>" ) ) ) |
|---|
| 410 |
{ |
|---|
| 411 |
StoreString( p_demux, (b_entry ? &psz_copyright_entry : &psz_copyright_asx), psz_backup, psz_parse ); |
|---|
| 412 |
psz_parse += 12; |
|---|
| 413 |
} |
|---|
| 414 |
else continue; |
|---|
| 415 |
} |
|---|
| 416 |
else if( !strncasecmp( psz_parse, "<MoreInfo ", 10 ) ) |
|---|
| 417 |
{ |
|---|
| 418 |
psz_parse = SkipBlanks(psz_parse+10, (unsigned)-1); |
|---|
| 419 |
if( !strncasecmp( psz_parse, "HREF", 4 ) ) |
|---|
| 420 |
{ |
|---|
| 421 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 422 |
{ |
|---|
| 423 |
psz_backup = ++psz_parse; |
|---|
| 424 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 425 |
{ |
|---|
| 426 |
StoreString( p_demux, (b_entry ? &psz_moreinfo_entry : &psz_moreinfo_asx), psz_backup, psz_parse ); |
|---|
| 427 |
} |
|---|
| 428 |
else continue; |
|---|
| 429 |
} |
|---|
| 430 |
else continue; |
|---|
| 431 |
} |
|---|
| 432 |
if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) ) |
|---|
| 433 |
psz_parse += 2; |
|---|
| 434 |
else continue; |
|---|
| 435 |
} |
|---|
| 436 |
else if( !strncasecmp( psz_parse, "<ABSTRACT>", 10 ) ) |
|---|
| 437 |
{ |
|---|
| 438 |
psz_backup = psz_parse+=10; |
|---|
| 439 |
if( ( psz_parse = strcasestr( psz_parse, "</ABSTRACT>" ) ) ) |
|---|
| 440 |
{ |
|---|
| 441 |
StoreString( p_demux, (b_entry ? &psz_abstract_entry : &psz_abstract_asx), psz_backup, psz_parse ); |
|---|
| 442 |
psz_parse += 11; |
|---|
| 443 |
} |
|---|
| 444 |
else continue; |
|---|
| 445 |
} |
|---|
| 446 |
else if( !strncasecmp( psz_parse, "<EntryRef ", 10 ) ) |
|---|
| 447 |
{ |
|---|
| 448 |
psz_parse = SkipBlanks(psz_parse+10, (unsigned)-1); |
|---|
| 449 |
if( !strncasecmp( psz_parse, "HREF", 4 ) ) |
|---|
| 450 |
{ |
|---|
| 451 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 452 |
{ |
|---|
| 453 |
psz_backup = ++psz_parse; |
|---|
| 454 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 455 |
{ |
|---|
| 456 |
i_strlen = psz_parse-psz_backup; |
|---|
| 457 |
if( i_strlen < 1 ) continue; |
|---|
| 458 |
psz_string = malloc( i_strlen*sizeof( char ) +1); |
|---|
| 459 |
memcpy( psz_string, psz_backup, i_strlen ); |
|---|
| 460 |
psz_string[i_strlen] = '\0'; |
|---|
| 461 |
input_item_t *p_input; |
|---|
| 462 |
p_input = input_item_New( p_demux, psz_string, psz_title_asx ); |
|---|
| 463 |
input_item_CopyOptions( p_current_input, p_input ); |
|---|
| 464 |
input_item_AddSubItem( p_current_input, p_input ); |
|---|
| 465 |
vlc_gc_decref( p_input ); |
|---|
| 466 |
free( psz_string ); |
|---|
| 467 |
} |
|---|
| 468 |
else continue; |
|---|
| 469 |
} |
|---|
| 470 |
else continue; |
|---|
| 471 |
} |
|---|
| 472 |
if( ( psz_parse = strcasestr( psz_parse, "/>" ) ) ) |
|---|
| 473 |
psz_parse += 2; |
|---|
| 474 |
else continue; |
|---|
| 475 |
} |
|---|
| 476 |
else if( !strncasecmp( psz_parse, "</Entry>", 8 ) ) |
|---|
| 477 |
{ |
|---|
| 478 |
input_item_t *p_entry = NULL; |
|---|
| 479 |
char *psz_name = NULL; |
|---|
| 480 |
|
|---|
| 481 |
char * ppsz_options[2]; |
|---|
| 482 |
int i_options = 0; |
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
psz_parse+=8; |
|---|
| 486 |
if( !b_entry ) |
|---|
| 487 |
{ |
|---|
| 488 |
msg_Err( p_demux, "end of entry without start?" ); |
|---|
| 489 |
continue; |
|---|
| 490 |
} |
|---|
| 491 |
|
|---|
| 492 |
if( !psz_href ) |
|---|
| 493 |
{ |
|---|
| 494 |
msg_Err( p_demux, "entry without href?" ); |
|---|
| 495 |
continue; |
|---|
| 496 |
} |
|---|
| 497 |
|
|---|
| 498 |
if( p_sys->b_skip_ads && b_skip_entry ) |
|---|
| 499 |
{ |
|---|
| 500 |
msg_Dbg( p_demux, "skipped entry %d %s (%s)", |
|---|
| 501 |
i_entry_count, ( psz_title_entry ? psz_title_entry : p_current_input->psz_name ), psz_href ); |
|---|
| 502 |
} |
|---|
| 503 |
else |
|---|
| 504 |
{ |
|---|
| 505 |
if( i_starttime || i_duration ) |
|---|
| 506 |
{ |
|---|
| 507 |
if( i_starttime ) |
|---|
| 508 |
{ |
|---|
| 509 |
if( asprintf(ppsz_options+i_options, ":start-time=%d", i_starttime) == -1 ) |
|---|
| 510 |
*(ppsz_options+i_options) = NULL; |
|---|
| 511 |
else |
|---|
| 512 |
++i_options; |
|---|
| 513 |
} |
|---|
| 514 |
if( i_duration ) |
|---|
| 515 |
{ |
|---|
| 516 |
if( asprintf(ppsz_options+i_options, ":stop-time=%d", i_starttime + i_duration) == -1 ) |
|---|
| 517 |
*(ppsz_options+i_options) = NULL; |
|---|
| 518 |
else |
|---|
| 519 |
++i_options; |
|---|
| 520 |
} |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
if( asprintf( &psz_name, "%d %s", i_entry_count, ( psz_title_entry ? psz_title_entry : p_current_input->psz_name ) ) != -1 ) |
|---|
| 525 |
{ |
|---|
| 526 |
p_entry = input_item_NewExt( p_demux, psz_href, psz_name, i_options, (const char * const *)ppsz_options, -1 ); |
|---|
| 527 |
FREENULL( psz_name ); |
|---|
| 528 |
input_item_CopyOptions( p_current_input, p_entry ); |
|---|
| 529 |
while( i_options ) |
|---|
| 530 |
{ |
|---|
| 531 |
psz_name = ppsz_options[--i_options]; |
|---|
| 532 |
FREENULL( psz_name ); |
|---|
| 533 |
} |
|---|
| 534 |
|
|---|
| 535 |
if( psz_title_entry ) input_item_SetTitle( p_entry, psz_title_entry ); |
|---|
| 536 |
if( psz_artist_entry ) input_item_SetArtist( p_entry, psz_artist_entry ); |
|---|
| 537 |
if( psz_copyright_entry ) input_item_SetCopyright( p_entry, psz_copyright_entry ); |
|---|
| 538 |
if( psz_moreinfo_entry ) input_item_SetURL( p_entry, psz_moreinfo_entry ); |
|---|
| 539 |
if( psz_abstract_entry ) input_item_SetDescription( p_entry, psz_abstract_entry ); |
|---|
| 540 |
input_item_AddSubItem( p_current_input, p_entry ); |
|---|
| 541 |
vlc_gc_decref( p_entry ); |
|---|
| 542 |
} |
|---|
| 543 |
} |
|---|
| 544 |
|
|---|
| 545 |
; |
|---|
| 546 |
FREENULL( psz_href ); |
|---|
| 547 |
FREENULL( psz_title_entry ); |
|---|
| 548 |
FREENULL( psz_base_entry ); |
|---|
| 549 |
FREENULL( psz_artist_entry ); |
|---|
| 550 |
FREENULL( psz_copyright_entry ); |
|---|
| 551 |
FREENULL( psz_moreinfo_entry ); |
|---|
| 552 |
FREENULL( psz_abstract_entry ); |
|---|
| 553 |
b_entry = false; |
|---|
| 554 |
} |
|---|
| 555 |
else if( !strncasecmp( psz_parse, "<Entry", 6 ) ) |
|---|
| 556 |
{ |
|---|
| 557 |
char *psz_clientskip; |
|---|
| 558 |
psz_parse+=6; |
|---|
| 559 |
if( b_entry ) |
|---|
| 560 |
{ |
|---|
| 561 |
msg_Err( p_demux, "We already are in an entry section" ); |
|---|
| 562 |
continue; |
|---|
| 563 |
} |
|---|
| 564 |
i_entry_count += 1; |
|---|
| 565 |
b_entry = true; |
|---|
| 566 |
psz_clientskip = strcasestr( psz_parse, "clientskip=\"no\"" ); |
|---|
| 567 |
psz_parse = strcasestr( psz_parse, ">" ); |
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
b_skip_entry = (NULL != psz_clientskip) && (psz_clientskip < psz_parse); |
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
FREENULL(psz_href); |
|---|
| 574 |
psz_href = NULL; |
|---|
| 575 |
i_starttime = 0; |
|---|
| 576 |
i_duration = 0; |
|---|
| 577 |
} |
|---|
| 578 |
else if( !strncasecmp( psz_parse, "<Ref ", 5 ) ) |
|---|
| 579 |
{ |
|---|
| 580 |
psz_parse = SkipBlanks(psz_parse+5, (unsigned)-1); |
|---|
| 581 |
if( !b_entry ) |
|---|
| 582 |
{ |
|---|
| 583 |
msg_Err( p_demux, "A ref outside an entry section" ); |
|---|
| 584 |
continue; |
|---|
| 585 |
} |
|---|
| 586 |
|
|---|
| 587 |
if( !strncasecmp( psz_parse, "HREF", 4 ) ) |
|---|
| 588 |
{ |
|---|
| 589 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 590 |
{ |
|---|
| 591 |
psz_backup = ++psz_parse; |
|---|
| 592 |
psz_backup = SkipBlanks(psz_backup, (unsigned)-1); |
|---|
| 593 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 594 |
{ |
|---|
| 595 |
char *psz_tmp; |
|---|
| 596 |
i_strlen = psz_parse-psz_backup; |
|---|
| 597 |
if( i_strlen < 1 ) continue; |
|---|
| 598 |
|
|---|
| 599 |
FREENULL(psz_href); |
|---|
| 600 |
psz_href = malloc( i_strlen*sizeof( char ) +1); |
|---|
| 601 |
memcpy( psz_href, psz_backup, i_strlen ); |
|---|
| 602 |
psz_href[i_strlen] = '\0'; |
|---|
| 603 |
psz_tmp = psz_href + (i_strlen-1); |
|---|
| 604 |
while( psz_tmp >= psz_href && |
|---|
| 605 |
( *psz_tmp == '\r' || *psz_tmp == '\n' ) ) |
|---|
| 606 |
{ |
|---|
| 607 |
*psz_tmp = '\0'; |
|---|
| 608 |
psz_tmp++; |
|---|
| 609 |
} |
|---|
| 610 |
} |
|---|
| 611 |
else continue; |
|---|
| 612 |
} |
|---|
| 613 |
else continue; |
|---|
| 614 |
} |
|---|
| 615 |
if( ( psz_parse = strcasestr( psz_parse, ">" ) ) ) |
|---|
| 616 |
psz_parse++; |
|---|
| 617 |
else continue; |
|---|
| 618 |
} |
|---|
| 619 |
else if( !strncasecmp( psz_parse, "<starttime ", 11 ) ) |
|---|
| 620 |
{ |
|---|
| 621 |
psz_parse = SkipBlanks(psz_parse+11, (unsigned)-1); |
|---|
| 622 |
if( !b_entry ) |
|---|
| 623 |
{ |
|---|
| 624 |
msg_Err( p_demux, "starttime outside an entry section" ); |
|---|
| 625 |
continue; |
|---|
| 626 |
} |
|---|
| 627 |
|
|---|
| 628 |
if( !strncasecmp( psz_parse, "value", 5 ) ) |
|---|
| 629 |
{ |
|---|
| 630 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 631 |
{ |
|---|
| 632 |
psz_backup = ++psz_parse; |
|---|
| 633 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 634 |
{ |
|---|
| 635 |
i_strlen = psz_parse-psz_backup; |
|---|
| 636 |
if( i_strlen < 1 ) continue; |
|---|
| 637 |
|
|---|
| 638 |
i_starttime = ParseTime(psz_backup, i_strlen); |
|---|
| 639 |
} |
|---|
| 640 |
else continue; |
|---|
| 641 |
} |
|---|
| 642 |
else continue; |
|---|
| 643 |
} |
|---|
| 644 |
if( ( psz_parse = strcasestr( psz_parse, ">" ) ) ) |
|---|
| 645 |
psz_parse++; |
|---|
| 646 |
else continue; |
|---|
| 647 |
} |
|---|
| 648 |
else if( !strncasecmp( psz_parse, "<duration ", 11 ) ) |
|---|
| 649 |
{ |
|---|
| 650 |
psz_parse = SkipBlanks(psz_parse+5, (unsigned)-1); |
|---|
| 651 |
if( !b_entry ) |
|---|
| 652 |
{ |
|---|
| 653 |
msg_Err( p_demux, "duration outside an entry section" ); |
|---|
| 654 |
continue; |
|---|
| 655 |
} |
|---|
| 656 |
|
|---|
| 657 |
if( !strncasecmp( psz_parse, "value", 5 ) ) |
|---|
| 658 |
{ |
|---|
| 659 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 660 |
{ |
|---|
| 661 |
psz_backup = ++psz_parse; |
|---|
| 662 |
if( ( psz_parse = strcasestr( psz_parse, "\"" ) ) ) |
|---|
| 663 |
{ |
|---|
| 664 |
i_strlen = psz_parse-psz_backup; |
|---|
| 665 |
if( i_strlen < 1 ) continue; |
|---|
| 666 |
|
|---|
| 667 |
i_duration = ParseTime(psz_backup, i_strlen); |
|---|
| 668 |
} |
|---|
| 669 |
else continue; |
|---|
| 670 |
} |
|---|
| 671 |
else continue; |
|---|
| 672 |
} |
|---|
| 673 |
if( ( psz_parse = strcasestr( psz_parse, ">" ) ) ) |
|---|
| 674 |
psz_parse++; |
|---|
| 675 |
else continue; |
|---|
| 676 |
} |
|---|
| 677 |
else if( !strncasecmp( psz_parse, "</ASX", 5 ) ) |
|---|
| 678 |
{ |
|---|
| 679 |
if( psz_title_asx ) input_item_SetTitle( p_current_input, psz_title_asx ); |
|---|
| 680 |
if( psz_artist_asx ) input_item_SetArtist( p_current_input, psz_artist_asx ); |
|---|
| 681 |
if( psz_copyright_asx ) input_item_SetCopyright( p_current_input, psz_copyright_asx ); |
|---|
| 682 |
if( psz_moreinfo_asx ) input_item_SetURL( p_current_input, psz_moreinfo_asx ); |
|---|
| 683 |
if( psz_abstract_asx ) input_item_SetDescription( p_current_input, psz_abstract_asx ); |
|---|
| 684 |
FREENULL( psz_base_asx ); |
|---|
| 685 |
FREENULL( psz_title_asx ); |
|---|
| 686 |
FREENULL( psz_artist_asx ); |
|---|
| 687 |
FREENULL( psz_copyright_asx ); |
|---|
| 688 |
FREENULL( psz_moreinfo_asx ); |
|---|
| 689 |
FREENULL( psz_abstract_asx ); |
|---|
| 690 |
psz_parse++; |
|---|
| 691 |
} |
|---|
| 692 |
else psz_parse++; |
|---|
| 693 |
} |
|---|
| 694 |
#if 0 |
|---|
| 695 |
|
|---|
| 696 |
PARAM |
|---|
| 697 |
EVENT |
|---|
| 698 |
REPEAT |
|---|
| 699 |
ENDMARK |
|---|
| 700 |
STARTMARK |
|---|
| 701 |
#endif |
|---|
| 702 |
} |
|---|
| 703 |
HANDLE_PLAY_AND_RELEASE; |
|---|
| 704 |
return 0; |
|---|
| 705 |
} |
|---|
| 706 |
|
|---|
| 707 |
static int Control( demux_t *p_demux, int i_query, va_list args ) |
|---|
| 708 |
{ |
|---|
| 709 |
VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args); |
|---|
| 710 |
return VLC_EGENERIC; |
|---|
| 711 |
} |
|---|