X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fwebtorrent.ts;h=68d532c48995a2f5efde250c233aec100f800594;hb=a5a79d15427372b581e34ac3999c73fc316699d5;hp=c75c058e4cb0628636383ef32327cd4779e479da;hpb=ad5db1044c8599eaaaa2a578b350777ae996b068;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index c75c058e4..68d532c48 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts @@ -13,6 +13,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager' import { MVideo } from '@server/types/models/video/video' import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' +import { sha1 } from '@shared/extra-utils' import { CONFIG } from '../initializers/config' import { promisify2 } from './core-utils' import { logger } from './logger' @@ -94,7 +95,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli 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) @@ -120,7 +121,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli }) } -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) @@ -133,15 +134,19 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi 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)) videoFile.torrentFilename = newTorrentFilename + videoFile.infoHash = sha1(encode(decoded.info)) } function generateMagnetUri ( @@ -171,7 +176,7 @@ function generateMagnetUri ( export { createTorrentPromise, - updateTorrentUrls, + updateTorrentMetadata, createTorrentAndSetInfoHash, generateMagnetUri, downloadWebTorrentVideo @@ -226,3 +231,7 @@ function buildAnnounceList () { function buildUrlList (video: MVideo, videoFile: MVideoFile) { return [ videoFile.getFileUrl(video) ] } + +function buildInfoName (video: MVideo, videoFile: MVideoFile) { + return `${video.name} ${videoFile.resolution}p${videoFile.extname}` +}