-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2278006
commit ad9ce6f
Showing
4 changed files
with
68 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
if: 'tag IS blank' | ||
env: | ||
global: | ||
- TRAVIS_TAG=v2.3 | ||
- TRAVIS_TAG=v2.4 | ||
jobs: | ||
include: | ||
- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
import base64 | ||
import chardet | ||
import functools | ||
import hashlib | ||
import json | ||
import os | ||
|
@@ -40,7 +41,7 @@ | |
__author__ = "Hsury" | ||
__email__ = "[email protected]" | ||
__license__ = "SATA" | ||
__version__ = "2020.7.4" | ||
__version__ = "2020.7.20" | ||
|
||
class Bilibili: | ||
app_key = "bca7e84c2d947ac6" | ||
|
@@ -112,6 +113,26 @@ def _solve_captcha(self, image): | |
response = self._requests("post", url, json=payload) | ||
return response['message'] if response and response.get("code") == 0 else None | ||
|
||
def __bvid_handle(args_index=None, kwargs_key="aid"): | ||
def decorator(func): | ||
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
self = args[0] | ||
if args_index is not None and args_index < len(args): | ||
result = Bilibili.bvid_to_aid(args[args_index]) | ||
if result: | ||
args = list(args) | ||
self._log(f"{args[args_index]}被自动转换为av{result}") | ||
args[args_index] = result | ||
if kwargs_key is not None and kwargs_key in kwargs: | ||
result = Bilibili.bvid_to_aid(kwargs[kwargs_key]) | ||
if result: | ||
self._log(f"{kwargs[kwargs_key]}被自动转换为av{result}") | ||
kwargs[kwargs_key] = result | ||
return func(*args, **kwargs) | ||
return wrapper | ||
return decorator | ||
|
||
def __push_to_queue(self, manufacturer, data): | ||
if self.__queue: | ||
self.__queue.put({ | ||
|
@@ -121,6 +142,24 @@ def __push_to_queue(self, manufacturer, data): | |
'data': data, | ||
}) | ||
|
||
@staticmethod | ||
def bvid_to_aid(bvid="BV17x411w7KC"): | ||
# Snippet source: https://www.zhihu.com/question/381784377/answer/1099438784 | ||
table = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF" | ||
tr = {} | ||
for i in range(58): | ||
tr[table[i]] = i | ||
s = [11, 10, 3, 8, 4, 6] | ||
xor = 177451812 | ||
add = 8728348608 | ||
r = 0 | ||
try: | ||
for i in range(6): | ||
r += tr[bvid[s[i]]] * 58 ** i | ||
return (r - add) ^ xor | ||
except: | ||
return None | ||
|
||
@staticmethod | ||
def calc_sign(param): | ||
salt = "60698ba2f68e01ce44738920a0ffe768" | ||
|
@@ -381,6 +420,7 @@ def silver_to_coin(self, app=True, pc=False): | |
self._log(f"银瓜子兑换硬币(PC通道)失败 {response}") | ||
|
||
# 观看 | ||
@__bvid_handle(1, "aid") | ||
def watch(self, aid): | ||
# aid = 稿件av号 | ||
url = f"{self.protocol}://api.bilibili.com/x/web-interface/view?aid={aid}" | ||
|
@@ -439,6 +479,7 @@ def watch(self, aid): | |
return False | ||
|
||
# 点赞 | ||
@__bvid_handle(1, "aid") | ||
def like(self, aid): | ||
# aid = 稿件av号 | ||
url = f"{self.protocol}://api.bilibili.com/x/web-interface/archive/like" | ||
|
@@ -461,6 +502,7 @@ def like(self, aid): | |
return False | ||
|
||
# 投币 | ||
@__bvid_handle(1, "aid") | ||
def reward(self, aid, double=True): | ||
# aid = 稿件av号 | ||
# double = 双倍投币 | ||
|
@@ -485,6 +527,7 @@ def reward(self, aid, double=True): | |
return self.reward(aid, False) if double else False | ||
|
||
# 收藏 | ||
@__bvid_handle(1, "aid") | ||
def favour(self, aid): | ||
# aid = 稿件av号 | ||
url = f"{self.protocol}://api.bilibili.com/x/v2/fav/folder" | ||
|
@@ -516,6 +559,7 @@ def favour(self, aid): | |
return False | ||
|
||
# 三连推荐 | ||
@__bvid_handle(1, "aid") | ||
def combo(self, aid): | ||
# aid = 稿件av号 | ||
url = f"{self.protocol}://api.bilibili.com/x/web-interface/archive/like/triple" | ||
|
@@ -537,6 +581,7 @@ def combo(self, aid): | |
return False | ||
|
||
# 分享 | ||
@__bvid_handle(1, "aid") | ||
def share(self, aid): | ||
# aid = 稿件av号 | ||
url = f"{self.protocol}://api.bilibili.com/x/web-interface/share/add" | ||
|
@@ -606,6 +651,7 @@ def follow_batch(self, mids): | |
return False | ||
|
||
# 弹幕发送 | ||
@__bvid_handle(1, "aid") | ||
def danmaku_post(self, aid, message, page=1, moment=-1): | ||
# aid = 稿件av号 | ||
# message = 弹幕内容 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters