Permalink
Browse files

Ported xmms2-scrobbler to rv-split.

  • Loading branch information...
1 parent b048b2d commit 29e8762ffe36cccd8429e74eec7e615f7ecd1379 Tilman Sauerbeck committed Oct 25, 2008
Showing with 54 additions and 36 deletions.
  1. +12 −12 src/submission.c
  2. +2 −2 src/submission.h
  3. +40 −22 src/xmms2-scrobbler.c
View
@@ -37,20 +37,20 @@ submission_new (StrBuf *sb, SubmissionType type)
}
Submission *
-now_playing_submission_new (xmmsc_result_t *res)
+now_playing_submission_new (xmmsv_t *dict)
{
StrBuf *sb;
const char *artist, *title, *val_s;
int32_t val_i;
int s;
/* artist is required */
- s = xmmsc_result_get_dict_entry_string (res, "artist", &artist);
+ s = xmmsv_get_dict_entry_string (dict, "artist", &artist);
if (!s)
return NULL;
/* title is required */
- s = xmmsc_result_get_dict_entry_string (res, "title", &title);
+ s = xmmsv_get_dict_entry_string (dict, "title", &title);
if (!s)
return NULL;
@@ -71,14 +71,14 @@ now_playing_submission_new (xmmsc_result_t *res)
/* album */
strbuf_append (sb, "&b=");
- s = xmmsc_result_get_dict_entry_string (res, "album", &val_s);
+ s = xmmsv_get_dict_entry_string (dict, "album", &val_s);
if (s)
strbuf_append_encoded (sb, (const uint8_t *) val_s);
/* duration in seconds */
strbuf_append (sb, "&l=");
- s = xmmsc_result_get_dict_entry_int (res, "duration", &val_i);
+ s = xmmsv_get_dict_entry_int (dict, "duration", &val_i);
if (s) {
char buf32[32];
@@ -95,15 +95,15 @@ now_playing_submission_new (xmmsc_result_t *res)
/* musicbrainz track id */
strbuf_append (sb, "&m=");
- s = xmmsc_result_get_dict_entry_string (res, "track_id", &val_s);
+ s = xmmsv_get_dict_entry_string (dict, "track_id", &val_s);
if (s)
strbuf_append (sb, val_s);
return submission_new (sb, SUBMISSION_TYPE_NOW_PLAYING);
}
Submission *
-profile_submission_new (xmmsc_result_t *res, uint32_t seconds_played,
+profile_submission_new (xmmsv_t *dict, uint32_t seconds_played,
time_t started_playing)
{
StrBuf *sb;
@@ -113,7 +113,7 @@ profile_submission_new (xmmsc_result_t *res, uint32_t seconds_played,
int s;
/* duration in seconds is required */
- s = xmmsc_result_get_dict_entry_int (res, "duration", &val_i);
+ s = xmmsv_get_dict_entry_int (dict, "duration", &val_i);
if (!s)
return NULL;
@@ -123,12 +123,12 @@ profile_submission_new (xmmsc_result_t *res, uint32_t seconds_played,
}
/* artist is required */
- s = xmmsc_result_get_dict_entry_string (res, "artist", &artist);
+ s = xmmsv_get_dict_entry_string (dict, "artist", &artist);
if (!s)
return NULL;
/* title is required */
- s = xmmsc_result_get_dict_entry_string (res, "title", &title);
+ s = xmmsv_get_dict_entry_string (dict, "title", &title);
if (!s)
return NULL;
@@ -166,7 +166,7 @@ profile_submission_new (xmmsc_result_t *res, uint32_t seconds_played,
/* album */
strbuf_append (sb, "&b[0]=");
- s = xmmsc_result_get_dict_entry_string (res, "album", &val_s);
+ s = xmmsv_get_dict_entry_string (dict, "album", &val_s);
if (s) {
strbuf_append_encoded (sb, (const uint8_t *) val_s);
}
@@ -180,7 +180,7 @@ profile_submission_new (xmmsc_result_t *res, uint32_t seconds_played,
/* musicbrainz track id */
strbuf_append (sb, "&m[0]=");
- s = xmmsc_result_get_dict_entry_string (res, "track_id", &val_s);
+ s = xmmsv_get_dict_entry_string (dict, "track_id", &val_s);
if (s)
strbuf_append (sb, val_s);
View
@@ -40,8 +40,8 @@ typedef struct {
} Submission;
Submission *submission_new (StrBuf *sb, SubmissionType type);
-Submission *now_playing_submission_new (xmmsc_result_t *res);
-Submission *profile_submission_new (xmmsc_result_t *res, uint32_t seconds_played, time_t started_playing);
+Submission *now_playing_submission_new (xmmsv_t *dict);
+Submission *profile_submission_new (xmmsv_t *dict, uint32_t seconds_played, time_t started_playing);
void submission_free (Submission *s);
#endif
View
@@ -60,6 +60,10 @@ static bool keep_running = true;
static struct sigaction sig;
+static const char *sources[] = {
+ "server", "plugins/*", "client/*", "*"
+};
+
static void
signal_handler (int sig)
{
@@ -374,32 +378,38 @@ enqueue (Submission *submission)
}
static void
-submit_now_playing (xmmsc_result_t *res)
+submit_now_playing (xmmsv_t *val)
{
Submission *submission;
+ xmmsv_t *dict;
- submission = now_playing_submission_new (res);
+ dict = xmmsv_propdict_to_dict (val, sources);
+ submission = now_playing_submission_new (dict);
+ xmmsv_unref (dict);
if (submission)
enqueue (submission);
}
static bool
-submit_to_profile (xmmsc_result_t *res)
+submit_to_profile (xmmsv_t *val)
{
Submission *submission;
+ xmmsv_t *dict;
- submission = profile_submission_new (res, seconds_played,
+ dict = xmmsv_propdict_to_dict (val, sources);
+ submission = profile_submission_new (dict, seconds_played,
started_playing);
+ xmmsv_unref (dict);
if (submission)
enqueue (submission);
return !!submission;
}
-static void
-on_medialib_get_info2 (xmmsc_result_t *res, void *udata)
+static int
+on_medialib_get_info2 (xmmsv_t *val, void *udata)
{
bool reset_current_id = XPOINTER_TO_INT (udata);
@@ -409,22 +419,22 @@ on_medialib_get_info2 (xmmsc_result_t *res, void *udata)
/* if we could submit this song we might have to reset
* 'current_id', so we don't submit it again.
*/
- if (submit_to_profile (res) && reset_current_id)
+ if (submit_to_profile (val) && reset_current_id)
current_id = UINT_MAX;
- xmmsc_result_unref (res);
+ return 0;
}
-static void
-on_medialib_get_info (xmmsc_result_t *res, void *udata)
+static int
+on_medialib_get_info (xmmsv_t *val, void *udata)
{
- submit_now_playing (res);
-
- xmmsc_result_unref (res);
+ submit_now_playing (val);
printf("resetting seconds_played\n");
last_unpause = started_playing = time (NULL);
seconds_played = 0;
+
+ return 0;
}
static void
@@ -443,8 +453,8 @@ maybe_submit_to_profile (bool reset_current_id)
xmmsc_result_unref (mediainfo_result);
}
-static void
-on_playback_current_id (xmmsc_result_t *res, void *udata)
+static int
+on_playback_current_id (xmmsv_t *val, void *udata)
{
xmmsc_result_t *mediainfo_result;
uint32_t id = UINT32_MAX;
@@ -456,7 +466,7 @@ on_playback_current_id (xmmsc_result_t *res, void *udata)
maybe_submit_to_profile (false);
/* get the new song's medialib id. */
- xmmsc_result_get_uint (res, &id);
+ xmmsv_get_uint (val, &id);
printf ("now playing %u\n", id);
@@ -467,17 +477,19 @@ on_playback_current_id (xmmsc_result_t *res, void *udata)
xmmsc_result_notifier_set (mediainfo_result,
on_medialib_get_info, NULL);
xmmsc_result_unref (mediainfo_result);
+
+ return 1;
}
-static void
-on_playback_status (xmmsc_result_t *res, void *udata)
+static int
+on_playback_status (xmmsv_t *val, void *udata)
{
xmms_playback_status_t status;
int s;
- s = xmmsc_result_get_uint (res, &status);
+ s = xmmsv_get_uint (val, &status);
if (!s)
- return;
+ return 1;
switch (status) {
case XMMS_PLAYBACK_STATUS_STOP:
@@ -491,12 +503,16 @@ on_playback_status (xmmsc_result_t *res, void *udata)
last_unpause = time (NULL);
break;
}
+
+ return 1;
}
-static void
-on_quit (xmmsc_result_t *res, void *udata)
+static int
+on_quit (xmmsv_t *val, void *udata)
{
keep_running = false;
+
+ return 0;
}
static void
@@ -749,10 +765,12 @@ main (int argc, char **argv)
curl_global_cleanup ();
+#if 0
/* disconnect broadcasts and signals */
xmmsc_result_disconnect (current_id_broadcast);
xmmsc_result_disconnect (playback_status_broadcast);
xmmsc_result_disconnect (quit_broadcast);
+#endif
xmmsc_unref (conn);

0 comments on commit 29e8762

Please sign in to comment.