@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.
- package/README.md +110 -0
- package/actions/getAlbumTracks.d.ts +2 -0
- package/actions/getAlbumTracks.js +78 -0
- package/actions/getMetadata.d.ts +2 -0
- package/actions/getMetadata.js +80 -0
- package/actions/hubSearch.d.ts +2 -0
- package/actions/hubSearch.js +85 -0
- package/index.d.ts +16 -0
- package/index.js +403 -0
- package/package.json +39 -0
- package/types/PlexMusicSearchApproach.d.ts +7 -0
- package/types/PlexMusicSearchApproach.js +2 -0
- package/types/PlexMusicSearchConfig.d.ts +7 -0
- package/types/PlexMusicSearchConfig.js +2 -0
- package/types/PlexMusicSearchTrack.d.ts +6 -0
- package/types/PlexMusicSearchTrack.js +2 -0
- package/types/PlexTrack.d.ts +23 -0
- package/types/PlexTrack.js +2 -0
- package/types/SearchResponse.d.ts +8 -0
- package/types/SearchResponse.js +2 -0
- package/types/actions/HubSearchAlbumResult.d.ts +17 -0
- package/types/actions/HubSearchAlbumResult.js +2 -0
- package/types/actions/HubSearchResult.d.ts +3 -0
- package/types/actions/HubSearchResult.js +2 -0
- package/types/actions/HubSearchTrackResult.d.ts +23 -0
- package/types/actions/HubSearchTrackResult.js +2 -0
- package/types/actions/index.d.ts +3 -0
- package/types/actions/index.js +19 -0
- package/types/index.d.ts +7 -0
- package/types/index.js +23 -0
- package/types/plex/GetPlaylistResponse.d.ts +7 -0
- package/types/plex/GetPlaylistResponse.js +2 -0
- package/types/plex/GetPlexPinResponse.d.ts +25 -0
- package/types/plex/GetPlexPinResponse.js +2 -0
- package/types/plex/GetUserResponse.d.ts +60 -0
- package/types/plex/GetUserResponse.js +2 -0
- package/types/plex/Hub.d.ts +11 -0
- package/types/plex/Hub.js +2 -0
- package/types/plex/HubSearchResponse.d.ts +7 -0
- package/types/plex/HubSearchResponse.js +2 -0
- package/types/plex/Media.d.ts +10 -0
- package/types/plex/Media.js +2 -0
- package/types/plex/MediaPart.d.ts +9 -0
- package/types/plex/MediaPart.js +2 -0
- package/types/plex/Metadata.d.ts +38 -0
- package/types/plex/Metadata.js +2 -0
- package/types/plex/Playlist.d.ts +19 -0
- package/types/plex/Playlist.js +2 -0
- package/types/plex/PostPinResponse.d.ts +25 -0
- package/types/plex/PostPinResponse.js +2 -0
- package/types/plex/index.d.ts +10 -0
- package/types/plex/index.js +26 -0
- package/utils/AxiosRequest.d.ts +7 -0
- package/utils/AxiosRequest.js +55 -0
- package/utils/getAPIUrl.d.ts +1 -0
- package/utils/getAPIUrl.js +9 -0
- package/utils/searching/hubSearchToPlexTrack.d.ts +3 -0
- package/utils/searching/hubSearchToPlexTrack.js +25 -0
- package/utils/searching/searchForAlbum.d.ts +66 -0
- package/utils/searching/searchForAlbum.js +89 -0
- package/utils/searching/searchForAlbumTracks.d.ts +2 -0
- package/utils/searching/searchForAlbumTracks.js +75 -0
- package/utils/searching/searchForTrack.d.ts +1 -0
- package/utils/searching/searchForTrack.js +83 -0
- package/utils/searching/searchResultToTracks.d.ts +3 -0
- package/utils/searching/searchResultToTracks.js +13 -0
@@ -0,0 +1,83 @@
|
|
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.searchForTrack = searchForTrack;
|
43
|
+
var hubSearch_1 = __importDefault(require("../../actions/hubSearch"));
|
44
|
+
function searchForTrack(uri_1, token_1, artist_1, track_1) {
|
45
|
+
return __awaiter(this, arguments, void 0, function (uri, token, artist, track, _album) {
|
46
|
+
var search, searchResult, alternativeSearchResult, alternativeSearchResult, alternative, alternativeSearchResult;
|
47
|
+
if (_album === void 0) { _album = ''; }
|
48
|
+
return __generator(this, function (_a) {
|
49
|
+
switch (_a.label) {
|
50
|
+
case 0:
|
51
|
+
search = "".concat(artist, " ").concat(track);
|
52
|
+
return [4 /*yield*/, (0, hubSearch_1.default)(uri, token, search, 20)];
|
53
|
+
case 1:
|
54
|
+
searchResult = _a.sent();
|
55
|
+
return [4 /*yield*/, (0, hubSearch_1.default)(uri, token, track, 50)];
|
56
|
+
case 2:
|
57
|
+
alternativeSearchResult = _a.sent();
|
58
|
+
alternativeSearchResult.forEach(function (item) {
|
59
|
+
if (searchResult.filter(function (existingItem) { return existingItem.guid == item.guid; }).length == 0)
|
60
|
+
searchResult.push(item);
|
61
|
+
});
|
62
|
+
return [4 /*yield*/, (0, hubSearch_1.default)(uri, token, artist, 50)];
|
63
|
+
case 3:
|
64
|
+
alternativeSearchResult = _a.sent();
|
65
|
+
alternativeSearchResult.forEach(function (item) {
|
66
|
+
if (searchResult.filter(function (existingItem) { return existingItem.guid == item.guid; }).length == 0)
|
67
|
+
searchResult.push(item);
|
68
|
+
});
|
69
|
+
if (!(track.indexOf(':') > -1)) return [3 /*break*/, 5];
|
70
|
+
alternative = track.slice(Math.max(0, track.indexOf(':') + 1));
|
71
|
+
return [4 /*yield*/, (0, hubSearch_1.default)(uri, token, alternative, 50)];
|
72
|
+
case 4:
|
73
|
+
alternativeSearchResult = _a.sent();
|
74
|
+
alternativeSearchResult.forEach(function (item) {
|
75
|
+
if (searchResult.filter(function (existingItem) { return existingItem.guid == item.guid; }).length == 0)
|
76
|
+
searchResult.push(item);
|
77
|
+
});
|
78
|
+
_a.label = 5;
|
79
|
+
case 5: return [2 /*return*/, searchResult];
|
80
|
+
}
|
81
|
+
});
|
82
|
+
});
|
83
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = searchResultToTracks;
|
4
|
+
function searchResultToTracks(items) {
|
5
|
+
return items
|
6
|
+
.filter(function (item) { return item.type != 'album'; })
|
7
|
+
.map(function (item) { return ({
|
8
|
+
id: item.id,
|
9
|
+
artist: item.artist.title,
|
10
|
+
title: item.title,
|
11
|
+
album: item.album.title
|
12
|
+
}); });
|
13
|
+
}
|