static void fixup_tags(struct media_file_info *mfi) { cfg_t *lib; size_t len; char *tag; char *sep = " - "; char *ca; if (mfi->genre && (strlen(mfi->genre) == 0)) { free(mfi->genre); mfi->genre = NULL; } if (mfi->artist && (strlen(mfi->artist) == 0)) { free(mfi->artist); mfi->artist = NULL; } if (mfi->title && (strlen(mfi->title) == 0)) { free(mfi->title); mfi->title = NULL; } /* * Default to mpeg4 video/audio for unknown file types * in an attempt to allow streaming of DRM-afflicted files */ if (mfi->codectype && strcmp(mfi->codectype, "unkn") == 0) { if (mfi->has_video) { strcpy(mfi->codectype, "mp4v"); strcpy(mfi->type, "m4v"); } else { strcpy(mfi->codectype, "mp4a"); strcpy(mfi->type, "m4a"); } } if (!mfi->artist) { if (mfi->orchestra && mfi->conductor) { len = strlen(mfi->orchestra) + strlen(sep) + strlen(mfi->conductor); tag = (char *)malloc(len + 1); if (tag) { sprintf(tag,"%s%s%s", mfi->orchestra, sep, mfi->conductor); mfi->artist = tag; } } else if (mfi->orchestra) { mfi->artist = strdup(mfi->orchestra); } else if (mfi->conductor) { mfi->artist = strdup(mfi->conductor); } } /* Handle TV shows, try to present prettier metadata */ if (mfi->tv_series_name && strlen(mfi->tv_series_name) != 0) { mfi->media_kind = MEDIA_KIND_TVSHOW; /* tv show */ /* Default to artist = series_name */ if (mfi->artist && strlen(mfi->artist) == 0) { free(mfi->artist); mfi->artist = NULL; } if (!mfi->artist) mfi->artist = strdup(mfi->tv_series_name); /* Default to album = "<series_name>, Season <season_num>" */ if (mfi->album && strlen(mfi->album) == 0) { free(mfi->album); mfi->album = NULL; } if (!mfi->album) { len = snprintf(NULL, 0, "%s, Season %u", mfi->tv_series_name, mfi->tv_season_num); mfi->album = (char *)malloc(len + 1); if (mfi->album) sprintf(mfi->album, "%s, Season %u", mfi->tv_series_name, mfi->tv_season_num); } } /* Check the 4 top-tags are filled */ if (!mfi->artist) mfi->artist = strdup("Unknown artist"); if (!mfi->album) mfi->album = strdup("Unknown album"); if (!mfi->genre) mfi->genre = strdup("Unknown genre"); if (!mfi->title) { /* fname is left untouched by unicode_fixup_mfi() for * obvious reasons, so ensure it is proper UTF-8 */ mfi->title = unicode_fixup_string(mfi->fname, "ascii"); if (mfi->title == mfi->fname) mfi->title = strdup(mfi->fname); } /* Ensure sort tags are filled, manipulated and normalized */ sort_tag_create(&mfi->artist_sort, mfi->artist); sort_tag_create(&mfi->album_sort, mfi->album); sort_tag_create(&mfi->title_sort, mfi->title); /* We need to set album_artist according to media type and config */ if (mfi->compilation) /* Compilation */ { lib = cfg_getsec(cfg, "library"); ca = cfg_getstr(lib, "compilation_artist"); if (ca && mfi->album_artist) { free(mfi->album_artist); mfi->album_artist = strdup(ca); } else if (ca && !mfi->album_artist) { mfi->album_artist = strdup(ca); } else if (!ca && !mfi->album_artist) { mfi->album_artist = strdup(""); mfi->album_artist_sort = strdup(""); } } else if (mfi->media_kind == MEDIA_KIND_PODCAST) /* Podcast */ { if (mfi->album_artist) free(mfi->album_artist); mfi->album_artist = strdup(""); mfi->album_artist_sort = strdup(""); } else if (!mfi->album_artist) /* Regular media without album_artist */ { mfi->album_artist = strdup(mfi->artist); } if (!mfi->album_artist_sort && (strcmp(mfi->album_artist, mfi->artist) == 0)) mfi->album_artist_sort = strdup(mfi->artist_sort); else sort_tag_create(&mfi->album_artist_sort, mfi->album_artist); /* Composer is not one of our mandatory tags, so take extra care */ if (mfi->composer_sort || mfi->composer) sort_tag_create(&mfi->composer_sort, mfi->composer); }
static void fixup_tags(struct media_file_info *mfi) { size_t len; char *tag; char *sep = " - "; if (mfi->genre && (strlen(mfi->genre) == 0)) { free(mfi->genre); mfi->genre = NULL; } if (mfi->artist && (strlen(mfi->artist) == 0)) { free(mfi->artist); mfi->artist = NULL; } if (mfi->title && (strlen(mfi->title) == 0)) { free(mfi->title); mfi->title = NULL; } /* * Default to mpeg4 video/audio for unknown file types * in an attempt to allow streaming of DRM-afflicted files */ if (mfi->codectype && strcmp(mfi->codectype, "unkn") == 0) { if (mfi->has_video) { strcpy(mfi->codectype, "mp4v"); strcpy(mfi->type, "m4v"); } else { strcpy(mfi->codectype, "mp4a"); strcpy(mfi->type, "m4a"); } } if (!mfi->artist) { if (mfi->orchestra && mfi->conductor) { len = strlen(mfi->orchestra) + strlen(sep) + strlen(mfi->conductor); tag = (char *)malloc(len + 1); if (tag) { sprintf(tag,"%s%s%s", mfi->orchestra, sep, mfi->conductor); mfi->artist = tag; } } else if (mfi->orchestra) { mfi->artist = strdup(mfi->orchestra); } else if (mfi->conductor) { mfi->artist = strdup(mfi->conductor); } } /* Handle TV shows, try to present prettier metadata */ if (mfi->tv_series_name && strlen(mfi->tv_series_name) != 0) { mfi->media_kind = 64; /* tv show */ /* Default to artist = series_name */ if (mfi->artist && strlen(mfi->artist) == 0) { free(mfi->artist); mfi->artist = NULL; } if (!mfi->artist) mfi->artist = strdup(mfi->tv_series_name); /* Default to album = "<series_name>, Season <season_num>" */ if (mfi->album && strlen(mfi->album) == 0) { free(mfi->album); mfi->album = NULL; } if (!mfi->album) { len = snprintf(NULL, 0, "%s, Season %d", mfi->tv_series_name, mfi->tv_season_num); mfi->album = (char *)malloc(len + 1); if (mfi->album) sprintf(mfi->album, "%s, Season %d", mfi->tv_series_name, mfi->tv_season_num); } } /* Check the 4 top-tags are filled */ if (!mfi->artist) mfi->artist = strdup("Unknown artist"); if (!mfi->album) mfi->album = strdup("Unknown album"); if (!mfi->genre) mfi->genre = strdup("Unknown genre"); if (!mfi->title) { /* fname is left untouched by unicode_fixup_mfi() for * obvious reasons, so ensure it is proper UTF-8 */ mfi->title = unicode_fixup_string(mfi->fname); if (mfi->title == mfi->fname) mfi->title = strdup(mfi->fname); } /* Ensure sort tags are filled and normalized */ normalize_fixup_tag(&mfi->artist_sort, mfi->artist); normalize_fixup_tag(&mfi->album_sort, mfi->album); normalize_fixup_tag(&mfi->title_sort, mfi->title); /* If we don't have an album_artist, set it to artist */ if (!mfi->album_artist) { if (mfi->compilation) { mfi->album_artist = strdup(""); mfi->album_artist_sort = strdup(""); } else mfi->album_artist = strdup(mfi->artist); } if (!mfi->album_artist_sort && (strcmp(mfi->album_artist, mfi->artist) == 0)) mfi->album_artist_sort = strdup(mfi->artist_sort); else normalize_fixup_tag(&mfi->album_artist_sort, mfi->album_artist); /* Composer is not one of our mandatory tags, so take extra care */ if (mfi->composer_sort || mfi->composer) normalize_fixup_tag(&mfi->composer_sort, mfi->composer); }