moved fallback APE/ID3 tag loader to song.c
Some plugins used the APE or ID3 tag loader as a fallback when their own methods of loading tags did not work. Move this code out of all decoder plugins, into song_file_update().
This commit is contained in:
		| @@ -443,19 +443,18 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream) | ||||
|  | ||||
| static struct tag *aacTagDup(const char *file) | ||||
| { | ||||
| 	struct tag *ret = NULL; | ||||
| 	int file_time = getAacTotalTime(file); | ||||
| 	struct tag *tag; | ||||
|  | ||||
| 	if (file_time >= 0) { | ||||
| 		if ((ret = tag_id3_load(file)) == NULL) | ||||
| 			ret = tag_new(); | ||||
| 		ret->time = file_time; | ||||
| 	} else { | ||||
| 	if (file_time < 0) { | ||||
| 		g_debug("aacTagDup: Failed to get total song time from: %s\n", | ||||
| 			file); | ||||
| 		return NULL; | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| 	tag = tag_new(); | ||||
| 	tag->time = file_time; | ||||
| 	return tag; | ||||
| } | ||||
|  | ||||
| static const char *const aac_suffixes[] = { "aac", NULL }; | ||||
|   | ||||
| @@ -282,23 +282,7 @@ flac_tag_load(const char *file) | ||||
| static struct tag * | ||||
| flac_tag_dup(const char *file) | ||||
| { | ||||
| 	struct tag *ret = NULL; | ||||
|  | ||||
| 	ret = flac_tag_load(file); | ||||
| 	if (!ret) { | ||||
| 		g_debug("Failed to grab information from: %s\n", file); | ||||
| 		return NULL; | ||||
| 	} | ||||
| 	if (tag_is_empty(ret)) { | ||||
| 		struct tag *temp = tag_id3_load(file); | ||||
| 		if (temp) { | ||||
| 			temp->time = ret->time; | ||||
| 			tag_free(ret); | ||||
| 			ret = temp; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| 	return flac_tag_load(file); | ||||
| } | ||||
|  | ||||
| static void | ||||
|   | ||||
| @@ -19,6 +19,7 @@ | ||||
| #include "../decoder_api.h" | ||||
| #include "../conf.h" | ||||
| #include "config.h" | ||||
| #include "tag_id3.h" | ||||
|  | ||||
| #include <assert.h> | ||||
| #include <unistd.h> | ||||
| @@ -1190,22 +1191,19 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) | ||||
|  | ||||
| static struct tag *mp3_tag_dup(const char *file) | ||||
| { | ||||
| 	struct tag *ret = NULL; | ||||
| 	struct tag *tag; | ||||
| 	int total_time; | ||||
|  | ||||
| 	ret = tag_id3_load(file); | ||||
|  | ||||
| 	total_time = mp3_total_file_time(file); | ||||
| 	if (total_time >= 0) { | ||||
| 		if (!ret) | ||||
| 			ret = tag_new(); | ||||
| 		ret->time = total_time; | ||||
| 	} else { | ||||
| 	if (total_time < 0) { | ||||
| 		g_debug("mp3_tag_dup: Failed to get total song time from: %s\n", | ||||
| 			file); | ||||
| 		return NULL; | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| 	tag = tag_new(); | ||||
| 	tag->time = total_time; | ||||
| 	return tag; | ||||
| } | ||||
|  | ||||
| static const char *const mp3_suffixes[] = { "mp3", "mp2", NULL }; | ||||
|   | ||||
| @@ -405,21 +405,7 @@ mp4_load_tag(const char *file) | ||||
| static struct tag * | ||||
| mp4_tag_dup(const char *file) | ||||
| { | ||||
| 	struct tag *ret = NULL; | ||||
|  | ||||
| 	ret = mp4_load_tag(file); | ||||
| 	if (!ret) | ||||
| 		return NULL; | ||||
| 	if (tag_is_empty(ret)) { | ||||
| 		struct tag *temp = tag_id3_load(file); | ||||
| 		if (temp) { | ||||
| 			temp->time = ret->time; | ||||
| 			tag_free(ret); | ||||
| 			ret = temp; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| 	return mp4_load_tag(file); | ||||
| } | ||||
|  | ||||
| static const char *const mp4_suffixes[] = { "m4a", "mp4", NULL }; | ||||
|   | ||||
| @@ -249,8 +249,8 @@ static float mpcGetTime(const char *file) | ||||
|  | ||||
| static struct tag *mpcTagDup(const char *file) | ||||
| { | ||||
| 	struct tag *ret = NULL; | ||||
| 	float total_time = mpcGetTime(file); | ||||
| 	struct tag *tag; | ||||
|  | ||||
| 	if (total_time < 0) { | ||||
| 		g_debug("mpcTagDup: Failed to get Songlength of file: %s\n", | ||||
| @@ -258,14 +258,9 @@ static struct tag *mpcTagDup(const char *file) | ||||
| 		return NULL; | ||||
| 	} | ||||
|  | ||||
| 	ret = tag_ape_load(file); | ||||
| 	if (!ret) | ||||
| 		ret = tag_id3_load(file); | ||||
| 	if (!ret) | ||||
| 		ret = tag_new(); | ||||
| 	ret->time = total_time; | ||||
|  | ||||
| 	return ret; | ||||
| 	tag = tag_new(); | ||||
| 	tag->time = total_time; | ||||
| 	return tag; | ||||
| } | ||||
|  | ||||
| static const char *const mpcSuffixes[] = { "mpc", NULL }; | ||||
|   | ||||
| @@ -29,7 +29,6 @@ | ||||
| #include "input_stream.h" | ||||
| #include "replay_gain.h" | ||||
| #include "tag.h" | ||||
| #include "tag_id3.h" | ||||
| #include "audio_format.h" | ||||
| #include "playerData.h" | ||||
|  | ||||
|   | ||||
							
								
								
									
										36
									
								
								src/song.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								src/song.c
									
									
									
									
									
								
							| @@ -24,6 +24,7 @@ | ||||
| #include "playlist.h" | ||||
| #include "decoder_list.h" | ||||
| #include "decoder_api.h" | ||||
| #include "tag_id3.h" | ||||
|  | ||||
| #include <glib.h> | ||||
|  | ||||
| @@ -98,6 +99,38 @@ song_free(struct song *song) | ||||
| 	g_free(song); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Attempts to load APE or ID3 tags from the specified file. | ||||
|  */ | ||||
| static struct tag * | ||||
| tag_load_fallback(const char *path) | ||||
| { | ||||
| 	struct tag *tag = tag_ape_load(path); | ||||
| 	if (tag == NULL) | ||||
| 		tag = tag_id3_load(path); | ||||
| 	return tag; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * The decoder plugin failed to load any tags: fall back to the APE or | ||||
|  * ID3 tag loader. | ||||
|  */ | ||||
| static struct tag * | ||||
| tag_fallback(const char *path, struct tag *tag) | ||||
| { | ||||
| 	struct tag *fallback = tag_load_fallback(path); | ||||
|  | ||||
| 	if (fallback != NULL) { | ||||
| 		/* tag was successfully loaded: copy the song | ||||
| 		   duration, and destroy the old (empty) tag */ | ||||
| 		fallback->time = tag->time; | ||||
| 		tag_free(tag); | ||||
| 		return fallback; | ||||
| 	} else | ||||
| 		/* no APE/ID3 tag found: return the empty tag */ | ||||
| 		return tag; | ||||
| } | ||||
|  | ||||
| bool | ||||
| song_file_update(struct song *song) | ||||
| { | ||||
| @@ -142,6 +175,9 @@ song_file_update(struct song *song) | ||||
| 		plugin = decoder_plugin_from_suffix(suffix, true); | ||||
| 	} while (plugin != NULL); | ||||
|  | ||||
| 	if (song->tag != NULL && tag_is_empty(song->tag)) | ||||
| 		song->tag = tag_fallback(path_fs, song->tag); | ||||
|  | ||||
| 	g_free(path_fs); | ||||
| 	return song->tag != NULL; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann