| 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 |
#ifdef HAVE_CONFIG_H |
|---|
| 30 |
# include "config.h" |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
#include <vlc_common.h> |
|---|
| 34 |
#include <vlc_interface.h> |
|---|
| 35 |
#include <vlc_playlist.h> |
|---|
| 36 |
#include <vlc_input.h> |
|---|
| 37 |
#include <vlc_meta.h> |
|---|
| 38 |
#include <vlc_strings.h> |
|---|
| 39 |
#include <vlc_url.h> |
|---|
| 40 |
#include <vlc_charset.h> |
|---|
| 41 |
#include "xspf.h" |
|---|
| 42 |
|
|---|
| 43 |
#include <assert.h> |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
int xspf_export_playlist( vlc_object_t *p_this ) |
|---|
| 52 |
{ |
|---|
| 53 |
const playlist_t *p_playlist = (playlist_t *)p_this; |
|---|
| 54 |
const playlist_export_t *p_export = |
|---|
| 55 |
(playlist_export_t *)p_playlist->p_private; |
|---|
| 56 |
int i, i_count; |
|---|
| 57 |
char *psz_temp; |
|---|
| 58 |
playlist_item_t *p_node = p_export->p_root; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
fprintf( p_export->p_file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
|---|
| 62 |
fprintf( p_export->p_file, |
|---|
| 63 |
"<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\" " \ |
|---|
| 64 |
"xmlns:vlc=\"http://www.videolan.org/vlc/playlist/ns/0/\">\n" ); |
|---|
| 65 |
|
|---|
| 66 |
if( !p_node ) return VLC_SUCCESS; |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
psz_temp = convert_xml_special_chars( p_node->p_input->psz_name ); |
|---|
| 70 |
if( *psz_temp ) |
|---|
| 71 |
{ |
|---|
| 72 |
fprintf( p_export->p_file, "\t<title>%s</title>\n", psz_temp ); |
|---|
| 73 |
} |
|---|
| 74 |
free( psz_temp ); |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
psz_temp = assertUTF8URI( p_export->psz_filename ); |
|---|
| 78 |
if( psz_temp && *psz_temp ) |
|---|
| 79 |
{ |
|---|
| 80 |
fprintf( p_export->p_file, "\t<location>%s</location>\n", psz_temp ); |
|---|
| 81 |
} |
|---|
| 82 |
free( psz_temp ); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
fprintf( p_export->p_file, "\t<trackList>\n" ); |
|---|
| 86 |
i_count = 0; |
|---|
| 87 |
for( i = 0; i < p_node->i_children; i++ ) |
|---|
| 88 |
{ |
|---|
| 89 |
xspf_export_item( p_node->pp_children[i], p_export->p_file, |
|---|
| 90 |
&i_count ); |
|---|
| 91 |
} |
|---|
| 92 |
fprintf( p_export->p_file, "\t</trackList>\n" ); |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
fprintf( p_export->p_file, "\t<extension application=\"" \ |
|---|
| 96 |
"http://www.videolan.org/vlc/playlist/0\">\n" ); |
|---|
| 97 |
i_count = 0; |
|---|
| 98 |
for( i = 0; i < p_node->i_children; i++ ) |
|---|
| 99 |
{ |
|---|
| 100 |
xspf_extension_item( p_node->pp_children[i], p_export->p_file, |
|---|
| 101 |
&i_count ); |
|---|
| 102 |
} |
|---|
| 103 |
fprintf( p_export->p_file, "\t</extension>\n" ); |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
fprintf( p_export->p_file, "</playlist>\n" ); |
|---|
| 107 |
|
|---|
| 108 |
return VLC_SUCCESS; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
static void xspf_export_item( playlist_item_t *p_item, FILE *p_file, |
|---|
| 118 |
int *p_i_count ) |
|---|
| 119 |
{ |
|---|
| 120 |
char *psz; |
|---|
| 121 |
char *psz_temp; |
|---|
| 122 |
int i; |
|---|
| 123 |
mtime_t i_duration; |
|---|
| 124 |
|
|---|
| 125 |
if( !p_item ) return; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
if( p_item->i_children > 0 ) |
|---|
| 129 |
{ |
|---|
| 130 |
int i; |
|---|
| 131 |
for( i = 0; i < p_item->i_children; i++ ) |
|---|
| 132 |
{ |
|---|
| 133 |
xspf_export_item( p_item->pp_children[i], p_file, p_i_count ); |
|---|
| 134 |
} |
|---|
| 135 |
return; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
if( p_item->i_children == 0 ) |
|---|
| 140 |
{ |
|---|
| 141 |
return; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
fprintf( p_file, "\t\t<track>\n" ); |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
char *psz_uri = input_item_GetURI( p_item->p_input ); |
|---|
| 150 |
|
|---|
| 151 |
if( psz_uri && *psz_uri ) |
|---|
| 152 |
{ |
|---|
| 153 |
psz = assertUTF8URI( psz_uri ); |
|---|
| 154 |
fprintf( p_file, "\t\t\t<location>%s</location>\n", psz ); |
|---|
| 155 |
free( psz ); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
char *psz_name = input_item_GetTitle( p_item->p_input ); |
|---|
| 160 |
if( psz_name && psz_uri && strcmp( psz_uri, psz_name ) ) |
|---|
| 161 |
{ |
|---|
| 162 |
psz_temp = convert_xml_special_chars( psz_name ); |
|---|
| 163 |
if( *psz_temp ) |
|---|
| 164 |
fprintf( p_file, "\t\t\t<title>%s</title>\n", psz_temp ); |
|---|
| 165 |
free( psz_temp ); |
|---|
| 166 |
} |
|---|
| 167 |
free( psz_name ); |
|---|
| 168 |
free( psz_uri ); |
|---|
| 169 |
|
|---|
| 170 |
if( p_item->p_input->p_meta == NULL ) |
|---|
| 171 |
{ |
|---|
| 172 |
goto xspfexportitem_end; |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
psz = input_item_GetArtist( p_item->p_input ); |
|---|
| 177 |
if( psz == NULL ) psz = strdup( "" ); |
|---|
| 178 |
psz_temp = convert_xml_special_chars( psz ); |
|---|
| 179 |
free( psz ); |
|---|
| 180 |
if( *psz_temp ) |
|---|
| 181 |
{ |
|---|
| 182 |
fprintf( p_file, "\t\t\t<creator>%s</creator>\n", psz_temp ); |
|---|
| 183 |
} |
|---|
| 184 |
free( psz_temp ); |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
psz = input_item_GetAlbum( p_item->p_input ); |
|---|
| 188 |
if( psz == NULL ) psz = strdup( "" ); |
|---|
| 189 |
psz_temp = convert_xml_special_chars( psz ); |
|---|
| 190 |
free( psz ); |
|---|
| 191 |
if( *psz_temp ) |
|---|
| 192 |
{ |
|---|
| 193 |
fprintf( p_file, "\t\t\t<album>%s</album>\n", psz_temp ); |
|---|
| 194 |
} |
|---|
| 195 |
free( psz_temp ); |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
psz = input_item_GetTrackNum( p_item->p_input ); |
|---|
| 199 |
if( psz == NULL ) psz = strdup( "" ); |
|---|
| 200 |
if( psz && *psz ) |
|---|
| 201 |
{ |
|---|
| 202 |
int i_tracknum = atoi( psz ); |
|---|
| 203 |
if( i_tracknum > 0 ) |
|---|
| 204 |
fprintf( p_file, "\t\t\t<trackNum>%i</trackNum>\n", i_tracknum ); |
|---|
| 205 |
} |
|---|
| 206 |
free( psz ); |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
psz = input_item_GetDescription( p_item->p_input ); |
|---|
| 210 |
if( psz == NULL ) psz = strdup( "" ); |
|---|
| 211 |
psz_temp = convert_xml_special_chars( psz ); |
|---|
| 212 |
free( psz ); |
|---|
| 213 |
if( *psz_temp ) |
|---|
| 214 |
{ |
|---|
| 215 |
fprintf( p_file, "\t\t\t<annotation>%s</annotation>\n", psz_temp ); |
|---|
| 216 |
} |
|---|
| 217 |
free( psz_temp ); |
|---|
| 218 |
|
|---|
| 219 |
psz = input_item_GetArtURL( p_item->p_input ); |
|---|
| 220 |
if( psz == NULL ) psz = strdup( "" ); |
|---|
| 221 |
if( !EMPTY_STR( psz ) ) |
|---|
| 222 |
{ |
|---|
| 223 |
psz_uri = assertUTF8URI( psz ); |
|---|
| 224 |
fprintf( p_file, "\t\t\t<image>%s</image>\n", psz_uri ); |
|---|
| 225 |
free( psz_uri ); |
|---|
| 226 |
} |
|---|
| 227 |
free( psz ); |
|---|
| 228 |
|
|---|
| 229 |
xspfexportitem_end: |
|---|
| 230 |
|
|---|
| 231 |
i_duration = input_item_GetDuration( p_item->p_input ); |
|---|
| 232 |
if( i_duration > 0 ) |
|---|
| 233 |
{ |
|---|
| 234 |
fprintf( p_file, "\t\t\t<duration>%ld</duration>\n", |
|---|
| 235 |
(long)(i_duration / 1000) ); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
fprintf( p_file, "\t\t\t<extension application=\"" \ |
|---|
| 241 |
"http://www.videolan.org/vlc/playlist/0\">\n" ); |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
fprintf( p_file, "\t\t\t\t<vlc:id>%i</vlc:id>\n", *p_i_count ); |
|---|
| 245 |
( *p_i_count )++; |
|---|
| 246 |
|
|---|
| 247 |
for( i = 0; i < p_item->p_input->i_options; i++ ) |
|---|
| 248 |
{ |
|---|
| 249 |
fprintf( p_file, "\t\t\t\t<vlc:option>%s</vlc:option>\n", |
|---|
| 250 |
p_item->p_input->ppsz_options[i][0] == ':' ? |
|---|
| 251 |
p_item->p_input->ppsz_options[i] + 1 : |
|---|
| 252 |
p_item->p_input->ppsz_options[i] ); |
|---|
| 253 |
} |
|---|
| 254 |
fprintf( p_file, "\t\t\t</extension>\n" ); |
|---|
| 255 |
|
|---|
| 256 |
fprintf( p_file, "\t\t</track>\n" ); |
|---|
| 257 |
|
|---|
| 258 |
return; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
static void xspf_extension_item( playlist_item_t *p_item, FILE *p_file, |
|---|
| 268 |
int *p_i_count ) |
|---|
| 269 |
{ |
|---|
| 270 |
if( !p_item ) return; |
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
if( p_item->i_children >= 0 ) |
|---|
| 274 |
{ |
|---|
| 275 |
int i; |
|---|
| 276 |
char *psz_temp; |
|---|
| 277 |
psz_temp = convert_xml_special_chars( p_item->p_input->psz_name ); |
|---|
| 278 |
fprintf( p_file, "\t\t<vlc:node title=\"%s\">\n", |
|---|
| 279 |
*psz_temp ? psz_temp : "" ); |
|---|
| 280 |
free( psz_temp ); |
|---|
| 281 |
|
|---|
| 282 |
for( i = 0; i < p_item->i_children; i++ ) |
|---|
| 283 |
{ |
|---|
| 284 |
xspf_extension_item( p_item->pp_children[i], p_file, p_i_count ); |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
fprintf( p_file, "\t\t</vlc:node>\n" ); |
|---|
| 288 |
return; |
|---|
| 289 |
} |
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
fprintf( p_file, "\t\t\t<vlc:item tid=\"%i\" />\n", *p_i_count ); |
|---|
| 294 |
( *p_i_count )++; |
|---|
| 295 |
|
|---|
| 296 |
return; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
static char *assertUTF8URI( char *psz_name ) |
|---|
| 307 |
{ |
|---|
| 308 |
char *psz_ret = NULL; |
|---|
| 309 |
char *psz_s = NULL, *psz_d = NULL; |
|---|
| 310 |
bool b_uri_is_file = false; |
|---|
| 311 |
|
|---|
| 312 |
if( !psz_name || !*psz_name ) |
|---|
| 313 |
return NULL; |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
if( !( psz_s = EnsureUTF8( psz_name ) ) ) |
|---|
| 318 |
return NULL; |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
psz_ret = (char *)malloc( sizeof(char)*strlen(psz_name)*6*3+8 ); |
|---|
| 323 |
if( !psz_ret ) |
|---|
| 324 |
return NULL; |
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
size_t i_delim = strcspn( psz_s, ":" ); |
|---|
| 328 |
if( i_delim != strlen( psz_s ) ) |
|---|
| 329 |
{ |
|---|
| 330 |
i_delim++; |
|---|
| 331 |
strncpy( psz_ret, psz_s, i_delim ); |
|---|
| 332 |
psz_d = psz_ret + i_delim; |
|---|
| 333 |
|
|---|
| 334 |
if( !strncmp( psz_s, "file://", 7 ) ) |
|---|
| 335 |
b_uri_is_file = true; |
|---|
| 336 |
|
|---|
| 337 |
psz_s += i_delim; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
else |
|---|
| 341 |
{ |
|---|
| 342 |
strcpy( psz_ret, "file://" ); |
|---|
| 343 |
psz_d = psz_ret + 7; |
|---|
| 344 |
b_uri_is_file = true; |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
while( *psz_s ) |
|---|
| 348 |
{ |
|---|
| 349 |
|
|---|
| 350 |
if( *psz_s & B10000000 || |
|---|
| 351 |
*psz_s == '<' || |
|---|
| 352 |
*psz_s == '>' || |
|---|
| 353 |
*psz_s == '&' || |
|---|
| 354 |
*psz_s == ' ' || |
|---|
| 355 |
*psz_s == '+' || |
|---|
| 356 |
*psz_s == '%' || |
|---|
| 357 |
( b_uri_is_file && ( |
|---|
| 358 |
*psz_s == ':' || |
|---|
| 359 |
*psz_s == '"' || |
|---|
| 360 |
*psz_s == '?' || |
|---|
| 361 |
*psz_s == '#' || |
|---|
| 362 |
*psz_s == '[' || |
|---|
| 363 |
*psz_s == ']' || |
|---|
| 364 |
*psz_s == '@' ) |
|---|
| 365 |
) |
|---|
| 366 |
) |
|---|
| 367 |
{ |
|---|
| 368 |
*psz_d++ = '%'; |
|---|
| 369 |
*psz_d++ = hexchars[(*psz_s >> 4) & B00001111]; |
|---|
| 370 |
*psz_d++ = hexchars[*psz_s & B00001111]; |
|---|
| 371 |
} |
|---|
| 372 |
else |
|---|
| 373 |
{ |
|---|
| 374 |
*psz_d++ = *psz_s; |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
psz_s++; |
|---|
| 378 |
} |
|---|
| 379 |
*psz_d = '\0'; |
|---|
| 380 |
|
|---|
| 381 |
return (char *)realloc( psz_ret, sizeof(char)*strlen( psz_ret ) + 1 ); |
|---|
| 382 |
} |
|---|