diff --git a/beamup.json b/beamup.json index 0b46db0..1ae93d7 100644 --- a/beamup.json +++ b/beamup.json @@ -1,4 +1,4 @@ { "projectName": "tmdb-addon", - "lastCommit": "a3477d6" + "lastCommit": "2aab372" } \ No newline at end of file diff --git a/lib/getManifest.js b/lib/getManifest.js index 79c5cad..0e131cb 100644 --- a/lib/getManifest.js +++ b/lib/getManifest.js @@ -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.` : ".";