NeteaseCloudMusic_PythonSDK/test.py

61 lines
1.5 KiB
Python
Raw Normal View History

2023-12-06 04:35:16 +00:00
import json
import os
from pprint import pprint
import dotenv
from main import NeteaseCloudMusicApi
2023-12-06 08:01:28 +00:00
dotenv.load_dotenv() # 从.env文件中加载环境变量
2023-12-06 04:35:16 +00:00
2023-12-06 08:01:28 +00:00
netease_cloud_music_api = NeteaseCloudMusicApi() # 初始化API
netease_cloud_music_api.cookie = os.getenv("COOKIE") # 设置cookie
netease_cloud_music_api.DEBUG = True # 开启调试模式
2023-12-06 04:35:16 +00:00
def songv1_test():
# 获取歌曲详情
response = netease_cloud_music_api.api("song_url_v1", {"id": 33894312, "level": "exhigh"})
pprint(json.loads(response.text))
def search_test():
# 搜索
response = netease_cloud_music_api.api("search", {"keywords": "海阔天空"})
2023-12-06 08:01:28 +00:00
# print("|", response.text, "|")
pprint(json.loads(response.text))
2023-12-06 04:35:16 +00:00
def search_default_test():
# 搜索
response = netease_cloud_music_api.api("search_default")
pprint(json.loads(response.text))
def user_account_test():
# 获取用户账号信息
response = netease_cloud_music_api.api("user_account")
2023-12-06 08:01:28 +00:00
pprint(json.loads(response.text))
def comment_new_test():
# 获取用户账号信息
response = netease_cloud_music_api.api("comment_new", {
"type": "0",
"id": "1407551413",
"sortType": 3,
"cursor": 1602072870260,
"pageSize": 20,
"pageNo": 2,
"realIP": "116.25.146.177",
})
pprint(json.loads(response.text))
2023-12-06 04:35:16 +00:00
if __name__ == '__main__':
2023-12-06 08:01:28 +00:00
pass
2023-12-06 04:35:16 +00:00
# songv1_test()
# search_test()
# search_default_test()
2023-12-06 08:01:28 +00:00
# user_account_test()
# comment_new_test()