Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies from CookieCloud #418

Open
latel opened this issue Apr 9, 2024 · 2 comments
Open

Cookies from CookieCloud #418

latel opened this issue Apr 9, 2024 · 2 comments

Comments

@latel
Copy link

latel commented Apr 9, 2024

There is an awesome self-hosted project named https://github.com/easychen/CookieCloud which syncs browsers cookies anywhere with an encrypted api, It's would be great if metube can get browsers cookie from cookiecloud.

@PikuZheng
Copy link
Contributor

PikuZheng commented Apr 10, 2024

main.py

from PyCookieCloud import PyCookieCloud
import os
import time
cookie_cloud = PyCookieCloud(os.environ["COOKIE_CLOUD_URL"], os.environ["COOKIE_CLOUD_UUID"], os.environ["COOKIE_CLOUD_PASSWORD"])
def getcookie():
  the_key = cookie_cloud.get_the_key()
  if not the_key:
    print('Failed to get the key')
    return
  encrypted_data = cookie_cloud.get_encrypted_data()
  if not encrypted_data:
    print('Failed to get encrypted data')
    return
  decrypted_data = cookie_cloud.get_decrypted_data()
  if not decrypted_data:
    print('Failed to get decrypted data')
    return
  with open("/data/cookies.txt", "w") as file:
    file.write(f"# Netscape HTTP Cookie File\n\n")
    for domain, cookies in decrypted_data.items():
      for cookie in cookies:
        domain_value = cookie.get('domain', '')
        hostOnly_value = 'FALSE' if cookie.get('hostOnly', '') else 'TRUE' #reverse boolean value
        path_value = cookie.get('path', '')
        httpOnly_value = 'TRUE' if cookie.get('httpOnly', '') else 'FALSE'
        expirationDate_value = int(cookie.get('expirationDate', '0'))
        name_value = cookie.get('name', '')
        value_value = cookie.get('value', '')
        file.write(f"{domain_value}\t{hostOnly_value}\t{path_value}\t{httpOnly_value}\t{expirationDate_value}\t{name_value}\t{value_value}\n")

while True:
  getcookie()
  time.sleep(10*60)

Dockerfile

FROM python:3.11-alpine
COPY main.py /app/
RUN pip install PyCookieCloud
ENV COOKIE_CLOUD_URL http://replace to your host:8088
ENV COOKIE_CLOUD_UUID mEaLDhTbtUhjKDmkMfndKv #replace to your id
ENV COOKIE_CLOUD_PASSWORD dhYK2tt2J7R3TgPEeHbmmz #replace to your key
CMD ["python","-u","/app/main.py"]

build and run

docker build -t "cookiecloud-clinet:1" .
docker run -d --name=cookiecloud-clinet -v /downloads/.metube:/data --restart=always cookiecloud-clinet:1

usage

YTDL_OPTIONS={"cookiefile":"/downloads/.metube/cookies.txt"}

or a path you define

@latel
Copy link
Author

latel commented Apr 19, 2024

main.py

from PyCookieCloud import PyCookieCloud
import os
import time
cookie_cloud = PyCookieCloud(os.environ["COOKIE_CLOUD_URL"], os.environ["COOKIE_CLOUD_UUID"], os.environ["COOKIE_CLOUD_PASSWORD"])
def getcookie():
  the_key = cookie_cloud.get_the_key()
  if not the_key:
    print('Failed to get the key')
    return
  encrypted_data = cookie_cloud.get_encrypted_data()
  if not encrypted_data:
    print('Failed to get encrypted data')
    return
  decrypted_data = cookie_cloud.get_decrypted_data()
  if not decrypted_data:
    print('Failed to get decrypted data')
    return
  with open("/data/cookies.txt", "w") as file:
    file.write(f"# Netscape HTTP Cookie File\n\n")
    for domain, cookies in decrypted_data.items():
      for cookie in cookies:
        domain_value = cookie.get('domain', '')
        hostOnly_value = 'FALSE' if cookie.get('hostOnly', '') else 'TRUE' #reverse boolean value
        path_value = cookie.get('path', '')
        httpOnly_value = 'TRUE' if cookie.get('httpOnly', '') else 'FALSE'
        expirationDate_value = int(cookie.get('expirationDate', '0'))
        name_value = cookie.get('name', '')
        value_value = cookie.get('value', '')
        file.write(f"{domain_value}\t{hostOnly_value}\t{path_value}\t{httpOnly_value}\t{expirationDate_value}\t{name_value}\t{value_value}\n")

while True:
  getcookie()
  time.sleep(10*60)

Dockerfile

FROM python:3.11-alpine
COPY main.py /app/
RUN pip install PyCookieCloud
ENV COOKIE_CLOUD_URL http://replace to your host:8088
ENV COOKIE_CLOUD_UUID mEaLDhTbtUhjKDmkMfndKv #replace to your id
ENV COOKIE_CLOUD_PASSWORD dhYK2tt2J7R3TgPEeHbmmz #replace to your key
CMD ["python","-u","/app/main.py"]

build and run

docker build -t "cookiecloud-clinet:1" .
docker run -d --name=cookiecloud-clinet -v /downloads/.metube:/data --restart=always cookiecloud-clinet:1

usage

YTDL_OPTIONS={"cookiefile":"/downloads/.metube/cookies.txt"}

or a path you define

thank you, this would be very helpful for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants