From 43b0bdc08a64554f9a3cf3f922e65a4e7d09bbdf Mon Sep 17 00:00:00 2001 From: Zed Date: Mon, 17 Jan 2022 04:13:27 +0100 Subject: [PATCH] Remove user agents --- src/agents.nim | 70 -------------------------------------------- src/routes/media.nim | 16 +++++----- src/tokens.nim | 3 +- 3 files changed, 8 insertions(+), 81 deletions(-) delete mode 100644 src/agents.nim diff --git a/src/agents.nim b/src/agents.nim deleted file mode 100644 index a907e7b..0000000 --- a/src/agents.nim +++ /dev/null @@ -1,70 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-only -import random, strformat, strutils, sequtils - -randomize() - -const rvs = [ - "11.0", "40.0", "42.0", "43.0", "47.0", "50.0", "52.0", "53.0", "54.0", - "61.0", "66.0", "67.0", "69.0", "70.0" -] - -proc rv(): string = - if rand(10) < 1: "" - else: "; rv:" & sample(rvs) - -# OS - -const enc = ["; U", "; N", "; I", ""] - -proc linux(): string = - const - window = ["X11", "Wayland", "Unknown"] - arch = ["i686", "x86_64", "arm"] - distro = ["", "; Ubuntu/14.10", "; Ubuntu/16.10", "; Ubuntu/19.10", - "; Ubuntu", "; Fedora"] - sample(window) & sample(enc) & "; Linux " & sample(arch) & sample(distro) - -proc windows(): string = - const - nt = ["5.1", "5.2", "6.0", "6.1", "6.2", "6.3", "6.4", "9.0", "10.0"] - arch = ["; WOW64", "; Win64; x64", "; ARM", ""] - trident = ["", "; Trident/5.0", "; Trident/6.0", "; Trident/7.0"] - "Windows " & sample(nt) & sample(enc) & sample(arch) & sample(trident) - -const macs = toSeq(6..15).mapIt($it) & @["14_4", "10_1", "9_3"] - -proc mac(): string = - "Macintosh; Intel Mac OS X 10_" & sample(macs) & sample(enc) - -# Browser - -proc presto(): string = - const p = ["2.12.388", "2.12.407", "22.9.168", "2.9.201", "2.8.131", "2.7.62", - "2.6.30", "2.5.24"] - const v = ["10.0", "11.0", "11.1", "11.5", "11.6", "12.00", "12.14", "12.16"] - &"Presto/{sample(p)} Version/{sample(v)}" - -# Samples - -proc product(): string = - const opera = ["Opera/9.80", "Opera/12.0"] - if rand(20) < 1: "Mozilla/5.0" - else: sample(opera) - -proc os(): string = - let r = rand(10) - let os = - if r < 6: windows() - elif r < 9: linux() - else: mac() - &"({os}{rv()})" - -proc browser(prod: string): string = - if "Opera" in prod: presto() - else: "like Gecko" - -# Agent - -proc getAgent*(): string = - let prod = product() - &"{prod} {os()} {browser(prod)}" diff --git a/src/routes/media.nim b/src/routes/media.nim index a2a6369..c953a93 100644 --- a/src/routes/media.nim +++ b/src/routes/media.nim @@ -5,7 +5,7 @@ import asynchttpserver, asyncstreams, asyncfile, asyncnet import jester import router_utils -import ".."/[types, formatters, agents, utils] +import ".."/[types, formatters, utils] export asynchttpserver, asyncstreams, asyncfile, asyncnet export httpclient, os, strutils, asyncstreams, base64, re @@ -14,10 +14,8 @@ const m3u8Mime* = "application/vnd.apple.mpegurl" maxAge* = "max-age=604800" -let mediaAgent* = getAgent() - -proc safeFetch*(url, agent: string): Future[string] {.async.} = - let client = newAsyncHttpClient(userAgent=agent) +proc safeFetch*(url: string): Future[string] {.async.} = + let client = newAsyncHttpClient() try: result = await client.getContent(url) except: discard finally: client.close() @@ -34,7 +32,7 @@ proc proxyMedia*(req: jester.Request; url: string): Future[HttpCode] {.async.} = result = Http200 let request = req.getNativeReq() - client = newAsyncHttpClient(userAgent=mediaAgent) + client = newAsyncHttpClient() try: let res = await client.get(url) @@ -116,14 +114,14 @@ proc createMediaRouter*(cfg: Config) = var content: string if ".vmap" in url: - let m3u8 = getM3u8Url(await safeFetch(url, mediaAgent)) + let m3u8 = getM3u8Url(await safeFetch(url)) if m3u8.len > 0: - content = await safeFetch(url, mediaAgent) + content = await safeFetch(url) else: resp Http404 if ".m3u8" in url: - let vid = await safeFetch(url, mediaAgent) + let vid = await safeFetch(url) content = proxifyVideo(vid, cookiePref(proxyVideos)) resp content, m3u8Mime diff --git a/src/tokens.nim b/src/tokens.nim index bc7ea55..d864a4c 100644 --- a/src/tokens.nim +++ b/src/tokens.nim @@ -2,7 +2,7 @@ import asyncdispatch, httpclient, times, sequtils, json, random import strutils, tables import zippy -import types, agents, consts, http_pool +import types, consts, http_pool const maxConcurrentReqs = 5 # max requests at a time per token, to avoid race conditions @@ -65,7 +65,6 @@ proc fetchToken(): Future[Token] {.async.} = "accept-encoding": "gzip", "accept-language": "en-US,en;q=0.5", "connection": "keep-alive", - "user-agent": getAgent(), "authorization": auth })