Skip to content

Commit fadb151

Browse files
committed
util.load_cookie: change back to use browsercookie
as both browsercookie3 and rookiepy are abandoned
1 parent d9554f3 commit fadb151

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

util.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# so we can use this file in other projects without installing them.
1616
# or to copy and paste the functions to other public projects directly.
1717
# to install them all, you can do:
18-
# pip install requests lxml beautifulsoup4 python-dateutil pytz pyperclip wcwidth rich rookiepy
18+
# pip install requests lxml beautifulsoup4 python-dateutil pytz pyperclip wcwidth rich browsercookie
1919

2020
# ==================== CONSTANTS ====================
2121

@@ -900,9 +900,8 @@ def load_cookie(s):
900900
"""
901901
from http.cookiejar import MozillaCookieJar
902902
from requests.cookies import RequestsCookieJar, create_cookie
903-
# import browser_cookie3
904-
import rookiepy
905-
# pip install browser_cookie3 rookiepy
903+
import browsercookie
904+
# pip install browsercookie
906905

907906
def convert(cj):
908907
cookies = RequestsCookieJar()
@@ -920,22 +919,16 @@ def convert(cj):
920919
return cookies
921920

922921
if m := re.search(r'^(chrome|firefox|edge)(/.+)?', str(s), re.IGNORECASE):
923-
# domain_name = m[2].lstrip('/') if m[2] else None
924-
# if m[1] == 'chrome':
925-
# cj = browser_cookie3.chrome(domain_name=domain_name)
926-
# elif m[1] == 'firefox':
927-
# cj = browser_cookie3.firefox(domain_name=domain_name)
928-
# elif m[1] == 'edge':
929-
# cj = browser_cookie3.edge(domain_name=domain_name)
930-
# return convert(cj)
931-
domains = [m[2].lstrip('/')] if m[2] else None
932-
if m[1] == 'chrome':
933-
rcookies = rookiepy.chrome(domains=domains)
934-
elif m[1] == 'firefox':
935-
rcookies = rookiepy.firefox(domains=domains)
936-
elif m[1] == 'edge':
937-
rcookies = rookiepy.edge(domains=domains)
938-
return convert(rookiepy.to_cookiejar(rcookies))
922+
domain_name = m[2].lstrip('/') if m[2] else None
923+
if m[1].lower() == 'chrome':
924+
cj = browsercookie.chrome()
925+
elif m[1].lower() == 'firefox':
926+
cj = browsercookie.firefox()
927+
elif m[1].lower() == 'edge':
928+
cj = browsercookie.edge()
929+
if domain_name:
930+
cj = [cookie for cookie in cj if domain_name in cookie.domain]
931+
return convert(cj)
939932

940933
if Path(s).exists():
941934
cj = MozillaCookieJar(s)

0 commit comments

Comments
 (0)