diff options
Diffstat (limited to 'shared/extra-utils/miscs/webtorrent.ts')
-rw-r--r-- | shared/extra-utils/miscs/webtorrent.ts | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/shared/extra-utils/miscs/webtorrent.ts b/shared/extra-utils/miscs/webtorrent.ts index 82548946d..63e648309 100644 --- a/shared/extra-utils/miscs/webtorrent.ts +++ b/shared/extra-utils/miscs/webtorrent.ts | |||
@@ -1,4 +1,8 @@ | |||
1 | import { readFile } from 'fs-extra' | ||
2 | import * as parseTorrent from 'parse-torrent' | ||
3 | import { join } from 'path' | ||
1 | import * as WebTorrent from 'webtorrent' | 4 | import * as WebTorrent from 'webtorrent' |
5 | import { ServerInfo } from '../server' | ||
2 | 6 | ||
3 | let webtorrent: WebTorrent.Instance | 7 | let webtorrent: WebTorrent.Instance |
4 | 8 | ||
@@ -11,6 +15,16 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { | |||
11 | return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) | 15 | return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) |
12 | } | 16 | } |
13 | 17 | ||
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 | |||
14 | export { | 27 | export { |
15 | webtorrentAdd | 28 | webtorrentAdd, |
29 | parseTorrentVideo | ||
16 | } | 30 | } |