-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLastFmDao.js
97 lines (97 loc) · 4.2 KB
/
LastFmDao.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"use strict";
/// <reference path="./definitions/DefinitelyTyped/underscore/underscore.d.ts"/>
/// <reference path="./definitions/dummy-definitions/lastfm.d.ts"/>
/// <reference path="./definitions/typescript-node-definitions/winston.d.ts"/>
exports.__esModule = true;
var winston = require("winston");
var DummyLastFmDao = (function () {
function DummyLastFmDao() {
}
DummyLastFmDao.prototype.postNowPlaying = function (song, lastFmUsername, session, callback) {
callback = callback || (function () { });
if (song.Artist && song.Track) {
winston.info("Faking post now playing to user " + lastFmUsername + ", session " + session + " of song:", song);
callback(null, "OK");
}
else {
callback("Invalid song", null);
}
};
DummyLastFmDao.prototype.scrobble = function (song, lastFmUsername, session, callback) {
callback = callback || (function () { });
if (song.Artist && song.Track) {
winston.info("Faking scrobble to user " + lastFmUsername + ", session " + session + " of song:", song);
callback(null, "OK");
}
else {
callback("Invalid song", null);
}
};
return DummyLastFmDao;
}());
exports.DummyLastFmDao = DummyLastFmDao;
var LastFmDaoImpl = (function () {
function LastFmDaoImpl(lastfmNode, postNowPlayingLength) {
this.lastfmNode = lastfmNode;
this.postNowPlayingLength = postNowPlayingLength;
}
LastFmDaoImpl.prototype.postNowPlaying = function (song, lastFmUsername, sessionKey, callback) {
callback = callback || (function () { });
if (!song || !song.Artist || !song.Track || !lastFmUsername || !sessionKey) {
winston.error("postNowPlaying invalid parameters:", { song: song, lastFmUsername: lastFmUsername, sessionKey: sessionKey });
callback("Invalid parameters", null);
return;
}
var updateOptions = {
artist: song.Artist,
track: song.Track,
duration: this.postNowPlayingLength,
handlers: {
success: function (data) {
winston.info("Success posting now playing for " + lastFmUsername, song);
callback(null, "OK");
},
retry: function (result) {
winston.warn("Retrying post now playing for " + lastFmUsername, result);
},
error: function (error) {
winston.error("Error posting now playing for " + lastFmUsername, error.message);
callback(error, null);
}
}
};
var session = this.lastfmNode.session(lastFmUsername, sessionKey);
this.lastfmNode.update('nowplaying', session, updateOptions);
};
LastFmDaoImpl.prototype.scrobble = function (song, lastFmUsername, sessionKey, callback) {
callback = callback || (function () { });
if (!song || !song.Artist || !song.Track || !lastFmUsername || !sessionKey) {
winston.error("scrobble invalid parameters:", { song: song, lastFmUsername: lastFmUsername, sessionKey: sessionKey });
callback("Invalid parameters", null);
return;
}
var updateOptions = {
artist: song.Artist,
track: song.Track,
timestamp: Math.round(song.StartTime / 1000),
handlers: {
success: function (data) {
winston.info("Success posting scrobble for " + lastFmUsername, song);
callback(null, "OK");
},
retry: function (result) {
winston.warn("Retrying scrobble for " + lastFmUsername, result);
},
error: function (error) {
winston.error("Error posting scrobble for " + lastFmUsername, error.message);
callback(error, null);
}
}
};
var session = this.lastfmNode.session(lastFmUsername, sessionKey);
this.lastfmNode.update('scrobble', session, updateOptions);
};
return LastFmDaoImpl;
}());
exports.LastFmDaoImpl = LastFmDaoImpl;
//# sourceMappingURL=LastFmDao.js.map