From 9eeadd7f8e3fd552730372b51b0bf716563682d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Fri, 21 May 2021 22:12:12 +0200 Subject: [PATCH] Add: Ability to sort --- README.md | 41 ++++++++++++++++++++++++++++++++ dist/plex-meets-homeassistant.js | 9 ++++--- src/modules/Plex.ts | 16 +++++++------ src/plex-meets-homeassistant.ts | 2 +- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2bf46d5..9b193d9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ More images [at the end of the readme](https://github.com/JurajNyiri/PlexMeetsHo **maxCount**: _Optional_ Maximum number of items to display in card. +**sort**: _Optional_ Define sort by. See See [detailed instructions](https://github.com/JurajNyiri/PlexMeetsHomeAssistant#sorting) + **entity**: You need to configure at least one supported media_player entity. - **androidtv**: Entity id of your media_player configured via [Android TV](https://www.home-assistant.io/integrations/androidtv/). See [detailed instructions](https://github.com/JurajNyiri/PlexMeetsHomeAssistant#android-tv-or-fire-tv). @@ -193,6 +195,45 @@ entity: ✅ Episodes +## Sorting + +You can use _:desc_ or _:asc_ after every value to change the order from ascending to descending. For example, titlesort would become titleSort:asc, or titleSort:desc. + +### TV Shows + +| Sort Value | Description | +| --------------------- | ------------------------------------------------- | +| titleSort | Sorts by title, removing words like "the" | +| title | Sorts by title, without removing words like "the" | +| year | Sorts by year | +| originallyAvailableAt | Sorts by release date | +| rating | Sorts by critic rating | +| audienceRating | Sorts by audience rating | +| userRating | Sorts by user rating | +| contentRating | Sorts by content rating | +| unviewedLeafCount | Sorts by unplayed count | +| episode.addedAt | Sorts by last episode date added | +| addedAt | Sorts by date added | +| lastViewedAt | Sorts by date viewed | + +### Movies + +| Sort Value | Description | +| --------------------- | ------------------------------------------------- | +| titleSort | Sorts by title, removing words like "the" | +| title | Sorts by title, without removing words like "the" | +| originallyAvailableAt | Sorts by release date | +| rating | Sorts by critic rating | +| audienceRating | Sorts by audience rating | +| userRating | Sorts by user rating | +| duration | Sorts by duration | +| viewOffset | Sorts by progress | +| viewCount | Sorts by plays | +| addedAt | Sorts by date added | +| lastViewedAt | Sorts by date viewed | +| mediaHeight | Sorts by resolution | +| mediaBitrate | Sorts by bitrate | + ## Ask for help or help development Join [Discord](https://discord.gg/jqqz9jQXWx) or [Home Assistant Community](https://community.home-assistant.io/t/custom-component-card-plex-meets-home-assistant/304349). diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 621f195..afde378 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -18668,7 +18668,7 @@ var axios = axios_1; /* eslint-disable @typescript-eslint/no-explicit-any */ class Plex { - constructor(ip, port = 32400, token, protocol = 'http') { + constructor(ip, port = 32400, token, protocol = 'http', sort = 'titleSort:asc') { this.serverInfo = {}; this.clients = []; this.requestTimeout = 5000; @@ -18716,7 +18716,9 @@ class Plex { const sections = await this.getSections(); const sectionsRequests = []; lodash.forEach(sections, section => { - sectionsRequests.push(axios.get(`${this.protocol}://${this.ip}:${this.port}/library/sections/${section.key}/all?X-Plex-Token=${this.token}`, { + let url = `${this.protocol}://${this.ip}:${this.port}/library/sections/${section.key}/all?X-Plex-Token=${this.token}`; + url += `&sort=${this.sort}`; + sectionsRequests.push(axios.get(url, { timeout: this.requestTimeout })); }); @@ -18739,6 +18741,7 @@ class Plex { this.port = port; this.token = token; this.protocol = protocol; + this.sort = sort; } } @@ -20309,7 +20312,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (config.maxCount) { this.maxCount = config.maxCount; } - this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol); + this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); }; this.getCardSize = () => { return 3; diff --git a/src/modules/Plex.ts b/src/modules/Plex.ts index 766da6c..57abdde 100644 --- a/src/modules/Plex.ts +++ b/src/modules/Plex.ts @@ -17,11 +17,14 @@ class Plex { requestTimeout = 5000; - constructor(ip: string, port = 32400, token: string, protocol: 'http' | 'https' = 'http') { + sort: string; + + constructor(ip: string, port = 32400, token: string, protocol: 'http' | 'https' = 'http', sort = 'titleSort:asc') { this.ip = ip; this.port = port; this.token = token; this.protocol = protocol; + this.sort = sort; } init = async (): Promise => { @@ -76,13 +79,12 @@ class Plex { const sections = await this.getSections(); const sectionsRequests: Array> = []; _.forEach(sections, section => { + let url = `${this.protocol}://${this.ip}:${this.port}/library/sections/${section.key}/all?X-Plex-Token=${this.token}`; + url += `&sort=${this.sort}`; sectionsRequests.push( - axios.get( - `${this.protocol}://${this.ip}:${this.port}/library/sections/${section.key}/all?X-Plex-Token=${this.token}`, - { - timeout: this.requestTimeout - } - ) + axios.get(url, { + timeout: this.requestTimeout + }) ); }); return this.exportSectionsData(await Promise.all(sectionsRequests)); diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 6a5bd19..eef96ae 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -880,7 +880,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.maxCount = config.maxCount; } - this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol); + this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); }; getCardSize = (): number => {