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

将browser_cookie3替换为rookiepy #261

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/TikTokDownloader.db
/settings.json
/Log/
__pycache__/
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 8 additions & 27 deletions src/tools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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="抖音",
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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)