From 64c9314cfaf62a14731177d8b896d0f21a78f4f3 Mon Sep 17 00:00:00 2001 From: Guilherme Pires Date: Tue, 6 Feb 2024 18:09:15 -0700 Subject: [PATCH] headers --- process_debates.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/process_debates.py b/process_debates.py index 5a7b73a..0e44f49 100644 --- a/process_debates.py +++ b/process_debates.py @@ -65,6 +65,7 @@ def get_audio(url, output_path, headers=None): ] if headers is not None: + headers = "\r\n".join([f"{k}: {v}" for k,v in headers.items()]) + "\r\n" cmd = ["ffmpeg", "-headers", headers, "-i", url, *options, output_path] else: cmd = ["ffmpeg", "-i", url, *options, output_path] @@ -135,7 +136,21 @@ def process_debate(*, title, url, output_root): audio_path = output_root / f"audio/{slug}.mp3" if "rtp.pt" in url: - headers = "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate, br\r\nReferer: https://www.rtp.pt/\r\nOrigin: https://www.rtp.pt\r\nDNT: 1\r\nSec-GPC: 1\r\nConnection: keep-alive\r\nSec-Fetch-Dest: empty\r\nSec-Fetch-Mode: cors\r\nSec-Fetch-Site: same-site\r\nTE: trailers\r\n" + headers = { + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0", + "Accept": "*/*", + "Accept-Language": "en-US,en;q=0.5", + "Accept-Encoding": "gzip, deflate, br", + "Referer": "https://www.rtp.pt/", + "Origin": "https://www.rtp.pt", + "DNT": "1", + "Sec-GPC": "1", + "Connection": "keep-alive", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "TE": "trailers" + } else: headers = None @@ -147,7 +162,7 @@ def process_debate(*, title, url, output_root): "title": title, "original_url": url, "m3u8_url": m3u8_url, - "headers": dict(zip([tup.split(": ") for tup in headers.split("\r\n")])) if headers is not None else {}, + "headers": headers, } with open(output_root / f"{slug}.json", "w") as f: