Update: Folders now work and display tracks

pull/52/head
Juraj Nyíri 3 years ago
parent 8a888ac0fd
commit f4e9eec304

@ -19101,8 +19101,8 @@ class Plex {
timeout: this.requestTimeout timeout: this.requestTimeout
})).data.MediaContainer.Metadata[0]; })).data.MediaContainer.Metadata[0];
}; };
this.getLibraryData = async (id) => { this.getLibraryData = async (path) => {
const url = this.authorizeURL(`${this.getBasicURL()}/library/metadata/${id}/children`); const url = this.authorizeURL(`${this.getBasicURL()}${path}`);
return (await axios.get(url, { return (await axios.get(url, {
timeout: this.requestTimeout timeout: this.requestTimeout
})).data.MediaContainer.Metadata; })).data.MediaContainer.Metadata;
@ -19303,7 +19303,12 @@ const createTrackView = (playController, plex, data, fontSize1, fontSize2, isEve
trackContainer.append(trackIndexElem); trackContainer.append(trackIndexElem);
const trackTitleElem = document.createElement('td'); const trackTitleElem = document.createElement('td');
trackTitleElem.className = 'trackTitleElem'; trackTitleElem.className = 'trackTitleElem';
trackTitleElem.innerHTML = escapeHtml(data.title); if (!lodash.isEmpty(data.title)) {
trackTitleElem.innerHTML = escapeHtml(data.title);
}
else if (!lodash.isEmpty(data.titleSort)) {
trackTitleElem.innerHTML = escapeHtml(data.titleSort);
}
trackTitleElem.style.fontSize = `${fontSize1}px`; trackTitleElem.style.fontSize = `${fontSize1}px`;
trackTitleElem.style.lineHeight = `${fontSize1}px`; trackTitleElem.style.lineHeight = `${fontSize1}px`;
trackTitleElem.style.marginBottom = `${margin1}px`; trackTitleElem.style.marginBottom = `${margin1}px`;
@ -22960,14 +22965,19 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.plex) { if (this.plex) {
let childrenData = {}; let childrenData = {};
if (lodash.isEqual(data.type, 'episode')) { if (lodash.isEqual(data.type, 'episode')) {
childrenData = await this.plex.getLibraryData(data.grandparentKey.split('/')[3]); childrenData = await this.plex.getLibraryData(data.grandparentKey);
} }
else if (data.childCount > 0 || lodash.isEqual(data.type, 'artist') || lodash.isEqual(data.type, 'album')) { else if (data.childCount > 0 ||
childrenData = await this.plex.getLibraryData(data.key.split('/')[3]); lodash.isEqual(data.type, 'artist') ||
lodash.isEqual(data.type, 'album') ||
lodash.includes(data.key, 'folder')) {
childrenData = await this.plex.getLibraryData(data.key);
} }
let dataDetails = {}; let dataDetails = {};
if (!lodash.isNil(data.key)) { if (!lodash.isNil(data.key)) {
dataDetails = await this.plex.getDetails(data.key.split('/')[3]); if (!lodash.includes(data.key, 'folder')) {
dataDetails = await this.plex.getDetails(data.key.split('/')[3]);
}
if (this.videoElem) { if (this.videoElem) {
const art = this.plex.authorizeURL(this.plex.getBasicURL() + data.art); const art = this.plex.authorizeURL(this.plex.getBasicURL() + data.art);
const trailerURL = findTrailerURL(dataDetails); const trailerURL = findTrailerURL(dataDetails);
@ -23087,9 +23097,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
tableView.style.border = 'none'; tableView.style.border = 'none';
tableView.cellSpacing = '0'; tableView.cellSpacing = '0';
tableView.cellPadding = '0'; tableView.cellPadding = '0';
if (lodash.isEqual(data.type, 'album')) { this.episodesElem.append(tableView);
this.episodesElem.append(tableView);
}
let isEven = false; let isEven = false;
lodash.forEach(childrenData, childData => { lodash.forEach(childrenData, childData => {
if (this.episodesElem && this.playController && this.plex) { if (this.episodesElem && this.playController && this.plex) {
@ -23124,7 +23132,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
else { else {
lodash.forEach(childrenData, childData => { lodash.forEach(childrenData, childData => {
if (this.seasonsElem && this.plex) { if (this.seasonsElem && this.plex) {
console.log(childData);
this.seasonsElemHidden = false; this.seasonsElemHidden = false;
const seasonContainer = document.createElement('div'); const seasonContainer = document.createElement('div');
seasonContainer.className = 'seasonContainer'; seasonContainer.className = 'seasonContainer';
@ -23242,7 +23249,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
(async () => { (async () => {
if (this.plex && (childData.leafCount > 0 || lodash.isEqual(childData.type, 'album'))) { if (this.plex && (childData.leafCount > 0 || lodash.isEqual(childData.type, 'album'))) {
this.episodesElemFreshlyLoaded = true; this.episodesElemFreshlyLoaded = true;
const episodesData = await this.plex.getLibraryData(childData.key.split('/')[3]); const episodesData = await this.plex.getLibraryData(childData.key);
if (this.episodesElem) { if (this.episodesElem) {
this.episodesElemHidden = false; this.episodesElemHidden = false;
this.episodesElem.style.display = 'block'; this.episodesElem.style.display = 'block';
@ -23358,7 +23365,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.episodesElem.style.transition = `0s`; this.episodesElem.style.transition = `0s`;
this.episodesElem.style.top = `${top + 2000}px`; this.episodesElem.style.top = `${top + 2000}px`;
if (lodash.isEqual(data.type, 'season')) { if (lodash.isEqual(data.type, 'season')) {
const episodesData = await this.plex.getLibraryData(data.key.split('/')[3]); const episodesData = await this.plex.getLibraryData(data.key);
lodash.forEach(episodesData, episodeData => { lodash.forEach(episodesData, episodeData => {
if (this.episodesElem && this.playController && this.plex) { if (this.episodesElem && this.playController && this.plex) {
this.episodesElem.append(createEpisodesView(this.playController, this.plex, episodeData, this.fontSize1, this.fontSize2)); this.episodesElem.append(createEpisodesView(this.playController, this.plex, episodeData, this.fontSize1, this.fontSize2));
@ -23498,8 +23505,11 @@ class PlexMeetsHomeAssistant extends HTMLElement {
movieElem.className = 'movieElem'; movieElem.className = 'movieElem';
movieElem.style.width = `${CSS_STYLE.width}px`; movieElem.style.width = `${CSS_STYLE.width}px`;
movieElem.style.height = `${CSS_STYLE.height}px`; movieElem.style.height = `${CSS_STYLE.height}px`;
if (!lodash.isNil(data.channelCallSign) || lodash.isEqual(data.type, 'artist') || lodash.isEqual(data.type, 'album')) { if (!lodash.isNil(data.channelCallSign) ||
if (!lodash.isEqual(data.type, 'artist') && !lodash.isEqual(data.type, 'album')) { lodash.isEqual(data.type, 'artist') ||
lodash.isEqual(data.type, 'album') ||
lodash.includes(data.key, 'folder')) {
if (!lodash.isEqual(data.type, 'artist') && !lodash.isEqual(data.type, 'album') && !lodash.includes(data.key, 'folder')) {
movieElem.style.backgroundSize = '80%'; movieElem.style.backgroundSize = '80%';
} }
movieElem.style.backgroundColor = 'rgba(0,0,0,0.2)'; movieElem.style.backgroundColor = 'rgba(0,0,0,0.2)';

@ -551,8 +551,8 @@ class Plex {
).data.MediaContainer.Metadata[0]; ).data.MediaContainer.Metadata[0];
}; };
getLibraryData = async (id: number): Promise<any> => { getLibraryData = async (path: string): Promise<any> => {
const url = this.authorizeURL(`${this.getBasicURL()}/library/metadata/${id}/children`); const url = this.authorizeURL(`${this.getBasicURL()}${path}`);
return ( return (
await axios.get(url, { await axios.get(url, {
timeout: this.requestTimeout timeout: this.requestTimeout

@ -232,7 +232,11 @@ const createTrackView = (
const trackTitleElem = document.createElement('td'); const trackTitleElem = document.createElement('td');
trackTitleElem.className = 'trackTitleElem'; trackTitleElem.className = 'trackTitleElem';
trackTitleElem.innerHTML = escapeHtml(data.title); if (!_.isEmpty(data.title)) {
trackTitleElem.innerHTML = escapeHtml(data.title);
} else if (!_.isEmpty(data.titleSort)) {
trackTitleElem.innerHTML = escapeHtml(data.titleSort);
}
trackTitleElem.style.fontSize = `${fontSize1}px`; trackTitleElem.style.fontSize = `${fontSize1}px`;
trackTitleElem.style.lineHeight = `${fontSize1}px`; trackTitleElem.style.lineHeight = `${fontSize1}px`;

@ -1339,13 +1339,21 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.plex) { if (this.plex) {
let childrenData: Record<string, any> = {}; let childrenData: Record<string, any> = {};
if (_.isEqual(data.type, 'episode')) { if (_.isEqual(data.type, 'episode')) {
childrenData = await this.plex.getLibraryData(data.grandparentKey.split('/')[3]); childrenData = await this.plex.getLibraryData(data.grandparentKey);
} else if (data.childCount > 0 || _.isEqual(data.type, 'artist') || _.isEqual(data.type, 'album')) { } else if (
childrenData = await this.plex.getLibraryData(data.key.split('/')[3]); data.childCount > 0 ||
_.isEqual(data.type, 'artist') ||
_.isEqual(data.type, 'album') ||
_.includes(data.key, 'folder')
) {
childrenData = await this.plex.getLibraryData(data.key);
} }
let dataDetails: Record<string, any> = {}; let dataDetails: Record<string, any> = {};
if (!_.isNil(data.key)) { if (!_.isNil(data.key)) {
dataDetails = await this.plex.getDetails(data.key.split('/')[3]); if (!_.includes(data.key, 'folder')) {
dataDetails = await this.plex.getDetails(data.key.split('/')[3]);
}
if (this.videoElem) { if (this.videoElem) {
const art = this.plex.authorizeURL(this.plex.getBasicURL() + data.art); const art = this.plex.authorizeURL(this.plex.getBasicURL() + data.art);
const trailerURL = findTrailerURL(dataDetails); const trailerURL = findTrailerURL(dataDetails);
@ -1474,9 +1482,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
tableView.style.border = 'none'; tableView.style.border = 'none';
tableView.cellSpacing = '0'; tableView.cellSpacing = '0';
tableView.cellPadding = '0'; tableView.cellPadding = '0';
if (_.isEqual(data.type, 'album')) { this.episodesElem.append(tableView);
this.episodesElem.append(tableView);
}
let isEven = false; let isEven = false;
_.forEach(childrenData, childData => { _.forEach(childrenData, childData => {
if (this.episodesElem && this.playController && this.plex) { if (this.episodesElem && this.playController && this.plex) {
@ -1513,7 +1519,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} else { } else {
_.forEach(childrenData, childData => { _.forEach(childrenData, childData => {
if (this.seasonsElem && this.plex) { if (this.seasonsElem && this.plex) {
console.log(childData);
this.seasonsElemHidden = false; this.seasonsElemHidden = false;
const seasonContainer = document.createElement('div'); const seasonContainer = document.createElement('div');
seasonContainer.className = 'seasonContainer'; seasonContainer.className = 'seasonContainer';
@ -1649,7 +1654,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
(async (): Promise<void> => { (async (): Promise<void> => {
if (this.plex && (childData.leafCount > 0 || _.isEqual(childData.type, 'album'))) { if (this.plex && (childData.leafCount > 0 || _.isEqual(childData.type, 'album'))) {
this.episodesElemFreshlyLoaded = true; this.episodesElemFreshlyLoaded = true;
const episodesData = await this.plex.getLibraryData(childData.key.split('/')[3]); const episodesData = await this.plex.getLibraryData(childData.key);
if (this.episodesElem) { if (this.episodesElem) {
this.episodesElemHidden = false; this.episodesElemHidden = false;
this.episodesElem.style.display = 'block'; this.episodesElem.style.display = 'block';
@ -1784,7 +1789,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.episodesElem.style.transition = `0s`; this.episodesElem.style.transition = `0s`;
this.episodesElem.style.top = `${top + 2000}px`; this.episodesElem.style.top = `${top + 2000}px`;
if (_.isEqual(data.type, 'season')) { if (_.isEqual(data.type, 'season')) {
const episodesData = await this.plex.getLibraryData(data.key.split('/')[3]); const episodesData = await this.plex.getLibraryData(data.key);
_.forEach(episodesData, episodeData => { _.forEach(episodesData, episodeData => {
if (this.episodesElem && this.playController && this.plex) { if (this.episodesElem && this.playController && this.plex) {
this.episodesElem.append( this.episodesElem.append(
@ -1946,8 +1951,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
movieElem.style.width = `${CSS_STYLE.width}px`; movieElem.style.width = `${CSS_STYLE.width}px`;
movieElem.style.height = `${CSS_STYLE.height}px`; movieElem.style.height = `${CSS_STYLE.height}px`;
if (!_.isNil(data.channelCallSign) || _.isEqual(data.type, 'artist') || _.isEqual(data.type, 'album')) { if (
if (!_.isEqual(data.type, 'artist') && !_.isEqual(data.type, 'album')) { !_.isNil(data.channelCallSign) ||
_.isEqual(data.type, 'artist') ||
_.isEqual(data.type, 'album') ||
_.includes(data.key, 'folder')
) {
if (!_.isEqual(data.type, 'artist') && !_.isEqual(data.type, 'album') && !_.includes(data.key, 'folder')) {
movieElem.style.backgroundSize = '80%'; movieElem.style.backgroundSize = '80%';
} }
movieElem.style.backgroundColor = 'rgba(0,0,0,0.2)'; movieElem.style.backgroundColor = 'rgba(0,0,0,0.2)';

Loading…
Cancel
Save