parent
57c1c37dcd
commit
efb17791e6
|
|
@ -226,6 +226,10 @@ export default defineUserConfig({
|
|||
text: "AlbumFull",
|
||||
link: "/references/interfaces/AlbumFull.html"
|
||||
},
|
||||
{
|
||||
text: "PlaylistDetailed",
|
||||
link: "/references/interfaces/PlaylistDetailed.html"
|
||||
},
|
||||
{
|
||||
text: "PlaylistFull",
|
||||
link: "/references/interfaces/PlaylistFull.html"
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@
|
|||
- [AlbumBasic](./interfaces/AlbumBasic.html)
|
||||
- [AlbumDetailed](./interfaces/AlbumDetailed.html)
|
||||
- [AlbumFull](./interfaces/AlbumFull.html)
|
||||
- [PlaylistDetailed](./interfaces/PlaylistDetailed.html)
|
||||
- [PlaylistFull](./interfaces/PlaylistFull.html)
|
||||
|
|
|
|||
|
|
@ -24,4 +24,6 @@ interface ArtistBasic {
|
|||
|
||||
[AlbumDetailed#artists](./AlbumDetailed.html)
|
||||
|
||||
[PlaylistDetailed#artist](./PlaylistDetailed.html)
|
||||
|
||||
[PlaylistFull#artist](./PlaylistFull.html)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
# PlaylistDetailed
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Data Type | Description |
|
||||
| :--------- | :---------------------------------- | :------------------------------- |
|
||||
| type | `"PLAYLIST"` | Type of data |
|
||||
| playlistId | `string` | Playlist ID |
|
||||
| name | `string` | Name |
|
||||
| artist | [ArtistBasic](#ArtistBasic) | Creator of the Playlist |
|
||||
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
|
||||
|
||||
## TypeScript Source Code
|
||||
|
||||
```ts
|
||||
interface PlaylistDetailed {
|
||||
type: "PLAYLIST"
|
||||
playlistId: string
|
||||
name: string
|
||||
artist: ArtistBasic
|
||||
thumbnails: ThumbnailFull[]
|
||||
}
|
||||
```
|
||||
|
||||
## Usages
|
||||
|
||||
[SearchResult](../types/SearchResult.html)
|
||||
|
||||
[YTMusic#searchPlaylists](../ytmusic/searchPlaylists.html)
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
| playlistId | `string` | Playlist ID |
|
||||
| name | `string` | Name |
|
||||
| artist | [ArtistBasic](#ArtistBasic) | Creator of the Playlist |
|
||||
| videoCount | `number` | Number of videos in the Playlist |
|
||||
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
|
||||
|
||||
## TypeScript Source Code
|
||||
|
|
@ -18,14 +19,11 @@ interface PlaylistFull {
|
|||
playlistId: string
|
||||
name: string
|
||||
artist: ArtistBasic
|
||||
videoCount: number
|
||||
thumbnails: ThumbnailFull[]
|
||||
}
|
||||
```
|
||||
|
||||
## Usages
|
||||
|
||||
[SearchResult](../types/SearchResult.html)
|
||||
|
||||
[YTMusic#searchPlaylists](../ytmusic/searchPlaylists.html)
|
||||
|
||||
[YTMusic#getPlaylist](../ytmusic/getPlaylist.html)
|
||||
|
|
|
|||
|
|
@ -28,4 +28,6 @@ interface ThumbnailFull {
|
|||
|
||||
[AlbumDetailed#thumbnails](./AlbumDetailed.html)
|
||||
|
||||
[PlaylistDetailed#thumbnails](./PlaylistDetailed.html)
|
||||
|
||||
[PlaylistFull#thumbnails](./PlaylistFull.html)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Either
|
|||
- [VideoDetailed](../interfaces/VideoDetailed.html)
|
||||
- [AlbumDetailed](../interfaces/AlbumDetailed.html)
|
||||
- [ArtistDetailed](../interfaces/ArtistDetailed.html)
|
||||
- [PlaylistFull](../interfaces/PlaylistFull.html)
|
||||
- [PlaylistDetailed](../interfaces/PlaylistDetailed.html)
|
||||
|
||||
## TypeScript Source Code
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ type SearchResult =
|
|||
| VideoDetailed
|
||||
| AlbumDetailed
|
||||
| ArtistDetailed
|
||||
| PlaylistFull
|
||||
| PlaylistDetailed
|
||||
```
|
||||
|
||||
## Usages
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ See the [guide](../../guides/usage/searchPlaylists.html) for information on how
|
|||
|
||||
## Returns
|
||||
|
||||
`Promise<`[PlaylistFull](../interfaces/PlaylistFull.html)`[]>`
|
||||
`Promise<`[PlaylistDetailed](../interfaces/PlaylistDetailed.html)`[]>`
|
||||
|
||||
## TypeScript Source Code
|
||||
|
||||
```ts
|
||||
public async searchPlaylists(query: string): Promise<PlaylistFull[]>
|
||||
public async searchPlaylists(query: string): Promise<PlaylistDetailed[]>
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ytmusic-api",
|
||||
"version": "4.2.0",
|
||||
"version": "4.3.0",
|
||||
"description": "YouTube Music API",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import {
|
|||
AlbumFull,
|
||||
ArtistDetailed,
|
||||
ArtistFull,
|
||||
PlaylistDetailed,
|
||||
PlaylistFull,
|
||||
SearchResult,
|
||||
SongDetailed,
|
||||
|
|
@ -305,7 +306,7 @@ export default class YTMusic {
|
|||
*
|
||||
* @param query Query string
|
||||
*/
|
||||
public async searchPlaylists(query: string): Promise<z.infer<typeof PlaylistFull>[]> {
|
||||
public async searchPlaylists(query: string): Promise<z.infer<typeof PlaylistDetailed>[]> {
|
||||
const searchData = await this.constructRequest("search", {
|
||||
query,
|
||||
params: "Eg-KAQwIABAAGAAgACgBMABqChAEEAMQCRAFEAo%3D",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {
|
|||
AlbumFull,
|
||||
ArtistDetailed,
|
||||
ArtistFull,
|
||||
PlaylistDetailed,
|
||||
PlaylistFull,
|
||||
SongDetailed,
|
||||
SongFull,
|
||||
|
|
@ -57,7 +58,7 @@ queries.forEach(query => {
|
|||
|
||||
it("Search Playlists", async () => {
|
||||
const playlists = await ytmusic.searchPlaylists(query)
|
||||
expect(playlists, z.array(PlaylistFull))
|
||||
expect(playlists, z.array(PlaylistDetailed))
|
||||
})
|
||||
|
||||
it("Search All", async () => {
|
||||
|
|
@ -66,7 +67,7 @@ queries.forEach(query => {
|
|||
results,
|
||||
z.array(
|
||||
AlbumDetailed.or(ArtistDetailed)
|
||||
.or(PlaylistFull)
|
||||
.or(PlaylistDetailed)
|
||||
.or(SongDetailed)
|
||||
.or(VideoDetailed),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export type {
|
|||
ArtistBasic,
|
||||
ArtistDetailed,
|
||||
ArtistFull,
|
||||
PlaylistDetailed,
|
||||
PlaylistFull,
|
||||
SearchResult,
|
||||
SongDetailed,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { PlaylistFull } from "../schemas"
|
||||
import { PlaylistDetailed, PlaylistFull } from "../schemas"
|
||||
import checkType from "../utils/checkType"
|
||||
import traverseList from "../utils/traverseList"
|
||||
import traverseString from "../utils/traverseString"
|
||||
|
|
@ -14,13 +14,19 @@ export default class PlaylistParser {
|
|||
artistId: traverseString(data, "header", "subtitle", "browseId")(),
|
||||
name: traverseString(data, "header", "subtitle", "text")(2),
|
||||
},
|
||||
videoCount:
|
||||
+traverseList(data, "header", "secondSubtitle", "text")
|
||||
.at(2)
|
||||
.split(" ")
|
||||
.at(0)
|
||||
.replaceAll(",", "") ?? null,
|
||||
thumbnails: traverseList(data, "header", "thumbnails"),
|
||||
},
|
||||
PlaylistFull,
|
||||
)
|
||||
}
|
||||
|
||||
public static parseSearchResult(item: any): PlaylistFull {
|
||||
public static parseSearchResult(item: any): PlaylistDetailed {
|
||||
const flexColumns = traverseList(item, "flexColumns")
|
||||
|
||||
return checkType(
|
||||
|
|
@ -34,7 +40,7 @@ export default class PlaylistParser {
|
|||
},
|
||||
thumbnails: traverseList(item, "thumbnails"),
|
||||
},
|
||||
PlaylistFull,
|
||||
PlaylistDetailed,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,15 @@ export const AlbumDetailed = z.object({
|
|||
thumbnails: z.array(ThumbnailFull),
|
||||
})
|
||||
|
||||
export type PlaylistDetailed = z.infer<typeof PlaylistDetailed>
|
||||
export const PlaylistDetailed = z.object({
|
||||
type: z.literal("PLAYLIST"),
|
||||
playlistId: z.string(),
|
||||
name: z.string(),
|
||||
artist: ArtistBasic,
|
||||
thumbnails: z.array(ThumbnailFull),
|
||||
})
|
||||
|
||||
export type SongFull = z.infer<typeof SongFull>
|
||||
export const SongFull = z.object({
|
||||
type: z.literal("SONG"),
|
||||
|
|
@ -119,6 +128,7 @@ export const PlaylistFull = z.object({
|
|||
playlistId: z.string(),
|
||||
name: z.string(),
|
||||
artist: ArtistBasic,
|
||||
videoCount: z.number(),
|
||||
thumbnails: z.array(ThumbnailFull),
|
||||
})
|
||||
|
||||
|
|
@ -126,4 +136,4 @@ export type SearchResult = z.infer<typeof SearchResult>
|
|||
export const SearchResult = SongDetailed.or(VideoDetailed)
|
||||
.or(AlbumDetailed)
|
||||
.or(ArtistDetailed)
|
||||
.or(PlaylistFull)
|
||||
.or(PlaylistDetailed)
|
||||
|
|
|
|||
Loading…
Reference in New Issue