Removed curl dependency and use wt's http client instead (used to fetch data from AcousticBrainz)
This commit is contained in:
@@ -44,7 +44,7 @@ The Subsonic API is enabled by default.
|
|||||||
## Installation
|
## Installation
|
||||||
Here are the required packages to build LMS on Debian Stretch:
|
Here are the required packages to build LMS on Debian Stretch:
|
||||||
```sh
|
```sh
|
||||||
apt-get install g++ autoconf automake libboost-filesystem-dev libboost-system-dev libavcodec-dev libavutil-dev libavformat-dev libav-tools libmagick++-dev libpstreams-dev libconfig++-dev libpstreams-dev ffmpeg libtag1-dev libcurl4-openssl-dev
|
apt-get install g++ autoconf automake libboost-filesystem-dev libboost-system-dev libavcodec-dev libavutil-dev libavformat-dev libav-tools libmagick++-dev libpstreams-dev libconfig++-dev libpstreams-dev ffmpeg libtag1-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
You also need wt4, that is not packaged yet on Debian. See [installation instructions](https://www.webtoolkit.eu/wt/doc/reference/html/InstallationUnix.html). You may need to build Wt4 in "Release" mode if you want to compile it natively on a Raspberry Pi3B+.
|
You also need wt4, that is not packaged yet on Debian. See [installation instructions](https://www.webtoolkit.eu/wt/doc/reference/html/InstallationUnix.html). You may need to build Wt4 in "Release" mode if you want to compile it natively on a Raspberry Pi3B+.
|
||||||
|
|||||||
+1
-6
@@ -16,7 +16,7 @@ fi
|
|||||||
AC_SUBST(MAGICKXX_CFLAGS)
|
AC_SUBST(MAGICKXX_CFLAGS)
|
||||||
AC_SUBST(MAGICKXX_LIBS)
|
AC_SUBST(MAGICKXX_LIBS)
|
||||||
|
|
||||||
AC_CHECK_HEADERS([Wt/WApplication.h pstreams/pstream.h curl/curl.h],
|
AC_CHECK_HEADERS([Wt/WApplication.h pstreams/pstream.h],
|
||||||
[],
|
[],
|
||||||
[AC_MSG_ERROR([Header not found or unusable !])])
|
[AC_MSG_ERROR([Header not found or unusable !])])
|
||||||
|
|
||||||
@@ -81,11 +81,6 @@ AC_CHECK_LIB( [config++],
|
|||||||
,
|
,
|
||||||
[AC_MSG_ERROR([libconfig++ not found!])])
|
[AC_MSG_ERROR([libconfig++ not found!])])
|
||||||
|
|
||||||
AC_CHECK_LIB( [curl],
|
|
||||||
[curl_easy_init],
|
|
||||||
,
|
|
||||||
[AC_MSG_ERROR([libcurl not found!])])
|
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile
|
AC_CONFIG_FILES([Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
test/Makefile
|
test/Makefile
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
#include <curl/curl.h>
|
|
||||||
|
#include <Wt/WIOService.h>
|
||||||
|
#include <Wt/Http/Client.h>
|
||||||
|
|
||||||
#include "main/Service.hpp"
|
#include "main/Service.hpp"
|
||||||
#include "utils/Config.hpp"
|
#include "utils/Config.hpp"
|
||||||
@@ -31,63 +33,52 @@
|
|||||||
namespace AcousticBrainz
|
namespace AcousticBrainz
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
static size_t writeToOStringStream(void *buffer, size_t size, size_t nmemb, void* ctx)
|
|
||||||
{
|
|
||||||
std::ostringstream& oss = *reinterpret_cast<std::ostringstream*>(ctx);
|
|
||||||
|
|
||||||
oss.write(reinterpret_cast<char*>(buffer), size * nmemb);
|
|
||||||
|
|
||||||
return size * nmemb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
getJsonData(const std::string& mbid)
|
getJsonData(const std::string& mbid)
|
||||||
{
|
{
|
||||||
static const std::string defaultAPIURL = "https://acousticbrainz.org/api/v1/";
|
static const std::string defaultAPIURL = "https://acousticbrainz.org/api/v1/";
|
||||||
|
|
||||||
std::string data;
|
const std::string url {getService<Config>()->getString("acousticbrainz-api-url", defaultAPIURL) + mbid + "/low-level"};
|
||||||
std::string url = getService<Config>()->getString("acousticbrainz-api-url", defaultAPIURL) + mbid + "/low-level";
|
|
||||||
|
|
||||||
CURL *curl;
|
boost::asio::io_service ioService;
|
||||||
CURLcode res;
|
|
||||||
|
|
||||||
curl = curl_easy_init();
|
Wt::Http::Client client {ioService};
|
||||||
if (!curl)
|
client.setFollowRedirect(true);
|
||||||
|
client.setSslCertificateVerificationEnabled(true);
|
||||||
|
client.setMaximumResponseSize(256*1024);
|
||||||
|
|
||||||
|
if (!client.get(url))
|
||||||
{
|
{
|
||||||
LMS_LOG(SIMILARITY, ERROR) << "CURL init failed";
|
LMS_LOG(SIMILARITY, ERROR) << "Cannot perform a GET request to url '" << url << "'";
|
||||||
return data;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::string response;
|
||||||
|
client.done().connect([&](Wt::AsioWrapper::error_code ec, const Wt::Http::Message &msg)
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeToOStringStream);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
|
|
||||||
|
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
if (res != CURLE_OK)
|
|
||||||
{
|
{
|
||||||
LMS_LOG(SIMILARITY, ERROR) << "CURL perform failed: " << curl_easy_strerror(res);
|
if (ec)
|
||||||
return data;
|
{
|
||||||
}
|
LMS_LOG(SIMILARITY, ERROR) << "GET request to url '" << url << "' failed: " << ec.message();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
curl_easy_cleanup(curl);
|
if (msg.status() != 200)
|
||||||
|
{
|
||||||
|
LMS_LOG(SIMILARITY, ERROR) << "GET request to url '" << url << "' failed: status = " << msg.status() << ", body = " << msg.body();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data = std::move(oss.str());
|
response = msg.body();
|
||||||
|
});
|
||||||
|
|
||||||
return data;
|
ioService.run();
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
extractLowLevelFeatures(const std::string& mbid)
|
extractLowLevelFeatures(const std::string& mbid)
|
||||||
{
|
{
|
||||||
if (boost::filesystem::exists("/storage/emeric/lms-dev/features/" + mbid))
|
|
||||||
{
|
|
||||||
std::ifstream ifs{std::string{"/storage/emeric/lms-dev/features/" + mbid}.c_str()};
|
|
||||||
return std::string {std::istreambuf_iterator<char>{ifs}, std::istreambuf_iterator<char>{}};
|
|
||||||
}
|
|
||||||
|
|
||||||
return getJsonData(mbid);
|
return getJsonData(mbid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,22 +160,22 @@ FeaturesScannerAddon::fetchFeatures(Database::IdType trackId, const std::string&
|
|||||||
std::map<std::string, double> features;
|
std::map<std::string, double> features;
|
||||||
|
|
||||||
LMS_LOG(DBUPDATER, DEBUG) << "Fetching low level features for track '" << MBID << "'";
|
LMS_LOG(DBUPDATER, DEBUG) << "Fetching low level features for track '" << MBID << "'";
|
||||||
std::string data {AcousticBrainz::extractLowLevelFeatures(MBID)};
|
const std::string data {AcousticBrainz::extractLowLevelFeatures(MBID)};
|
||||||
if (data.empty())
|
if (data.empty())
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, ERROR) << "Track " << trackId << ", MBID = '" << MBID << "': cannot extract features using AcousticBrainz";
|
LMS_LOG(DBUPDATER, ERROR) << "Track " << trackId << ", MBID = '" << MBID << "': cannot extract features using AcousticBrainz";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto uniqueTransaction {_dbSession->createUniqueTransaction()};
|
{
|
||||||
|
auto uniqueTransaction {_dbSession->createUniqueTransaction()};
|
||||||
|
|
||||||
Wt::Dbo::ptr<Database::Track> track {Database::Track::getById(*_dbSession, trackId)};
|
Wt::Dbo::ptr<Database::Track> track {Database::Track::getById(*_dbSession, trackId)};
|
||||||
if (!track)
|
if (!track)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LMS_LOG(DBUPDATER, DEBUG) << "Successfully extracted AcousticBrainz lowlevel features for track '" << track->getPath().string() << "'";
|
Database::TrackFeatures::create(*_dbSession, track, data);
|
||||||
|
}
|
||||||
Database::TrackFeatures::create(*_dbSession, track, data);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user