Fix for cleaning up tv shows

This commit is contained in:
farfalleflickan 2024-12-27 00:22:59 +01:00
parent 87445fd8a4
commit 4699ede21d

View File

@ -909,7 +909,9 @@ 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);
cJSON_AddItemToArray(newJSON, threadObj[i].oldJSON); if (threadObj[i].oldJSON != NULL) {
cJSON_AddItemToArray(newJSON, threadObj[i].oldJSON);
}
} }
thisThread->oldJSON=cJSON_Duplicate(newJSON, true); thisThread->oldJSON=cJSON_Duplicate(newJSON, true);
cJSON_Delete(newJSON); cJSON_Delete(newJSON);
@ -924,40 +926,86 @@ 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) {
cJSON *episode=NULL; episodesArray=cJSON_Duplicate(cJSON_GetObjectItem(show, "Episodes"), true);
int i=0, numDeleted=0; cJSON *episode=NULL;
cJSON_ArrayForEach(episode, episodesArray) { int i=0, numDeleted=0;
if (episode!=NULL && cJSON_GetObjectItem(episode, "File")!=NULL) { cJSON_ArrayForEach(episode, episodesArray) {
char *tempStr=cJSON_GetStringValue(cJSON_GetObjectItem(episode, "File")); if (episode!=NULL && cJSON_GetObjectItem(episode, "File")!=NULL) {
if (tempStr!=NULL) { char *tempStr=cJSON_GetStringValue(cJSON_GetObjectItem(episode, "File"));
if (access(tempStr, F_OK)==0) { if (tempStr!=NULL) {
cJSON *subsArray=cJSON_Duplicate(cJSON_GetObjectItem(episode, "Subs"), true); if (access(tempStr, F_OK)==0) {
int j=0, subsDeleted=0; cJSON *subsArray=cJSON_Duplicate(cJSON_GetObjectItem(episode, "Subs"), true);
cJSON *sub=NULL; int j=0, subsDeleted=0;
cJSON_ArrayForEach(sub, subsArray) { cJSON *sub=NULL;
char *tempSubStr=cJSON_GetStringValue(cJSON_GetObjectItem(sub, "subFile")); cJSON_ArrayForEach(sub, subsArray) {
if (tempSubStr!=NULL) { char *tempSubStr=cJSON_GetStringValue(cJSON_GetObjectItem(sub, "subFile"));
if (access(tempSubStr, F_OK)!=0) { if (tempSubStr!=NULL) {
cJSON *tempSubs=cJSON_GetObjectItem(cJSON_GetArrayItem(cJSON_GetObjectItem(show, "Episodes"), i-numDeleted), "Subs"); if (access(tempSubStr, F_OK)!=0) {
cJSON_DeleteItemFromArray(tempSubs, j-subsDeleted); cJSON *tempSubs=cJSON_GetObjectItem(cJSON_GetArrayItem(cJSON_GetObjectItem(show, "Episodes"), i-numDeleted), "Subs");
subsDeleted++; cJSON_DeleteItemFromArray(tempSubs, j-subsDeleted);
subsDeleted++;
}
} }
j++;
} }
j++; cJSON_Delete(subsArray);
} else {
cJSON_DeleteItemFromArray(cJSON_GetObjectItem(show, "Episodes"), i-numDeleted);
numDeleted++;
} }
cJSON_Delete(subsArray);
} else {
cJSON_DeleteItemFromArray(cJSON_GetObjectItem(show, "Episodes"), i-numDeleted);
numDeleted++;
} }
} }
i++;
} }
i++; episodesArraySize=cJSON_GetArraySize(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;
} }
cJSON_Delete(episodesArray);
} }
return NULL; return NULL;