youtubei 1.8.0 → 1.8.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.
@@ -45,6 +45,7 @@ class MusicSearchResult extends MusicContinuable_1.MusicContinuable {
45
45
  /** @hidden */
46
46
  constructor({ client, type }) {
47
47
  super({ client });
48
+ this.top = null;
48
49
  if (type)
49
50
  this.type = type;
50
51
  }
@@ -70,6 +71,7 @@ class MusicSearchResult extends MusicContinuable_1.MusicContinuable {
70
71
  },
71
72
  });
72
73
  const { data, continuation } = MusicSearchResultParser_1.MusicSearchResultParser.parseInitialSearchResult(response.data, this.client);
74
+ this.top = MusicSearchResultParser_1.MusicSearchResultParser.parseTopResult(response.data, this.client) || null;
73
75
  this.items.push(...data);
74
76
  this.continuation = continuation;
75
77
  return this;
@@ -14,20 +14,16 @@ class MusicSearchResultParser {
14
14
  var _a, _b;
15
15
  const sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
16
16
  .sectionListRenderer.contents;
17
- const topContent = sectionContents.find((c) => "musicCardShelfRenderer" in c);
18
17
  const resultContents = sectionContents.find((c) => "musicShelfRenderer" in c);
19
- const topResult = this.parseTopResult(topContent, client);
20
18
  if (!resultContents) {
21
19
  // no results
22
20
  return {
23
- data: topResult ? [topResult] : [],
21
+ data: [],
24
22
  continuation: undefined,
25
23
  };
26
24
  }
27
25
  const { contents, continuations } = resultContents.musicShelfRenderer;
28
26
  const result = MusicSearchResultParser.parseSearchResult(contents, client);
29
- if (topResult)
30
- result.unshift(topResult);
31
27
  return {
32
28
  data: result,
33
29
  continuation: (_b = (_a = continuations === null || continuations === void 0 ? void 0 : continuations[0]) === null || _a === void 0 ? void 0 : _a.nextContinuationData) === null || _b === void 0 ? void 0 : _b.continuation,
@@ -41,9 +37,12 @@ class MusicSearchResultParser {
41
37
  };
42
38
  }
43
39
  static parseTopResult(data, client) {
44
- const top = data === null || data === void 0 ? void 0 : data.musicCardShelfRenderer;
40
+ const sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
41
+ .sectionListRenderer.contents;
42
+ const topContent = sectionContents.find((c) => "musicCardShelfRenderer" in c);
43
+ const top = topContent === null || topContent === void 0 ? void 0 : topContent.musicCardShelfRenderer;
45
44
  if (!top)
46
- return;
45
+ return null;
47
46
  const { browseEndpoint, watchEndpoint } = top.title.runs[0].navigationEndpoint;
48
47
  const id = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.videoId) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseId);
49
48
  const type = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType);
@@ -97,7 +96,18 @@ class MusicSearchResultParser {
97
96
  thumbnails: new common_1.Thumbnails().load(thumbnail),
98
97
  });
99
98
  }
100
- return topResult;
99
+ if (!topResult)
100
+ return null;
101
+ let more = [];
102
+ if (top.contents) {
103
+ more = top.contents
104
+ .filter((c) => c.musicResponsiveListItemRenderer)
105
+ .map((c) => this.parseSearchItem(c, client));
106
+ }
107
+ return {
108
+ item: topResult,
109
+ more,
110
+ };
101
111
  }
102
112
  static parseSearchResult(shelfContents, client) {
103
113
  const rawContents = shelfContents.filter((c) => "musicResponsiveListItemRenderer" in c);
@@ -104,6 +104,7 @@ var MusicSearchResult = /** @class */ (function (_super) {
104
104
  function MusicSearchResult(_a) {
105
105
  var client = _a.client, type = _a.type;
106
106
  var _this = _super.call(this, { client: client }) || this;
107
+ _this.top = null;
107
108
  if (type)
108
109
  _this.type = type;
109
110
  return _this;
@@ -136,6 +137,7 @@ var MusicSearchResult = /** @class */ (function (_super) {
136
137
  case 1:
137
138
  response = _c.sent();
138
139
  _a = MusicSearchResultParser.parseInitialSearchResult(response.data, this.client), data = _a.data, continuation = _a.continuation;
140
+ this.top = MusicSearchResultParser.parseTopResult(response.data, this.client) || null;
139
141
  (_b = this.items).push.apply(_b, __spread(data));
140
142
  this.continuation = continuation;
141
143
  return [2 /*return*/, this];
@@ -40,20 +40,16 @@ var MusicSearchResultParser = /** @class */ (function () {
40
40
  var _a, _b;
41
41
  var sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
42
42
  .sectionListRenderer.contents;
43
- var topContent = sectionContents.find(function (c) { return "musicCardShelfRenderer" in c; });
44
43
  var resultContents = sectionContents.find(function (c) { return "musicShelfRenderer" in c; });
45
- var topResult = this.parseTopResult(topContent, client);
46
44
  if (!resultContents) {
47
45
  // no results
48
46
  return {
49
- data: topResult ? [topResult] : [],
47
+ data: [],
50
48
  continuation: undefined,
51
49
  };
52
50
  }
53
51
  var _c = resultContents.musicShelfRenderer, contents = _c.contents, continuations = _c.continuations;
54
52
  var result = MusicSearchResultParser.parseSearchResult(contents, client);
55
- if (topResult)
56
- result.unshift(topResult);
57
53
  return {
58
54
  data: result,
59
55
  continuation: (_b = (_a = continuations === null || continuations === void 0 ? void 0 : continuations[0]) === null || _a === void 0 ? void 0 : _a.nextContinuationData) === null || _b === void 0 ? void 0 : _b.continuation,
@@ -67,9 +63,13 @@ var MusicSearchResultParser = /** @class */ (function () {
67
63
  };
68
64
  };
69
65
  MusicSearchResultParser.parseTopResult = function (data, client) {
70
- var top = data === null || data === void 0 ? void 0 : data.musicCardShelfRenderer;
66
+ var _this = this;
67
+ var sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
68
+ .sectionListRenderer.contents;
69
+ var topContent = sectionContents.find(function (c) { return "musicCardShelfRenderer" in c; });
70
+ var top = topContent === null || topContent === void 0 ? void 0 : topContent.musicCardShelfRenderer;
71
71
  if (!top)
72
- return;
72
+ return null;
73
73
  var _a = top.title.runs[0].navigationEndpoint, browseEndpoint = _a.browseEndpoint, watchEndpoint = _a.watchEndpoint;
74
74
  var id = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.videoId) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseId);
75
75
  var type = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType);
@@ -123,7 +123,18 @@ var MusicSearchResultParser = /** @class */ (function () {
123
123
  thumbnails: new Thumbnails().load(thumbnail),
124
124
  });
125
125
  }
126
- return topResult;
126
+ if (!topResult)
127
+ return null;
128
+ var more = [];
129
+ if (top.contents) {
130
+ more = top.contents
131
+ .filter(function (c) { return c.musicResponsiveListItemRenderer; })
132
+ .map(function (c) { return _this.parseSearchItem(c, client); });
133
+ }
134
+ return {
135
+ item: topResult,
136
+ more: more,
137
+ };
127
138
  };
128
139
  MusicSearchResultParser.parseSearchResult = function (shelfContents, client) {
129
140
  var e_1, _a;
@@ -36,6 +36,10 @@ declare type MusicLyricsProperties = MusicContinuableConstructorParams & {
36
36
  * @noInheritDoc
37
37
  */
38
38
  export declare class MusicSearchResult<T extends MusicSearchType = undefined> extends MusicContinuable<MusicSearchResultItem<T>> {
39
+ top: {
40
+ item: MusicSearchResultItem;
41
+ more: MusicSearchResultItem[];
42
+ } | null;
39
43
  private type;
40
44
  /** @hidden */
41
45
  constructor({ client, type }: MusicLyricsProperties);
@@ -10,7 +10,10 @@ declare type ParseReturnType = {
10
10
  export declare class MusicSearchResultParser {
11
11
  static parseInitialSearchResult(data: YoutubeRawData, client: MusicClient): ParseReturnType;
12
12
  static parseContinuationSearchResult(data: YoutubeRawData, client: MusicClient): ParseReturnType;
13
- private static parseTopResult;
13
+ static parseTopResult(data: YoutubeRawData, client: MusicClient): {
14
+ item: MusicSearchResultItem;
15
+ more: MusicSearchResultItem[];
16
+ } | null;
14
17
  private static parseSearchResult;
15
18
  private static parseSearchItem;
16
19
  static parseVideoItem(item: YoutubeRawData, pageType: string, client: MusicClient): MusicSongCompact | MusicVideoCompact | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "youtubei",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Simple package to get information from youtube such as videos, playlists, channels, video information & comments, related videos, up next video, and more!",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",