GithubHelp home page GithubHelp logo

s12mmm3 / qcloudmusicapi Goto Github PK

View Code? Open in Web Editor NEW
62.0 2.0 13.0 609 KB

Qt C++版 网易云音乐 API

Home Page: https://s12mmm3.github.io/QCloudMusicApi/

License: MIT License

CMake 3.19% C++ 91.27% C 1.99% Python 1.03% C# 1.35% Rust 1.18%
api apis cloudmusic neteasecloud qt qt6 cpp qt5

qcloudmusicapi's Introduction

QCloudMusicApi - Qt版 网易云音乐 API

GitHub Actions CI Status GitHub Actions CI Status GitHub Actions CI Status

C++ version Qt version Qt version GitHub license

简介

本项目翻译自Node.js项目Binaryify/NeteaseCloudMusicApi

更新尽量与原项目同步,实现了大部分接口;支持跨语言调用,支持跨平台编译,支持多种编译器编译

使用方式参考原项目文档,参数与返回结果与原项目完全一致;支持设置Http服务器(需要Qt6.4及以上)

目录


需求和依赖

使用说明

可参考文档API 参考

使用ApiHelper类

该类实现了API的cookie管理;支持Qt反射调用

通过对应方法字符串调用

#include "apihelper.h"

ApiHelper helper;
qDebug() << helper.invoke("lyric_new", { { "id", "1408586353" } });

传入Url调用

ApiHelper helper;
qDebug() << helper.invokeUrl("/song/url/v1?id=2058263032, 2057797340&level=exhigh");
qDebug() << helper.invokeUrl("http://localhost:3000/activate/init/profile");

使用NeteaseCloudMusicApi类

若无需保存cookie,可直接使用该类,直接调用类函数; 支持Qt反射调用,所有方法均注册至Qt元对象系统中

#include "module.h"

NeteaseCloudMusicApi api;
qDebug() << api.lyric_new({ { "id", "1408586353" } });

跨语言调用

动态库提供C接口,开放给Python、Java和C#等支持与C语言交互的语言调用

/**
 * @brief 反射调用API的成员函数。
 * @param memberName 调用成员函数的名称
 * @param value 参数的JSON格式字符串
 * @return 调用结果的JSON格式字符串
 */
const char* invoke(char* memberName, char* value);

调用例子参考跨语言调用

引用动态库文件

在CMakeLists.txt文件中加上

set(LIBRARY_DIR "${PROJECT_SOURCE_DIR}/QCloudMusicApi")
# 添加头文件路径
include_directories(${LIBRARY_DIR}/include)
# 添加库文件路径
link_directories(${LIBRARY_DIR}/bin)

在项目中引用CMake项目

在CMakeLists.txt文件中加上

add_subdirectory(QCloudMusicApi)
add_executable(${PROJECT_NAME}
    ./QCloudMusicApi/QCloudMusicApi/apihelper.h
  main.cpp
)
target_compile_definitions(${PROJECT_NAME} PRIVATE QCLOUDMUSICAPI_LIBRARY)
target_link_libraries(${PROJECT_NAME}  QCloudMusicApi)

引用头文件

#include "QCloudMusicApi/QCloudMusicApi/apihelper.h"

编译方式

git clone --recursive https://github.com/s12mmm3/QCloudMusicApi.git
cd QCloudMusicApi
cmake -B build
cmake --build build -j

License

The MIT License (MIT)

qcloudmusicapi's People

Contributors

ahdbshsnsndnnm avatar frzmtrsprt avatar s12mmm3 avatar zeyugao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

qcloudmusicapi's Issues

cookie api内保存

api内部可以尝试做一个session保存cookie,用户保存的话还得手动管理,类似于pyncm中的

anonymous_token的初始化时机

anonymous_token现在是用这个初始化方式

const QString anonymous_token = []() {
QString tmpPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
QFile file(QDir(tmpPath).absoluteFilePath("anonymous_token"));
file.open(QIODevice::ReadOnly | QIODevice::Text);
return file.readAll();
}();

我现在用这个库的时候是动态链接上去的,在调用invoke之前,会设置一下环境变量 QT_LOGGING_RULES=*.debug=false 来关掉debug信息,依赖qt在我设置环境变量后初始化

但是anonymous_token在init的时候就调用了,使得我的应用程序没法干预qt的初始化过程,导致QT_LOGGING_RULES的设置无效,可以改改anonymous_token的初始化方式吗,在调用的时候再去使用。

而且现在anonymous_token这个文件依赖于ApiServer生成,如果没有启动过ApiServer,这个文件就永远不存在,使得anonymous_token是空的

无法登录

使用login_cellphone,无论账号密码是否正确都返回

{
    "body": "",
    "cookie": null,
    "status": 200
}

openssl动态库版本问题

qt新的版本中使用的是openssl3,早期版本使用的是openssl1.1,而本项目使用的1.1版本。
所以我使用新版qt发送https请求时会链接到openssl3导致出错。

songUpload里面用wanproxy.127.net拿到的ip无法上传

这一段拿到的ip

auto reply = Request::axios(
QNetworkAccessManager::GetOperation,
"https://wanproxy.127.net/lbs?version=1.0&bucketname=" + bucket,
{}, {}, "");
reply->manager()->deleteLater();
const QVariantMap lbs = QJsonDocument::fromJson(reply->readAll()).toVariant().toMap();
reply = Request::axios(
QNetworkAccessManager::PostOperation,
"http://" + lbs["upload}"].toList()[0].toString() + "/" + bucket + "/" + objectKey + "?offset=0&complete=true&version=1.0",

上传的时候,qt的网络status( reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ) )是 Invalid 的,但是如果换成原来的 45.127.129.8 就是好的

cookie、login_status返回不完整

在用 login_qr_check 接口得到结果之后,虽然网易返回的cookie有很多,但是好像返回到json里面的只有第一个

image

login_status 好像也不知道为什么没有把body传回到api前面

image

都是用的capi,翻了一下代码,没看懂哪里错了(

Linux下直接调用c_api会crash

example/capi.py 下面的 QCloudMusicApi.dll 改成 libQCloudMusicApi.so,python就会直接crash

image

用一个这样的代码,在 build/bin 文件夹下面进行编译

#include "../../QCloudMusicApi/api_c.h"

int main()
{
    invoke("login_qr_key", "{}");
}
gcc main.c ./libQCloudMusicApi.so -o main
LD_LIBRARY_PATH=. ./main
image

gdb调试看是挂在了

image

系统是 ubuntu 22.04,qt版本6.2.4

scrobble接口是有效的吗

听歌打卡接口里面,即使返回了200和success,但是在手机上面看听歌时间仍然是没有变的

我看和nodejs那一边做对比,好像也没有区别

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.