diff options
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r-- | server/helpers/webtorrent.ts | 15 |
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 | ||
123 | async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | 123 | async 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 | ||
172 | export { | 175 | export { |
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 () { | |||
226 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { | 229 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { |
227 | return [ videoFile.getFileUrl(video) ] | 230 | return [ videoFile.getFileUrl(video) ] |
228 | } | 231 | } |
232 | |||
233 | function buildInfoName (video: MVideo, videoFile: MVideoFile) { | ||
234 | return `${video.name} ${videoFile.resolution}p${videoFile.extname}` | ||
235 | } | ||