]>
Commit | Line | Data |
---|---|---|
6697cfd2 JN |
1 | import |
2 | httpClient, | |
3 | json, | |
4 | re, | |
5 | strformat, | |
6 | strutils | |
7 | ||
8 | let PEERTUBE_REGEX = re"videos\/watch\/[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}" | |
9 | ||
10 | proc getPeerTubeMagnetLink*(url: string): string = | |
11 | ## Gets the magnet link of the best possible resolution from PeerTube | |
12 | let uuid = url.substr(find(url, PEERTUBE_REGEX) + "videos/watch/".len) | |
13 | let domainName = url.substr(8, find(url, '/', start=8) - 1) | |
14 | let apiURL = &"https://{domainName}/api/v1/videos/{uuid}" | |
15 | let client = newHttpClient() | |
16 | let response = get(client, apiURL) | |
17 | let jsonNode = parseJson($response.body) | |
18 | jsonNode["files"][0]["magnetUri"].getStr() |