From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- shared/extra-utils/miscs/webtorrent.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'shared/extra-utils/miscs') 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 @@ +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 @@ -11,6 +15,16 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { return new Promise(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 + webtorrentAdd, + parseTorrentVideo } -- cgit v1.2.3