Add function to sort catalogs

This commit is contained in:
mrcanelas
2025-01-30 20:34:11 -03:00
parent 2aab372e70
commit 56c063059d
2 changed files with 40 additions and 22 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
{
"projectName": "tmdb-addon",
"lastCommit": "a3477d6"
"lastCommit": "2aab372"
}
+39 -21
View File
@@ -87,6 +87,22 @@ function getOptionsForCatalog(catalogDef, type, { years, genres_movie, genres_se
}
}
function sortCatalogs(catalogs) {
return catalogs.sort((a, b) => {
const typeA = a.id.split('.')[1];
const typeB = b.id.split('.')[1];
const orderA = Object.keys(CATALOG_TYPES).findIndex(category => CATALOG_TYPES[category][typeA]);
const orderB = Object.keys(CATALOG_TYPES).findIndex(category => CATALOG_TYPES[category][typeB]);
if (orderA !== orderB) {
return orderA - orderB;
}
return a.type === "movie" && b.type === "series" ? -1 : 1;
});
}
async function getManifest(config) {
const language = config.language || DEFAULT_LANGUAGE;
const tmdbPrefix = config.tmdbPrefix === "true";
@@ -111,27 +127,29 @@ async function getManifest(config) {
const filterLanguages = setOrderLanguage(language, languagesArray);
const options = { years, genres_movie, genres_series, filterLanguages };
const catalogs = userCatalogs
.filter(userCatalog => {
const catalogDef = getCatalogDefinition(userCatalog.id);
if (!catalogDef) return false;
if (catalogDef.requiresAuth && !sessionId) return false;
return true;
})
.map(userCatalog => {
const catalogDef = getCatalogDefinition(userCatalog.id);
const catalogOptions = getOptionsForCatalog(catalogDef, userCatalog.type, options);
return createCatalog(
userCatalog.id,
userCatalog.type,
catalogDef,
catalogOptions,
tmdbPrefix,
translatedCatalogs,
userCatalog.showInHome
);
});
const catalogs = sortCatalogs(
userCatalogs
.filter(userCatalog => {
const catalogDef = getCatalogDefinition(userCatalog.id);
if (!catalogDef) return false;
if (catalogDef.requiresAuth && !sessionId) return false;
return true;
})
.map(userCatalog => {
const catalogDef = getCatalogDefinition(userCatalog.id);
const catalogOptions = getOptionsForCatalog(catalogDef, userCatalog.type, options);
return createCatalog(
userCatalog.id,
userCatalog.type,
catalogDef,
catalogOptions,
tmdbPrefix,
translatedCatalogs,
userCatalog.showInHome
);
})
);
const descriptionSuffix = language && language !== DEFAULT_LANGUAGE ? ` with ${language} language.` : ".";