1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-30 15:14:14 +01:00

Update user-agent to something newer

This commit is contained in:
Johan Andersson 2023-04-19 03:27:59 +02:00
parent 46077b7cd2
commit ce43d1ba4a
2 changed files with 5 additions and 9 deletions

View File

@ -4,13 +4,13 @@ import pathlib
import platform import platform
import re import re
import sys import sys
from json import dumps
from random import sample from random import sample
from shutil import which from shutil import which
from requests import codes from requests import codes
from requests import post from requests import post
from requests import Timeout from requests import Timeout
from svtplay_dl.utils.http import FIREFOX_UA
from svtplay_dl.utils.output import formatname from svtplay_dl.utils.output import formatname
from svtplay_dl.utils.proc import run_program from svtplay_dl.utils.proc import run_program
from svtplay_dl.utils.stream import subtitle_filter from svtplay_dl.utils.stream import subtitle_filter
@ -185,14 +185,10 @@ def _sublanguage(stream, config, subfixes):
def query(self): def query(self):
_ = parse(self) _ = parse(self)
random_sentences = " ".join(sample(_, len(_) if len(_) < 8 else 8)).replace("\r\n", "") random_sentences = " ".join(sample(_, len(_) if len(_) < 8 else 8)).replace("\r\n", "")
url = "https://whatlanguage.herokuapp.com" url = "https://svtplay-dl.se/langdetect/"
payload = {"query": random_sentences} headers = {"User-Agent": f"{FIREFOX_UA} {platform.machine()}"}
# Note: requests handles json from version 2.4.2 and onwards so i use json.dumps for now.
headers = {"content-type": "application/json"}
try: try:
# Note: reasonable timeout i guess? svtplay-dl is mainly used while multitasking i presume, r = post(url, json={"query": random_sentences}, headers=headers, timeout=30)
# and it is heroku after all (fast enough)
r = post(url, data=dumps(payload), headers=headers, timeout=30)
if r.status_code == codes.ok: if r.status_code == codes.ok:
try: try:
response = r.json() response = r.json()

View File

@ -10,7 +10,7 @@ from svtplay_dl.utils.output import formatname
from svtplay_dl.utils.parser import Options from svtplay_dl.utils.parser import Options
# Used for UA spoofing in get_http_data() # Used for UA spoofing in get_http_data()
FIREFOX_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.3" FIREFOX_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
retry = Retry(total=5, read=5, connect=5, backoff_factor=0.3, status_forcelist=(500, 502, 504)) retry = Retry(total=5, read=5, connect=5, backoff_factor=0.3, status_forcelist=(500, 502, 504))