import { logger } from './logger'
import { generateVideoImportTmpPath } from './utils'
import { extractVideo } from './video'
+import { pipeline } from 'stream'
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
.then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
}
+ logger.debug('Got torrent from webtorrent %s.', id, { infoHash: torrent.infoHash })
+
file = torrent.files[0]
// FIXME: avoid creating another stream when https://github.com/webtorrent/webtorrent/issues/1517 is fixed
.catch(err => logger.error('Cannot destroy webtorrent.', { err }))
})
- file.createReadStream().pipe(writeStream)
+ pipeline(
+ file.createReadStream(),
+ writeStream,
+ err => {
+ if (err) rej(err)
+ }
+ )
})
torrent.on('error', err => rej(err))
const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution)
const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename)
- logger.info('Updating torrent URLs %s.', newTorrentPath)
+ logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath)
await writeFile(newTorrentPath, bencode.encode(decoded))
-
- // Remove old torrent file if it existed
- if (videoFile.hasTorrent()) {
- await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
- }
+ await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
videoFile.torrentFilename = newTorrentFilename
}