Load cookie from file. Returns (cookie_str, sapisid).
()
| 103 | |
| 104 | |
| 105 | def load_cookie() -> tuple: |
| 106 | """Load cookie from file. Returns (cookie_str, sapisid).""" |
| 107 | cookie_file = CONFIG.get("cookie_file") |
| 108 | if not cookie_file: |
| 109 | return "", None |
| 110 | if not os.path.exists(cookie_file): |
| 111 | return "", None |
| 112 | try: |
| 113 | with open(cookie_file, "r") as f: |
| 114 | content = f.read().strip() |
| 115 | if content.startswith("{"): |
| 116 | data = json.loads(content) |
| 117 | cookie_str = data.get("cookie", "") |
| 118 | sapisid = data.get("sapisid", "") |
| 119 | else: |
| 120 | cookie_str = content |
| 121 | pairs = dict(p.split("=", 1) for p in cookie_str.split("; ") if "=" in p) |
| 122 | sapisid = pairs.get("SAPISID", "") |
| 123 | return cookie_str, sapisid if sapisid else None |
| 124 | except Exception as e: |
| 125 | log(f"Cookie load error: {e}") |
| 126 | return "", None |
| 127 | |
| 128 | |
| 129 | def make_sapisidhash(sapisid: str) -> str: |
no test coverage detected