Compare commits
2 Commits
196614955d
...
93fa5b0666
Author | SHA1 | Date |
---|---|---|
Arthur POULET | 93fa5b0666 | |
Thibaut Broggi | f13fa72672 |
|
@ -85,14 +85,10 @@ class PlaylistsManager {
|
|||
|
||||
async import({ message, params }) {
|
||||
const [playlist_title, query] = params
|
||||
try {
|
||||
const playlist = await youtube_instance.get_playlist(query)
|
||||
this.#playlists[playlist_title] = playlist
|
||||
await PlaylistsManager.writeFile(this.#filepath, this.#playlists)
|
||||
message.channel.send(`:white_check_mark: Playlist \`${playlist_title}\` imported`)
|
||||
} catch (err) {
|
||||
message.channel.send(`:warning: Cannot import ${query}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class Youtube {
|
|||
* @returns {Playlist}
|
||||
*/
|
||||
async get_playlist(playlist_query) {
|
||||
const playlist_id = playlist_query.match(/list=(\w+)/)?.[1] || playlist
|
||||
const playlist_id = playlist_query.match(/list=([\w-]+)/)?.[1] || playlist_query
|
||||
const req = await fetch(`https://www.youtube.com/playlist?list=${playlist_id}`)
|
||||
const body = await req.text()
|
||||
const json = JSON.parse(body.match(/ytInitialData = (.*);<\/script>/)[1])
|
||||
|
@ -46,7 +46,7 @@ class Youtube {
|
|||
const results = json.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].playlistVideoListRenderer.contents
|
||||
|
||||
const tracks = results
|
||||
.filter(video => video.playlistVideoRenderer.lengthText)
|
||||
.filter(video => video?.playlistVideoRenderer?.lengthText)
|
||||
.map((video) => new Track({
|
||||
title: video.playlistVideoRenderer.title.runs[0].text,
|
||||
url: 'https://www.youtube.com/watch?v=' + video.playlistVideoRenderer.videoId,
|
||||
|
|
Loading…
Reference in New Issue