Skip to content

Commit

Permalink
login增加countrycode参数;拉取代码时,判断是否存在配置文件;限制actions并发,避免部署出错
Browse files Browse the repository at this point in the history
  • Loading branch information
chen310 committed Dec 13, 2021
1 parent e2ef4d1 commit 4a8cc0e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ name: 'deploy'
on:
workflow_dispatch:

concurrency:
group: deploy-workflow

jobs:
deploy-to-scf:
name: Deploy to scf
name: Deploy to Tencent Cloud Serverless Cloud Function
runs-on: ubuntu-latest
steps:
- name: clone local repository
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ REGION 默认为`ap-guangzhou` ,可不更改。
``` json
"users":[
{
"username": "188xxxx8888",
"username": "188xxxx8888",
"countrycode": "",
"md5": false,
"password": "mypassword",
"X-Real-IP": ""
Expand All @@ -64,7 +65,7 @@ REGION 默认为`ap-guangzhou` ,可不更改。
// ...
```

`username`里填写手机号或邮箱,`password`里填写账号密码。如果使用的是加密后的密码,则需要将`md5``false`改成`true``X-Real-IP`里填写国内任意IP,否则可能会有无法登录等情况出现,可填写本机IP,查看方法为:百度搜索ip,填写显示的ip即可。
`username`里填写手机号或邮箱,`password`里填写账号密码`countrycode`为手机号前缀,使用非中国大陆的手机号登录需填写。如果使用的是加密后的密码,则需要将`md5``false`改成`true``X-Real-IP`里填写国内任意IP,否则可能会有无法登录等情况出现,可填写本机IP,查看方法为:百度搜索ip,填写显示的ip即可。

#### 签到
``` json
Expand Down
10 changes: 6 additions & 4 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def request(self, method, path, params={}, base_url=BASE_URL, default={"code": -
finally:
return data

def login(self, username, password):
def login(self, username, password, countrycode='86'):
username = str(username)
cookie_file = self.get_cookie_file(username)
if len(cookie_file) > 0:
Expand All @@ -132,8 +132,10 @@ def login(self, username, password):

if username.isdigit():
path = "/weapi/login/cellphone"
params = dict(phone=username, password=password,
rememberLogin="true")
if len(countrycode) == 0:
countrycode = '86'
params = dict(phone=username, countrycode=countrycode,
password=password, rememberLogin="true")
else:
# magic token for login
# see https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/router/login.js#L15
Expand Down Expand Up @@ -407,4 +409,4 @@ def expire_attention(self):
def signin_progress(self, moduleId):
path = "/weapi/act/modules/signin/v2/progress"
params = dict(moduleId=moduleId)
return self.request("POST", path, params)
return self.request("POST", path, params)
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{
/* 填写手机号或邮箱 */
"username": "",
/* 如果使用非中国大陆的手机号登录则需填写 countrycode,其他情况都不用填写 */
"countrycode": "",
/* 是否使用md5密码,若为false,请使用原密码,若为true,请使用md5加密后的密码 */
"md5": false,
/* 填写密码 */
Expand Down Expand Up @@ -131,7 +133,7 @@
/* 满级时自动停止 */
"full_stop": true,
/* 歌曲数 */
"song_number": 500,
"song_number": 300,
/* 休眠时间 */
"sleep_time": 10,
"upload_num": 300
Expand Down
4 changes: 2 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def start(event, context):
user_setting[key] = user_config['setting'][key]

user = User()
user.setUser(username=user_config['username'], password=user_config['password'],
isMd5=user_config['md5'], user_setting=user_setting, No=user_count, ip=user_config['X-Real-IP'])
user.setUser(username=user_config['username'], password=user_config['password'], isMd5=user_config['md5'],
countrycode=user_config['countrycode'], user_setting=user_setting, No=user_count, ip=user_config['X-Real-IP'])
if user.isLogined:
user.userInfo()

Expand Down
21 changes: 18 additions & 3 deletions serverless/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ else
echo "正在解压"
unzip -o code.zip -d code/ >> /dev/null;
rm -f code.zip;
sudo mv ./code/config.json ./oldconfig.json;
python ./serverless/loadconfig.py;
echo "已加载配置文件";
config_file="./config.json"
old_config_file="./config.old.json"
example_config_file="./config.example.json"
if [ -e "./code/config.json" ]; then
sudo mv ./code/config.json $old_config_file
sudo cp $config_file $example_config_file
python ./serverless/loadconfig.py $config_file $old_config_file
if [ $? -ne 0 ]; then
echo "配置文件复制错误,请检查config.json文件是否填写正确"
echo -e "\033[1;31m 部署失败 \033[0m"
exit 1
fi
echo "已加载配置文件"
else
echo "配置文件不存在,请检查FUNCTION_NAME填写是否正确,避免覆盖其他函数"
echo -e "\033[1;31m 部署失败 \033[0m"
exit 1
fi
fi

echo "开始安装ServerlessFramework";
Expand Down
10 changes: 6 additions & 4 deletions serverless/loadconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import json5
import re
import copy
import sys

key_list = ['version', 'desp']

def copy_config(src, dst):
target = copy.deepcopy(dst)
if isinstance(src, dict):
for key in src:
if key in target:
if key != 'version':
if key not in key_list:
target[key] = copy_config(src[key], target[key])
else:
target[key] = src[key]
Expand All @@ -32,9 +34,9 @@ def copy_config(src, dst):
return target


config = json5.load(open('./config.json', 'r', encoding='utf-8'))
oldconfig = json5.load(open('./oldconfig.json', 'r', encoding='utf-8'))
config = json5.load(open(sys.argv[1], 'r', encoding='utf-8'))
oldconfig = json5.load(open(sys.argv[2], 'r', encoding='utf-8'))

data = copy_config(oldconfig, config)
with open('./config.json', 'w', encoding='utf-8') as f:
with open(sys.argv[1], 'w', encoding='utf-8') as f:
f.write(json.dumps(data, indent=4, ensure_ascii=False))
9 changes: 5 additions & 4 deletions user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def __init__(self):
self.listenSongs = 0
self.vipType = 0

def setUser(self, username, password, isMd5=False, user_setting={}, No=0, ip=""):
self.music = self.login_check(username, password, isMd5, ip)
def setUser(self, username, password, isMd5=False, countrycode='', user_setting={}, No=0, ip=""):
self.music = self.login_check(
username, password, isMd5, countrycode, ip)
self.taskUser(No)
if self.music.uid != 0:
self.isLogined = True
Expand All @@ -39,7 +40,7 @@ def setUser(self, username, password, isMd5=False, user_setting={}, No=0, ip="")
self.taskInfo('登录失败,请检查账号、密码')
self.finishTask()

def login_check(self, username, pwd='', is_md5=True, ip=""):
def login_check(self, username, pwd='', is_md5=True, countrycode='', ip=""):
music = NetEase(username)
if len(ip) > 0:
music.header["X-Real-IP"] = ip
Expand All @@ -52,7 +53,7 @@ def login_check(self, username, pwd='', is_md5=True, ip=""):
else:
if not is_md5:
pwd = md5(pwd.encode(encoding='UTF-8')).hexdigest()
login_resp = music.login(username, pwd)
login_resp = music.login(username, pwd, countrycode)
if login_resp['code'] == 200:
music.uid = login_resp['profile']['userId']
music.nickname = login_resp['profile']['nickname']
Expand Down

0 comments on commit 4a8cc0e

Please sign in to comment.