seedr.cc 的完整 Python API 包装器
项目描述
Seedr.cc 的 Python API 包装器
目录
安装
-
通过PyPi安装
pip install seedrcc
-
从源安装
git clone https://github.com/hemantapkh/seedrcc && cd seedrcc && python setup.py sdist && pip install dist/*
我如何获得 API 端点
Seedr 不向免费增值用户提供API 。但是,Seedr 有一个适用于所有用户的chrome和kodi扩展。一些端点(很少)是从这些扩展中提取的。
在分析了seedr站点(旧版本)发送的请求后,我发现seedr-site API(需要验证码)与seedr-chrome和seedr-kode API类似。所以,我只是预测了其他端点。
该 API 适用于所有用户,因为它使用了 seedr-chrome 和 seedr-kodi API。
入门指南
获取令牌
有两种方法可以获取帐户令牌。您可以使用用户名/密码或通过设备代码授权登录。
使用用户名和密码登录
此方法使用播种机 Chrome 扩展 API。
from seedrcc import Login
seedr = Login('foo@bar.com', 'password')
response = seedr.authorize()
print(response)
# Getting the token
print(seedr.token)
使用设备代码授权
此方法使用 seedr kodi API。
要使用此方法,请生成设备和用户代码。将用户代码粘贴到https://seedr.cc/devices并使用设备代码进行授权。
from seedrcc import Login
seedr = Login()
deviceCode = seedr.getDeviceCode()
# Go to https://seedr.cc/devices and paste the user code
print(deviceCode)
# Authorize with device code
response = seedr.authorize(deviceCode['device_code'])
print(response)
# Getting the token
seedr.token
✏️ 注意:您必须使用实例变量“token”中的令牌,而不是响应中的“access_token”或“refresh_token”。
基本示例
有关所有可用方法,请参阅文档。此外,建议设置回调函数,请在此处阅读更多信息。
from seedrcc import Seedr
account = Seedr(token='token')
# Getting user settings
print(account.getSettings())
# Adding torrent
response = account.addTorrent('magnetlink')
print(response)
#Listing folder contents
response = account.listContents()
print(response)
管理令牌
访问令牌可能会在一定时间后过期,需要刷新。但是,此过程由模块处理,您不必担心。
⚠️ 令牌在此过程后更新,如果您将令牌存储在文件/数据库中并从中读取令牌,建议使用回调函数更新数据库/文件中的令牌。如果在这种情况下不更新令牌,模块将在每个会话中刷新令牌,这将花费额外的请求并增加响应时间。
回调函数
您可以设置一个回调函数,每次刷新令牌时都会自动调用该回调函数。您可以使用此类功能来处理刷新的令牌。
✏️ 注意:回调函数必须至少有一个参数。回调函数的第一个参数将是更新的令牌。
单参数回调函数
这是一个带有单个参数的回调函数示例,它读取和更新名为token.txt.
# Read the token from token.txt
token = open('token.txt', 'r').read().strip()
# Defining the callback function
def afterRefresh(token):
with open('token.txt', 'w') as f:
f.write(token)
account = Seedr(token, callbackFunc=afterRefresh)
具有多个参数的回调函数
在需要向回调函数传递多个参数的情况下,可以使用 lambda 函数。如果您的应用程序正在处理多个用户,则具有多个参数的回调函数可能很有用。
这是一个带有多个参数的回调函数示例,该函数将在刷新该用户的令牌后更新数据库中某个用户的令牌。
# Defining the callback function
def afterRefresh(token, userId):
# Add your code to deal with the database
print(f'Token of the user {userId} is updated.')
# Creating a Seedr object for user 12345
account = Seedr(token='token', callbackFunc=lambda token: afterRefresh(token, userId='12345'))
文档
每种方法的详细文档可在此处获得。
贡献
非常感谢您所做的任何贡献。
- 分叉项目
- 创建您的功能分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开拉取请求
感谢为此项目做出贡献的每一位贡献者。
使用此 API 的项目
想在这里列出您的项目吗?只需提出拉取请求。
执照
根据 MIT 许可证分发。有关更多信息,请参阅许可证。
作者/维护者:Hemanta Pokharel
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。