diff --git a/.gitignore b/.gitignore index 207c3b88..c531775e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /TikTokDownloader.db /settings.json /Log/ +__pycache__/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ed7093d0..9ba5043b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ qrcode>=7.4.2 emoji>=2.10.1 rich>=13.7.1 lxml>=5.1.0 -browser-cookie3>=0.19.1 aiosqlite>=0.20.0 httpx>=0.27.0 gmssl>=3.2.2 +rookiepy==0.5.2 \ No newline at end of file diff --git a/src/tools/browser.py b/src/tools/browser.py index dd9ae26f..b79f2fdc 100644 --- a/src/tools/browser.py +++ b/src/tools/browser.py @@ -2,18 +2,9 @@ from types import SimpleNamespace from typing import TYPE_CHECKING -from browser_cookie3 import ( - chrome, - chromium, - opera, - opera_gx, - brave, +from rookiepy import ( edge, - vivaldi, - firefox, - librewolf, - safari, - BrowserCookieError, + to_cookiejar ) from src.custom import WARNING @@ -29,16 +20,7 @@ class Browser: """代码参考:https://github.com/Johnserf-Seed/f2/blob/main/f2/apps/douyin/cli.py""" browser = ( - chrome, - chromium, - opera, - opera_gx, - brave, - edge, - vivaldi, - firefox, - librewolf, - safari) + edge,) platform = { False: SimpleNamespace( name="抖音", @@ -57,8 +39,7 @@ def __init__(self, parameters: "Parameter", cookie_object: "Cookie"): def run(self, tiktok=False): browser = self.console.input( f"自动读取指定浏览器的 {self.platform[tiktok].name} Cookie 并写入配置文件\n" - "支持浏览器:1 Chrome, 2 Chromium, 3 Opera, 4 Opera GX, 5 Brave, 6 Edge, 7 Vivaldi, 8 Firefox, 9 LibreWolf, " - "10 Safari\n" + "支持浏览器:1 Edge, " "请关闭所有浏览器,然后输入浏览器序号:") try: cookie = self.__read_cookie( @@ -72,7 +53,7 @@ def run(self, tiktok=False): self.console.print( "读取 Cookie 失败,浏览器未完全关闭!", style=WARNING) - except BrowserCookieError: + except Exception: self.console.print( "读取 Cookie 失败,未找到对应浏览器的 Cookie 数据!", style=WARNING) @@ -81,9 +62,9 @@ def run(self, tiktok=False): def __read_cookie(self, browser, tiktok: bool): platform = self.platform[tiktok] cookie = CookieJar() - cookies = (browser(domain_name=i) for i in platform.domain) - [cookie.set_cookie(item) for domain in cookies for item in domain] + cookies = to_cookiejar(browser(domains=list(platform.domain))) + [cookie.set_cookie(item) for item in cookies] return cookie def __save_cookie(self, cookie: dict, tiktok: bool): - self.cookie_object.save_cookie(cookie, self.platform[tiktok].key) + self.cookie_object.save_cookie(cookie, self.platform[tiktok].key) \ No newline at end of file