15 std::vector<std::string> providers = {
20 std::string provider = std::getenv(
"DISCMAN_ALBUMART_PROVIDER")
21 ? std::getenv(
"DISCMAN_ALBUMART_PROVIDER")
24 std::transform(provider.begin(), provider.end(), provider.begin(), [](
unsigned char c) {
25 return std::tolower(c);
28 auto it = std::find(providers.begin(), providers.end(), provider);
30 int providerIndex = std::distance(providers.begin(), it);
32 switch (providerIndex) {
37 }
catch (std::exception&) {
44 }
catch (std::exception&) {
65 cURLpp::Cleanup cleanup;
66 cURLpp::Easy easyhandle;
69 easyhandle.setOpt(cURLpp::Options::Url(url));
70 easyhandle.setOpt(cURLpp::Options::WriteStream(&ss));
73 std::string data = ss.str();
74 Glib::RefPtr<Glib::Bytes> bytes = Glib::Bytes::create(data.c_str(), data.size());
75 Glib::RefPtr<Gio::MemoryInputStream> is = Gio::MemoryInputStream::create();
79 .art = Gdk::Pixbuf::create_from_stream_at_scale(is, width, height,
true),
87 std::string new_url(url);
88 if (new_url[new_url.length() - 1] !=
'/') new_url +=
'/';
92 for (std::map<std::string, std::string>::const_iterator it=params.cbegin(); it!=params.cend(); ++it) {
93 ss << (it == params.cbegin() ?
'?' :
'&');
95 ss << it->first <<
'=' <<
url_encode(it->second);
102 std::stringstream escaped;
106 for (std::string::const_iterator i = input.begin(), n = input.end(); i != n; ++i) {
107 const std::string::value_type c = (*i);
109 if (isalnum(c) || c ==
'-' || c ==
'_' || c ==
'.' || c ==
'~') {
112 }
else if (c ==
' ') {
117 escaped << std::uppercase;
118 escaped <<
'%' << std::setw(2) << int((
unsigned char) c);
119 escaped << std::nouppercase;
122 return escaped.str();
Abstracts web services that provide album art images.
virtual std::vector< AlbumArt > album_art(const std::string &artist, const std::string &title, const int width, const int height)=0
Return all album art matching the criteria, at a specific width and height.
virtual void init()
Initializes the AlbumArtProvider (i.e. retrieve an API key).
static AlbumArtProvider * _instance
The global AlbumArtProvider instance.
static std::string url_encode(const std::string &input)
Encodes an arbitrary string into a query parameter value.
static void destroy()
Destroys the AlbumArtProvider.
AlbumArtProvider()
AlbumArtProvider constructor.
static AlbumArtProvider * instance()
Factory method to return the album art provider. It may be called one or more times....
static std::string url_with_params(const std::string &url, const std::map< std::string, std::string > ¶ms)
Returns the URL of the API endpoint with the given parameters encoded as query parameters.
An interface to last.fm for retrieving album art.
An interface to Spotify for retrieving album art.
An album art image and its URL.