- getTorrentFilePath (videoFile: MVideoFile) {
- return join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
- }
-
- getVideoFilePath (videoFile: MVideoFile) {
- return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
- }
-
- async createTorrentAndSetInfoHash (videoFile: MVideoFile) {
- const options = {
- // Keep the extname, it's used by the client to stream the file inside a web browser
- name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`,
- createdBy: 'PeerTube',
- announceList: [
- [ WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT + '/tracker/socket' ],
- [ WEBSERVER.URL + '/tracker/announce' ]
- ],
- urlList: [ WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ]
- }
-
- const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options)
-
- const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
- logger.info('Creating torrent %s.', filePath)
-
- await writeFile(filePath, torrent)
-
- const parsedTorrent = parseTorrent(torrent)
- videoFile.infoHash = parsedTorrent.infoHash
- }
-