Mercurial > audlegacy-plugins
comparison src/madplug/input.c @ 1687:d158ce84fda7
Modified for Tuplez/plugin API changes.
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Wed, 05 Sep 2007 09:29:26 +0300 |
| parents | 4e612b01f303 |
| children | 0d5f7629171f |
comparison
equal
deleted
inserted
replaced
| 1600:49fe2225d236 | 1687:d158ce84fda7 |
|---|---|
| 320 g_print("i: string = %s\n", rtn); | 320 g_print("i: string = %s\n", rtn); |
| 321 #endif | 321 #endif |
| 322 return rtn; | 322 return rtn; |
| 323 } | 323 } |
| 324 | 324 |
| 325 static void input_set_and_free_tag(struct id3_tag *tag, Tuple *tuple, const gchar *frame, const gchar *tuple_name) | 325 static void input_set_and_free_tag(struct id3_tag *tag, Tuple *tuple, const gchar *frame, const gint nfield) |
| 326 { | 326 { |
| 327 gchar *scratch = input_id3_get_string(tag, frame); | 327 gchar *scratch = input_id3_get_string(tag, frame); |
| 328 | 328 |
| 329 tuple_associate_string(tuple, tuple_name, scratch); | 329 tuple_associate_string(tuple, nfield, NULL, scratch); |
| 330 tuple_associate_string(tuple, frame, scratch); | 330 tuple_associate_string(tuple, -1, frame, scratch); |
| 331 | 331 |
| 332 g_free(scratch); | 332 g_free(scratch); |
| 333 } | 333 } |
| 334 | 334 |
| 335 static void input_alloc_tag(struct mad_info_t *info) | 335 static void input_alloc_tag(struct mad_info_t *info) |
| 337 Tuple *tuple; | 337 Tuple *tuple; |
| 338 | 338 |
| 339 if (info->tuple == NULL) { | 339 if (info->tuple == NULL) { |
| 340 tuple = tuple_new(); | 340 tuple = tuple_new(); |
| 341 info->tuple = tuple; | 341 info->tuple = tuple; |
| 342 tuple_associate_int(info->tuple, "length", -1); | 342 tuple_associate_int(info->tuple, FIELD_LENGTH, NULL, -1); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * read the ID3 tag | 347 * read the ID3 tag |
| 348 */ | 348 */ |
| 349 static void input_read_tag(struct mad_info_t *info) | 349 static void input_read_tag(struct mad_info_t *info) |
| 350 { | 350 { |
| 351 gchar *string = NULL; | 351 gchar *string = NULL; |
| 352 gchar *realfn = NULL; | |
| 353 Tuple *tuple; | 352 Tuple *tuple; |
| 354 glong curpos = 0; | 353 glong curpos = 0; |
| 355 | 354 |
| 356 #ifdef DEBUG | 355 #ifdef DEBUG |
| 357 g_message("f: input_read_tag"); | 356 g_message("f: input_read_tag"); |
| 358 #endif | 357 #endif |
| 359 if (info->tuple == NULL) { | 358 if (info->tuple != NULL) |
| 360 tuple = tuple_new(); | 359 tuple_free(info->tuple); |
| 361 info->tuple = tuple; | 360 |
| 362 } | 361 tuple = tuple_new_from_filename(info->filename); |
| 363 else | 362 info->tuple = tuple; |
| 364 tuple = info->tuple; | |
| 365 | 363 |
| 366 if(info->infile) { | 364 if(info->infile) { |
| 367 curpos = vfs_ftell(info->infile); | 365 curpos = vfs_ftell(info->infile); |
| 368 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); | 366 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); |
| 369 } | 367 } |
| 384 g_message("read_tag: no tag"); | 382 g_message("read_tag: no tag"); |
| 385 #endif | 383 #endif |
| 386 return; | 384 return; |
| 387 } | 385 } |
| 388 | 386 |
| 389 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_ARTIST, "artist"); | 387 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_ARTIST, FIELD_ARTIST); |
| 390 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_TITLE, "title"); | 388 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_TITLE, FIELD_TITLE); |
| 391 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_ALBUM, "album"); | 389 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_ALBUM, FIELD_ALBUM); |
| 392 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_GENRE, "genre"); | 390 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_GENRE, FIELD_GENRE); |
| 393 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_COMMENT, "comment"); | 391 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_COMMENT, FIELD_COMMENT); |
| 394 | 392 |
| 395 string = input_id3_get_string(info->tag, ID3_FRAME_TRACK); | 393 string = input_id3_get_string(info->tag, ID3_FRAME_TRACK); |
| 396 if (string) { | 394 if (string) { |
| 397 tuple_associate_int(tuple, "track-number", atoi(string)); | 395 tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, atoi(string)); |
| 398 g_free(string); | 396 g_free(string); |
| 399 string = NULL; | 397 string = NULL; |
| 400 } | 398 } |
| 401 | 399 |
| 402 // year | 400 // year |
| 404 string = input_id3_get_string(info->tag, ID3_FRAME_YEAR); //TDRC | 402 string = input_id3_get_string(info->tag, ID3_FRAME_YEAR); //TDRC |
| 405 if (!string) | 403 if (!string) |
| 406 string = input_id3_get_string(info->tag, "TYER"); | 404 string = input_id3_get_string(info->tag, "TYER"); |
| 407 | 405 |
| 408 if (string) { | 406 if (string) { |
| 409 tuple_associate_int(tuple, "year", atoi(string)); | 407 tuple_associate_int(tuple, FIELD_YEAR, NULL, atoi(string)); |
| 410 g_free(string); | 408 g_free(string); |
| 411 string = NULL; | 409 string = NULL; |
| 412 } | 410 } |
| 413 | 411 |
| 414 // length | 412 // length |
| 415 string = input_id3_get_string(info->tag, "TLEN"); | 413 string = input_id3_get_string(info->tag, "TLEN"); |
| 416 if (string) { | 414 if (string) { |
| 417 tuple_associate_int(tuple, "length", atoi(string)); | 415 tuple_associate_int(tuple, FIELD_LENGTH, NULL, atoi(string)); |
| 418 #ifdef DEBUG | 416 #ifdef DEBUG |
| 419 g_message("input_read_tag: TLEN = %d", atoi(string)); | 417 g_message("input_read_tag: TLEN = %d", atoi(string)); |
| 420 #endif | 418 #endif |
| 421 g_free(string); | 419 g_free(string); |
| 422 string = NULL; | 420 string = NULL; |
| 423 } | 421 } |
| 424 | 422 |
| 425 realfn = g_filename_from_uri(info->filename, NULL, NULL); | 423 tuple_associate_string(tuple, FIELD_CODEC, NULL, "MPEG Audio (MP3)"); |
| 426 | 424 tuple_associate_string(tuple, FIELD_QUALITY, NULL, "lossy"); |
| 427 string = g_strdup(g_basename(realfn ? realfn : info->filename)); | |
| 428 tuple_associate_string(tuple, "file-name", string); | |
| 429 g_free(string); | |
| 430 | |
| 431 string = g_path_get_dirname(realfn ? realfn : info->filename); | |
| 432 tuple_associate_string(tuple, "file-path", string); | |
| 433 g_free(string); | |
| 434 | |
| 435 if ((string = strrchr(realfn ? realfn : info->filename, '.'))) { | |
| 436 *string = '\0'; // make filename end at dot. | |
| 437 tuple_associate_string(tuple, "file-ext", string + 1); | |
| 438 } | |
| 439 | |
| 440 g_free(realfn); realfn = NULL; | |
| 441 | |
| 442 tuple_associate_string(tuple, "codec", "MPEG Audio (MP3)"); | |
| 443 tuple_associate_string(tuple, "quality", "lossy"); | |
| 444 | 425 |
| 445 info->title = tuple_formatter_make_title_string(tuple, audmad_config.title_override == TRUE ? | 426 info->title = tuple_formatter_make_title_string(tuple, audmad_config.title_override == TRUE ? |
| 446 audmad_config.id3_format : get_gentitle_format()); | 427 audmad_config.id3_format : get_gentitle_format()); |
| 447 | 428 |
| 448 // for connection via proxy, we have to stop transfer once. I can't explain the reason. | 429 // for connection via proxy, we have to stop transfer once. I can't explain the reason. |
| 468 #endif | 449 #endif |
| 469 #endif | 450 #endif |
| 470 | 451 |
| 471 g_free(info->title); | 452 g_free(info->title); |
| 472 info->title = NULL; | 453 info->title = NULL; |
| 473 tuple_disassociate(info->tuple, "title"); | 454 tuple_disassociate(info->tuple, FIELD_TITLE, NULL); |
| 474 tuple_disassociate(info->tuple, "album"); | 455 tuple_disassociate(info->tuple, FIELD_ALBUM, NULL); |
| 475 | 456 |
| 476 tmp = vfs_get_metadata(info->infile, "track-name"); | 457 tmp = vfs_get_metadata(info->infile, "track-name"); |
| 477 if(tmp){ | 458 if(tmp){ |
| 478 metadata = TRUE; | 459 metadata = TRUE; |
| 479 gchar *scratch; | 460 gchar *scratch; |
| 480 | 461 |
| 481 scratch = str_to_utf8(tmp); | 462 scratch = str_to_utf8(tmp); |
| 482 tuple_associate_string(info->tuple, "title", scratch); | 463 tuple_associate_string(info->tuple, FIELD_TITLE, NULL, scratch); |
| 483 g_free(scratch); | 464 g_free(scratch); |
| 484 | 465 |
| 485 g_free(tmp); | 466 g_free(tmp); |
| 486 tmp = NULL; | 467 tmp = NULL; |
| 487 } | 468 } |
| 490 if(tmp){ | 471 if(tmp){ |
| 491 metadata = TRUE; | 472 metadata = TRUE; |
| 492 gchar *scratch; | 473 gchar *scratch; |
| 493 | 474 |
| 494 scratch = str_to_utf8(tmp); | 475 scratch = str_to_utf8(tmp); |
| 495 tuple_associate_string(info->tuple, "album", scratch); | 476 tuple_associate_string(info->tuple, FIELD_ALBUM, NULL, scratch); |
| 496 tuple_associate_string(info->tuple, "stream", scratch); | 477 tuple_associate_string(info->tuple, -1, "stream", scratch); |
| 497 g_free(scratch); | 478 g_free(scratch); |
| 498 | 479 |
| 499 g_free(tmp); | 480 g_free(tmp); |
| 500 tmp = NULL; | 481 tmp = NULL; |
| 501 } | 482 } |
