mirror of
https://github.com/farfalleflickan/cmyflix.git
synced 2025-02-05 08:45:31 +00:00
Fix for cleaning up tv shows
This commit is contained in:
parent
87445fd8a4
commit
4699ede21d
52
src/tvshow.c
52
src/tvshow.c
@ -909,8 +909,10 @@ void *cleanTV(void *threadArg) {
|
|||||||
cJSON *newJSON=cJSON_CreateArray();
|
cJSON *newJSON=cJSON_CreateArray();
|
||||||
for (i=0; i<numThreads; i++) {
|
for (i=0; i<numThreads; i++) {
|
||||||
pthread_join(threads[i], NULL);
|
pthread_join(threads[i], NULL);
|
||||||
|
if (threadObj[i].oldJSON != NULL) {
|
||||||
cJSON_AddItemToArray(newJSON, threadObj[i].oldJSON);
|
cJSON_AddItemToArray(newJSON, threadObj[i].oldJSON);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
thisThread->oldJSON=cJSON_Duplicate(newJSON, true);
|
thisThread->oldJSON=cJSON_Duplicate(newJSON, true);
|
||||||
cJSON_Delete(newJSON);
|
cJSON_Delete(newJSON);
|
||||||
tryFree(threads);
|
tryFree(threads);
|
||||||
@ -924,9 +926,14 @@ void *cleanTV(void *threadArg) {
|
|||||||
void *cleanShow(void *threadArg) {
|
void *cleanShow(void *threadArg) {
|
||||||
threadStruct *thisThread=threadArg;
|
threadStruct *thisThread=threadArg;
|
||||||
cJSON *show=thisThread->oldJSON;
|
cJSON *show=thisThread->oldJSON;
|
||||||
|
cJSON *episodesArray;
|
||||||
|
cJSON *extrasArray;
|
||||||
|
int episodesArraySize=0;
|
||||||
|
int extrasArraySize=0;
|
||||||
|
|
||||||
if (show!=NULL && cJSON_GetObjectItem(show, "Episodes")!=NULL) {
|
if (show!=NULL) {
|
||||||
cJSON *episodesArray=cJSON_Duplicate(cJSON_GetObjectItem(show, "Episodes"), true);
|
if (cJSON_GetObjectItem(show, "Episodes")!=NULL) {
|
||||||
|
episodesArray=cJSON_Duplicate(cJSON_GetObjectItem(show, "Episodes"), true);
|
||||||
cJSON *episode=NULL;
|
cJSON *episode=NULL;
|
||||||
int i=0, numDeleted=0;
|
int i=0, numDeleted=0;
|
||||||
cJSON_ArrayForEach(episode, episodesArray) {
|
cJSON_ArrayForEach(episode, episodesArray) {
|
||||||
@ -957,8 +964,49 @@ void *cleanShow(void *threadArg) {
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
episodesArraySize=cJSON_GetArraySize(episodesArray);
|
||||||
cJSON_Delete(episodesArray);
|
cJSON_Delete(episodesArray);
|
||||||
}
|
}
|
||||||
|
if (cJSON_GetObjectItem(show, "Extras")!=NULL) {
|
||||||
|
extrasArray=cJSON_Duplicate(cJSON_GetObjectItem(show, "Extras"), true);
|
||||||
|
cJSON *extra=NULL;
|
||||||
|
int i=0, numDeleted=0;
|
||||||
|
cJSON_ArrayForEach(extra, extrasArray) {
|
||||||
|
if (extra!=NULL && cJSON_GetObjectItem(extra, "File")!=NULL) {
|
||||||
|
char *tempStr=cJSON_GetStringValue(cJSON_GetObjectItem(extra, "File"));
|
||||||
|
if (tempStr!=NULL) {
|
||||||
|
if (access(tempStr, F_OK)==0) {
|
||||||
|
cJSON *subsArray=cJSON_Duplicate(cJSON_GetObjectItem(extra, "Subs"), true);
|
||||||
|
int j=0, subsDeleted=0;
|
||||||
|
cJSON *sub=NULL;
|
||||||
|
cJSON_ArrayForEach(sub, subsArray) {
|
||||||
|
char *tempSubStr=cJSON_GetStringValue(cJSON_GetObjectItem(sub, "subFile"));
|
||||||
|
if (tempSubStr!=NULL) {
|
||||||
|
if (access(tempSubStr, F_OK)!=0) {
|
||||||
|
cJSON *tempSubs=cJSON_GetObjectItem(cJSON_GetArrayItem(cJSON_GetObjectItem(show, "Extras"), i-numDeleted), "Subs");
|
||||||
|
cJSON_DeleteItemFromArray(tempSubs, j-subsDeleted);
|
||||||
|
subsDeleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
cJSON_Delete(subsArray);
|
||||||
|
} else {
|
||||||
|
cJSON_DeleteItemFromArray(cJSON_GetObjectItem(show, "Extras"), i-numDeleted);
|
||||||
|
numDeleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
extrasArraySize=cJSON_GetArraySize(extrasArray);
|
||||||
|
cJSON_Delete(extrasArray);
|
||||||
|
}
|
||||||
|
if ((episodesArraySize+extrasArraySize) == 0) {
|
||||||
|
//TODO: parse "Show" tag for filename then delete HTML show file?
|
||||||
|
thisThread->oldJSON = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user