From 8ed17ed69b35b9b8b441505d6c67ce6466e135b7 Mon Sep 17 00:00:00 2001 From: farfalleflickan <6597735+farfalleflickan@users.noreply.github.com> Date: Mon, 2 Jan 2023 12:27:49 +0100 Subject: [PATCH] Version bump, TV show & poster fix Version bump, fixed TV show HTML generation, fixed poster search (will re-try without language setting if none found) --- src/main.c | 2 +- src/movies.c | 8 ++++- src/tvshow.c | 90 +++++++++++++++++++++++++++++++--------------------- src/utils.c | 4 +-- 4 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src/main.c b/src/main.c index d9eb9c1..c1e6676 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ #include "main.h" #define REPO_URL "https://github.com/farfalleflickan/cmyflix" -#define VERSION_STRING "0.2" +#define VERSION_STRING "0.21" // GLOBAL VARIABLES FILE *LOGFILE=NULL; diff --git a/src/movies.c b/src/movies.c index 980bbd5..3756081 100644 --- a/src/movies.c +++ b/src/movies.c @@ -300,6 +300,12 @@ char *getMoviePoster(progConfig *conf, int tmdb_id) { snprintf(posterURL, posterURLSize, "%s%s%d%s%s%s,%s", tmdbSite, tmdbM, tmdb_id, tmdbP, conf->TMDBapi, tmdbP_Opts, conf->prefImgLangM); if (posterURL!=NULL) { imgURL=getPoster(posterURL, conf, conf->prefImgWidthM, conf->prefImgRatioM, conf->prefImgLangM); + if (imgURL==NULL) { + printError("getMoviePoster error", true, HRED, "failed while using URL '%s';\nRetrying without language option...\n", posterURL); + posterURL[0]='\0'; + snprintf(posterURL, posterURLSize, "%s%s%d%s%s", tmdbSite, tmdbM, tmdb_id, tmdbP, conf->TMDBapi); + imgURL=getPoster(posterURL, conf, conf->prefImgWidthM, conf->prefImgRatioM, NULL); + } if (imgURL==NULL) { printError("getMoviePoster error", true, HRED, "failed while using URL '%s';\n", posterURL); } else { @@ -327,7 +333,7 @@ char *getMoviePoster(progConfig *conf, int tmdb_id) { } } } - tryFree(posterURL); + tryFree(posterURL); } else { printError("getMoviePoster error", false, HRED, "could not build URL request string, something went wrong...\n"); } diff --git a/src/tvshow.c b/src/tvshow.c index c41bb0c..7463280 100755 --- a/src/tvshow.c +++ b/src/tvshow.c @@ -495,31 +495,46 @@ char *getShowPoster(progConfig *conf, unsigned int tmdb_id) { mallocMacro(posterURL, posterURLSize, "getShowPoster error"); posterURL[0]='\0'; snprintf(posterURL, posterURLSize, "%s%s%u%s%s%s,%s", tmdbSite, tmdbTV, tmdb_id, tmdbP, conf->TMDBapi, tmdbP_Opts, conf->prefImgLangTV); - imgURL=getPoster(posterURL, conf, conf->prefImgWidthTV, conf->prefImgRatioTV, conf->prefImgLangTV); - - printInfo("getShowPoster info", true, "got poster for \"%d\", URL: \"%s\";\n", tmdb_id, imgURL); - if (imgURL!=NULL && conf->dTVImg) { // if image should actually be downloaded, otherwise will just link to imgURL - if (checkFolder(conf->dTVFolder, true)==0) { - size_t dlFileStrLen=strlen(imgURL)+strlen(conf->dTVFolder); - char *dlFileName=NULL; - mallocMacro(dlFileName, dlFileStrLen, "getShowPoster error"); - dlFileName[0]='\0'; - snprintf(dlFileName, dlFileStrLen, "%s%s", conf->dTVFolder, strrchr(imgURL, '/')+1); - - if (dlFile(conf, imgURL, dlFileName)==CURLE_OK) { // downloaded poster! - imgURL=realloc(imgURL, dlFileStrLen+1); - if (imgURL==NULL) - fatalError_abort("getShowPoster error", "could not realloc;\nError: %s;\n", strerror(errno)); - - strlcpy(imgURL, dlFileName, dlFileStrLen); - if (conf->compressImgTV) { - imgURL=compressImg(conf->compressImgTVCmd, imgURL, true); + if (posterURL!=NULL) { + imgURL=getPoster(posterURL, conf, conf->prefImgWidthTV, conf->prefImgRatioTV, conf->prefImgLangTV); + + if (imgURL==NULL) { + printError("getShowPoster error", true, HRED, "failed while using URL '%s';\nRetrying without language option...\n", posterURL); + posterURL[0]='\0'; + snprintf(posterURL, posterURLSize, "%s%s%u%s%s", tmdbSite, tmdbTV, tmdb_id, tmdbP, conf->TMDBapi); + imgURL=getPoster(posterURL, conf, conf->prefImgWidthTV, conf->prefImgRatioTV, NULL); + } + + if (imgURL==NULL) { + printError("getShowPoster error", true, HRED, "failed while using URL '%s';\n", posterURL); + } else { + printInfo("getShowPoster info", true, "got poster for \"%d\", URL: \"%s\";\n", tmdb_id, imgURL); + if (imgURL!=NULL && conf->dTVImg) { // if image should actually be downloaded, otherwise will just link to imgURL + if (checkFolder(conf->dTVFolder, true)==0) { + size_t dlFileStrLen=strlen(imgURL)+strlen(conf->dTVFolder); + char *dlFileName=NULL; + mallocMacro(dlFileName, dlFileStrLen, "getShowPoster error"); + dlFileName[0]='\0'; + snprintf(dlFileName, dlFileStrLen, "%s%s", conf->dTVFolder, strrchr(imgURL, '/')+1); + + if (dlFile(conf, imgURL, dlFileName)==CURLE_OK) { // downloaded poster! + imgURL=realloc(imgURL, dlFileStrLen+1); + if (imgURL==NULL) + fatalError_abort("getShowPoster error", "could not realloc;\nError: %s;\n", strerror(errno)); + + strlcpy(imgURL, dlFileName, dlFileStrLen); + if (conf->compressImgTV) { + imgURL=compressImg(conf->compressImgTVCmd, imgURL, true); + } + } + tryFree(dlFileName); } - } - tryFree(dlFileName); + } } - } tryFree(posterURL); + } else { + printError("getShowPoster error", false, HRED, "could not build URL request string, something went wrong...\n"); + } return imgURL; } @@ -677,11 +692,6 @@ void *showHTML(void *threadArg) { fatalError_abort("showHTML error", "showName==NULL; JSON was:\n%s\n--- END ---\n", cJSON_Print(myJSON)); } - char *numOfSeasonsStr=cJSON_GetStringValue(cJSON_GetObjectItem(myJSON, "Seasons")); - int myNumSeasons=0; - if (numOfSeasonsStr!=NULL) { - myNumSeasons=parseStrToInt(numOfSeasonsStr); - } int uuid=thisThread->id; cJSON *episodesArray=cJSON_GetObjectItem(myJSON, "Episodes"); cJSON *extrasArray=cJSON_GetObjectItem(myJSON, "Extras"); @@ -689,7 +699,6 @@ void *showHTML(void *threadArg) { fatalError_abort("showHTML error", " episodesArray or extrasArray were equal to NULL; JSON was:\n%s\n--- END ---\n ", cJSON_Print(myJSON)); } printInfo("showHTML info", true, "building HTML for \"%s\";\n", showName); - cJSON *episode=NULL; addData(this_show, SHOW_HTML_TOP); @@ -702,15 +711,22 @@ void *showHTML(void *threadArg) { snprintf(tempStr, tempStrSize, SHOW_HTML_SEL, uuid); addData(this_show, tempStr); - while (currSeasoncurrSeason) { + currSeason=this_seasonNum; + tempStrSize=strlen(SHOW_HTML_OPT_SEASON)+intSize(currSeason)+intSize(currSeason)+1; + tempStr=realloc(tempStr, tempStrSize); + if (tempStr==NULL) { + fatalError_abort("showHTML error", "could not realloc;\nError: %s;\n", strerror(errno)); + } + snprintf(tempStr, tempStrSize, SHOW_HTML_OPT_SEASON, currSeason, currSeason); + addData(this_show, tempStr); } - snprintf(tempStr, tempStrSize, SHOW_HTML_OPT_SEASON, currSeason, currSeason); - addData(this_show, tempStr); } if (extrasArray!=NULL && cJSON_GetArraySize(extrasArray)>0) { currSeason++; @@ -801,7 +817,7 @@ void episodeHTML(fileList *this_show, progConfig *conf, cJSON *episode, int *cur if (*currSeason>0) { // new season, so close prev season list addData(this_show, "\n\n"); } - (*currSeason)++; + (*currSeason)=this_seasonNum; tempStrSize=intSize(*uuid)+intSize(*currSeason)+strlen(SHOW_HTML_UL)+1; tempStr=realloc(tempStr, tempStrSize); if (tempStr==NULL) { diff --git a/src/utils.c b/src/utils.c index a8fd7ee..6503771 100644 --- a/src/utils.c +++ b/src/utils.c @@ -780,7 +780,7 @@ char *getPoster(const char *posterURL, progConfig *conf, int prefImgWidth, doubl cJSON *lang=cJSON_DetachItemFromObject(item, "iso_639_1"); if ((width!=NULL && cJSON_GetNumberValue(width)==prefImgWidth) || (ratio!=NULL && cJSON_GetNumberValue(ratio)==prefImgRatio)) { - if (lang!=NULL && cJSON_GetStringValue(lang)!=NULL && strcmp(cJSON_GetStringValue(lang), prefImgLang)==0) { + if ((prefImgLang!=NULL && lang!=NULL && cJSON_GetStringValue(lang)!=NULL && strcmp(cJSON_GetStringValue(lang), prefImgLang)==0) || prefImgLang==NULL) { cJSON *imgStr=cJSON_DetachItemFromObject(item, "file_path"); if (imgStr!=NULL && cJSON_GetStringValue(imgStr)!=NULL) { size_t urlLen=strlen(tmdbImg)+strlen(cJSON_GetStringValue(imgStr))+1; @@ -805,7 +805,7 @@ char *getPoster(const char *posterURL, progConfig *conf, int prefImgWidth, doubl cJSON_Delete(item); } if (imgURL==NULL) { - printError("getPoster warning", true, HYEL, "request error, URL: '%s';\nitem==NULL - json_posters was:\n", posterURL); + printError("getPoster warning", true, HYEL, "request error, URL: '%s';\nCould not find a poster - json_posters was:\n", posterURL); char *tempStr=cJSON_Print(json_posters); printError("", true, COLOR_RESET, tempStr); printError("", true, HYEL, "\nEND;\n");