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