+ const parsedTorrent = parseTorrent(torrentContent)
+ videoFile.infoHash = parsedTorrent.infoHash
+ videoFile.torrentFilename = torrentFilename
+ })
+}
+
+async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) {
+ const video = extractVideo(videoOrPlaylist)
+
+ const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
+
+ const torrentContent = await readFile(oldTorrentPath)
+ const decoded = decode(torrentContent)
+
+ decoded['announce-list'] = buildAnnounceList()
+ decoded.announce = decoded['announce-list'][0][0]
+
+ 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 metadata %s -> %s.', oldTorrentPath, newTorrentPath)
+
+ await writeFile(newTorrentPath, encode(decoded))
+ await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
+
+ videoFile.torrentFilename = newTorrentFilename
+ videoFile.infoHash = sha1(encode(decoded.info))