comparison src/madplug/input.c @ 1328:38fb3bb3e21e

- make probing for tuple completely reuse fd. - fix bugs in __audmad_get_song_tuple() against remote sources.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sun, 22 Jul 2007 04:28:20 +0900
parents e7cd962732cb
children 4993976d7ed0
comparison
equal deleted inserted replaced
1327:4f9bea634312 1328:38fb3bb3e21e
67 extern gboolean scan_file(struct mad_info_t *info, gboolean fast); 67 extern gboolean scan_file(struct mad_info_t *info, gboolean fast);
68 68
69 /** 69 /**
70 * init the mad_info_t struct. 70 * init the mad_info_t struct.
71 */ 71 */
72 gboolean input_init(struct mad_info_t * info, const char *url) 72 gboolean input_init(struct mad_info_t * info, const char *url, VFSFile *fd)
73 { 73 {
74 #ifdef DEBUG 74 #ifdef DEBUG
75 g_message("f: input_init"); 75 g_message("f: input_init");
76 #endif 76 #endif
77 memset(info, 0, sizeof(struct mad_info_t)); 77 memset(info, 0, sizeof(struct mad_info_t));
110 110
111 info->tuple = NULL; 111 info->tuple = NULL;
112 112
113 info->filename = g_strdup(url); 113 info->filename = g_strdup(url);
114 114
115 info->infile = vfs_fopen(info->filename, "rb"); 115 if(!fd){
116 if (info->infile == NULL) { 116 info->infile = vfs_fopen(info->filename, "rb");
117 return FALSE; 117 if (info->infile == NULL) {
118 } 118 return FALSE;
119 }
120 }
121 else{
122 #ifdef DEBUG
123 printf("input_init: vfs_dup\n");
124 #endif
125 info->infile = vfs_dup(fd);
126 }
127
119 // obtain file size 128 // obtain file size
120 info->size = vfs_fsize(info->infile); 129 info->size = vfs_fsize(info->infile);
121 info->remote = info->size == 0 ? TRUE : FALSE; //proxy connection may result in non-zero size. 130 info->remote = info->size == 0 ? TRUE : FALSE; //proxy connection may result in non-zero size.
122 if(audmad_is_remote((gchar *)url)) 131 if(audmad_is_remote((gchar *)url))
123 info->remote = TRUE; 132 info->remote = TRUE;
368 377
369 if(info->infile) { 378 if(info->infile) {
370 curpos = vfs_ftell(info->infile); 379 curpos = vfs_ftell(info->infile);
371 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); 380 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY);
372 } 381 }
373 else 382 else {
374 info->id3file = id3_file_open(info->filename, ID3_FILE_MODE_READONLY); 383 info->id3file = id3_file_open(info->filename, ID3_FILE_MODE_READONLY);
384 }
375 385
376 if (!info->id3file) { 386 if (!info->id3file) {
377 #ifdef DEBUG 387 #ifdef DEBUG
378 g_message("read_tag: no id3file"); 388 g_message("read_tag: no id3file");
379 #endif 389 #endif
484 494
485 if (info->tuple->track_name && info->tuple->album_name) 495 if (info->tuple->track_name && info->tuple->album_name)
486 tmp = g_strdup_printf("%s (%s)", info->tuple->track_name, info->tuple->album_name); 496 tmp = g_strdup_printf("%s (%s)", info->tuple->track_name, info->tuple->album_name);
487 else if (info->tuple->album_name) 497 else if (info->tuple->album_name)
488 tmp = g_strdup(info->tuple->album_name); 498 tmp = g_strdup(info->tuple->album_name);
489 else 499 else {
490 tmp = g_strdup(g_basename(info->filename)); 500 gchar *realfn = g_filename_from_uri(info->filename, NULL, NULL);
501 gchar *tmp2 = g_path_get_basename(realfn ? realfn : info->filename); // info->filename is uri. --yaz
502 tmp = str_to_utf8(tmp2);
503 g_free(tmp2); tmp2 = NULL;
504 g_free(realfn); realfn = NULL;
505 // tmp = g_strdup(g_basename(info->filename)); //XXX maybe ok. --yaz
506 }
491 507
492 /* call set_info only if tmp is different from prev_tmp */ 508 /* call set_info only if tmp is different from prev_tmp */
493 if ( ( ( info->prev_title != NULL ) && ( strcmp(info->prev_title,tmp) ) ) || 509 if ( ( ( info->prev_title != NULL ) && ( strcmp(info->prev_title,tmp) ) ) ||
494 ( info->prev_title == NULL ) ) 510 ( info->prev_title == NULL ) )
495 { 511 {
537 vfs_fseek(info->infile, 0, SEEK_SET); 553 vfs_fseek(info->infile, 0, SEEK_SET);
538 info->offset = 0; 554 info->offset = 0;
539 555
540 /* use the filename for the title as a last resort */ 556 /* use the filename for the title as a last resort */
541 if (!info->title) { 557 if (!info->title) {
542 char *pos = strrchr(info->filename, DIR_SEPARATOR); 558 char *pos = strrchr(info->filename, DIR_SEPARATOR); //XXX info->filename is uri. --yaz
543 if (pos) 559 if (pos)
544 info->title = g_strdup(pos + 1); 560 info->title = g_strdup(pos + 1);
545 else 561 else
546 info->title = g_strdup(info->filename); 562 info->title = g_strdup(info->filename); //XXX info->filename is uri. --yaz
547 } 563 }
548 564
549 #ifdef DEBUG 565 #ifdef DEBUG
550 g_message("e: input_get_info"); 566 g_message("e: input_get_info");
551 #endif /* DEBUG */ 567 #endif /* DEBUG */