import { AccountModel } from '../server/models/account/account'
import { VideoChannelModel } from '../server/models/video/video-channel'
import { initDatabaseModels } from '../server/initializers/database'
-import { updateTorrentUrls } from '@server/helpers/webtorrent'
+import { updateTorrentMetadata } from '@server/helpers/webtorrent'
import { getServerActor } from '@server/models/application/application'
run()
for (const file of video.VideoFiles) {
console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
- await updateTorrentUrls(video, file)
+ await updateTorrentMetadata(video, file)
await file.save()
}
for (const file of (playlist?.VideoFiles || [])) {
console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid)
- await updateTorrentUrls(video, file)
+ await updateTorrentMetadata(video, file)
await file.save()
}
import express from 'express'
import { Transaction } from 'sequelize/types'
+import { updateTorrentMetadata } from '@server/helpers/webtorrent'
import { changeVideoChannelShare } from '@server/lib/activitypub/share'
import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video'
import { openapiOperationDoc } from '@server/middlewares/doc'
return videoInstanceUpdated
})
- if (wasConfidentialVideo) {
- Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
- }
+ if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated)
+ if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
} catch (err) {
return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
}
}
+
+async function updateTorrentsMetadata (video: MVideoFullLight) {
+ for (const file of video.getAllFiles()) {
+ await updateTorrentMetadata(video, file)
+ }
+}
const options = {
// Keep the extname, it's used by the client to stream the file inside a web browser
- name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`,
+ name: buildInfoName(video, videoFile),
createdBy: 'PeerTube',
announceList: buildAnnounceList(),
urlList: buildUrlList(video, videoFile)
})
}
-async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
+async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
const video = extractVideo(videoOrPlaylist)
const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
decoded['url-list'] = buildUrlList(video, videoFile)
+ decoded.info.name = buildInfoName(video, videoFile)
+ decoded['creation date'] = Math.ceil(Date.now() / 1000)
+
const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution)
const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename)
- logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath)
+ logger.info('Updating torrent metadata %s -> %s.', oldTorrentPath, newTorrentPath)
await writeFile(newTorrentPath, encode(decoded))
await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
export {
createTorrentPromise,
- updateTorrentUrls,
+ updateTorrentMetadata,
createTorrentAndSetInfoHash,
generateMagnetUri,
downloadWebTorrentVideo
function buildUrlList (video: MVideo, videoFile: MVideoFile) {
return [ videoFile.getFileUrl(video) ]
}
+
+function buildInfoName (video: MVideo, videoFile: MVideoFile) {
+ return `${video.name} ${videoFile.resolution}p${videoFile.extname}`
+}
import { remove } from 'fs-extra'
import { join } from 'path'
import { logger } from '@server/helpers/logger'
-import { updateTorrentUrls } from '@server/helpers/webtorrent'
+import { updateTorrentMetadata } from '@server/helpers/webtorrent'
import { CONFIG } from '@server/initializers/config'
import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants'
import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage'
file.fileUrl = fileUrl
file.storage = VideoStorage.OBJECT_STORAGE
- await updateTorrentUrls(videoOrPlaylist, file)
+ await updateTorrentMetadata(videoOrPlaylist, file)
await file.save()
logger.debug('Removing %s because it\'s now on object storage', oldPath)
}
const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`)
- return VideoPlaylistElementModel.update({ position: positionQuery as any }, query)
+ return VideoPlaylistElementModel.update({ position: positionQuery }, query)
}
static increasePositionOf (
return this.VideoChannel.Account.Actor.Server?.isBlocked() || this.VideoChannel.Account.isBlocked()
}
+ getAllFiles () {
+ let files: MVideoFile[] = []
+
+ if (Array.isArray(this.VideoFiles)) {
+ files = files.concat(this.VideoFiles)
+ }
+
+ const hls = this.getHLSPlaylist()
+ if (hls) {
+ files = files.concat(hls.VideoFiles)
+ }
+
+ return files
+ }
+
getQualityFileBy<T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) {
// We first transcode to WebTorrent format, so try this array first
if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) {
expect(torrent.files).to.be.an('array')
expect(torrent.files.length).to.equal(1)
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
+ expect(torrent.files[0].name).to.equal(`${videoDetails.name} ${file.resolution.id}p${extension}`)
}
expect(videoDetails.thumbnailPath).to.exist