File size: 2,119 Bytes
77d5f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import yt_dlp, traceback, sys, os
from http.cookiejar import MozillaCookieJar

class YDLLogger:
    def debug(self, msg): print("[DEBUG]", msg)
    def warning(self, msg): print("[WARN]", msg)
    def error(self, msg): print("[ERROR]", msg)

def probe(url, cookies=None):
    ydl_opts = {
        "format": "bestaudio/best",
        "cachedir": False,
        "logger": YDLLogger(),
        "no_warnings": False,
        "quiet": False,
        # don't try postprocessing during probe
        "postprocessors": [],
        # helpful to mimic a browser if site is picky:
        "http_headers": {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"},
    }
    if cookies:
        ydl_opts["cookiefile"] = cookies

    try:
        with yt_dlp.YoutubeDL(ydl_opts) as ydl:
            print("Probing (no download)...")
            info = ydl.extract_info(url, download=False)
            print("Top-level keys in info:", list(info.keys()))
            formats = info.get("formats")
            if formats:
                print("Found formats (count):", len(formats))
                for f in formats[:10]:
                    print(f" - id={f.get('format_id')}, ext={f.get('ext')}, abr={f.get('abr')}, vbr={f.get('vbr')}, note={f.get('format_note')}")
            else:
                print("No formats found. Inspecting other info fields:")
                for k in ("webpage_url", "extractor", "requested_formats", "is_live", "entries"):
                    print(f"  {k}: {info.get(k)}")
            return info
    except Exception as e:
        print("EXCEPTION during probe:")
        traceback.print_exc()
        # also dump any HTML/diagnostic text if available in exception text
        print("Exception message:", str(e))

if __name__ == "__main__":
    cookies = None
    if len(sys.argv) > 1:
        cookies = sys.argv[1]
        if not os.path.isfile(cookies):
            print(f"Cookie file '{cookies}' not found.")
            sys.exit(1)
    url = "https://www.youtube.com/watch?v=wDchsz8nmbo"
    probe(url, cookies)