kv-tube/restore_cookies.py

185 lines
5.9 KiB
Python

import json
import time
cookies_data = [
{
"domain": ".youtube.com",
"expirationDate": 1802692356.635205,
"hostOnly": False,
"httpOnly": True,
"name": "__Secure-3PSID",
"path": "/",
"sameSite": "no_restriction",
"secure": True,
"session": False,
"storeId": None,
"value": "g.a0005gie1lAkmYZc-EPeGx77pCrXo_Cz5eAi-e9aryb9Qoz967v4Caiou6Tt5ZyLR4iMp5I51wACgYKASISARESFQHGX2MiopTeGBKXybppZWNr7JzmKhoVAUF8yKrgfPx-gEb02gGAV3ZaVOGr0076"
},
{
"domain": ".youtube.com",
"expirationDate": 1800281710.070798,
"hostOnly": False,
"httpOnly": True,
"name": "__Secure-1PSIDTS",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "sidts-CjQB7I_69DRJdiQQGddE6tt-GHilv2IjDZd8S6FlWCjx2iReOoNtQMUkb55vaBdl8vBK7J_DEAA"
},
{
"domain": ".youtube.com",
"expirationDate": 1802692356.635439,
"hostOnly": False,
"httpOnly": False,
"name": "SAPISID",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "DP6iRyLCM_cFV1Gw/AN2nemkVrvJ2p8MWb"
},
{
"domain": ".youtube.com",
"expirationDate": 1800281710.070999,
"hostOnly": False,
"httpOnly": True,
"name": "__Secure-1PSIDCC",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "AKEyXzU66C7YKqYKgxpR8BbWvDlICFaXQCERc_NLnU_QLkcHrmR0aPQJTFLW1WesYcSYtIJYW3o"
},
{
"domain": ".youtube.com",
"expirationDate": 1802692356.635327,
"hostOnly": False,
"httpOnly": True,
"name": "SSID",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "A4isk9AE9xActvzYy"
},
{
"domain": ".youtube.com",
"expirationDate": 1802692356.635505,
"hostOnly": False,
"httpOnly": False,
"name": "__Secure-1PAPISID",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "DP6iRyLCM_cFV1Gw/AN2nemkVrvJ2p8MWb"
},
{
"domain": ".youtube.com",
"expirationDate": 1802692356.635139,
"hostOnly": False,
"httpOnly": True,
"name": "__Secure-1PSID",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "g.a0005gie1lAkmYZc-EPeGx77pCrXo_Cz5eAi-e9aryb9Qoz967v4-rF3xTavVHrJoyJAqShH6gACgYKAX0SARESFQHGX2MiOdAbUPmCj4MueYyh-2km5RoVAUF8yKp2ehWQC6tX8n-9UNg11RV60076"
},
{
"domain": ".youtube.com",
"expirationDate": 1802692356.635559,
"hostOnly": False,
"httpOnly": False,
"name": "__Secure-3PAPISID",
"path": "/",
"sameSite": "no_restriction",
"secure": True,
"session": False,
"storeId": None,
"value": "DP6iRyLCM_cFV1Gw/AN2nemkVrvJ2p8MWb"
},
{
"domain": ".youtube.com",
"expirationDate": 1800281710.071036,
"hostOnly": False,
"httpOnly": True,
"name": "__Secure-3PSIDCC",
"path": "/",
"sameSite": "no_restriction",
"secure": True,
"session": False,
"storeId": None,
"value": "AKEyXzUv06PBPrBxCnsrFCJPVRWYCKjXadcrSQPokD-DHGumtiOBRC96ipf2COBQcX_7RjiO8g"
},
{
"domain": ".youtube.com",
"expirationDate": 1800281710.070914,
"hostOnly": False,
"httpOnly": True,
"name": "__Secure-3PSIDTS",
"path": "/",
"sameSite": "no_restriction",
"secure": True,
"session": False,
"storeId": None,
"value": "sidts-CjQB7I_69DRJdiQQGddE6tt-GHilv2IjDZd8S6FlWCjx2iReOoNtQMUkb55vaBdl8vBK7J_DEAA"
},
{
"domain": ".youtube.com",
"expirationDate": 1792154873.499957,
"hostOnly": False,
"httpOnly": True,
"name": "LOGIN_INFO",
"path": "/",
"sameSite": "no_restriction",
"secure": True,
"session": False,
"storeId": None,
"value": "AFmmF2swRQIgVjJk8Mho4_JuKr6SZzrhBdlL1LdxWxcwDMu4cjaRRgcCIQCTtJpmYKJH54Tiei3at3f4YT3US7gSL0lW_TZ04guKjQ:QUQ3MjNmeWlwRDJSNDl2NE9uX2JWWG5tWllHN0RsNUVZVUhsLVp4N2dWbldaeC14SnNybWVERnNoaXFpanFJczhKTjJSRGN6MEs3c1VkLTE1TGJVeFBPT05BY29NMFh0Q1VPdFU3dUdvSUpET3lQbU1ZMUlHUGltajlXNDllNUQxZHdzZko1WXF1UUJWclNxQVJ0TXVEYnF2bXJRY2V6Vl9n"
},
{
"domain": ".youtube.com",
"expirationDate": 1803304605.839449,
"hostOnly": False,
"httpOnly": False,
"name": "PREF",
"path": "/",
"sameSite": None,
"secure": True,
"session": False,
"storeId": None,
"value": "tz=Etc.GMT-7&f7=150"
}
]
def json_to_netscape(json_cookies, output_file):
with open(output_file, 'w') as f:
f.write("# Netscape HTTP Cookie File\n")
f.write("# This file is generated by a script.\n\n")
for cookie in json_cookies:
domain = cookie.get('domain', '')
# Netscape format requires domain to start with . for subdomains usually,
# flag TRUE/FALSE depends on if it's a domain cookie.
# Simplified:
flag = "TRUE" if domain.startswith('.') else "FALSE"
path = cookie.get('path', '/')
secure = "TRUE" if cookie.get('secure', False) else "FALSE"
expiration = str(int(cookie.get('expirationDate', 0)))
name = cookie.get('name', '')
value = cookie.get('value', '')
f.write(f"{domain}\t{flag}\t{path}\t{secure}\t{expiration}\t{name}\t{value}\n")
print(f"Successfully converted {len(json_cookies)} cookies to {output_file}")
if __name__ == "__main__":
json_to_netscape(cookies_data, 'cookies.txt')