mirror of
https://github.com/LukeHagar/plex-api-oauth.git
synced 2025-12-06 12:37:50 +00:00
LIBRARY DATA MAAAAAN
Used this guide https://www.youtube.com/watch?v=H-BiAoE4emk&ab_channel=willjw3 Converted the issue Library data function to for of instead of forEach or Map
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "plex-api-oauth",
|
"name": "plex-api-oauth",
|
||||||
"version": "1.0.134",
|
"version": "1.0.135",
|
||||||
"description": "An NPM Module designed to make Plex Media Server and plex.tv API calls easier to implement in JavaScript and React projects",
|
"description": "An NPM Module designed to make Plex Media Server and plex.tv API calls easier to implement in JavaScript and React projects",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ export class PlexAPIOAuth {
|
|||||||
plexTVUserData;
|
plexTVUserData;
|
||||||
plexServers;
|
plexServers;
|
||||||
plexLibraries;
|
plexLibraries;
|
||||||
|
plexMusicLibraries;
|
||||||
|
plexMovieLibraries;
|
||||||
|
plexTVShowLibraries;
|
||||||
plexDevices;
|
plexDevices;
|
||||||
constructor(
|
constructor(
|
||||||
clientId = "",
|
clientId = "",
|
||||||
@@ -27,6 +30,9 @@ export class PlexAPIOAuth {
|
|||||||
plexTVUserData = {},
|
plexTVUserData = {},
|
||||||
plexServers = [],
|
plexServers = [],
|
||||||
plexLibraries = [],
|
plexLibraries = [],
|
||||||
|
plexMusicLibraries = [],
|
||||||
|
plexMovieLibraries = [],
|
||||||
|
plexTVShowLibraries = [],
|
||||||
plexDevices = []
|
plexDevices = []
|
||||||
) {
|
) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
@@ -40,6 +46,9 @@ export class PlexAPIOAuth {
|
|||||||
this.plexTVUserData = plexTVUserData;
|
this.plexTVUserData = plexTVUserData;
|
||||||
this.plexServers = plexServers;
|
this.plexServers = plexServers;
|
||||||
this.plexLibraries = plexLibraries;
|
this.plexLibraries = plexLibraries;
|
||||||
|
this.plexMusicLibraries = plexMusicLibraries;
|
||||||
|
this.plexMovieLibraries = plexMovieLibraries;
|
||||||
|
this.plexTVShowLibraries = plexTVShowLibraries;
|
||||||
this.plexDevices = plexDevices;
|
this.plexDevices = plexDevices;
|
||||||
|
|
||||||
this.plexClientInformation = {
|
this.plexClientInformation = {
|
||||||
@@ -63,6 +72,9 @@ export class PlexAPIOAuth {
|
|||||||
this.plexTVUserData = {};
|
this.plexTVUserData = {};
|
||||||
this.plexServers = [];
|
this.plexServers = [];
|
||||||
this.plexLibraries = [];
|
this.plexLibraries = [];
|
||||||
|
this.plexMusicLibraries = [];
|
||||||
|
this.plexMovieLibraries = [];
|
||||||
|
this.plexTVShowLibraries = [];
|
||||||
this.plexDevices = [];
|
this.plexDevices = [];
|
||||||
this.plexClientInformation = {
|
this.plexClientInformation = {
|
||||||
clientIdentifier: this.clientId, // This is a unique identifier used to identify your app with Plex. - If none is provided a new one is generated and saved locally
|
clientIdentifier: this.clientId, // This is a unique identifier used to identify your app with Plex. - If none is provided a new one is generated and saved locally
|
||||||
@@ -85,6 +97,9 @@ export class PlexAPIOAuth {
|
|||||||
plexTVUserData = {},
|
plexTVUserData = {},
|
||||||
plexServers = [],
|
plexServers = [],
|
||||||
plexLibraries = [],
|
plexLibraries = [],
|
||||||
|
plexMusicLibraries = [],
|
||||||
|
plexMovieLibraries = [],
|
||||||
|
plexTVShowLibraries = [],
|
||||||
plexDevices = [],
|
plexDevices = [],
|
||||||
}) {
|
}) {
|
||||||
this.plexTVAuthToken = plexTVAuthToken;
|
this.plexTVAuthToken = plexTVAuthToken;
|
||||||
@@ -97,6 +112,9 @@ export class PlexAPIOAuth {
|
|||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.plexServers = plexServers;
|
this.plexServers = plexServers;
|
||||||
this.plexLibraries = plexLibraries;
|
this.plexLibraries = plexLibraries;
|
||||||
|
this.plexMusicLibraries = plexMusicLibraries;
|
||||||
|
this.plexMovieLibraries = plexMovieLibraries;
|
||||||
|
this.plexTVShowLibraries = plexTVShowLibraries;
|
||||||
this.plexDevices = plexDevices;
|
this.plexDevices = plexDevices;
|
||||||
|
|
||||||
this.plexClientInformation = {
|
this.plexClientInformation = {
|
||||||
@@ -122,6 +140,9 @@ export class PlexAPIOAuth {
|
|||||||
platform: this.platform,
|
platform: this.platform,
|
||||||
plexServers: this.plexServers,
|
plexServers: this.plexServers,
|
||||||
plexLibraries: this.plexLibraries,
|
plexLibraries: this.plexLibraries,
|
||||||
|
plexMusicLibraries: this.plexMusicLibraries,
|
||||||
|
plexMovieLibraries: this.plexMovieLibraries,
|
||||||
|
plexTVShowLibraries: this.plexTVShowLibraries,
|
||||||
plexDevices: this.plexDevices,
|
plexDevices: this.plexDevices,
|
||||||
plexClientInformation: this.plexClientInformation,
|
plexClientInformation: this.plexClientInformation,
|
||||||
};
|
};
|
||||||
@@ -294,9 +315,9 @@ export class PlexAPIOAuth {
|
|||||||
return this.plexServers;
|
return this.plexServers;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPlexLibraries() {
|
async GetPlexLibraries() {
|
||||||
let libraryArray = null;
|
let libraryArray = [];
|
||||||
this.plexServers.forEach(async (server) => {
|
for (const server of this.plexServers) {
|
||||||
let response = await axios({
|
let response = await axios({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url:
|
url:
|
||||||
@@ -309,46 +330,50 @@ export class PlexAPIOAuth {
|
|||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
if (libraryArray == null) {
|
for (const library of response.data.MediaContainer.Directory) {
|
||||||
libraryArray = [...response?.data?.MediaContainer?.Directory];
|
libraryArray.push({
|
||||||
} else {
|
server: server.clientIdentifier,
|
||||||
libraryArray = [
|
allowSync: library.allowSync,
|
||||||
...libraryArray,
|
art: library.art,
|
||||||
...response?.data?.MediaContainer?.Directory,
|
composite: library.composite,
|
||||||
];
|
filters: library.filters,
|
||||||
|
refreshing: library.refreshing,
|
||||||
|
thumb: library.thumb,
|
||||||
|
key: library.key,
|
||||||
|
type: library.type,
|
||||||
|
title: library.title,
|
||||||
|
agent: library.agent,
|
||||||
|
scanner: library.scanner,
|
||||||
|
language: library.language,
|
||||||
|
uuid: library.uuid,
|
||||||
|
updatedAt: library.updatedAt,
|
||||||
|
createdAt: library.createdAt,
|
||||||
|
scannedAt: library.scannedAt,
|
||||||
|
content: library.content,
|
||||||
|
directory: library.directory,
|
||||||
|
contentChangedAt: library.contentChangedAt,
|
||||||
|
hidden: library.hidden,
|
||||||
|
Location: library.Location,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this.plexLibraries = libraryArray;
|
// console.log(libraryArray);
|
||||||
|
// this.plexLibraries = libraryArray;
|
||||||
// return await response?.data?.MediaContainer?.Directory.map((entry) => {
|
// return await response?.data?.MediaContainer?.Directory.map((entry) => {
|
||||||
// return {
|
|
||||||
// server: server.clientIdentifier,
|
|
||||||
// allowSync: entry.allowSync,
|
|
||||||
// art: entry.art,
|
|
||||||
// composite: entry.composite,
|
|
||||||
// filters: entry.filters,
|
|
||||||
// refreshing: entry.refreshing,
|
|
||||||
// thumb: entry.thumb,
|
|
||||||
// key: entry.key,
|
|
||||||
// type: entry.type,
|
|
||||||
// title: entry.title,
|
|
||||||
// agent: entry.agent,
|
|
||||||
// scanner: entry.scanner,
|
|
||||||
// language: entry.language,
|
|
||||||
// uuid: entry.uuid,
|
|
||||||
// updatedAt: entry.updatedAt,
|
|
||||||
// createdAt: entry.createdAt,
|
|
||||||
// scannedAt: entry.scannedAt,
|
|
||||||
// content: entry.content,
|
|
||||||
// directory: entry.directory,
|
|
||||||
// contentChangedAt: entry.contentChangedAt,
|
|
||||||
// hidden: entry.hidden,
|
|
||||||
// Location: entry.Location,
|
|
||||||
// };
|
|
||||||
// });
|
// });
|
||||||
});
|
}
|
||||||
// Promise.all(response).then((results) => {
|
// Promise.all(response).then((results) => {
|
||||||
// this.plexLibraries = results;
|
// this.plexLibraries = results;
|
||||||
// });
|
// });
|
||||||
return this.plexLibraries;
|
this.plexLibraries = libraryArray;
|
||||||
|
this.plexMusicLibraries = libraryArray.filter(
|
||||||
|
(Obj) => Obj.type === "artist"
|
||||||
|
);
|
||||||
|
this.plexMovieLibraries = libraryArray.filter(
|
||||||
|
(Obj) => Obj.type === "movie"
|
||||||
|
);
|
||||||
|
this.plexTVShowLibraries = libraryArray.filter(
|
||||||
|
(Obj) => Obj.type === "show"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// async PopulateLibraryContent(server: PlexServer, library: PlexLibrary) {
|
// async PopulateLibraryContent(server: PlexServer, library: PlexLibrary) {
|
||||||
|
|||||||
@@ -39,12 +39,20 @@ describe("Login Test", function () {
|
|||||||
console.log(PlexSession.plexServers);
|
console.log(PlexSession.plexServers);
|
||||||
});
|
});
|
||||||
it("Get Plex Libraries", async function () {
|
it("Get Plex Libraries", async function () {
|
||||||
//this.timeout(10000);
|
this.timeout(10000);
|
||||||
let response = await PlexSession.GetPlexLibraries();
|
let response = await PlexSession.GetPlexLibraries();
|
||||||
assert.notEqual(PlexSession.plexLibraries, null);
|
assert.notEqual(PlexSession.plexLibraries, null);
|
||||||
assert.notEqual(PlexSession.plexLibraries, undefined);
|
assert.notEqual(PlexSession.plexLibraries, undefined);
|
||||||
assert.notEqual(PlexSession.plexLibraries, emptyArray);
|
assert.notEqual(PlexSession.plexLibraries, emptyArray);
|
||||||
assert.notEqual(await response, null);
|
assert.notEqual(PlexSession.plexMusicLibraries, null);
|
||||||
|
assert.notEqual(PlexSession.plexMusicLibraries, undefined);
|
||||||
|
assert.notEqual(PlexSession.plexMusicLibraries, emptyArray);
|
||||||
|
assert.notEqual(PlexSession.plexMovieLibraries, null);
|
||||||
|
assert.notEqual(PlexSession.plexMovieLibraries, undefined);
|
||||||
|
assert.notEqual(PlexSession.plexMovieLibraries, emptyArray);
|
||||||
|
assert.notEqual(PlexSession.plexTVShowLibraries, null);
|
||||||
|
assert.notEqual(PlexSession.plexTVShowLibraries, undefined);
|
||||||
|
assert.notEqual(PlexSession.plexTVShowLibraries, emptyArray);
|
||||||
console.log("Plex Libraries");
|
console.log("Plex Libraries");
|
||||||
console.log(PlexSession.plexLibraries);
|
console.log(PlexSession.plexLibraries);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user