Add: Ability to sort

pull/16/head
Juraj Nyíri 4 years ago
parent 38c7b95af1
commit 9eeadd7f8e

@ -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).

@ -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;

@ -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<void> => {
@ -76,13 +79,12 @@ class Plex {
const sections = await this.getSections();
const sectionsRequests: Array<Promise<any>> = [];
_.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}`,
{
axios.get(url, {
timeout: this.requestTimeout
}
)
})
);
});
return this.exportSectionsData(await Promise.all(sectionsRequests));

@ -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 => {

Loading…
Cancel
Save