Discman
Loading...
Searching...
No Matches
album_art_provider.h
Go to the documentation of this file.
1
6
7#ifndef ALBUM_ART_PROVIDER_H
8#define ALBUM_ART_PROVIDER_H
9
10#include <algorithm>
11#include <cctype>
12#include <string>
13#include <sstream>
14#include <curlpp/Easy.hpp>
15#include <curlpp/Options.hpp>
16#include <curlpp/cURLpp.hpp>
17
18#include <glibmm.h>
19#include <giomm/memoryinputstream.h>
20#include <gdkmm/pixbuf.h>
21
24 public:
25
27 struct InitializationFailed : public std::exception {
28 const char* what() const throw() {
29 return "Album art provider could not initialize. Please check your environment variables.";
30 }
31 };
32
34 struct NotFoundException : public std::exception {
35 const char* what() const throw() {
36 return "Resource could not be found.";
37 }
38 };
39
41 struct AlbumArt {
42 Glib::RefPtr<Gdk::Pixbuf> art;
43 std::string url;
44 };
45
51 static AlbumArtProvider* instance();
52
54 static void destroy();
55
58 virtual void init();
59
66 virtual std::vector<AlbumArt> album_art(const std::string& artist, const std::string& title, const int width, const int height) = 0;
67
73 AlbumArt album_art(const std::string& url, const int width, const int height);
74
79 static std::string url_with_params(const std::string& url, const std::map<std::string, std::string>& params);
80
84 static std::string url_encode(const std::string& input);
85
86
87 private:
89
90 protected:
93
95 virtual ~AlbumArtProvider() {};
96};
97
98#endif // ALBUM_ART_PROVIDER_H
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 > &params)
Returns the URL of the API endpoint with the given parameters encoded as query parameters.
virtual ~AlbumArtProvider()
AlbumArtProvider destructor.
An album art image and its URL.
Glib::RefPtr< Gdk::Pixbuf > art
Thrown when the provider cannot be reached.
Thrown when the provider cannot find album art images.