NeteaseCloudMusic_PythonSDK/test.py

100 lines
2.6 KiB
Python
Raw Normal View History

2023-12-11 10:31:07 +00:00
# 使用示例
2023-12-06 04:35:16 +00:00
import json
import os
from pprint import pprint
import dotenv
2023-12-11 10:31:07 +00:00
from NeteaseCloudMusic import NeteaseCloudMusicApi, api_help, api_list
2023-12-06 04:35:16 +00:00
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():
# 获取歌曲详情
2023-12-11 10:31:07 +00:00
response = netease_cloud_music_api.request("song_url_v1", {"id": 33894312, "level": "exhigh"})
pprint(response)
2023-12-06 04:35:16 +00:00
def search_test():
# 搜索
2023-12-11 10:31:07 +00:00
response = netease_cloud_music_api.request("search", {"keywords": "海阔天空"})
2023-12-06 08:01:28 +00:00
# print("|", response.text, "|")
2023-12-11 10:31:07 +00:00
pprint(response)
2023-12-06 04:35:16 +00:00
def search_default_test():
# 搜索
2023-12-11 10:31:07 +00:00
response = netease_cloud_music_api.request("search_default")
pprint(response)
2023-12-06 04:35:16 +00:00
def user_account_test():
# 获取用户账号信息
2023-12-11 10:31:07 +00:00
response = netease_cloud_music_api.request("user_account")
pprint(response)
2023-12-06 08:01:28 +00:00
def comment_new_test():
# 获取用户账号信息
2023-12-11 10:31:07 +00:00
response = netease_cloud_music_api.request("comment_new", {
2023-12-06 08:01:28 +00:00
"type": "0",
"id": "1407551413",
"sortType": 3,
"cursor": 1602072870260,
"pageSize": 20,
"pageNo": 2,
"realIP": "116.25.146.177",
})
2023-12-11 10:31:07 +00:00
pprint(response)
def toplist_detail_test():
# 获取用户账号信息
response = netease_cloud_music_api.request("toplist_detail")
pprint(response)
def playlist_detail_test():
# 获取用户账号信息
response = netease_cloud_music_api.request("playlist_detail", {"id": 19723756})
pprint(response)
def top_playlist_highquality_test():
response = netease_cloud_music_api.request("/top/playlist/highquality")
pprint(response)
def captcha_sent_test():
response = netease_cloud_music_api.request("/captcha/sent", {"phone": "15234941791"})
pprint(response)
def login_cellphone_test():
# 注意这里需要调用login_cellphone方法而不是api方法具体实现可以看main.py
# 有后续操作的api都需要自己实现一下
pass
# response = netease_cloud_music_api.login_cellphone("15234941791", "9464")
# pprint(response)
2023-12-06 04:35:16 +00:00
if __name__ == '__main__':
2023-12-06 08:01:28 +00:00
pass
2023-12-11 10:31:07 +00:00
print(api_list())
print(api_help())
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()
2023-12-11 10:31:07 +00:00
# toplist_detail_test()
# playlist_detail_test()
# top_playlist_highquality_test()
# captcha_sent_test()
# login_cellphone_test()