From d4b22ce191693f7b31c3a835debf0aee2f50efbb Mon Sep 17 00:00:00 2001 From: farfalleflickan <6597735+farfalleflickan@users.noreply.github.com> Date: Fri, 10 Jan 2025 21:34:46 +0100 Subject: [PATCH] Added support for webm/ogv/mkv files --- README.md | 2 +- src/iofiles.c | 59 ++++++++++++++++++++++++++++----------------------- src/iofiles.h | 2 +- src/movies.c | 26 +++++++++++++++++------ src/movies.h | 7 ++++-- src/tvshow.c | 49 ++++++++++++++++++++++++++++++++---------- src/tvshow.h | 5 ++++- src/utils.c | 2 +- src/utils.h | 2 +- 9 files changed, 103 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index de6853d..7d1fb89 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Either install from source with make install OR use a pre-compiled package from Beware, the pre-compiled `deb` file is built using the default `libcurl4-openssl-dev` backend. # Requirements to run: -cmyflix uses libcjson(>=1.7.15), libcurl(>=7.68), imagemagick, ffmpeg and a TMDB api key. Please do also note that cmyflix searches for `mp4` files due to the usage of HTML5 and its supported formats. +cmyflix uses libcjson(>=1.7.15), libcurl(>=7.68), imagemagick, ffmpeg and a TMDB api key. Please do also note that cmyflix searches for `mp4`,`mkv`,`ogv` and `webm` files due to the usage of HTML5 and its supported formats. # Configuration & usage: For starters, cmyflix looks for `cmyflix.cfg` first in the same folder as the binary, then in `$HOME/.config/cmyflix/` and lastly in `/etc/cmyflix/`. Same thing applies for folder `html` and its contents. diff --git a/src/iofiles.c b/src/iofiles.c index d35e50b..4ac40c9 100755 --- a/src/iofiles.c +++ b/src/iofiles.c @@ -10,7 +10,7 @@ #include "iofiles.h" // Own implementation with opendir/readdir. nftw might be faster? Dunno, nftw seemed slower in tests -struct fileList *find(progConfig *conf, char *dirPath, char *searchStr, ioMode mode, bool recursive) { +struct fileList *find(progConfig *conf, char *dirPath, char **searchStrs, ioMode mode, bool recursive) { DIR *directory = opendir(dirPath); if (directory == NULL) { printError("find warning", false, HYEL, "failed while opening directory \"%s\";\nError: %s;\n", dirPath, strerror(errno)); @@ -46,7 +46,7 @@ struct fileList *find(progConfig *conf, char *dirPath, char *searchStr, ioMode m list = initList(list, NULL, 0); addData(list, path); } - fileList *temp = find(conf, path, searchStr, mode, recursive); + fileList *temp = find(conf, path, searchStrs, mode, recursive); if (temp != NULL) { list = joinLists(list, temp); } @@ -56,36 +56,41 @@ struct fileList *find(progConfig *conf, char *dirPath, char *searchStr, ioMode m addData(newFile, fileP->d_name); list=joinLists(newFile, list); } - } else if (strstr(fileP->d_name, searchStr) && (mode & FI_MODE)!=0) { // if filename matches the string we looking for AND in file mode - char **fileMatch = NULL; - if ((mode & TV_MODE)!=0) { // if TV mode bit set - // if ( conf->tvDB_exists==true && (mode & CK_MODE)!=0 && strstr(conf->tvDB_str, path)!=NULL) { // if filename already in database & in 'check mode' - for (int i=0; iregexTVnum && fileMatch == NULL; i++) { - fileMatch=matchReg(path, conf->regexTVstr[i], conf->regexTVgroups); - if (fileMatch!=NULL) { - fileList *newFile=newList(); - for (int j=1; j<=parseStrToInt(fileMatch[0]); j++) { - addData(newFile, fileMatch[j]); - if (j==1) { - addData(newFile, dirPath); - addData(newFile, fileP->d_name); + } else if ((mode & FI_MODE)!=0) { // if filename matches the string we looking for AND in file mode + for (char **currentStr = searchStrs; *currentStr != NULL; currentStr++) { + if (strstr(fileP->d_name, *currentStr) != NULL) { + char **fileMatch = NULL; + if ((mode & TV_MODE)!=0) { // if TV mode bit set + // if ( conf->tvDB_exists==true && (mode & CK_MODE)!=0 && strstr(conf->tvDB_str, path)!=NULL) { // if filename already in database & in 'check mode' + for (int i=0; iregexTVnum && fileMatch == NULL; i++) { + fileMatch=matchReg(path, conf->regexTVstr[i], conf->regexTVgroups); + if (fileMatch!=NULL) { + fileList *newFile=newList(); + for (int j=1; j<=parseStrToInt(fileMatch[0]); j++) { + addData(newFile, fileMatch[j]); + if (j==1) { + addData(newFile, dirPath); + addData(newFile, fileP->d_name); + } + } + list = joinLists(newFile, list); } } - list = joinLists(newFile, list); + } else if ((mode & MO_MODE)!=0) { // if movie mode bit set... + /* + * Nothing, else works just as well + */ + } else { // if in file mode but NOT in movie/tv mode... + fileList *newFile=newList(); + addData(newFile, path); + addData(newFile, dirPath); + addData(newFile, fileP->d_name); + list=joinLists(newFile, list); } + freeStrArr(fileMatch); + break; } - } else if ((mode & MO_MODE)!=0) { // if movie mode bit set... - /* - * Nothing, else works just as well - */ - } else { // if in file mode but NOT in movie/tv mode... - fileList *newFile=newList(); - addData(newFile, path); - addData(newFile, dirPath); - addData(newFile, fileP->d_name); - list=joinLists(newFile, list); } - freeStrArr(fileMatch); } tryFree(path); } diff --git a/src/iofiles.h b/src/iofiles.h index 20e0137..da79168 100755 --- a/src/iofiles.h +++ b/src/iofiles.h @@ -9,4 +9,4 @@ typedef enum { TV_MODE=1 << 3 // TV show mode } ioMode; -struct fileList *find(progConfig *conf, char *dirPath, char *searchStr, ioMode mode, bool recursive); +struct fileList *find(progConfig *conf, char *dirPath, char **searchStrs, ioMode mode, bool recursive); diff --git a/src/movies.c b/src/movies.c index bc95415..13dd3da 100644 --- a/src/movies.c +++ b/src/movies.c @@ -15,7 +15,7 @@ struct fileList *createMoviesDB(progConfig *conf) { char *infoStr="building home movies' database..."; if (conf->homeMovies==false) { infoStr="building movies' database..."; - folders=find(conf, conf->MoviesPath, "", DI_MODE, false); + folders=find(conf, conf->MoviesPath, (char *[]){"", NULL}, DI_MODE, false); } printInfo("createMoviesDB info", true, "%s\n", infoStr); @@ -432,11 +432,25 @@ void *movieHTML(void *threadArg) { } printInfo("movieHTML info", true, "building HTML for \"%s\";\n", movieName); - size_t tempStrSize=strlen(MOVIE_HTML_VIDEO)+intSize(thisThread->id)*3+strlen(moviePoster)+strlen(movieFile)+strlen(movieName)*2+1; char *tempStr=NULL; - mallocMacro(tempStr, tempStrSize, "movieHTML error"); - - snprintf(tempStr, tempStrSize, MOVIE_HTML_VIDEO, thisThread->id, movieName, moviePoster, movieName, thisThread->id, thisThread->id, movieFile); + size_t tempStrSize = 0; + if (strstr(movieFile, ".webm") != NULL) { + tempStrSize=strlen(MOVIE_HTML_VIDEO_WEBM)+intSize(thisThread->id)*3+strlen(moviePoster)+strlen(movieFile)+strlen(movieName)*2+1; + mallocMacro(tempStr, tempStrSize, "movieHTML error"); + snprintf(tempStr, tempStrSize, MOVIE_HTML_VIDEO_WEBM, thisThread->id, movieName, moviePoster, movieName, thisThread->id, thisThread->id, movieFile); + } else if (strstr(movieFile, ".ogv") != NULL) { + tempStrSize=strlen(MOVIE_HTML_VIDEO_OGG)+intSize(thisThread->id)*3+strlen(moviePoster)+strlen(movieFile)+strlen(movieName)*2+1; + mallocMacro(tempStr, tempStrSize, "movieHTML error"); + snprintf(tempStr, tempStrSize, MOVIE_HTML_VIDEO_OGG, thisThread->id, movieName, moviePoster, movieName, thisThread->id, thisThread->id, movieFile); + } else if (strstr(movieFile, ".mp4") != NULL) { + tempStrSize=strlen(MOVIE_HTML_VIDEO_MP4)+intSize(thisThread->id)*3+strlen(moviePoster)+strlen(movieFile)+strlen(movieName)*2+1; + mallocMacro(tempStr, tempStrSize, "movieHTML error"); + snprintf(tempStr, tempStrSize, MOVIE_HTML_VIDEO_MP4, thisThread->id, movieName, moviePoster, movieName, thisThread->id, thisThread->id, movieFile); + } else { + tempStrSize=strlen(MOVIE_HTML_VIDEO)+intSize(thisThread->id)*3+strlen(moviePoster)+strlen(movieFile)+strlen(movieName)*2+1; + mallocMacro(tempStr, tempStrSize, "movieHTML error"); + snprintf(tempStr, tempStrSize, MOVIE_HTML_VIDEO, thisThread->id, movieName, moviePoster, movieName, thisThread->id, thisThread->id, movieFile); + } addData(thisThread->list, tempStr); cJSON *currSub=NULL; @@ -454,7 +468,7 @@ void *movieHTML(void *threadArg) { } tryFree(subPath); } - addData(thisThread->list, MOVIE_HTML_VIDEO_BOT); + addData(thisThread->list, MOVIE_HTML_VIDEO_BOTTOM); tryFree(moviePoster); tryFree(movieFile); tryFree(tempStr); diff --git a/src/movies.h b/src/movies.h index 42005ef..660d5ab 100644 --- a/src/movies.h +++ b/src/movies.h @@ -4,11 +4,14 @@ #define MOVIE_HTML_TOP "\n\n\ncmyflix\n\n\n\n\n\n\n\n\n\n
" -#define MOVIE_HTML_VIDEO "
\n\n
\n
\n