@jjdenhertog/plex-music-search 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +110 -0
  2. package/actions/getAlbumTracks.d.ts +2 -0
  3. package/actions/getAlbumTracks.js +78 -0
  4. package/actions/getMetadata.d.ts +2 -0
  5. package/actions/getMetadata.js +80 -0
  6. package/actions/hubSearch.d.ts +2 -0
  7. package/actions/hubSearch.js +85 -0
  8. package/index.d.ts +16 -0
  9. package/index.js +403 -0
  10. package/package.json +39 -0
  11. package/types/PlexMusicSearchApproach.d.ts +7 -0
  12. package/types/PlexMusicSearchApproach.js +2 -0
  13. package/types/PlexMusicSearchConfig.d.ts +7 -0
  14. package/types/PlexMusicSearchConfig.js +2 -0
  15. package/types/PlexMusicSearchTrack.d.ts +6 -0
  16. package/types/PlexMusicSearchTrack.js +2 -0
  17. package/types/PlexTrack.d.ts +23 -0
  18. package/types/PlexTrack.js +2 -0
  19. package/types/SearchResponse.d.ts +8 -0
  20. package/types/SearchResponse.js +2 -0
  21. package/types/actions/HubSearchAlbumResult.d.ts +17 -0
  22. package/types/actions/HubSearchAlbumResult.js +2 -0
  23. package/types/actions/HubSearchResult.d.ts +3 -0
  24. package/types/actions/HubSearchResult.js +2 -0
  25. package/types/actions/HubSearchTrackResult.d.ts +23 -0
  26. package/types/actions/HubSearchTrackResult.js +2 -0
  27. package/types/actions/index.d.ts +3 -0
  28. package/types/actions/index.js +19 -0
  29. package/types/index.d.ts +7 -0
  30. package/types/index.js +23 -0
  31. package/types/plex/GetPlaylistResponse.d.ts +7 -0
  32. package/types/plex/GetPlaylistResponse.js +2 -0
  33. package/types/plex/GetPlexPinResponse.d.ts +25 -0
  34. package/types/plex/GetPlexPinResponse.js +2 -0
  35. package/types/plex/GetUserResponse.d.ts +60 -0
  36. package/types/plex/GetUserResponse.js +2 -0
  37. package/types/plex/Hub.d.ts +11 -0
  38. package/types/plex/Hub.js +2 -0
  39. package/types/plex/HubSearchResponse.d.ts +7 -0
  40. package/types/plex/HubSearchResponse.js +2 -0
  41. package/types/plex/Media.d.ts +10 -0
  42. package/types/plex/Media.js +2 -0
  43. package/types/plex/MediaPart.d.ts +9 -0
  44. package/types/plex/MediaPart.js +2 -0
  45. package/types/plex/Metadata.d.ts +38 -0
  46. package/types/plex/Metadata.js +2 -0
  47. package/types/plex/Playlist.d.ts +19 -0
  48. package/types/plex/Playlist.js +2 -0
  49. package/types/plex/PostPinResponse.d.ts +25 -0
  50. package/types/plex/PostPinResponse.js +2 -0
  51. package/types/plex/index.d.ts +10 -0
  52. package/types/plex/index.js +26 -0
  53. package/utils/AxiosRequest.d.ts +7 -0
  54. package/utils/AxiosRequest.js +55 -0
  55. package/utils/getAPIUrl.d.ts +1 -0
  56. package/utils/getAPIUrl.js +9 -0
  57. package/utils/searching/hubSearchToPlexTrack.d.ts +3 -0
  58. package/utils/searching/hubSearchToPlexTrack.js +25 -0
  59. package/utils/searching/searchForAlbum.d.ts +66 -0
  60. package/utils/searching/searchForAlbum.js +89 -0
  61. package/utils/searching/searchForAlbumTracks.d.ts +2 -0
  62. package/utils/searching/searchForAlbumTracks.js +75 -0
  63. package/utils/searching/searchForTrack.d.ts +1 -0
  64. package/utils/searching/searchForTrack.js +83 -0
  65. package/utils/searching/searchResultToTracks.d.ts +3 -0
  66. package/utils/searching/searchResultToTracks.js +13 -0
@@ -0,0 +1,25 @@
1
+ export type GetPlexPinResponse = {
2
+ id: number;
3
+ code: string;
4
+ product: string;
5
+ trusted: boolean;
6
+ qr: string;
7
+ clientIdentifier: string;
8
+ location: {
9
+ code: string;
10
+ european_union_member: boolean;
11
+ continent_code: string;
12
+ country: string;
13
+ city: string;
14
+ time_zone: string;
15
+ postal_code: string;
16
+ in_privacy_restricted_country: boolean;
17
+ subdivisions: string;
18
+ coordinates: string;
19
+ };
20
+ expiresIn: number;
21
+ createdAt: string;
22
+ expiresAt: string;
23
+ authToken: string;
24
+ newRegistration: boolean;
25
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,60 @@
1
+ export type GetUserResponse = {
2
+ id: number;
3
+ uuid: string;
4
+ username: string;
5
+ title: string;
6
+ email: string;
7
+ friendlyName: string;
8
+ locale: null;
9
+ confirmed: boolean;
10
+ joinedAt: number;
11
+ emailOnlyAuth: boolean;
12
+ hasPassword: boolean;
13
+ protected: boolean;
14
+ thumb: string;
15
+ authToken: string;
16
+ mailingListStatus: string;
17
+ mailingListActive: boolean;
18
+ scrobbleTypes: string;
19
+ country: string;
20
+ subscription: {
21
+ active: boolean;
22
+ subscribedAt: string;
23
+ status: string;
24
+ paymentService: string;
25
+ plan: string;
26
+ features: string[];
27
+ };
28
+ subscriptionDescription: string;
29
+ restricted: boolean;
30
+ anonymous: boolean;
31
+ home: boolean;
32
+ guest: boolean;
33
+ homeSize: number;
34
+ homeAdmin: boolean;
35
+ maxHomeSize: number;
36
+ rememberExpiresAt: number;
37
+ profile: {
38
+ autoSelectAudio: boolean;
39
+ defaultAudioLanguage: string;
40
+ defaultSubtitleLanguage: string;
41
+ autoSelectSubtitle: number;
42
+ defaultSubtitleAccessibility: number;
43
+ defaultSubtitleForced: number;
44
+ };
45
+ entitlements: string[];
46
+ roles: string[];
47
+ services: {
48
+ identifier: string;
49
+ endpoint: string;
50
+ token: string;
51
+ secret: null;
52
+ status: string;
53
+ }[];
54
+ adsConsent: null;
55
+ adsConsentSetAt: null;
56
+ adsConsentReminderAt: null;
57
+ experimentalFeatures: boolean;
58
+ twoFactorEnabled: boolean;
59
+ backupCodesCreated: boolean;
60
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { Metadata } from "./Metadata";
2
+ export type Hub = {
3
+ title: "Tracks" | "Shows" | "Artists" | "Albums" | "Episodes" | "Movies" | "Photo" | "Automatic" | "Photos" | "Tags" | "Actors" | "Directors" | "Genres" | "Collections" | "Playlists" | "Shared" | "Places";
4
+ type: "track" | "show" | "artist" | "album" | "episode" | "movie" | "photoalbum" | "autotag" | "photo" | "tag" | "actor" | "director" | "genre" | "collection" | "playlist" | "shared" | "place";
5
+ hubIdentifier: "track" | "show" | "artist" | "album" | "episode" | "movie" | "photoalbum" | "autotag" | "photo" | "tag" | "actor" | "director" | "genre" | "collection" | "playlist" | "shared" | "place";
6
+ context: string;
7
+ size: number;
8
+ more: boolean;
9
+ style: string;
10
+ Metadata: Metadata[];
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { Hub } from "./Hub";
2
+ export type HubSearchResponse = {
3
+ MediaContainer: {
4
+ size: number;
5
+ Hub: Hub[];
6
+ };
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { MediaPart } from "./MediaPart";
2
+ export type Media = {
3
+ id: number;
4
+ duration: number;
5
+ bitrate: number;
6
+ audioChannels: number;
7
+ audioCodec: string;
8
+ container: string;
9
+ Part: MediaPart[];
10
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export type MediaPart = {
2
+ id: number;
3
+ key: string;
4
+ duration: number;
5
+ file: string;
6
+ size: number;
7
+ container: string;
8
+ hasThumbnail: '1' | '0';
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ import { Media } from "./Media";
2
+ export type Metadata = {
3
+ librarySectionTitle: string;
4
+ score: number;
5
+ ratingKey: string;
6
+ year: number;
7
+ key: string;
8
+ parentRatingKey: string;
9
+ grandparentRatingKey: string;
10
+ guid: string;
11
+ originalTitle?: string;
12
+ parentGuid: string;
13
+ grandparentGuid: string;
14
+ parentStudio: string;
15
+ type: string;
16
+ title: string;
17
+ grandparentKey: string;
18
+ parentKey: string;
19
+ librarySectionID: 1;
20
+ librarySectionKey: string;
21
+ grandparentTitle: string;
22
+ parentTitle: string;
23
+ summary: string;
24
+ index: number;
25
+ parentIndex: number;
26
+ ratingCount: number;
27
+ parentYear: number;
28
+ thumb: string;
29
+ art: string;
30
+ parentThumb: string;
31
+ grandparentThumb: string;
32
+ grandparentArt: string;
33
+ duration: number;
34
+ addedAt: number;
35
+ updatedAt: number;
36
+ musicAnalysisVersion: string;
37
+ Media: Media[];
38
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ export type Playlist = {
2
+ ratingKey: string;
3
+ key: string;
4
+ guid: string;
5
+ type: string;
6
+ title: string;
7
+ titleSort: string;
8
+ summary: string;
9
+ smart: true;
10
+ playlistType: string;
11
+ composite: string;
12
+ icon: string;
13
+ viewCount: number;
14
+ lastViewedAt: number;
15
+ duration: number;
16
+ leafCount: number;
17
+ addedAt: number;
18
+ updatedAt: number;
19
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,25 @@
1
+ export type PostPinResponse = {
2
+ id: number;
3
+ code: string;
4
+ product: string;
5
+ trusted: boolean;
6
+ qr: string;
7
+ clientIdentifier: string;
8
+ location: {
9
+ code: string;
10
+ european_union_member: boolean;
11
+ continent_code: string;
12
+ country: string;
13
+ city: string;
14
+ time_zone: string;
15
+ postal_code: string;
16
+ in_privacy_restricted_country: boolean;
17
+ subdivisions: string;
18
+ coordinates: string;
19
+ };
20
+ expiresIn: number;
21
+ createdAt: string;
22
+ expiresAt: string;
23
+ authToken: string;
24
+ newRegistration: string;
25
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ export * from './GetPlaylistResponse';
2
+ export * from './GetPlexPinResponse';
3
+ export * from './GetUserResponse';
4
+ export * from './Hub';
5
+ export * from './HubSearchResponse';
6
+ export * from './Media';
7
+ export * from './MediaPart';
8
+ export * from './Metadata';
9
+ export * from './Playlist';
10
+ export * from './PostPinResponse';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./GetPlaylistResponse"), exports);
18
+ __exportStar(require("./GetPlexPinResponse"), exports);
19
+ __exportStar(require("./GetUserResponse"), exports);
20
+ __exportStar(require("./Hub"), exports);
21
+ __exportStar(require("./HubSearchResponse"), exports);
22
+ __exportStar(require("./Media"), exports);
23
+ __exportStar(require("./MediaPart"), exports);
24
+ __exportStar(require("./Metadata"), exports);
25
+ __exportStar(require("./Playlist"), exports);
26
+ __exportStar(require("./PostPinResponse"), exports);
@@ -0,0 +1,7 @@
1
+ import { AxiosRequestConfig } from "axios";
2
+ export declare const AxiosRequest: {
3
+ get<T>(url: string, token: string, config?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<T, any>>;
4
+ post<T>(url: string, token: string): Promise<import("axios").AxiosResponse<T, any>>;
5
+ put<T>(url: string, token: string): Promise<import("axios").AxiosResponse<T, any>>;
6
+ delete<T>(url: string, token: string): Promise<import("axios").AxiosResponse<T, any>>;
7
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AxiosRequest = void 0;
18
+ var axios_1 = __importDefault(require("axios"));
19
+ var node_https_1 = require("node:https");
20
+ var agent = new node_https_1.Agent({ rejectUnauthorized: false });
21
+ exports.AxiosRequest = {
22
+ get: function (url, token, config) {
23
+ if (config === void 0) { config = {}; }
24
+ return axios_1.default.get(url, __assign(__assign({}, config), { httpsAgent: agent, headers: {
25
+ "X-Plex-Token": token,
26
+ } }));
27
+ },
28
+ post: function (url, token) {
29
+ return axios_1.default.post(url, {}, {
30
+ httpsAgent: agent,
31
+ headers: {
32
+ 'Accept': 'application/json',
33
+ "X-Plex-Token": token,
34
+ }
35
+ });
36
+ },
37
+ put: function (url, token) {
38
+ return axios_1.default.put(url, {}, {
39
+ httpsAgent: agent,
40
+ headers: {
41
+ 'Accept': 'application/json',
42
+ "X-Plex-Token": token,
43
+ }
44
+ });
45
+ },
46
+ delete: function (url, token) {
47
+ return axios_1.default.delete(url, {
48
+ httpsAgent: agent,
49
+ headers: {
50
+ 'Accept': 'application/json',
51
+ "X-Plex-Token": token,
52
+ }
53
+ });
54
+ }
55
+ };
@@ -0,0 +1 @@
1
+ export default function getAPIUrl(uri: string, path: string): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getAPIUrl;
4
+ function getAPIUrl(uri, path) {
5
+ var url = new URL(uri);
6
+ if (!(url === null || url === void 0 ? void 0 : url.port))
7
+ throw new Error("The link to the Plex seems invalid. The port number might be missing");
8
+ return "".concat(url.protocol, "//").concat(url.host).concat(path);
9
+ }
@@ -0,0 +1,3 @@
1
+ import { HubSearchResult } from "../../types/actions/HubSearchResult";
2
+ import { PlexTrack } from "../../types/PlexTrack";
3
+ export default function hubSearchToPlexTrack(item: HubSearchResult): PlexTrack;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.default = hubSearchToPlexTrack;
15
+ function hubSearchToPlexTrack(item) {
16
+ return {
17
+ id: item.id,
18
+ guid: item.guid,
19
+ image: item.image,
20
+ title: item.title,
21
+ src: 'tbd',
22
+ album: item.type == 'track' ? __assign({}, item.album) : undefined,
23
+ artist: __assign({}, item.artist)
24
+ };
25
+ }
@@ -0,0 +1,66 @@
1
+ export declare function searchForAlbum(uri: string, token: string, artist: string, album: string, artistMatch?: {
2
+ contain: boolean;
3
+ similarity: number;
4
+ }): Promise<({
5
+ matching: {
6
+ album: {
7
+ match: boolean;
8
+ contains: boolean;
9
+ similarity: number;
10
+ };
11
+ artist: {
12
+ match: boolean;
13
+ contains: boolean;
14
+ similarity: number;
15
+ };
16
+ };
17
+ id: string;
18
+ type: "album";
19
+ ratingKey: string;
20
+ guid: string;
21
+ score: number;
22
+ image: string;
23
+ year: number;
24
+ title: string;
25
+ artist: {
26
+ guid: string;
27
+ id: string;
28
+ title: string;
29
+ alternative_title: string;
30
+ image: string;
31
+ };
32
+ } | {
33
+ matching: {
34
+ album: {
35
+ match: boolean;
36
+ contains: boolean;
37
+ similarity: number;
38
+ };
39
+ artist: {
40
+ match: boolean;
41
+ contains: boolean;
42
+ similarity: number;
43
+ };
44
+ };
45
+ type: "track";
46
+ id: string;
47
+ ratingKey: string;
48
+ guid: string;
49
+ score: number;
50
+ image: string;
51
+ title: string;
52
+ src?: string;
53
+ album: {
54
+ guid: string;
55
+ id: string;
56
+ title: string;
57
+ year: number;
58
+ image: string;
59
+ };
60
+ artist: {
61
+ guid: string;
62
+ id: string;
63
+ title: string;
64
+ image: string;
65
+ };
66
+ })[]>;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.searchForAlbum = searchForAlbum;
54
+ var music_search_1 = require("@jjdenhertog/music-search");
55
+ var hubSearch_1 = __importDefault(require("../../actions/hubSearch"));
56
+ // eslint-disable-next-line unicorn/no-object-as-default-parameter
57
+ function searchForAlbum(uri_1, token_1, artist_1, album_1) {
58
+ return __awaiter(this, arguments, void 0, function (uri, token, artist, album, artistMatch) {
59
+ var hubSearchResult, foundAlbums;
60
+ if (artistMatch === void 0) { artistMatch = { similarity: 0.6, contain: true }; }
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0: return [4 /*yield*/, (0, hubSearch_1.default)(uri, token, album, 10)];
64
+ case 1:
65
+ hubSearchResult = _a.sent();
66
+ foundAlbums = hubSearchResult.map(function (item) {
67
+ return __assign(__assign({}, item), { matching: {
68
+ album: (0, music_search_1.compareTitles)(item.title, album),
69
+ artist: (0, music_search_1.compareTitles)(item.artist.title, artist)
70
+ } });
71
+ });
72
+ return [2 /*return*/, foundAlbums.filter(function (item) {
73
+ if (item.type != "album")
74
+ return false;
75
+ if (item.matching.album.match && (item.matching.artist.match ||
76
+ item.matching.artist.similarity >= artistMatch.similarity ||
77
+ (item.matching.artist.contains && artistMatch.contain))) {
78
+ return true;
79
+ }
80
+ return false;
81
+ }).sort(function (a, b) {
82
+ var aMatches = a.matching.artist.similarity + a.matching.album.similarity;
83
+ var bMatches = b.matching.artist.similarity + b.matching.album.similarity;
84
+ return bMatches - aMatches;
85
+ })];
86
+ }
87
+ });
88
+ });
89
+ }
@@ -0,0 +1,2 @@
1
+ import { HubSearchResult } from "../../types/actions/HubSearchResult";
2
+ export declare function searchForAlbumTracks(uri: string, token: string, artist: string, _track: string, album: string): Promise<HubSearchResult[]>;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.searchForAlbumTracks = searchForAlbumTracks;
43
+ var getAlbumTracks_1 = __importDefault(require("../../actions/getAlbumTracks"));
44
+ var searchForAlbum_1 = require("./searchForAlbum");
45
+ function searchForAlbumTracks(uri, token, artist, _track, album) {
46
+ return __awaiter(this, void 0, void 0, function () {
47
+ var foundAlbums, results, i, foundAlbum, trackResult;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4 /*yield*/, (0, searchForAlbum_1.searchForAlbum)(uri, token, artist, album)];
51
+ case 1:
52
+ foundAlbums = _a.sent();
53
+ results = [];
54
+ i = 0;
55
+ _a.label = 2;
56
+ case 2:
57
+ if (!(i < foundAlbums.length)) return [3 /*break*/, 5];
58
+ foundAlbum = foundAlbums[i];
59
+ if (!foundAlbum) return [3 /*break*/, 4];
60
+ return [4 /*yield*/, (0, getAlbumTracks_1.default)(uri, token, foundAlbum.id)];
61
+ case 3:
62
+ trackResult = _a.sent();
63
+ trackResult.forEach(function (item) {
64
+ if (results.filter(function (existingItem) { return existingItem.guid == item.guid; }).length == 0)
65
+ results.push(item);
66
+ });
67
+ _a.label = 4;
68
+ case 4:
69
+ i++;
70
+ return [3 /*break*/, 2];
71
+ case 5: return [2 /*return*/, results];
72
+ }
73
+ });
74
+ });
75
+ }
@@ -0,0 +1 @@
1
+ export declare function searchForTrack(uri: string, token: string, artist: string, track: string, _album?: string): Promise<import("../..").HubSearchResult[]>;