diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c index a10225f6..8750bdc1 100644 --- a/src/libFLAC/metadata_iterators.c +++ b/src/libFLAC/metadata_iterators.c @@ -158,6 +158,8 @@ static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC_ { level0_client_data cd; FLAC__StreamDecoder *decoder; + FILE *file; + FLAC__bool open_as_ogg = false; FLAC__ASSERT(0 != filename); @@ -173,10 +175,29 @@ static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC_ FLAC__stream_decoder_set_metadata_ignore_all(decoder); FLAC__stream_decoder_set_metadata_respond(decoder, type); - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - return 0; + /* Try to open the file and determine whether it is Ogg */ + if(0 != (file = flac_fopen(filename, "rb"))) { + FLAC__byte signature[4]; + if(fread(&signature, 1, 4, file) == 4) { + if(memcmp(&signature,"OggS",4) == 0) + open_as_ogg = true; + } + fclose(file); + } + + if(!open_as_ogg) { + if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) { + (void)FLAC__stream_decoder_finish(decoder); + FLAC__stream_decoder_delete(decoder); + return 0; + } + } + else { + if(FLAC__stream_decoder_init_ogg_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) { + (void)FLAC__stream_decoder_finish(decoder); + FLAC__stream_decoder_delete(decoder); + return 0; + } } if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder) || cd.got_error) {