-
Notifications
You must be signed in to change notification settings - Fork 4
curl_to_ytdlp.py #10
Copy link
Copy link
Open
Labels
Description
import shlex
import subprocess
import re
def parse_curl_to_ytdlp(curl_cmd: str):
tokens = shlex.split(curl_cmd)
# Extract URL
url = None
for token in tokens:
if token.startswith("http"):
url = token
break
if not url:
raise ValueError("No URL found in cURL command.")
# Extract headers
headers = []
for i, token in enumerate(tokens):
if token in ("-H", "--header") and i + 1 < len(tokens):
header = tokens[i + 1]
headers.append(shlex.split(header)[0]) # clean quotes if needed
# Build yt-dlp command
ytdlp_cmd = ["yt-dlp"]
for h in headers:
ytdlp_cmd += ["--add-header", h]
ytdlp_cmd.append(url)
return ytdlp_cmd
def main():
print("Paste your full cURL command (single line):")
curl_input = input().strip()
try:
ytdlp_cmd = parse_curl_to_ytdlp(curl_input)
print("\n[INFO] Running yt-dlp command:")
print(" ".join(shlex.quote(arg) for arg in ytdlp_cmd))
subprocess.run(ytdlp_cmd)
except Exception as e:
print(f"[ERROR] {e}")
if __name__ == "__main__":
main()Reactions are currently unavailable