Discman
Loading...
Searching...
No Matches
AlbumArtProvider Class Referenceabstract

Abstracts web services that provide album art images. More...

#include <album_art_provider.h>

Inheritance diagram for AlbumArtProvider:
Collaboration diagram for AlbumArtProvider:

Classes

struct  AlbumArt
 An album art image and its URL. More...
 
struct  InitializationFailed
 Thrown when the provider cannot be reached. More...
 
struct  NotFoundException
 Thrown when the provider cannot find album art images. More...
 

Public Member Functions

virtual void init ()
 Initializes the AlbumArtProvider (i.e. retrieve an API key).
 
virtual std::vector< AlbumArtalbum_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.
 
AlbumArt album_art (const std::string &url, const int width, const int height)
 Retrieves the album art image at a given URL.
 

Static Public Member Functions

static AlbumArtProviderinstance ()
 Factory method to return the album art provider. It may be called one or more times. Be sure to destroy() the instance in order to avoid leaks. It is suggested to do so in the teardown of the first caller.
 
static void destroy ()
 Destroys the AlbumArtProvider.
 
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.
 
static std::string url_encode (const std::string &input)
 Encodes an arbitrary string into a query parameter value.
 

Protected Member Functions

 AlbumArtProvider ()
 AlbumArtProvider constructor.
 
virtual ~AlbumArtProvider ()
 AlbumArtProvider destructor.
 

Static Private Attributes

static AlbumArtProvider_instance = nullptr
 The global AlbumArtProvider instance.
 

Detailed Description

Abstracts web services that provide album art images.

Definition at line 23 of file album_art_provider.h.

Constructor & Destructor Documentation

◆ AlbumArtProvider()

AlbumArtProvider::AlbumArtProvider ( )
inlineprotected

AlbumArtProvider constructor.

Definition at line 92 of file album_art_provider.h.

◆ ~AlbumArtProvider()

virtual AlbumArtProvider::~AlbumArtProvider ( )
inlineprotectedvirtual

AlbumArtProvider destructor.

Definition at line 95 of file album_art_provider.h.

Member Function Documentation

◆ album_art() [1/2]

virtual std::vector< AlbumArt > AlbumArtProvider::album_art ( const std::string & artist,
const std::string & title,
const int width,
const int height )
pure virtual

Return all album art matching the criteria, at a specific width and height.

Parameters
[in]artistAlbum artist.
[in]titleAlbum title.
[in]widthAlbum art image width.
[in]heightAlbum art image height.
Returns
A list of album art images.

Implemented in LastFM, and Spotify.

◆ album_art() [2/2]

AlbumArtProvider::AlbumArt AlbumArtProvider::album_art ( const std::string & url,
const int width,
const int height )

Retrieves the album art image at a given URL.

Parameters
[in]urlURL of the album art image to retrieve.
[in]widthWidth of the returned image.
[in]heightHeight of the returned image.
Returns
An album art image.

Definition at line 64 of file album_art_provider.cc.

◆ destroy()

void AlbumArtProvider::destroy ( )
static

Destroys the AlbumArtProvider.

Definition at line 54 of file album_art_provider.cc.

◆ init()

void AlbumArtProvider::init ( )
virtual

Initializes the AlbumArtProvider (i.e. retrieve an API key).

Reimplemented in LastFM, and Spotify.

Definition at line 58 of file album_art_provider.cc.

◆ instance()

AlbumArtProvider * AlbumArtProvider::instance ( )
static

Factory method to return the album art provider. It may be called one or more times. Be sure to destroy() the instance in order to avoid leaks. It is suggested to do so in the teardown of the first caller.

Returns
The provider that has been selected via configuration file.

Definition at line 13 of file album_art_provider.cc.

◆ url_encode()

std::string AlbumArtProvider::url_encode ( const std::string & input)
static

Encodes an arbitrary string into a query parameter value.

Parameters
[in]inputAn arbitrary string.
Returns
The URL encoded input.

Definition at line 101 of file album_art_provider.cc.

◆ url_with_params()

std::string AlbumArtProvider::url_with_params ( const std::string & url,
const std::map< std::string, std::string > & params )
static

Returns the URL of the API endpoint with the given parameters encoded as query parameters.

Parameters
[in]urlAn API endpoint. This usually corresponds to an API method.
[in]paramsThe method parameters as key-value pairs.
Returns
An API endpoint URL.

Definition at line 86 of file album_art_provider.cc.

Member Data Documentation

◆ _instance

AlbumArtProvider * AlbumArtProvider::_instance = nullptr
staticprivate

The global AlbumArtProvider instance.

Definition at line 88 of file album_art_provider.h.


The documentation for this class was generated from the following files: