使用 rookiepy 替代 browser-cookie3

This commit is contained in:
JoeanAmier
2024-07-27 17:27:55 +08:00
parent 5e33081e76
commit 3e67dfb634
11 changed files with 70 additions and 39 deletions

View File

@@ -210,6 +210,12 @@ async def example():
# 支持传入多个作品链接
print(await xhs.extract(multiple_links, download, ))
</pre>
<h1>📋 读取剪贴板</h1>
<p>项目使用 <code>pyperclip</code> 实现读取剪贴板功能,该模块在不同的系统上会有差异。</p>
<p>在 Windows 上,不需要额外的模块。</p>
<p>在 Mac 上,该模块使用 pbcopy 和 pbpaste 命令,这些命令应该随操作系统一起提供。</p>
<p>在 Linux 上,该模块使用 xclip 或 xsel 命令,这些命令应该随操作系统一起提供。否则,请运行 "sudo apt-get install xclip" 或 "sudo apt-get install xsel"注意xsel 似乎并不总是有效)</p>
<p>在其他 Linux 系统上,你需要安装 qtpy 或 PyQT5 模块。</p>
<h1>⚙️ 配置文件</h1>
<p>项目根目录下的 <code>settings.json</code> 文件,首次运行自动生成,可以自定义部分运行参数。</p>
<p>如果设置了无效的参数值,程序将会使用参数默认值!</p>
@@ -381,6 +387,9 @@ async def example():
<li><b>TikTokDownloader抖音 / TikTok</b><a href="https://github.com/JoeanAmier/TikTokDownloader">https://github.com/JoeanAmier/TikTokDownloader</a></li>
<li><b>KS-Downloader快手</b><a href="https://github.com/JoeanAmier/KS-Downloader">https://github.com/JoeanAmier/KS-Downloader</a></li>
</ul>
<h1>💰 项目赞助</h1>
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/PyCharm.svg" alt="PyCharm logo">
<p><b>JetBrains</b> 支持全球开源社区认可的活跃项目,并为非商业开发提供免费许可证。</p>
<h1>⚠️ 免责声明</h1>
<ul>
<li>使用者对本项目的使用由使用者自行决定,并自行承担风险。作者对使用者使用本项目所产生的任何损失、责任、或风险概不负责。</li>
@@ -405,4 +414,4 @@ async def example():
* https://textual.textualize.io/
* https://aiosqlite.omnilib.dev/en/stable/
* https://click.palletsprojects.com/en/8.1.x/
* https://github.com/borisbabic/browser_cookie3
* https://github.com/thewh1teagle/rookie

View File

@@ -214,6 +214,12 @@ async def example():
# 支持传入多个作品链接
print(await xhs.extract(multiple_links, download, ))
</pre>
<h1>📋 Read Clipboard</h1>
<p>The project uses <code>pyperclip</code> to implement clipboard reading functionality, which varies across different systems.</p>
<p>On Windows, no additional modules are needed.</p>
<p>On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os.</p>
<p>On Linux, this module makes use of the xclip or xsel commands, which should come with the os. Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.)</p>
<p>Otherwise on Linux, you will need the qtpy or PyQT5 modules installed.</p>
<h1>⚙️ Configuration File</h1>
<p>The <code>settings.json</code> file in the root directory of the project is automatically generated on the first run and allows customization of some runtime parameters.</p>
<p>If invalid parameter values are set, the program will use the default values!</p>
@@ -382,6 +388,9 @@ async def example():
<li><b>TikTokDownloader抖音 / TikTok</b><a href="https://github.com/JoeanAmier/TikTokDownloader">https://github.com/JoeanAmier/TikTokDownloader</a></li>
<li><b>KS-Downloader快手</b><a href="https://github.com/JoeanAmier/KS-Downloader">https://github.com/JoeanAmier/KS-Downloader</a></li>
</ul>
<h1>💰 Sponsor</h1>
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/PyCharm.svg" alt="PyCharm logo">
<p><b>JetBrains</b> support active projects recognized within the global open-source community with complimentary licenses for non-commercial development.</p>
<h1>⚠️ Disclaimer</h1>
<ul>
<li>Users decide on their own how to use this project and bear the risks themselves. The author is not responsible for any losses, liabilities, or risks incurred by users in the use of this project</li>
@@ -406,4 +415,4 @@ async def example():
* https://textual.textualize.io/
* https://aiosqlite.omnilib.dev/en/stable/
* https://click.palletsprojects.com/en/8.1.x/
* https://github.com/borisbabic/browser_cookie3
* https://github.com/thewh1teagle/rookie

Binary file not shown.

View File

@@ -214,8 +214,8 @@ msgstr "New version detected: {0}.{1}"
msgid "作品 {0} 存在下载记录,跳过下载"
msgstr "works {0} has a download record, skip download"
msgid "从指定的浏览器读取小红书网页版 Cookie需要关闭对应的浏览器,支持1 Chrome, 2 Chromium, 3 Opera, 4 Opera GX, 5 Brave, 6 Edge, 7 Vivaldi, 8 Firefox, 9 LibreWolf, 10 Safari输入浏览器类型或序号"
msgstr "To read the Xiaohongshu web version cookie from the specified browser, the corresponding browser needs to be closed. Supports: 1 Chrome, 2 Chromium, 3 Opera, 4 Opera GX, 5 Brave, 6 Edge, 7 Vivaldi, 8 Firefox, 9 LibreWolf, 10 Safari, enter the browser type or serial number"
msgid "从指定的浏览器读取小红书网页版 Cookie支持1 Arc, 2 Brave, 3 Chrome, 4 Chromium, 5 Edge, 6 Firefox, 7 LibreWolf, 8 Opera, 9 Vivaldi; 输入浏览器名称或序号"
msgstr "To read the Xiaohongshu web version cookie from the specified browser, the corresponding browser needs to be closed. Supports: 1 Arc, 2 Brave, 3 Chrome, 4 Chromium, 5 Edge, 6 Firefox, 7 LibreWolf, 8 Opera, 9 Vivaldi, enter the browser name or serial number"
msgid "查看 XHS-Downloader 版本"
msgstr "View XHS Downloader Version"
@@ -291,3 +291,6 @@ msgstr "Agent {0} test timeout"
msgid "代理 {0} 测试失败:{1}"
msgstr "Agent {0} test failed: {1}"
msgid "浏览器名称或序号输入错误!"
msgstr "Browser name or serial number input error!"

View File

@@ -214,7 +214,7 @@ msgstr ""
msgid "作品 {0} 存在下载记录,跳过下载"
msgstr ""
msgid "从指定的浏览器读取小红书网页版 Cookie需要关闭对应的浏览器,支持1 Chrome, 2 Chromium, 3 Opera, 4 Opera GX, 5 Brave, 6 Edge, 7 Vivaldi, 8 Firefox, 9 LibreWolf, 10 Safari输入浏览器类型或序号"
msgid "从指定的浏览器读取小红书网页版 Cookie支持1 Arc, 2 Brave, 3 Chrome, 4 Chromium, 5 Edge, 6 Firefox, 7 LibreWolf, 8 Opera, 9 Vivaldi; 输入浏览器名称或序号"
msgstr ""
msgid "查看 XHS-Downloader 版本"
@@ -291,3 +291,6 @@ msgstr ""
msgid "代理 {0} 测试失败:{1}"
msgstr ""
msgid "浏览器名称或序号输入错误!"
msgstr ""

View File

@@ -4,7 +4,7 @@ lxml>=5.2.2
PyYAML>=6.0.1
aiosqlite>=0.20.0
click>=8.1.7
browser_cookie3>=0.19.1
rookiepy>=0.5.2
httpx>=0.27.0
fastapi>=0.111.0
uvicorn>=0.30.1

View File

@@ -101,9 +101,7 @@ class CLI:
@staticmethod
@check_value
def read_cookie(ctx: Context, param, value) -> str:
if len(value) == 1:
value = int(value)
return BrowserCookie.get(value, domain="xiaohongshu.com")
return BrowserCookie.get(value, domains=["xiaohongshu.com", ])
@staticmethod
@check_value
@@ -139,8 +137,8 @@ class CLI:
("--language", "-l", "choice", _("设置程序语言目前支持zh_CN、en_GB")),
("--settings", "-s", "str", _("读取指定配置文件")),
("--browser_cookie", "-bc", "choice",
fill(_("从指定的浏览器读取小红书网页版 Cookie需要关闭对应的浏览器,支持1 Chrome, 2 Chromium, 3 Opera, 4 Opera GX, "
"5 Brave, 6 Edge, 7 Vivaldi, 8 Firefox, 9 LibreWolf, 10 Safari输入浏览器类型或序号"), width=45)),
fill(_("从指定的浏览器读取小红书网页版 Cookie支持1 Arc, 2 Brave, 3 Chrome, 4 Chromium, "
"5 Edge, 6 Firefox, 7 LibreWolf, 8 Opera, 9 Vivaldi; 输入浏览器名称或序号"), width=40)),
("--update_settings", "-us", "flag", _("是否更新配置文件")),
("--help", "-h", "flag", _("查看详细参数说明")),
("--version", "-v", "flag", _("查看 XHS-Downloader 版本")),

View File

@@ -303,7 +303,7 @@ class XHS:
@staticmethod
def read_browser_cookie(value: str | int) -> str:
return BrowserCookie.get(
value, domain="xiaohongshu.com") if value else ""
value, domains=["xiaohongshu.com", ]) if value else ""
# @staticmethod
# async def index(request):

View File

@@ -1,15 +1,17 @@
from browser_cookie3 import (
from contextlib import suppress
from rookiepy import (
arc,
brave,
chrome,
chromium,
opera,
opera_gx,
brave,
edge,
vivaldi,
firefox,
librewolf,
safari,
BrowserCookieError,
opera,
# opera_gx,
# safari,
vivaldi,
)
__all__ = ["BrowserCookie"]
@@ -17,35 +19,43 @@ __all__ = ["BrowserCookie"]
class BrowserCookie:
SUPPORT_BROWSER = {
"arc": arc,
"chrome": chrome,
"chromium": chromium,
"opera": opera,
"opera_gx": opera_gx,
# "opera_gx": opera_gx,
"brave": brave,
"edge": edge,
"vivaldi": vivaldi,
"firefox": firefox,
"librewolf": librewolf,
"safari": safari,
# "safari": safari,
}
@classmethod
def get(cls, browser: str | int, domain: str) -> str:
browser = cls.__browser_object(browser)
def get(cls, browser: str | int, domains: list[str]) -> str:
if not (browser := cls.__browser_object(browser)):
print("浏览器名称或序号输入错误!")
return ""
try:
cookie = browser(domain_name=domain)
cookie = [f"{i.name}={i.value}" for i in cookie]
return "; ".join(cookie)
except PermissionError:
print("读取 Cookie 失败,浏览器未关闭!")
except BrowserCookieError:
cookies = browser(domains=domains)
return "; ".join(f"{i["name"]}={i["value"]}" for i in cookies)
except RuntimeError:
print("获取 Cookie 失败,未找到 Cookie 数据!")
return ""
@classmethod
def __browser_object(cls, browser: str | int):
with suppress(ValueError):
browser = int(browser)
if isinstance(browser, int):
try:
return list(cls.SUPPORT_BROWSER.values())[browser - 1]
except IndexError:
return None
if isinstance(browser, str):
return cls.SUPPORT_BROWSER[browser.lower()]
elif isinstance(browser, int):
return list(cls.SUPPORT_BROWSER.values())[browser - 1]
try:
return cls.SUPPORT_BROWSER[browser.lower()]
except KeyError:
return None
raise TypeError

View File

@@ -24,8 +24,8 @@ __all__ = [
]
VERSION_MAJOR = 2
VERSION_MINOR = 1
VERSION_BETA = False
VERSION_MINOR = 2
VERSION_BETA = True
ROOT = Path(__file__).resolve().parent.parent.parent
PROJECT = f"XHS-Downloader V{VERSION_MAJOR}.{
VERSION_MINOR}{" Beta" if VERSION_BETA else ""}"

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name XHS-Downloader
// @namespace https://github.com/JoeanAmier/XHS-Downloader
// @version 1.5.1
// @version 1.5.2
// @description 提取小红书作品/用户链接,下载小红书无水印图文/视频作品文件
// @author JoeanAmier
// @match http*://xhslink.com/*
@@ -43,7 +43,8 @@
3. 提取账号发布、收藏、点赞作品链接时脚本会尝试自动滚动屏幕直至加载全部作品滚动检测间隔2.5 秒
4. 提取搜索结果作品、用户链接时脚本会自动滚动屏幕以尝试加载更多内容滚动屏幕次数10 次
5. 可以修改滚动检测间隔、滚动屏幕次数,修改后立即生效;亦可关闭自动滚动屏幕功能,手动滚动屏幕加载内容
6. XHS-Downloader 用户脚本仅实现可见即可得的数据采集功能,无任何收费功能和破解功能
6. 使用全局代理工具可能会导致脚本下载文件失败,如有异常,请尝试关闭代理工具,必要时向作者反馈
7. XHS-Downloader 用户脚本仅实现可见即可得的数据采集功能,无任何收费功能和破解功能
项目开源地址https://github.com/JoeanAmier/XHS-Downloader
`
@@ -212,9 +213,7 @@
try {
// 使用 fetch 获取文件数据
let response = await fetch(link, {
headers: {
'Accept': 'application/octet-stream'
}
method: "GET",
});
// 检查响应状态码