import { sequelizeTypescript } from '../initializers/database'
import { VideoFileModel } from '../models/video/video-file'
import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
-import { getVideoFilename, getVideoFilePath } from './video-paths'
+import { getVideoFilePath } from './video-paths'
async function updateStreamingPlaylistsInfohashesIfNeeded () {
const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion()
const streamingPlaylist = video.getHLSPlaylist()
for (const file of streamingPlaylist.VideoFiles) {
+ const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution)
+
// If we did not generated a playlist for this resolution, skip
- const filePlaylistPath = join(directory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution))
+ const filePlaylistPath = join(directory, playlistFilename)
if (await pathExists(filePlaylistPath) === false) continue
const videoFilePath = getVideoFilePath(streamingPlaylist, file)
let line = `#EXT-X-STREAM-INF:${bandwidth},${resolution}`
if (file.fps) line += ',FRAME-RATE=' + file.fps
- const videoCodec = await getVideoStreamCodec(videoFilePath)
- line += `,CODECS="${videoCodec}`
-
- const audioCodec = await getAudioStreamCodec(videoFilePath)
- if (audioCodec) line += `,${audioCodec}`
+ const codecs = await Promise.all([
+ getVideoStreamCodec(videoFilePath),
+ getAudioStreamCodec(videoFilePath)
+ ])
- line += '"'
+ line += `,CODECS="${codecs.filter(c => !!c).join(',')}"`
masterPlaylists.push(line)
- masterPlaylists.push(VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution))
+ masterPlaylists.push(playlistFilename)
}
await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n')
}
await close(fd)
- const videoFilename = getVideoFilename(hlsPlaylist, file)
+ const videoFilename = file.filename
json[videoFilename] = rangeHashes
}
logger.info('Importing HLS playlist %s', playlistUrl)
- return new Promise<string>(async (res, rej) => {
+ return new Promise<void>(async (res, rej) => {
const tmpDirectory = join(CONFIG.STORAGE.TMP_DIR, await generateRandomString(10))
await ensureDir(tmpDirectory)
const destPath = join(tmpDirectory, basename(fileUrl))
const bodyKBLimit = 10 * 1000 * 1000 // 10GB
- await doRequestAndSaveToFile({ uri: fileUrl }, destPath, bodyKBLimit)
+ await doRequestAndSaveToFile(fileUrl, destPath, { bodyKBLimit })
}
clearTimeout(timer)
}
async function fetchUniqUrls (playlistUrl: string) {
- const { body } = await doRequest<string>({ uri: playlistUrl })
+ const { body } = await doRequest(playlistUrl)
if (!body) return []