youtubei 1.2.0 → 1.3.0

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 (55) hide show
  1. package/dist/cjs/music/MusicClient/MusicClient.js +13 -13
  2. package/dist/cjs/music/MusicClient/index.js +0 -1
  3. package/dist/cjs/music/MusicContinuable/MusicContinuable.js +43 -0
  4. package/dist/cjs/music/MusicContinuable/index.js +13 -0
  5. package/dist/cjs/music/{MusicClient/MusicSearchResultParser.js → MusicSearchResult/MusicAllSearchResultParser.js} +29 -22
  6. package/dist/cjs/music/MusicSearchResult/MusicSearchResult.js +92 -0
  7. package/dist/cjs/music/MusicSearchResult/MusicSearchResultParser.js +34 -0
  8. package/dist/cjs/music/MusicSearchResult/index.js +15 -0
  9. package/dist/cjs/music/MusicSearchResult/proto/MusicSearchProto.js +2 -0
  10. package/dist/cjs/music/MusicSearchResult/proto/index.js +35 -0
  11. package/dist/cjs/youtube/BaseChannel/ChannelLive.js +3 -3
  12. package/dist/cjs/youtube/BaseChannel/ChannelShorts.js +7 -7
  13. package/dist/cjs/youtube/BaseChannel/index.js +2 -0
  14. package/dist/cjs/youtube/BaseVideo/BaseVideoParser.js +1 -1
  15. package/dist/cjs/youtube/Client/Client.js +1 -1
  16. package/dist/cjs/youtube/Playlist/PlaylistParser.js +2 -1
  17. package/dist/cjs/youtube/SearchResult/SearchResult.js +1 -1
  18. package/dist/cjs/youtube/SearchResult/proto/index.js +5 -5
  19. package/dist/cjs/youtube/Transcript/proto/TranscriptParamsProto.js +3 -3
  20. package/dist/esm/music/MusicClient/MusicClient.js +15 -14
  21. package/dist/esm/music/MusicClient/index.js +0 -1
  22. package/dist/esm/music/MusicContinuable/MusicContinuable.js +125 -0
  23. package/dist/esm/music/MusicContinuable/index.js +1 -0
  24. package/dist/esm/music/{MusicClient/MusicSearchResultParser.js → MusicSearchResult/MusicAllSearchResultParser.js} +27 -24
  25. package/dist/esm/music/MusicSearchResult/MusicSearchResult.js +169 -0
  26. package/dist/esm/music/MusicSearchResult/MusicSearchResultParser.js +56 -0
  27. package/dist/esm/music/MusicSearchResult/index.js +3 -0
  28. package/dist/esm/music/MusicSearchResult/proto/MusicSearchProto.js +1 -0
  29. package/dist/esm/music/MusicSearchResult/proto/index.js +15 -0
  30. package/dist/esm/youtube/BaseChannel/ChannelLive.js +3 -3
  31. package/dist/esm/youtube/BaseChannel/ChannelShorts.js +7 -7
  32. package/dist/esm/youtube/BaseChannel/index.js +2 -0
  33. package/dist/esm/youtube/BaseVideo/BaseVideoParser.js +1 -1
  34. package/dist/esm/youtube/Client/Client.js +1 -1
  35. package/dist/esm/youtube/Playlist/PlaylistParser.js +3 -2
  36. package/dist/esm/youtube/SearchResult/SearchResult.js +1 -1
  37. package/dist/esm/youtube/SearchResult/proto/index.js +2 -2
  38. package/dist/esm/youtube/Transcript/proto/TranscriptParamsProto.js +2 -2
  39. package/dist/typings/music/MusicBaseArtist/MusicBaseArtist.d.ts +1 -1
  40. package/dist/typings/music/MusicClient/MusicClient.d.ts +2 -0
  41. package/dist/typings/music/MusicClient/index.d.ts +0 -1
  42. package/dist/typings/music/MusicContinuable/MusicContinuable.d.ts +24 -0
  43. package/dist/typings/music/MusicContinuable/index.d.ts +1 -0
  44. package/dist/typings/music/{MusicClient/MusicSearchResultParser.d.ts → MusicSearchResult/MusicAllSearchResultParser.d.ts} +4 -3
  45. package/dist/typings/music/MusicSearchResult/MusicSearchResult.d.ts +46 -0
  46. package/dist/typings/music/MusicSearchResult/MusicSearchResultParser.d.ts +13 -0
  47. package/dist/typings/music/MusicSearchResult/index.d.ts +3 -0
  48. package/dist/typings/music/MusicSearchResult/proto/MusicSearchProto.d.ts +14 -0
  49. package/dist/typings/music/MusicSearchResult/proto/index.d.ts +5 -0
  50. package/dist/typings/youtube/BaseChannel/ChannelLive.d.ts +4 -4
  51. package/dist/typings/youtube/BaseChannel/ChannelShorts.d.ts +8 -8
  52. package/dist/typings/youtube/BaseChannel/index.d.ts +2 -0
  53. package/dist/typings/youtube/SearchResult/proto/index.d.ts +2 -41
  54. package/dist/typings/youtube/Transcript/proto/TranscriptParamsProto.d.ts +2 -11
  55. package/package.json +2 -2
@@ -0,0 +1,125 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (_) try {
30
+ 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;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ var __read = (this && this.__read) || function (o, n) {
51
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
52
+ if (!m) return o;
53
+ var i = m.call(o), r, ar = [], e;
54
+ try {
55
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
56
+ }
57
+ catch (error) { e = { error: error }; }
58
+ finally {
59
+ try {
60
+ if (r && !r.done && (m = i["return"])) m.call(i);
61
+ }
62
+ finally { if (e) throw e.error; }
63
+ }
64
+ return ar;
65
+ };
66
+ var __spread = (this && this.__spread) || function () {
67
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
68
+ return ar;
69
+ };
70
+ import { MusicBase } from "../MusicBase";
71
+ /** Represents a continuable list of items `T` (like pagination) */
72
+ var MusicContinuable = /** @class */ (function (_super) {
73
+ __extends(MusicContinuable, _super);
74
+ /** @hidden */
75
+ function MusicContinuable(_a) {
76
+ var client = _a.client, strictContinuationCheck = _a.strictContinuationCheck;
77
+ var _this = _super.call(this, client) || this;
78
+ _this.items = [];
79
+ _this.strictContinuationCheck = !!strictContinuationCheck;
80
+ if (_this.strictContinuationCheck)
81
+ _this.continuation = null;
82
+ return _this;
83
+ }
84
+ /** Fetch next items using continuation token */
85
+ MusicContinuable.prototype.next = function (count) {
86
+ if (count === void 0) { count = 1; }
87
+ return __awaiter(this, void 0, void 0, function () {
88
+ var newItems, i, _a, items, continuation;
89
+ var _b;
90
+ return __generator(this, function (_c) {
91
+ switch (_c.label) {
92
+ case 0:
93
+ newItems = [];
94
+ i = 0;
95
+ _c.label = 1;
96
+ case 1:
97
+ if (!(i < count || count == 0)) return [3 /*break*/, 4];
98
+ if (!this.hasContinuation)
99
+ return [3 /*break*/, 4];
100
+ return [4 /*yield*/, this.fetch()];
101
+ case 2:
102
+ _a = _c.sent(), items = _a.items, continuation = _a.continuation;
103
+ this.continuation = continuation;
104
+ newItems.push.apply(newItems, __spread(items));
105
+ _c.label = 3;
106
+ case 3:
107
+ i++;
108
+ return [3 /*break*/, 1];
109
+ case 4:
110
+ (_b = this.items).push.apply(_b, __spread(newItems));
111
+ return [2 /*return*/, newItems];
112
+ }
113
+ });
114
+ });
115
+ };
116
+ Object.defineProperty(MusicContinuable.prototype, "hasContinuation", {
117
+ get: function () {
118
+ return this.strictContinuationCheck ? this.continuation !== undefined : !!this.continuation;
119
+ },
120
+ enumerable: false,
121
+ configurable: true
122
+ });
123
+ return MusicContinuable;
124
+ }(MusicBase));
125
+ export { MusicContinuable };
@@ -0,0 +1 @@
1
+ export * from "./MusicContinuable";
@@ -22,10 +22,10 @@ import { MusicBaseChannel } from "../MusicBaseChannel";
22
22
  import { MusicPlaylistCompact } from "../MusicPlaylistCompact";
23
23
  import { MusicSongCompact } from "../MusicSongCompact";
24
24
  import { MusicVideoCompact } from "../MusicVideoCompact";
25
- var MusicSearchResultParser = /** @class */ (function () {
26
- function MusicSearchResultParser() {
25
+ var MusicAllSearchResultParser = /** @class */ (function () {
26
+ function MusicAllSearchResultParser() {
27
27
  }
28
- MusicSearchResultParser.parseSearchResult = function (data, client) {
28
+ MusicAllSearchResultParser.parseSearchResult = function (data, client) {
29
29
  var sectionListContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
30
30
  .sectionListRenderer.contents;
31
31
  var shelves = sectionListContents
@@ -34,11 +34,11 @@ var MusicSearchResultParser = /** @class */ (function () {
34
34
  return shelves.map(function (m) { return ({
35
35
  title: m.title.runs.map(function (r) { return r.text; }).join(),
36
36
  items: m.contents.map(function (c) {
37
- return MusicSearchResultParser.parseSearchItem(c, client);
37
+ return MusicAllSearchResultParser.parseSearchItem(c, client);
38
38
  }),
39
39
  }); });
40
40
  };
41
- MusicSearchResultParser.parseSearchItem = function (content, client) {
41
+ MusicAllSearchResultParser.parseSearchItem = function (content, client) {
42
42
  var _a;
43
43
  var item = content.musicResponsiveListItemRenderer;
44
44
  var playEndpoint = (_a = item.overlay) === null || _a === void 0 ? void 0 : _a.musicItemThumbnailOverlayRenderer.content.musicPlayButtonRenderer.playNavigationEndpoint;
@@ -47,25 +47,25 @@ var MusicSearchResultParser = /** @class */ (function () {
47
47
  .watchEndpointMusicConfig.musicVideoType;
48
48
  if (pageType === "MUSIC_VIDEO_TYPE_PODCAST_EPISODE")
49
49
  return;
50
- return MusicSearchResultParser.parseVideoItem(item, pageType, client);
50
+ return MusicAllSearchResultParser.parseVideoItem(item, pageType, client);
51
51
  }
52
52
  else if (playEndpoint === null || playEndpoint === void 0 ? void 0 : playEndpoint.watchPlaylistEndpoint.params) {
53
- return MusicSearchResultParser.parsePlaylistItem(item, client);
53
+ return MusicAllSearchResultParser.parsePlaylistItem(item, client);
54
54
  }
55
55
  else if (playEndpoint === null || playEndpoint === void 0 ? void 0 : playEndpoint.watchPlaylistEndpoint) {
56
- return MusicSearchResultParser.parseAlbumItem(item, client);
56
+ return MusicAllSearchResultParser.parseAlbumItem(item, client);
57
57
  }
58
58
  else {
59
- return MusicSearchResultParser.parseArtistItem(item, client);
59
+ return MusicAllSearchResultParser.parseArtistItem(item, client);
60
60
  }
61
61
  };
62
- MusicSearchResultParser.parseVideoItem = function (item, pageType, client) {
62
+ MusicAllSearchResultParser.parseVideoItem = function (item, pageType, client) {
63
63
  var _a = __read(item.flexColumns.map(function (c) { return c.musicResponsiveListItemFlexColumnRenderer.text.runs; }), 2), topColumn = _a[0], bottomColumn = _a[1];
64
64
  var id = topColumn[0].navigationEndpoint.watchEndpoint.videoId;
65
65
  var title = topColumn[0].text;
66
66
  var duration = getDuration(bottomColumn.at(-1).text) || undefined;
67
67
  var thumbnails = new Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
68
- var artists = MusicSearchResultParser.parseArtists(bottomColumn, client);
68
+ var artists = MusicAllSearchResultParser.parseArtists(bottomColumn, client);
69
69
  if (pageType === "MUSIC_VIDEO_TYPE_ATV") {
70
70
  var rawAlbum = bottomColumn.find(function (r) {
71
71
  var _a;
@@ -92,59 +92,62 @@ var MusicSearchResultParser = /** @class */ (function () {
92
92
  return new MusicVideoCompact({ client: client, id: id, title: title, artists: artists, thumbnails: thumbnails, duration: duration });
93
93
  }
94
94
  };
95
- MusicSearchResultParser.parsePlaylistItem = function (item, client) {
95
+ MusicAllSearchResultParser.parsePlaylistItem = function (item, client) {
96
96
  var _a = __read(item.flexColumns.map(function (c) { return c.musicResponsiveListItemFlexColumnRenderer.text.runs; }), 2), topColumn = _a[0], bottomColumn = _a[1];
97
97
  var id = item.overlay.musicItemThumbnailOverlayRenderer.content.musicPlayButtonRenderer
98
98
  .playNavigationEndpoint.watchPlaylistEndpoint.playlistId;
99
99
  var title = topColumn[0].text;
100
100
  var songCount = stripToInt(bottomColumn.at(-1).text) || undefined;
101
101
  var thumbnails = new Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
102
- var channel = MusicSearchResultParser.parseChannel(bottomColumn, client);
102
+ var channel = MusicAllSearchResultParser.parseChannel(bottomColumn, client);
103
103
  return new MusicPlaylistCompact({ client: client, id: id, title: title, thumbnails: thumbnails, songCount: songCount, channel: channel });
104
104
  };
105
- MusicSearchResultParser.parseAlbumItem = function (item, client) {
105
+ MusicAllSearchResultParser.parseAlbumItem = function (item, client) {
106
106
  var _a = __read(item.flexColumns.map(function (c) { return c.musicResponsiveListItemFlexColumnRenderer.text.runs; }), 2), topColumn = _a[0], bottomColumn = _a[1];
107
107
  var id = item.overlay.musicItemThumbnailOverlayRenderer.content.musicPlayButtonRenderer
108
108
  .playNavigationEndpoint.watchPlaylistEndpoint.playlistId;
109
109
  var title = topColumn[0].text;
110
110
  var year = stripToInt(bottomColumn.at(-1).text) || undefined;
111
111
  var thumbnails = new Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
112
- var artists = MusicSearchResultParser.parseArtists(bottomColumn, client);
112
+ var artists = MusicAllSearchResultParser.parseArtists(bottomColumn, client);
113
113
  return new MusicAlbumCompact({ client: client, id: id, title: title, thumbnails: thumbnails, artists: artists, year: year });
114
114
  };
115
- MusicSearchResultParser.parseArtistItem = function (item, client) {
115
+ MusicAllSearchResultParser.parseArtistItem = function (item, client) {
116
116
  var _a = __read(item.flexColumns.map(function (c) { return c.musicResponsiveListItemFlexColumnRenderer.text.runs; }), 1), topColumn = _a[0];
117
117
  var id = item.navigationEndpoint.browseEndpoint.browseId;
118
118
  var name = topColumn[0].text;
119
119
  var thumbnails = new Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
120
120
  return new MusicArtistCompact({ client: client, id: id, name: name, thumbnails: thumbnails });
121
121
  };
122
- MusicSearchResultParser.parseArtists = function (items, client) {
122
+ MusicAllSearchResultParser.parseArtists = function (items, client) {
123
123
  return this.parseArtistOrChannel(items).map(function (r) {
124
+ var _a;
124
125
  return new MusicBaseArtist({
125
126
  client: client,
126
127
  name: r.text,
127
- id: r.navigationEndpoint.browseEndpoint.browseId,
128
+ id: (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
128
129
  });
129
130
  });
130
131
  };
131
- MusicSearchResultParser.parseChannel = function (items, client) {
132
+ MusicAllSearchResultParser.parseChannel = function (items, client) {
132
133
  var _a = __read(this.parseArtistOrChannel(items).map(function (r) {
134
+ var _a;
133
135
  return new MusicBaseChannel({
134
136
  client: client,
135
137
  name: r.text,
136
- id: r.navigationEndpoint.browseEndpoint.browseId,
138
+ id: (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
137
139
  });
138
140
  }), 1), channel = _a[0];
139
141
  return channel;
140
142
  };
141
- MusicSearchResultParser.parseArtistOrChannel = function (items) {
142
- return items.filter(function (r) {
143
+ MusicAllSearchResultParser.parseArtistOrChannel = function (items) {
144
+ var contents = items.filter(function (r) {
143
145
  var _a;
144
146
  var pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
145
147
  return (pageType === "MUSIC_PAGE_TYPE_ARTIST" || pageType === "MUSIC_PAGE_TYPE_USER_CHANNEL");
146
148
  });
149
+ return !contents.length && items[0] ? [items[0]] : contents;
147
150
  };
148
- return MusicSearchResultParser;
151
+ return MusicAllSearchResultParser;
149
152
  }());
150
- export { MusicSearchResultParser };
153
+ export { MusicAllSearchResultParser };
@@ -0,0 +1,169 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (_) try {
30
+ 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;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ var __read = (this && this.__read) || function (o, n) {
51
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
52
+ if (!m) return o;
53
+ var i = m.call(o), r, ar = [], e;
54
+ try {
55
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
56
+ }
57
+ catch (error) { e = { error: error }; }
58
+ finally {
59
+ try {
60
+ if (r && !r.done && (m = i["return"])) m.call(i);
61
+ }
62
+ finally { if (e) throw e.error; }
63
+ }
64
+ return ar;
65
+ };
66
+ var __spread = (this && this.__spread) || function () {
67
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
68
+ return ar;
69
+ };
70
+ import { MusicContinuable, } from "../MusicContinuable";
71
+ import { I_END_POINT } from "../constants";
72
+ import { MusicSearchResultParser } from "./MusicSearchResultParser";
73
+ import { MusicSearchProto, optionsToProto } from "./proto";
74
+ export var MusicSearchTypeEnum;
75
+ (function (MusicSearchTypeEnum) {
76
+ MusicSearchTypeEnum["Song"] = "song";
77
+ MusicSearchTypeEnum["Video"] = "video";
78
+ })(MusicSearchTypeEnum || (MusicSearchTypeEnum = {}));
79
+ /**
80
+ * Represents search result, usually returned from `client.search();`.
81
+ *
82
+ * {@link MusicSearchResult} is a helper class to manage search result
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const result = await music.search("Keyword", "song");
87
+ *
88
+ * console.log(result.items); // search result from first page
89
+ *
90
+ * let nextSearchResult = await result.next();
91
+ * console.log(nextSearchResult); // search result from second page
92
+ *
93
+ * nextSearchResult = await result.next();
94
+ * console.log(nextSearchResult); // search result from third page
95
+ *
96
+ * console.log(result.items); // search result from first, second, and third page.
97
+ * ```
98
+ *
99
+ * @noInheritDoc
100
+ */
101
+ var MusicSearchResult = /** @class */ (function (_super) {
102
+ __extends(MusicSearchResult, _super);
103
+ /** @hidden */
104
+ function MusicSearchResult(_a) {
105
+ var client = _a.client;
106
+ return _super.call(this, { client: client }) || this;
107
+ }
108
+ /**
109
+ * Initialize data from search
110
+ *
111
+ * @param query Search query
112
+ * @param options Search Options
113
+ *
114
+ * @hidden
115
+ */
116
+ MusicSearchResult.prototype.search = function (query, type) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var bufferParams, response, _a, data, continuation;
119
+ var _b;
120
+ return __generator(this, function (_c) {
121
+ switch (_c.label) {
122
+ case 0:
123
+ this.items = [];
124
+ bufferParams = MusicSearchProto.encode(optionsToProto(type)).finish();
125
+ return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
126
+ data: {
127
+ query: query,
128
+ params: Buffer.from(bufferParams).toString("base64"),
129
+ },
130
+ })];
131
+ case 1:
132
+ response = _c.sent();
133
+ _a = MusicSearchResultParser.parseInitialSearchResult(response.data, type, this.client), data = _a.data, continuation = _a.continuation;
134
+ (_b = this.items).push.apply(_b, __spread(data));
135
+ this.continuation = continuation;
136
+ return [2 /*return*/, this];
137
+ }
138
+ });
139
+ });
140
+ };
141
+ MusicSearchResult.prototype.fetch = function () {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var response, _a, data, continuation;
144
+ return __generator(this, function (_b) {
145
+ switch (_b.label) {
146
+ case 0:
147
+ if (!this.type) {
148
+ return [2 /*return*/, {
149
+ items: [],
150
+ continuation: undefined,
151
+ }];
152
+ }
153
+ return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
154
+ data: { continuation: this.continuation },
155
+ })];
156
+ case 1:
157
+ response = _b.sent();
158
+ _a = MusicSearchResultParser.parseContinuationSearchResult(response.data, this.type, this.client), data = _a.data, continuation = _a.continuation;
159
+ return [2 /*return*/, {
160
+ items: data,
161
+ continuation: continuation,
162
+ }];
163
+ }
164
+ });
165
+ });
166
+ };
167
+ return MusicSearchResult;
168
+ }(MusicContinuable));
169
+ export { MusicSearchResult };
@@ -0,0 +1,56 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import { MusicAllSearchResultParser } from "./MusicAllSearchResultParser";
13
+ var MusicSearchResultParser = /** @class */ (function () {
14
+ function MusicSearchResultParser() {
15
+ }
16
+ MusicSearchResultParser.parseInitialSearchResult = function (data, type, client) {
17
+ var _a, _b;
18
+ var _c = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].musicShelfRenderer, contents = _c.contents, continuations = _c.continuations;
19
+ return {
20
+ data: MusicSearchResultParser.parseSearchResult(contents, type, client),
21
+ continuation: (_b = (_a = continuations[0]) === null || _a === void 0 ? void 0 : _a.nextContinuationData) === null || _b === void 0 ? void 0 : _b.continuation,
22
+ };
23
+ };
24
+ MusicSearchResultParser.parseContinuationSearchResult = function (data, type, client) {
25
+ var shelf = data.continuationContents.musicShelfContinuation;
26
+ return {
27
+ data: MusicSearchResultParser.parseSearchResult(shelf.contents, type, client),
28
+ continuation: shelf.continuations[0].nextContinuationData.continuation,
29
+ };
30
+ };
31
+ MusicSearchResultParser.parseSearchResult = function (shelfContents, type, client) {
32
+ var e_1, _a;
33
+ var rawContents = shelfContents
34
+ .filter(function (c) { return "musicResponsiveListItemRenderer" in c; })
35
+ .map(function (c) { return c.musicResponsiveListItemRenderer; });
36
+ var contents = [];
37
+ try {
38
+ for (var rawContents_1 = __values(rawContents), rawContents_1_1 = rawContents_1.next(); !rawContents_1_1.done; rawContents_1_1 = rawContents_1.next()) {
39
+ var c = rawContents_1_1.value;
40
+ var parsed = MusicAllSearchResultParser.parseVideoItem(c, type === "video" ? "MUSIC_VIDEO_TYPE_UGC" : "MUSIC_VIDEO_TYPE_ATV", client);
41
+ if (parsed)
42
+ contents.push(parsed);
43
+ }
44
+ }
45
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
46
+ finally {
47
+ try {
48
+ if (rawContents_1_1 && !rawContents_1_1.done && (_a = rawContents_1.return)) _a.call(rawContents_1);
49
+ }
50
+ finally { if (e_1) throw e_1.error; }
51
+ }
52
+ return contents;
53
+ };
54
+ return MusicSearchResultParser;
55
+ }());
56
+ export { MusicSearchResultParser };
@@ -0,0 +1,3 @@
1
+ export * from "./MusicAllSearchResultParser";
2
+ export * from "./MusicSearchResult";
3
+ export * from "./MusicSearchResultParser";
@@ -0,0 +1,15 @@
1
+ import protobuf from "protobufjs";
2
+ // TODO move this to .proto file
3
+ export var MusicSearchProto = protobuf
4
+ .parse("\n\tmessage MusicSearchOptions {\n\t\tmessage Options {\n\t\t\toptional int32 song = 1;\n\t\t\toptional int32 video = 2;\n\t\t}\n\n\t\tmessage Params {\n\t\t\toptional Options options = 17;\n\t\t}\n\n\t\toptional Params params = 2;\n\t}\n")
5
+ .root.lookupType("MusicSearchOptions");
6
+ export var optionsToProto = function (type) {
7
+ return {
8
+ params: {
9
+ options: {
10
+ song: type === "song" ? 1 : undefined,
11
+ video: type === "video" ? 1 : undefined,
12
+ },
13
+ },
14
+ };
15
+ };
@@ -61,11 +61,11 @@ import { BaseChannelParser } from "./BaseChannelParser";
61
61
  * await channel.live.next();
62
62
  * console.log(channel.live.items) // first 30 live videos
63
63
  *
64
- * let newVideos = await channel.videos.next();
65
- * console.log(newVideos) // 30 loaded videos
64
+ * let newLives = await channel.videos.next();
65
+ * console.log(newLives) // 30 loaded live videos
66
66
  * console.log(channel.live.items) // first 60 live videos
67
67
  *
68
- * await channel.live.next(0); // load the rest of the videos in the channel
68
+ * await channel.live.next(0); // load the rest of the live videos in the channel
69
69
  * ```
70
70
  */
71
71
  var ChannelLive = /** @class */ (function (_super) {
@@ -53,19 +53,19 @@ import { VideoCompact } from "../VideoCompact";
53
53
  import { I_END_POINT } from "../constants";
54
54
  import { BaseChannelParser } from "./BaseChannelParser";
55
55
  /**
56
- * {@link Continuable} of videos inside a {@link BaseChannel}
56
+ * {@link Continuable} of shorts inside a {@link BaseChannel}
57
57
  *
58
58
  * @example
59
59
  * ```js
60
60
  * const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
61
- * await channel.videos.next();
62
- * console.log(channel.videos.items) // first 30 videos
61
+ * await channel.short.next();
62
+ * console.log(channel.short.items) // first 30 shorts
63
63
  *
64
- * let newVideos = await channel.videos.next();
65
- * console.log(newVideos) // 30 loaded videos
66
- * console.log(channel.videos.items) // first 60 videos
64
+ * let newShorts = await channel.short.next();
65
+ * console.log(newShorts) // 30 loaded shorts
66
+ * console.log(channel.short.items) // first 60 shorts
67
67
  *
68
- * await channel.videos.next(0); // load the rest of the videos in the channel
68
+ * await channel.short.next(0); // load the rest of the shorts in the channel
69
69
  * ```
70
70
  */
71
71
  var ChannelShorts = /** @class */ (function (_super) {
@@ -1,4 +1,6 @@
1
1
  export * from "./BaseChannel";
2
2
  export * from "./BaseChannelParser";
3
+ export * from "./ChannelLive";
3
4
  export * from "./ChannelPlaylists";
5
+ export * from "./ChannelShorts";
4
6
  export * from "./ChannelVideos";
@@ -41,7 +41,7 @@ var BaseVideoParser = /** @class */ (function () {
41
41
  // Tags and description
42
42
  target.tags =
43
43
  ((_b = (_a = videoInfo.superTitleLink) === null || _a === void 0 ? void 0 : _a.runs) === null || _b === void 0 ? void 0 : _b.map(function (r) { return r.text.trim(); }).filter(function (t) { return t; })) || [];
44
- target.description = videoInfo.shortDescription || "";
44
+ target.description = videoInfo.videoDetails.shortDescription || "";
45
45
  // related videos
46
46
  var secondaryContents = data[3].response.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults
47
47
  .results;
@@ -178,7 +178,7 @@ var Client = /** @class */ (function () {
178
178
  return __generator(this, function (_a) {
179
179
  switch (_a.label) {
180
180
  case 0:
181
- bufferParams = TranscriptParamsProto.TranscriptParams.encode({ videoId: videoId });
181
+ bufferParams = TranscriptParamsProto.encode({ videoId: videoId }).finish();
182
182
  return [4 /*yield*/, this.http.post(I_END_POINT + "/get_transcript", {
183
183
  data: { params: Buffer.from(bufferParams).toString("base64") },
184
184
  })];
@@ -24,7 +24,8 @@ var PlaylistParser = /** @class */ (function () {
24
24
  target.id = (_a = Object.values(metadata)
25
25
  .find(function (v) { return v.includes("playlist?list="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1];
26
26
  target.title = metadata.title;
27
- target.thumbnails = new Thumbnails().load(primaryRenderer.thumbnailRenderer.playlistVideoThumbnailRenderer.thumbnail.thumbnails);
27
+ var _d = primaryRenderer.thumbnailRenderer, playlistVideoThumbnailRenderer = _d.playlistVideoThumbnailRenderer, playlistCustomThumbnailRenderer = _d.playlistCustomThumbnailRenderer;
28
+ target.thumbnails = new Thumbnails().load((playlistVideoThumbnailRenderer || playlistCustomThumbnailRenderer).thumbnail.thumbnails);
28
29
  var stats = primaryRenderer.stats;
29
30
  if (primaryRenderer.stats.length === 3) {
30
31
  target.videoCount = PlaylistParser.parseSideBarInfo(stats[0], true);
@@ -41,7 +42,7 @@ var PlaylistParser = /** @class */ (function () {
41
42
  // Channel
42
43
  var videoOwner = (_c = sidebarRenderer[1]) === null || _c === void 0 ? void 0 : _c.playlistSidebarSecondaryInfoRenderer.videoOwner;
43
44
  if (videoOwner) {
44
- var _d = videoOwner.videoOwnerRenderer, title = _d.title, thumbnail = _d.thumbnail;
45
+ var _e = videoOwner.videoOwnerRenderer, title = _e.title, thumbnail = _e.thumbnail;
45
46
  target.channel = new BaseChannel({
46
47
  id: title.runs[0].navigationEndpoint.browseEndpoint.browseId,
47
48
  name: title.runs[0].text,
@@ -165,7 +165,7 @@ var SearchResult = /** @class */ (function (_super) {
165
165
  case 0:
166
166
  this.items = [];
167
167
  this.estimatedResults = 0;
168
- bufferParams = SearchProto.SearchOptions.encode(optionsToProto(options));
168
+ bufferParams = SearchProto.encode(optionsToProto(options)).finish();
169
169
  return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
170
170
  data: {
171
171
  query: query,
@@ -9,9 +9,9 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import proto from "protocol-buffers";
12
+ import protobuf from "protobufjs";
13
13
  // TODO move this to .proto file
14
- export var SearchProto = proto("\n\tmessage SearchOptions {\n\t\tmessage Options {\n\t\t\toptional int32 uploadDate = 1;\n\t\t\toptional int32 type = 2;\n\t\t\toptional int32 duration = 3;\n\t\t\toptional int32 hd = 4;\n\t\t\toptional int32 subtitles = 5;\n\t\t\toptional int32 creativeCommons = 6;\n\t\t\toptional int32 live = 8;\n\t\t\toptional int32 4k = 14;\n\t\t\toptional int32 360 = 15;\n\t\t\toptional int32 location = 23;\n\t\t\toptional int32 hdr = 25;\n\t\t\toptional int32 vr180 = 26;\n\t\t}\n\n\t\toptional int32 sortBy = 1;\n\t\toptional Options options = 2;\n\t}\n");
14
+ export var SearchProto = protobuf.parse("\n\tmessage SearchOptions {\n\t\tmessage Options {\n\t\t\toptional int32 uploadDate = 1;\n\t\t\toptional int32 type = 2;\n\t\t\toptional int32 duration = 3;\n\t\t\toptional int32 hd = 4;\n\t\t\toptional int32 subtitles = 5;\n\t\t\toptional int32 creativeCommons = 6;\n\t\t\toptional int32 live = 8;\n\t\t\toptional int32 _4k = 14;\n\t\t\toptional int32 _360 = 15;\n\t\t\toptional int32 location = 23;\n\t\t\toptional int32 hdr = 25;\n\t\t\toptional int32 vr180 = 26;\n\t\t}\n\n\t\toptional int32 sortBy = 1;\n\t\toptional Options options = 2;\n\t}\n").root.lookupType("SearchOptions");
15
15
  var searchUploadDateProto = {
16
16
  all: 0,
17
17
  hour: 1,
@@ -1,2 +1,2 @@
1
- import proto from "protocol-buffers";
2
- export var TranscriptParamsProto = proto("\n\tmessage TranscriptParams {\n\t\toptional string videoId = 1;\n\t}\n");
1
+ import protobuf from "protobufjs";
2
+ export var TranscriptParamsProto = protobuf.parse("\n\tmessage TranscriptParams {\n\t\toptional string videoId = 1;\n\t}\n").root.lookupType("TranscriptParams");
@@ -5,7 +5,7 @@ export interface MusicBaseArtistProperties extends MusicBaseProperties {
5
5
  name?: string;
6
6
  }
7
7
  export declare class MusicBaseArtist extends MusicBase implements MusicBaseArtistProperties {
8
- id: string;
8
+ id?: string;
9
9
  /** The name of this artist */
10
10
  name: string;
11
11
  /** @hidden */