return dvr_do_prefix(id, fmt, buf, tmp, tmplen);
}
+static const char *
+_dvr_get_tvmovies_subdir(const dvr_entry_t *de)
+{
+ dvr_config_t *config = de->de_config;
+ if (config && !strempty(config->dvr_format_tvshows_subdir))
+ return config->dvr_format_tvshows_subdir;
+ return "tvshows";
+}
+
static const char *
_dvr_sub_scraper_friendly(const char *id, const char *fmt, const void *aux, char *tmp, size_t tmplen, int with_genre_subdir)
{
- char date_buf[512] = { 0 };
- char episode_buf[512] = { 0 };
const dvr_entry_t *de = aux;
epg_broadcast_t *ebc = de->de_bcast;
tvhdebug(LS_DVR, "fmt = %s is_movie = %d content_type = %d", fmt ?: "<none>", is_movie, de->de_content_type);
+ char *date_buf = NULL, *episode_buf = NULL;
+
if (is_movie) {
/* Include the year if available. This helps scraper differentiate
* between numerous remakes of the same film.
*/
if (ebc) {
if (ebc->copyright_year) {
+ date_buf = alloca(10);
sprintf(date_buf, "%04d", ebc->copyright_year);
} else {
/* Some providers use first_aired as really the copyright date. */
/* Get just the year part */
struct tm tm;
if (localtime_r(&first_aired, &tm)) {
+ date_buf = alloca(10);
sprintf(date_buf, "%04d", tm.tm_year + 1900);
}
}
/* Not a movie */
if (ebc) {
/* Get episode information */
- epg_broadcast_epnumber_format(ebc,
- episode_buf, sizeof(episode_buf),
+ episode_buf = alloca(512);
+ epg_broadcast_epnumber_format(ebc, episode_buf, 512,
NULL, "S%02d", NULL, "E%02d", NULL);
const time_t first_aired = ebc->first_aired;
*/
struct tm tm;
if (localtime_r(&first_aired, &tm)) {
- strftime(date_buf, sizeof date_buf, "%F", &tm);
+ date_buf = alloca(32);
+ strftime(date_buf, 32, "%F", &tm);
}
}
}
*/
size_t offset = 0;
- const dvr_config_t *config = de->de_config;
if (is_movie) {
/* TV movies are probably best saved in one folder rather than
* "title (yyyy)" (without genre_subdir)
* "title" (without genre_subdir, no airdate)
*/
- if (with_genre_subdir) {
- const char *subdir = config && config->dvr_format_tvmovies_subdir && *config->dvr_format_tvmovies_subdir ?
- config->dvr_format_tvmovies_subdir : "tvmovies";
- tvh_strlcatf(tmp, tmplen, offset, "%s/", subdir);
- }
+ if (with_genre_subdir)
+ tvh_strlcatf(tmp, tmplen, offset, "%s/", _dvr_get_tvmovies_subdir(de));
- if (*title_buf) tvh_strlcatf(tmp, tmplen, offset, "%s", title_buf);
+ if (!strempty(title_buf))
+ tvh_strlcatf(tmp, tmplen, offset, "%s", title_buf);
/* Movies don't have anything relevant in sub-titles field so
* anything there should be ignored. I think some channels store a
* translated movie name there (title=original movie name,
* subtitle=local language name for movie), but only use title
* since scrapers only handle one title.
*/
- // if (*subtitle_buf) tvh_strlcatf(tmp, tmplen, offset, " - %s", subtitle_buf);
- if (*date_buf) tvh_strlcatf(tmp, tmplen, offset, " (%s)", date_buf);
+ // if (!strempty(subtitle_buf))
+ // tvh_strlcatf(tmp, tmplen, offset, " - %s", subtitle_buf);
+ if (!strempty(date_buf))
+ tvh_strlcatf(tmp, tmplen, offset, " (%s)", date_buf);
} else {
/* TV shows have to go in separate directories based on their title in
* order to be scraped properly.
* "title - subtitle_2001-05-04" (without genre_subdir, long running show)
* "title - subtitle" (without genre_subdir, no epg info on show)
*/
- if (with_genre_subdir) {
- const char *subdir = config && config->dvr_format_tvshows_subdir && *config->dvr_format_tvshows_subdir ?
- config->dvr_format_tvshows_subdir : "tvshows";
- tvh_strlcatf(tmp, tmplen, offset, "%s/", subdir);
- }
- if (*title_buf) tvh_strlcatf(tmp, tmplen, offset, "%s/%s", title_buf, title_buf);
- if (*episode_buf) tvh_strlcatf(tmp, tmplen, offset, " - %s", episode_buf);
- if (*subtitle_buf) tvh_strlcatf(tmp, tmplen, offset, " - %s", subtitle_buf);
+ if (with_genre_subdir)
+ tvh_strlcatf(tmp, tmplen, offset, "%s/", _dvr_get_tvmovies_subdir(de));
+ if (!strempty(title_buf))
+ tvh_strlcatf(tmp, tmplen, offset, "%s/%s", title_buf, title_buf);
+ if (!strempty(episode_buf))
+ tvh_strlcatf(tmp, tmplen, offset, " - %s", episode_buf);
+ if (!strempty(subtitle_buf))
+ tvh_strlcatf(tmp, tmplen, offset, " - %s", subtitle_buf);
/* Only include date if we don't have an explicit episode number. */
- if (!*episode_buf && *date_buf) tvh_strlcatf(tmp, tmplen, offset, "_%s", date_buf);
+ if (strempty(episode_buf) && !strempty(date_buf))
+ tvh_strlcatf(tmp, tmplen, offset, "_%s", date_buf);
}
return tmp;
}