NeteaseCloudMusic_PythonSDK/test.py

113 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用示例
import json
import os
from pprint import pprint
import dotenv
from package.NeteaseCloudMusic import NeteaseCloudMusicApi, api_help, api_list
# from NeteaseCloudMusic import NeteaseCloudMusicApi, api_help, api_list
dotenv.load_dotenv() # 从.env文件中加载环境变量
netease_cloud_music_api = NeteaseCloudMusicApi() # 初始化API
netease_cloud_music_api.cookie = os.getenv("COOKIE") # 设置cookie
netease_cloud_music_api.DEBUG = True # 开启调试模式
def song_url_v1_test():
# 获取歌曲详情
response = netease_cloud_music_api.request("song_url_v1", {"id": 33894312, "level": "exhigh"})
pprint(response)
def search_test():
# 搜索
response = netease_cloud_music_api.request("search", {"keywords": "海阔天空"})
# print("|", response.text, "|")
pprint(response)
def search_default_test():
# 搜索
response = netease_cloud_music_api.request("search_default")
pprint(response)
def user_account_test():
# 获取用户账号信息
response = netease_cloud_music_api.request("user_account")
pprint(response)
def comment_new_test():
# 获取用户账号信息
response = netease_cloud_music_api.request("comment_new", {
"type": "0",
"id": "1407551413",
"sortType": 3,
"cursor": 1602072870260,
"pageSize": 20,
"pageNo": 2,
"realIP": "116.25.146.177",
})
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)
def personalized_djprogram_test():
response = netease_cloud_music_api.request("personalized_djprogram")
pprint(response)
def top_mv_test():
response = netease_cloud_music_api.request("top_mv", {'limit': 6})
pprint(response)
if __name__ == '__main__':
pass
# print(api_list())
# print(api_help())
# song_url_v1_test()
top_mv_test()
# search_test()
# search_default_test()
# user_account_test()
# comment_new_test()
# toplist_detail_test()
# playlist_detail_test()
# top_playlist_highquality_test()
# captcha_sent_test()
# login_cellphone_test()