Skip to content

Commit

Permalink
增加批量关注组件
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaMisty authored Jul 2, 2020
1 parent d528791 commit d6bccc3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if: 'tag IS blank'
env:
global:
- TRAVIS_TAG=v2.1
- TRAVIS_TAG=v2.2
jobs:
include:
-
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h1 align="center">- Bilibili Toolkit -</h1>

<p align="center">
<img src="https://img.shields.io/badge/version-2019.12.22-green.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/version-2020.7.2-green.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/license-SATA-blue.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/travis/com/Hsury/Bilibili-Toolkit?style=for-the-badge">
</p>
Expand All @@ -31,6 +31,7 @@
|combo |2018/12/18 |三连推荐 |
|share |2018/6/20 |分享 |
|follow |2018/7/8 |关注 |
|follow_batch |2020/7/2 |批量关注 |
|danmaku_post |2019/3/11 |弹幕发送 |
|comment_like |2018/6/27 |评论点赞 |
|comment_post |2019/8/3 |评论发表 |
Expand Down
26 changes: 25 additions & 1 deletion bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
__author__ = "Hsury"
__email__ = "i@hsury.com"
__license__ = "SATA"
__version__ = "2019.12.22"
__version__ = "2020.7.2"

class Bilibili:
app_key = "1d8b6e7d45233436"
Expand Down Expand Up @@ -579,6 +579,28 @@ def follow(self, mid, secret=False):
self._log(f"用户{mid}{'悄悄' if secret else ''}关注失败 {response}")
return False

# 批量关注
def follow_batch(self, mids):
# mids = 被关注用户UID
url = f"{self.protocol}://api.bilibili.com/x/relation/batch/modify"
payload = {
'fids': ",".join(map(str, mids)),
'act': 1,
'csrf': self.get_csrf(),
're_src': 222,
}
headers = {
'Host': "api.bilibili.com",
'Referer': "https://www.bilibili.com/blackboard/live/activity-NfUS01P8.html",
}
response = self._requests("post", url, data=payload, headers=headers)
if response and response.get("code") == 0:
self._log(f"用户{', '.join(map(str, mids))}批量关注成功")
return True
else:
self._log(f"用户{', '.join(map(str, mids))}批量关注失败 {response}")
return False

# 弹幕发送
def danmaku_post(self, aid, message, page=1, moment=-1):
# aid = 稿件av号
Expand Down Expand Up @@ -1384,6 +1406,8 @@ def delay_wrapper(func, interval, arg_list=[()], shuffle=False):
threads.append(threading.Thread(target=delay_wrapper, args=(instance.share, 5, list(zip(config['share']['aid'])))))
if config['follow']['enable']:
threads.append(threading.Thread(target=delay_wrapper, args=(instance.follow, 5, list(zip(config['follow']['mid'], config['follow']['secret'])))))
if config['follow_batch']['enable']:
threads.append(threading.Thread(target=delay_wrapper, args=(instance.follow_batch, 5, list((config['follow_batch']['mid'][i:i + 50],) for i in range(0, len(config['follow_batch']['mid']), 50)))))
if config['danmaku_post']['enable']:
threads.append(threading.Thread(target=delay_wrapper, args=(instance.danmaku_post, 5, list(zip(config['danmaku_post']['aid'], config['danmaku_post']['message'], config['danmaku_post']['page'], config['danmaku_post']['moment'])))))
if config['comment_like']['enable']:
Expand Down
5 changes: 5 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ enable = false # 开关
mid = [2, 208259] # 被关注用户UID
secret = [true, false] # 悄悄关注

# 批量关注
[follow_batch]
enable = false # 开关
mid = [2, 208259] # 被关注用户UID

# 弹幕发送
[danmaku_post]
enable = false # 开关
Expand Down

0 comments on commit d6bccc3

Please sign in to comment.