-
Notifications
You must be signed in to change notification settings - Fork 22
/
audioscrobbler.h
54 lines (44 loc) · 1.19 KB
/
audioscrobbler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _AUDIOSCROBBLER_H
#define _AUDIOSCROBBLER_H
class CAudioScrobbler
{
public:
CAudioScrobbler(CConfig *cfg);
~CAudioScrobbler();
void Handshake();
std::string CreateScrobbleMessage(int index, const CacheEntry& entry);
bool Scrobble(const CacheEntry& entry);
void ReportResponse(char* buf, size_t size);
bool LoveTrack(const Song& song, bool unlove = false);
bool SendNowPlaying(const Song& song);
void Failure();
private:
std::string GetServiceURL();
void OpenURL(std::string url, const char* postfields, char* errbuf);
bool CheckFailure(std::string response);
CConfig *_cfg;
CURL* _handle;
std::string _password;
std::string _response;
std::string _sessionid;
bool _authed;
int _failcount;
};
class CLastFMMessage
{
public:
CLastFMMessage(CURL *curl_handle) { this->curl_handle = curl_handle; }
void AddField(std::string name, std::string value) { valueMap[name] = value; }
void AddField(std::string name, int value) {
std::ostringstream str;
str << value;
AddField(name, str.str());
}
std::string GetMessage();
private:
std::map<std::string, std::string> valueMap;
std::string GetSignatureHash();
CURL *curl_handle;
};
extern CAudioScrobbler* AudioScrobbler;
#endif