#include "jellyfin.h" #include "config.h" #include #include #include #include #include #include #include void trigger_jellyfin_scan(void) { if (!g_cfg.jellyfin_url[0]) return; CURL *c = curl_easy_init(); if (!c) return; curl_easy_setopt(c, CURLOPT_URL, g_cfg.jellyfin_url); curl_easy_setopt(c, CURLOPT_POST, 1L); curl_easy_setopt(c, CURLOPT_POSTFIELDSIZE, 0L); curl_easy_setopt(c, CURLOPT_TIMEOUT, 10L); curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, NULL); curl_easy_perform(c); curl_easy_cleanup(c); } static int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } void update_show_manifest(const char *season_dir, const char *title_hint) { (void)title_hint; char show_dir[512]; strncpy(show_dir, season_dir, sizeof(show_dir)-1); show_dir[sizeof(show_dir)-1] = 0; char *slash = strrchr(show_dir, '/'); if (!slash) return; *slash = 0; const char *title = strrchr(show_dir, '/'); title = title ? title+1 : show_dir; char manifest[640]; snprintf(manifest, sizeof(manifest), "%s/show.json", show_dir); char **files = NULL; int fc = 0, fcap = 0; DIR *sd = opendir(show_dir); if (!sd) return; struct dirent *se; while ((se = readdir(sd))) { if (strncmp(se->d_name, "Season ", 7) != 0) continue; char sdir[640]; snprintf(sdir, sizeof(sdir), "%s/%s", show_dir, se->d_name); DIR *ed = opendir(sdir); if (!ed) continue; struct dirent *ee; while ((ee = readdir(ed))) { if (ee->d_name[0] == '.') continue; char fpath[768]; snprintf(fpath, sizeof(fpath), "%s/%s", sdir, ee->d_name); struct stat st; if (stat(fpath, &st) != 0 || !S_ISREG(st.st_mode)) continue; char entry[900]; snprintf(entry, sizeof(entry), "{\"file\":\"%s/%s\",\"size\":%lld}", se->d_name, ee->d_name, (long long)st.st_size); if (fc >= fcap) { fcap = fcap ? fcap*2 : 32; files = realloc(files, fcap*sizeof(char*)); } files[fc++] = strdup(entry); } closedir(ed); } closedir(sd); if (fc > 1) qsort(files, fc, sizeof(char*), cmp_str); FILE *f = fopen(manifest, "w"); if (f) { fprintf(f, "{\"title\":\"%s\",\"updated\":%ld,\"count\":%d,\"episodes\":[", title, (long)time(NULL), fc); for (int i = 0; i < fc; i++) { if (i) fputc(',', f); fputs(files[i], f); } fputs("]}", f); fclose(f); } for (int i = 0; i < fc; i++) free(files[i]); free(files); }