aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-08 11:07:19 +0100
committerChocobozzz <me@florianbigard.com>2021-12-08 11:07:19 +0100
commit9b293cd6a2ce9ed1e1ccd41adbf7f2dbe2da8231 (patch)
tree3419e23d551937f716612f93747f58f2d381d310 /server/helpers
parenta23f6c94edee1cb11875585a64dc61f1004c1792 (diff)
downloadPeerTube-9b293cd6a2ce9ed1e1ccd41adbf7f2dbe2da8231.tar.gz
PeerTube-9b293cd6a2ce9ed1e1ccd41adbf7f2dbe2da8231.tar.zst
PeerTube-9b293cd6a2ce9ed1e1ccd41adbf7f2dbe2da8231.zip
Update torrent metadata on video update
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/webtorrent.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index c75c058e4..b350c9718 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -94,7 +94,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli
94 94
95 const options = { 95 const options = {
96 // Keep the extname, it's used by the client to stream the file inside a web browser 96 // Keep the extname, it's used by the client to stream the file inside a web browser
97 name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`, 97 name: buildInfoName(video, videoFile),
98 createdBy: 'PeerTube', 98 createdBy: 'PeerTube',
99 announceList: buildAnnounceList(), 99 announceList: buildAnnounceList(),
100 urlList: buildUrlList(video, videoFile) 100 urlList: buildUrlList(video, videoFile)
@@ -120,7 +120,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli
120 }) 120 })
121} 121}
122 122
123async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { 123async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
124 const video = extractVideo(videoOrPlaylist) 124 const video = extractVideo(videoOrPlaylist)
125 125
126 const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) 126 const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
@@ -133,10 +133,13 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi
133 133
134 decoded['url-list'] = buildUrlList(video, videoFile) 134 decoded['url-list'] = buildUrlList(video, videoFile)
135 135
136 decoded.info.name = buildInfoName(video, videoFile)
137 decoded['creation date'] = Math.ceil(Date.now() / 1000)
138
136 const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) 139 const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution)
137 const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename) 140 const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename)
138 141
139 logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) 142 logger.info('Updating torrent metadata %s -> %s.', oldTorrentPath, newTorrentPath)
140 143
141 await writeFile(newTorrentPath, encode(decoded)) 144 await writeFile(newTorrentPath, encode(decoded))
142 await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) 145 await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
@@ -171,7 +174,7 @@ function generateMagnetUri (
171 174
172export { 175export {
173 createTorrentPromise, 176 createTorrentPromise,
174 updateTorrentUrls, 177 updateTorrentMetadata,
175 createTorrentAndSetInfoHash, 178 createTorrentAndSetInfoHash,
176 generateMagnetUri, 179 generateMagnetUri,
177 downloadWebTorrentVideo 180 downloadWebTorrentVideo
@@ -226,3 +229,7 @@ function buildAnnounceList () {
226function buildUrlList (video: MVideo, videoFile: MVideoFile) { 229function buildUrlList (video: MVideo, videoFile: MVideoFile) {
227 return [ videoFile.getFileUrl(video) ] 230 return [ videoFile.getFileUrl(video) ]
228} 231}
232
233function buildInfoName (video: MVideo, videoFile: MVideoFile) {
234 return `${video.name} ${videoFile.resolution}p${videoFile.extname}`
235}