From 5ffe9a4030db19a22b329da8d0c5f6bfed5cc6d3 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Tue, 25 Dec 2018 00:13:52 -0800 Subject: Function to produce LWPCookieJar from lwp string --- youtube/accounts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'youtube') diff --git a/youtube/accounts.py b/youtube/accounts.py index a8362b9..53b3d49 100644 --- a/youtube/accounts.py +++ b/youtube/accounts.py @@ -6,7 +6,7 @@ from youtube import common import re import settings import http.cookiejar - +import io try: with open(os.path.join(settings.data_dir, 'accounts.txt'), 'r', encoding='utf-8') as f: @@ -28,6 +28,12 @@ def add_account(username, password, save): "cookies":cookie_jar.as_lwp_str(ignore_discard=False, ignore_expires=False), } +def cookie_jar_from_lwp_str(lwp_str): + cookie_jar = http.cookiejar.LWPCookieJar() + # HACK: cookiejar module insists on using filenames and reading files for you, + # so present a StringIO to this internal method which takes a filelike object + cookie_jar._really_load(self, io.StringIO(lwp_str), "", False, False) + return cookie_jar # --------------------------------- # Code ported from youtube-dl -- cgit v1.2.3