-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.ts
170 lines (167 loc) · 4.33 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import * as HomePage from './lib/endpoints/HomePage'
import * as Playlist from './lib/endpoints/Playlist'
import * as Browsing from './lib/endpoints/Browsing'
import * as Browse from './lib/endpoints/Browse'
import { search } from './lib/endpoints/Search'
import { Player } from './lib/endpoints/Player'
import { getURLVideoID } from './lib/utils'
export class YTMUSIC {
userID?: string
authUser: number | undefined
constructor(
private cookie: string,
private args?: { userID: string; authUser?: number }
) {
this.cookie = cookie
if (args?.userID) {
this.userID = args.userID
}
if (args?.authUser) {
this.authUser = args.authUser
}
}
/**
* Returns First Part of HomePage
*
* @usage
*
* ```js
* const api = new YTMUSIC(cookie)
* const data = await api.getHomePage()
* ```
*
* You can call `data.continue()` to get next part
* @returns {@link HomePage}
*
*/
getHomePage = async () => {
return await HomePage.getHomePage(this.cookie, this)
}
getPlaylists = async () => {
return await Browse.getPlaylists(this.cookie, this)
}
getPlaylist = async (id: string, limit?: number) =>
await Playlist.getPlaylist(this.cookie, this, id, limit)
addToPlaylist = async (ids: string[], playlistId: string) =>
await Playlist.addToPlaylist(this.cookie, this, ids, playlistId)
/**
* Returns Full HomePage
*
* @usage
* ```js
* const api = new YTMUSIC(cookie)
* const data = await api.getFullHomePage()
* ```
* @returns {@link HomePage}
*
*/
getFullHomePage = async () => {
return await HomePage.getFullHomePage(this.cookie, this)
}
/**
* Search
*
* @usage
*
* ```js
* const api = new YTMUSIC(cookie)
* const data = await api.createPlaylist('Summer Songs', 'PUBLIC', 'Some songs for summer')
* const songs = await api.search('Hot stuff')
* await api.addToPlaylist([songs[0].id], playlist.id)
* ```
* @param query - Search query
* @param filter - What type to search
* @param max - maximum results (recommended 1-3, because next results might be unparsable) default: infinity
*
*/
search = async (
query: string,
options?: {
filter?: 'songs' | 'albums' | 'playlists' | 'videos' | 'artists'
max?: number
}
) => await search(this.cookie, this, query, options)
/**
* Create playlist
*
* @usage
*
* ```js
* const api = new YTMUSIC(cookie)
* const data = await api.createPlaylist('Summer Songs', 'PUBLIC', 'Some songs for summer')
* await api.addToPlaylist(['-mLpe7KUg9U', '5hFevwJ4JXI'], playlist.id)
* ```
* @param title - Title
* @param privacyStatus - Privacy Status of playlist
* @param description - Description of playlist
```
*/
createPlaylist = async (
title: string,
privacyStatus: 'PRIVATE' | 'PUBLIC' | 'UNLISTED',
description?: string
) =>
await Playlist.createPlaylist(
this.cookie,
this,
title,
privacyStatus,
description
)
/**
* Delete playlist
*
* @usage
*
* ```js
* const api = new YTMUSIC(cookie)
* const data = await api.createPlaylist('Summer Songs', 'PUBLIC', 'Some songs for summer')
* await api.deletePlaylist(playlist.id)
* ```
* @param id - id of the playlist
*/
deletePlaylist = async (id: string) =>
await Playlist.deletePlaylist(this.cookie, this, id)
/**
* Remove song(s) from playlist
*
* @usage
*
* ```js
* const api = new YTMUSIC(cookie)
* const data = await api.removeFromPlaylist(['-mLpe7KUg9U', '5hFevwJ4JXI'], 'RDAMVM5hFevwJ4JXI')
* ```
* @param ids - Array of song ids to remove
* @param playlistId - ID of playlist
```
*/
removeFromPlaylist = async (
ids: string[],
playlistId: string,
setVideoId?: string
) =>
await Playlist.removeFromPlaylist(
this.cookie,
this,
ids,
playlistId,
setVideoId
)
getArtist = async (channelId: string) =>
Browsing.getArtist(this.cookie, this, channelId)
/**
* Get song info
*
* @usage
*
* ```js
* const api = new YTMUSIC(cookie)
* const song = await api.getSongInfo('https://music.youtube.com/watch?v=DPXHMBKY39M&feature=share')
* console.log(song.title)
* ```
* @param url - Search query
*
*/
getSongInfo = async (url: string) =>
await Player(this.cookie, this, getURLVideoID(url))
}