static gboolean ol_player_listen_get_music_info (OlMusicInfo *info) { /* ol_log_func (); */ ol_assert (info != NULL); if (connection == NULL || proxy == NULL) if (!ol_player_listen_init_dbus ()) { ol_debug ("Initialize dbus proxy failed\n"); return FALSE; } gchar *buf; enum OlPlayerStatus status = ol_player_listen_get_status (); ol_debugf (" status: %d\n", (int)status); if (status == OL_PLAYER_PLAYING) { ol_music_info_clear (info); /* gets the title of current music */ if (!ol_dbus_get_string (proxy, get_title, &info->title)) { ol_error (" Get title failed"); } /* gets the artist of current music */ if (!ol_dbus_get_string (proxy, get_artist, &info->artist)) { ol_error (" Get artist failed"); } /* gets the album of current music */ if (!ol_dbus_get_string (proxy, get_album, &info->album)) { ol_error (" Get album failed"); } /* gets the location of the file */ if (!ol_dbus_get_string (proxy, get_uri, &info->uri)) { ol_error (" Get track number failed"); } return TRUE; } else if (status == OL_PLAYER_STOPPED) { return TRUE; } else { ol_errorf (" unknown status\n"); return FALSE; } }
static gboolean _get_music_info_and_length (OlMusicInfo *info, int *len) { ol_log_func (); if (!_ensure_connection ()) return FALSE; char *infostr = NULL; if (!ol_dbus_get_string (proxy, GET_CURRENT_SONG, &infostr)) return FALSE; if (info != NULL) ol_music_info_clear (info); char *current, *next; current = infostr; while (current != NULL) { char *key, *value; next = ol_split_a_line (current); key = current; value = strchr (current, ':'); *value = '\0'; value++; key = ol_trim_string (key); value = ol_trim_string (value); if (strcmp (key, PROP_TITLE) == 0) { if (info != NULL) ol_music_info_set_title (info, value); } else if (strcmp (key, PROP_ARTIST) == 0) { if (info != NULL) ol_music_info_set_artist (info, value); } else if (strcmp (key, PROP_ALBUM) == 0) { if (info != NULL) ol_music_info_set_album (info, value); } else if (strcmp (key, PROP_URI) == 0) { if (info != NULL) ol_music_info_set_uri (info, value); } else if (strcmp (key, PROP_TRACK_NUMBER) == 0) { if (info != NULL) ol_music_info_set_track_number (info, atoi (value)); } else if (strcmp (key, PROP_DURATION) == 0) { if (len != NULL) *len = atoi (value) * 1000; } current = next; } return TRUE; }
static gboolean _get_music_info (OlMusicInfo *info) { ol_assert_ret (info != NULL, FALSE); if (!_ensure_dbus ()) return FALSE; ol_music_info_clear (info); char *value = NULL; if (!ol_dbus_get_string_with_str_arg (proxy, TRACK_PROP, TITLE, &value)) return FALSE; ol_music_info_set_title (info, value); if (value != NULL) g_free (value); if (!ol_dbus_get_string_with_str_arg (proxy, TRACK_PROP, ARTIST, &value)) return FALSE; ol_music_info_set_artist (info, value); if (value != NULL) g_free (value); if (!ol_dbus_get_string_with_str_arg (proxy, TRACK_PROP, ALBUM, &value)) return FALSE; ol_music_info_set_album (info, value); if (value != NULL) g_free (value); /* FIXME: Escape the URI */ if (!ol_dbus_get_string_with_str_arg (proxy, TRACK_PROP, PATH, &value)) return FALSE; ol_music_info_set_uri (info, value); if (value != NULL) g_free (value); int track = -1; if (!ol_dbus_get_string_with_str_arg (proxy, TRACK_PROP, TRACK, &value)) return FALSE; if (sscanf (value, "%d", &track) == 1) ol_music_info_set_track_number (info, track); if (value != NULL) g_free (value); /* ol_debugf(" artist:%s\n" */ /* " title:%s\n" */ /* " album:%s\n" */ /* " track:%d\n" */ /* " uri:%s\n", */ /* ol_music_info_get_artist (info), */ /* ol_music_info_get_title (info), */ /* ol_music_info_get_album (info), */ /* ol_music_info_get_track_number (info), */ /* ol_music_info_get_uri (info)); */ return TRUE; }
static gboolean ol_player_xmms2_get_music_info (OlMusicInfo *info) { /* ol_log_func (); */ ol_assert_ret (info != NULL, FALSE); if (!ol_player_xmms2_ensure_connection ()) return FALSE; ol_music_info_clear (info); int32_t id = ol_player_xmms2_get_currend_id (); if (id > 0) { xmmsc_result_t *result = xmmsc_medialib_get_info (connection, id); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_error ("Get music info from XMMS2 failed."); } else { xmmsv_t *dict = xmmsv_propdict_to_dict (return_value, NULL); info->title = ol_player_xmms2_get_dict_string (dict, "title"); info->artist = ol_player_xmms2_get_dict_string (dict, "artist"); info->album = ol_player_xmms2_get_dict_string (dict, "album"); info->track_number = ol_player_xmms2_get_dict_int (dict, "tracknr"); info->uri = ol_player_xmms2_get_dict_string (dict, "url"); ol_logf (OL_DEBUG, "%s\n" " title:%s\n" " artist:%s\n" " album:%s\n" " uri:%s\n", __FUNCTION__, info->title, info->artist, info->album, info->uri); xmmsv_unref (dict); } xmmsc_result_unref (result); } return TRUE; }
static gboolean ol_player_amarok1_get_music_info (OlMusicInfo *info) { ol_assert_ret (info != NULL, FALSE); ol_music_info_clear (info); if (!ol_player_amarok1_get_string (TITLE_CMD, &info->title)) return FALSE; if (!ol_player_amarok1_get_string (ARTIST_CMD, &info->artist)) return FALSE; if (!ol_player_amarok1_get_string (ALBUM_CMD, &info->album)) return FALSE; if (!ol_player_amarok1_get_uint (TRACK_CMD, &info->track_number)) return FALSE; ol_debugf (" title: %s\n" " artist: %s\n" " album: %s\n", ol_music_info_get_title (info), ol_music_info_get_artist (info), ol_music_info_get_album (info)); return TRUE; }
static gboolean ol_player_moc_get_music_info (OlMusicInfo *info) { /* ol_log_func (); */ ol_assert_ret (info != NULL, FALSE); if (!ol_player_moc_get_activated ()) return FALSE; int status = ol_player_moc_get_status (); if (status != OL_PLAYER_PLAYING && status != OL_PLAYER_PAUSED) { ol_music_info_clear (info); return TRUE; } char *format = g_strdup_printf ("%s\\n%s\\n%s\\n%s", QUERY_TITLE, QUERY_ARTIST, QUERY_ALBUM, QUERY_URI); char *cmd = g_strdup_printf (QUERY_CMD, format); g_free (format); char *output = NULL; gboolean ret = ol_cmd_get_string (cmd, &output); g_free (cmd); if (output == NULL) { ret = FALSE; } else if (ret) { /* ol_debugf (" output:\n%s", output); */ ol_music_info_clear (info); char *current = output; char *next = ol_split_a_line (current); info->title = g_strdup (ol_trim_string (current)); if (next != NULL) { current = next; next = ol_split_a_line (current); info->artist = g_strdup (ol_trim_string (current)); } if (next != NULL) { current = next; next = ol_split_a_line (current); info->album = g_strdup (ol_trim_string (current)); } if (next != NULL) { current = next; next = ol_split_a_line (current); info->uri = g_strdup (ol_trim_string (current)); } /* ol_debugf(" artist:%s\n" */ /* " title:%s\n" */ /* " album:%s\n" */ /* " track:%d\n" */ /* " uri:%s\n", */ /* info->artist, */ /* info->title, */ /* info->album, */ /* info->track_number, */ /* info->uri); */ } if (output != NULL) g_free (output); return ret; }