blob: 63e648309e6275aed88029cfbab810116b2e992e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import { readFile } from 'fs-extra'
import * as parseTorrent from 'parse-torrent'
import { join } from 'path'
import * as WebTorrent from 'webtorrent'
import { ServerInfo } from '../server'
let webtorrent: WebTorrent.Instance
function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
const WebTorrent = require('webtorrent')
if (!webtorrent) webtorrent = new WebTorrent()
if (refreshWebTorrent === true) webtorrent = new WebTorrent()
return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
}
async function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {
const torrentName = videoUUID + '-' + resolution + '.torrent'
const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName))
const data = await readFile(torrentPath)
return parseTorrent(data)
}
export {
webtorrentAdd,
parseTorrentVideo
}
|