mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Add playlistUrl metadata in json to hls files
This commit is contained in:
parent
7895697ce1
commit
eaf6fccbbb
5 changed files with 31 additions and 4 deletions
|
@ -11,5 +11,5 @@ export interface VideoStreamingPlaylist {
|
||||||
baseUrl: string
|
baseUrl: string
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
files: VideoFile[]
|
files: (VideoFile & { playlistUrl: string })[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,6 +257,8 @@ export async function completeCheckHlsPlaylist (options: {
|
||||||
expect(file.magnetUri).to.have.lengthOf.above(2)
|
expect(file.magnetUri).to.have.lengthOf.above(2)
|
||||||
await checkWebTorrentWorks(file.magnetUri)
|
await checkWebTorrentWorks(file.magnetUri)
|
||||||
|
|
||||||
|
expect(file.playlistUrl).to.equal(file.fileUrl.replace(/-fragmented.mp4$/, '.m3u8'))
|
||||||
|
|
||||||
{
|
{
|
||||||
const nameReg = `${uuidRegex}-${file.resolution.id}`
|
const nameReg = `${uuidRegex}-${file.resolution.id}`
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ export async function completeWebVideoFilesCheck (options: {
|
||||||
expect(file.id).to.exist
|
expect(file.id).to.exist
|
||||||
expect(file.magnetUri).to.have.lengthOf.above(2)
|
expect(file.magnetUri).to.have.lengthOf.above(2)
|
||||||
|
|
||||||
|
expect((file as any).playlistUrl).to.not.exist
|
||||||
|
|
||||||
if (server.internalServerNumber === originServer.internalServerNumber) {
|
if (server.internalServerNumber === originServer.internalServerNumber) {
|
||||||
if (objectStorageBaseUrl) {
|
if (objectStorageBaseUrl) {
|
||||||
expect(file.storage).to.equal(FileStorage.OBJECT_STORAGE)
|
expect(file.storage).to.equal(FileStorage.OBJECT_STORAGE)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
import { uuidToShort } from '@peertube/peertube-node-utils'
|
import { uuidToShort } from '@peertube/peertube-node-utils'
|
||||||
import { generateMagnetUri } from '@server/helpers/webtorrent.js'
|
import { generateMagnetUri } from '@server/helpers/webtorrent.js'
|
||||||
import { tracer } from '@server/lib/opentelemetry/tracing.js'
|
import { tracer } from '@server/lib/opentelemetry/tracing.js'
|
||||||
|
import { getHlsResolutionPlaylistFilename } from '@server/lib/paths.js'
|
||||||
import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls.js'
|
import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls.js'
|
||||||
import { VideoViewsManager } from '@server/lib/views/video-views-manager.js'
|
import { VideoViewsManager } from '@server/lib/views/video-views-manager.js'
|
||||||
import { isArray } from '../../../helpers/custom-validators/misc.js'
|
import { isArray } from '../../../helpers/custom-validators/misc.js'
|
||||||
|
@ -202,18 +203,30 @@ export function streamingPlaylistsModelToFormattedJSON (
|
||||||
? playlist.RedundancyVideos.map(r => ({ baseUrl: r.fileUrl }))
|
? playlist.RedundancyVideos.map(r => ({ baseUrl: r.fileUrl }))
|
||||||
: [],
|
: [],
|
||||||
|
|
||||||
files: videoFilesModelToFormattedJSON(video, playlist.VideoFiles)
|
files: videoFilesModelToFormattedJSON(video, playlist.VideoFiles, { includePlaylistUrl: true })
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export function videoFilesModelToFormattedJSON (
|
||||||
|
video: MVideoFormattable,
|
||||||
|
videoFiles: MVideoFile[],
|
||||||
|
options?: {
|
||||||
|
includePlaylistUrl?: true
|
||||||
|
includeMagnet?: boolean
|
||||||
|
}
|
||||||
|
): (VideoFile & { playlistUrl: string })[]
|
||||||
|
|
||||||
export function videoFilesModelToFormattedJSON (
|
export function videoFilesModelToFormattedJSON (
|
||||||
video: MVideoFormattable,
|
video: MVideoFormattable,
|
||||||
videoFiles: MVideoFile[],
|
videoFiles: MVideoFile[],
|
||||||
options: {
|
options: {
|
||||||
|
includePlaylistUrl?: boolean // default false
|
||||||
includeMagnet?: boolean // default true
|
includeMagnet?: boolean // default true
|
||||||
} = {}
|
} = {}
|
||||||
): VideoFile[] {
|
): VideoFile[] {
|
||||||
const { includeMagnet = true } = options
|
const { includePlaylistUrl = false, includeMagnet = true } = options
|
||||||
|
|
||||||
if (isArray(videoFiles) === false) return []
|
if (isArray(videoFiles) === false) return []
|
||||||
|
|
||||||
|
@ -225,6 +238,8 @@ export function videoFilesModelToFormattedJSON (
|
||||||
.filter(f => !f.isLive())
|
.filter(f => !f.isLive())
|
||||||
.sort(sortByResolutionDesc)
|
.sort(sortByResolutionDesc)
|
||||||
.map(videoFile => {
|
.map(videoFile => {
|
||||||
|
const fileUrl = videoFile.getFileUrl(video)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: videoFile.id,
|
id: videoFile.id,
|
||||||
|
|
||||||
|
@ -251,7 +266,7 @@ export function videoFilesModelToFormattedJSON (
|
||||||
torrentUrl: videoFile.getTorrentUrl(),
|
torrentUrl: videoFile.getTorrentUrl(),
|
||||||
torrentDownloadUrl: videoFile.getTorrentDownloadUrl(),
|
torrentDownloadUrl: videoFile.getTorrentDownloadUrl(),
|
||||||
|
|
||||||
fileUrl: videoFile.getFileUrl(video),
|
fileUrl,
|
||||||
fileDownloadUrl: videoFile.getFileDownloadUrl(video),
|
fileDownloadUrl: videoFile.getFileDownloadUrl(video),
|
||||||
|
|
||||||
metadataUrl: videoFile.metadataUrl ?? getLocalVideoFileMetadataUrl(video, videoFile),
|
metadataUrl: videoFile.metadataUrl ?? getLocalVideoFileMetadataUrl(video, videoFile),
|
||||||
|
@ -259,6 +274,10 @@ export function videoFilesModelToFormattedJSON (
|
||||||
hasAudio: videoFile.hasAudio(),
|
hasAudio: videoFile.hasAudio(),
|
||||||
hasVideo: videoFile.hasVideo(),
|
hasVideo: videoFile.hasVideo(),
|
||||||
|
|
||||||
|
playlistUrl: includePlaylistUrl === true
|
||||||
|
? getHlsResolutionPlaylistFilename(fileUrl)
|
||||||
|
: undefined,
|
||||||
|
|
||||||
storage: video.remote
|
storage: video.remote
|
||||||
? null
|
? null
|
||||||
: videoFile.storage
|
: videoFile.storage
|
||||||
|
|
|
@ -8214,6 +8214,10 @@ components:
|
||||||
type: string
|
type: string
|
||||||
description: Direct URL of the video
|
description: Direct URL of the video
|
||||||
format: url
|
format: url
|
||||||
|
playlistUrl:
|
||||||
|
type: string
|
||||||
|
description: Playlist URL of the file if it is owned by a playlist
|
||||||
|
format: url
|
||||||
fileDownloadUrl:
|
fileDownloadUrl:
|
||||||
type: string
|
type: string
|
||||||
description: URL endpoint that transfers the video file as an attachment (so that the browser opens a download dialog)
|
description: URL endpoint that transfers the video file as an attachment (so that the browser opens a download dialog)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue