MCPcopy Create free account
hub / github.com/DialmasterOrg/Youtarr / getLibrariesWithParams

Method getLibrariesWithParams

server/modules/plexModule.js:114–159  ·  view source on GitHub ↗
(plexIP, plexApiKey, plexPort, plexViaHttps)

Source from the content-addressed store, hash-verified

112 }
113
114 async getLibrariesWithParams(plexIP, plexApiKey, plexPort, plexViaHttps) {
115 try {
116 if (!plexApiKey) {
117 logger.warn('Missing Plex API key');
118 return [];
119 }
120
121 const config = configModule.getConfig();
122 const baseUrl = this.getBaseUrl(plexIP, config, plexPort, plexViaHttps);
123
124 if (!baseUrl) {
125 logger.warn('Missing Plex server URL');
126 return [];
127 }
128
129 logger.info(`Attempting to fetch Plex libraries via URL: ${baseUrl}`);
130
131 const response = await axios.get(
132 `${baseUrl}/library/sections?X-Plex-Token=${plexApiKey}`,
133 { timeout: PLEX_REQUEST_TIMEOUT_MS }
134 );
135
136 const libraries = response.data.MediaContainer.Directory.map(
137 (directory) => ({
138 id: directory.key,
139 title: directory.title,
140 locations: directory.Location.map((location) => ({
141 // map the Location array
142 id: location.id,
143 path: location.path,
144 })),
145 })
146 );
147
148 return libraries;
149 } catch (error) {
150 logger.error({ err: error }, 'Failed to get Plex libraries');
151 if (error.code === 'ECONNREFUSED') {
152 logger.warn('Could not connect to Plex server - returning empty library list');
153 } else if (error.code === 'ECONNABORTED') {
154 logger.warn('Plex request timed out - returning empty library list');
155 }
156 // Return empty array instead of throwing to prevent frontend crashes
157 return [];
158 }
159 }
160
161 // Reads /identity to determine whether the Plex server is claimed by a Plex
162 // account. Used by the UI to warn that an unclaimed server needs the

Callers 3

getLibrariesMethod · 0.95
plexModule.test.jsFile · 0.80
plex.jsFile · 0.80

Calls 2

getBaseUrlMethod · 0.95
getConfigMethod · 0.80

Tested by

no test coverage detected