diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-15 10:02:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | d23dd9fbfc4d26026352c10f81d2795ceaf2908a (patch) | |
tree | da82286d423c5e834a1ee2dcd5970076b8263cf1 /shared/extra-utils/miscs/webtorrent.ts | |
parent | 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (diff) | |
download | PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.gz PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.zst PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.zip |
Introduce videos command
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 | } |