summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-22 12:16:31 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-22 12:16:31 +0200
commita3a3898e37944e64a58d412022931496318e6209 (patch)
tree1591d52be044c60be5d8a49a278f0451ef2366ab
parent7758eeaaafb49bb8c2ced598f3a9480978ba8265 (diff)
downloadpianobar-a3a3898e37944e64a58d412022931496318e6209.tar.gz
pianobar-a3a3898e37944e64a58d412022931496318e6209.tar.bz2
pianobar-a3a3898e37944e64a58d412022931496318e6209.zip
client: last.fm scrobbling implemented
Very very ugly... We should spawn another thread. But for now it's working. (Though the played times are wrong for me, could be a wardrobe issue...)
-rw-r--r--configure.in2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/main.c36
-rw-r--r--src/pianobar.19
-rw-r--r--src/settings.c10
-rw-r--r--src/settings.h3
6 files changed, 61 insertions, 3 deletions
diff --git a/configure.in b/configure.in
index 9dec623..f4f1c7d 100644
--- a/configure.in
+++ b/configure.in
@@ -37,6 +37,6 @@ AC_CHECK_FUNCS([memset])
AC_TYPE_SIZE_T
AC_CONFIG_FILES(Makefile src/Makefile)
-AC_CONFIG_SUBDIRS([libpiano])
+AC_CONFIG_SUBDIRS([libpiano libwardrobe])
AC_OUTPUT
diff --git a/src/Makefile.am b/src/Makefile.am
index 606430b..e3a98a4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,8 +3,8 @@ bin_PROGRAMS = pianobar
pianobar_SOURCES = main.c terminal.c terminal.h settings.c settings.h \
player.c player.h
pianobar_CPPFLAGS = ${LIBCURL_CFLAGS} ${LIBAO_CFLAGS} ${LIBXML_CFLAGS} \
- -I../libpiano/src
+ -I../libpiano/src -I../libwardrobe/src
pianobar_LDADD = ${LIBCURL_LIBS} ${LIBAO_LIBS} ${LIBFAAD_LIBS} \
${LIBREADLINE_LIBS} ${LIBXML_LIBS} -lpthread \
- ../libpiano/src/libpiano.la
+ ../libpiano/src/libpiano.la ../libwardrobe/src/libwardrobe.la
dist_man1_MANS = pianobar.1
diff --git a/src/main.c b/src/main.c
index 872bc62..f8ce101 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,6 +21,7 @@ THE SOFTWARE.
*/
#include <piano.h>
+#include <wardrobe.h>
#include <curl/curl.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
@@ -31,6 +32,7 @@ THE SOFTWARE.
#include <unistd.h>
#include <poll.h>
#include <readline/readline.h>
+#include <time.h>
#include "terminal.h"
#include "settings.h"
@@ -156,6 +158,8 @@ int main (int argc, char **argv) {
PianoStation_t *curStation = NULL;
BarSettings_t bsettings;
pthread_t playerThread;
+ WardrobeSong_t scrobbleSong;
+ WardrobeHandle_t wh;
printf ("Welcome to " PACKAGE_STRING "! Press ? for help.\n");
@@ -177,6 +181,13 @@ int main (int argc, char **argv) {
}
PianoInit (&ph);
+ WardrobeInit (&wh);
+
+ if (bsettings.enableScrobbling) {
+ wh.user = strdup (bsettings.lastfmUser);
+ wh.password = strdup (bsettings.lastfmPassword);
+ }
+
/* setup control connection */
if (bsettings.controlProxy != NULL &&
bsettings.controlProxyType != -1) {
@@ -216,6 +227,21 @@ int main (int argc, char **argv) {
if (player.finishedPlayback == 1) {
/* already played a song, clean up things */
if (player.url != NULL) {
+ scrobbleSong.length = BarSamplesToSeconds (player.samplerate,
+ player.channels, player.sampleSizeN);
+ /* scrobble when >= 90% are played */
+ if (BarSamplesToSeconds (player.samplerate,
+ player.channels, player.sampleSizeCurr) * 100 /
+ scrobbleSong.length >= 90 &&
+ bsettings.enableScrobbling) {
+ if (WardrobeSubmit (&wh, &scrobbleSong) ==
+ WARDROBE_RET_OK) {
+ printf ("Scrobbled. \n");
+ } else {
+ printf ("Errror while scrobbling. \n");
+ }
+ }
+ WardrobeSongDestroy (&scrobbleSong);
free (player.url);
memset (&player, 0, sizeof (player));
pthread_join (playerThread, NULL);
@@ -236,9 +262,18 @@ int main (int argc, char **argv) {
}
}
if (curSong != NULL) {
+ time_t currTime = time (NULL);
+ time_t currGmTime = mktime (gmtime (&currTime));
printf ("\"%s\" by \"%s\"%s\n", curSong->title,
curSong->artist, (curSong->rating ==
PIANO_RATE_LOVE) ? " (Loved)" : "");
+ /* setup artist and song name for scrobbling (curSong
+ * may be NULL later) */
+ WardrobeSongInit (&scrobbleSong);
+ scrobbleSong.artist = strdup (curSong->artist);
+ scrobbleSong.title = strdup (curSong->title);
+ scrobbleSong.started = currGmTime;
+
/* FIXME: why do we need to zero everything again? */
memset (&player, 0, sizeof (player));
player.url = strdup (curSong->audioUrl);
@@ -394,6 +429,7 @@ int main (int argc, char **argv) {
}
/* destroy everything (including the world...) */
PianoDestroy (&ph);
+ WardrobeDestroy (&wh);
curl_global_cleanup ();
ao_shutdown();
xmlCleanupParser ();
diff --git a/src/pianobar.1 b/src/pianobar.1
index 0478af3..c17a3c3 100644
--- a/src/pianobar.1
+++ b/src/pianobar.1
@@ -87,6 +87,15 @@ needs an IP address specified in
.B control_proxy
.TP
+.B lastfm_user = your_username
+If you want to send your played song to last.fm set this to your last.fm
+username.
+
+.TP
+.B lastfm_password = plain_password
+A password is needed too if you want to scrobble your played song.
+
+.TP
.B password = plaintext_password
Your pandora.com password. Plain-text.
diff --git a/src/settings.c b/src/settings.c
index 91fce9a..abdf5b7 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -62,6 +62,9 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->controlProxy);
free (settings->username);
free (settings->password);
+ free (settings->lastfmUser);
+ free (settings->lastfmPassword);
+ memset (settings, 0, sizeof (*settings));
}
/* read app settings from file; format is: key = value\n
@@ -104,8 +107,15 @@ void readSettings (BarSettings_t *settings) {
settings->username = strdup (val);
} else if (strcmp ("password", key) == 0) {
settings->password = strdup (val);
+ } else if (strcmp ("lastfm_user", key) == 0) {
+ settings->lastfmUser = strdup (val);
+ } else if (strcmp ("lastfm_password", key) == 0) {
+ settings->lastfmPassword = strdup (val);
}
}
+ if (settings->lastfmUser != NULL && settings->lastfmPassword != NULL) {
+ settings->enableScrobbling = 1;
+ }
fclose (configfd);
}
diff --git a/src/settings.h b/src/settings.h
index 15b5396..71737f2 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -30,6 +30,9 @@ struct BarSettings {
char *password;
char *controlProxy; /* non-american listeners need this */
curl_proxytype controlProxyType;
+ char *lastfmUser;
+ char *lastfmPassword;
+ char enableScrobbling;
};
typedef struct BarSettings BarSettings_t;