mirror of https://github.com/Chocobozzz/PeerTube
Load all playlist elements
parent
1a8c2d74d1
commit
fb13852d30
|
@ -143,8 +143,11 @@ export class PeerTubeEmbed {
|
|||
return fetch(this.getPlaylistUrl(playlistId))
|
||||
}
|
||||
|
||||
loadPlaylistElements (playlistId: string): Promise<Response> {
|
||||
return fetch(this.getPlaylistUrl(playlistId) + '/videos')
|
||||
loadPlaylistElements (playlistId: string, start = 0): Promise<Response> {
|
||||
const url = new URL(this.getPlaylistUrl(playlistId) + '/videos')
|
||||
url.search = new URLSearchParams({ start: '' + start, count: '100' }).toString()
|
||||
|
||||
return fetch(url.toString())
|
||||
}
|
||||
|
||||
loadConfig (): Promise<ServerConfig> {
|
||||
|
@ -257,6 +260,28 @@ export class PeerTubeEmbed {
|
|||
}
|
||||
}
|
||||
|
||||
private async loadAllPlaylistVideos (playlistId: string, baseResult: ResultList<VideoPlaylistElement>) {
|
||||
let elements = baseResult.data
|
||||
let total = baseResult.total
|
||||
let i = 0
|
||||
|
||||
while (total > elements.length && i < 10) {
|
||||
const result = await this.loadPlaylistElements(playlistId, elements.length)
|
||||
|
||||
const json = await result.json() as ResultList<VideoPlaylistElement>
|
||||
total = json.total
|
||||
|
||||
elements = elements.concat(json.data)
|
||||
i++
|
||||
}
|
||||
|
||||
if (i === 10) {
|
||||
console.error('Cannot fetch all playlists elements, there are too many!')
|
||||
}
|
||||
|
||||
return elements
|
||||
}
|
||||
|
||||
private async loadPlaylist (playlistId: string) {
|
||||
const playlistPromise = this.loadPlaylistInfo(playlistId)
|
||||
const playlistElementsPromise = this.loadPlaylistElements(playlistId)
|
||||
|
@ -534,7 +559,7 @@ export class PeerTubeEmbed {
|
|||
this.playlist = await res.playlistResponse.json()
|
||||
|
||||
const playlistElementResult = await res.videosResponse.json()
|
||||
this.playlistElements = playlistElementResult.data
|
||||
this.playlistElements = await this.loadAllPlaylistVideos(playlistId, playlistElementResult)
|
||||
|
||||
this.currentPlaylistElement = this.playlistElements[0]
|
||||
videoId = this.currentPlaylistElement.video.uuid
|
||||
|
|
Loading…
Reference in New Issue