Mercurial > audlegacy-plugins
changeset 1010:8bad1b46ef78 trunk
[svn] - make this compile again and indent properly
author | nenolod |
---|---|
date | Thu, 10 May 2007 21:43:57 -0700 |
parents | f30aaf18916a |
children | 4a693f5b7054 |
files | ChangeLog src/lastfm/lastfm.c src/lastfm/lastfm.h |
diffstat | 3 files changed, 86 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu May 10 17:48:34 2007 -0700 +++ b/ChangeLog Thu May 10 21:43:57 2007 -0700 @@ -1,3 +1,11 @@ +2007-05-11 00:48:34 +0000 Cristi Magherusan <majeru@atheme.org> + revision [2182] + added primitive metadata handling (just gets printed in the terminal) + + trunk/src/lastfm/lastfm.c | 79 ++++++++++++++++++++++++++++++---------------- + 1 file changed, 52 insertions(+), 27 deletions(-) + + 2007-05-10 23:41:13 +0000 Cristi Magherusan <majeru@atheme.org> revision [2180] a few cleanups
--- a/src/lastfm/lastfm.c Thu May 10 17:48:34 2007 -0700 +++ b/src/lastfm/lastfm.c Thu May 10 21:43:57 2007 -0700 @@ -26,9 +26,9 @@ LastFM *LastFMGlobalData; - /*this keeps the login data in a global place since - * we cannot login on every fopen call* if anyone - * has a better solution to this any hint is welcome */ + /*this keeps the login data in a global place since + * we cannot login on every fopen call* if anyone + * has a better solution to this any hint is welcome */ static size_t lastfm_store_res(void *ptr, size_t size, size_t nmemb, void *udata) { @@ -37,9 +37,9 @@ return size * nmemb; } -gint get_data_from_url(gchar buf[4096],GString* res ) +gint get_data_from_url(gchar buf[4096], GString * res) { - CURL* curl = curl_easy_init(); + CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_USERAGENT, "Audacious"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, lastfm_store_res); @@ -50,7 +50,7 @@ curl_easy_setopt(curl, CURLOPT_WRITEDATA, res); gint status = curl_easy_perform(curl); curl_easy_cleanup(curl); -return status; + return status; } static gboolean lastfm_login(void) @@ -78,11 +78,11 @@ else return FALSE; - status=get_data_from_url(buf,res); + status = get_data_from_url(buf, res); #ifdef DEBUG - g_print("URL:%s\n",buf); - g_print("Downloaded data:%s\n",res->str); + g_print("URL:%s\n", buf); + g_print("Downloaded data:%s\n", res->str); #endif if (status == CURLE_OK) { @@ -110,15 +110,15 @@ gchar tmp[4096], **split = NULL; gboolean ret = FALSE; GString *res = g_string_new(NULL); - + if (LastFMGlobalData->lastfm_session_id == NULL) return FALSE; snprintf(tmp, sizeof(tmp), LASTFM_ADJUST_URL, LastFMGlobalData->lastfm_session_id, url); - status=get_data_from_url(tmp,res); + status = get_data_from_url(tmp, res); #ifdef DEBUG - g_print("Adjust received data:%s\n",res->str); + g_print("Adjust received data:%s\n", res->str); #endif if (status == CURLE_OK) { @@ -132,7 +132,7 @@ { LastFMGlobalData->lastfm_station_name = g_strdup(split[i] + 12); #ifdef DEBUG - g_print("StationnName:%s\n",LastFMGlobalData->lastfm_station_name); + g_print("StationnName:%s\n", LastFMGlobalData->lastfm_station_name); #endif } } @@ -149,82 +149,83 @@ gint status, i; gchar tmp[4096], **split = NULL; GString *res = g_string_new(NULL); - + if (handle->lastfm_session_id == NULL) - return NULL ; - snprintf(tmp, sizeof(tmp), LASTFM_METADATA_URL, handle->lastfm_session_id); + return NULL; + snprintf(tmp, sizeof(tmp), LASTFM_METADATA_URL, handle->lastfm_session_id); - for(;;) - { - handle->lastfm_duration =0; - handle->lastfm_progress=0; - status=get_data_from_url(tmp,res); + for (;;) + { + handle->lastfm_duration = 0; + handle->lastfm_progress = 0; + status = get_data_from_url(tmp, res); #ifdef DEBUG - g_print("Getting Metadata\n"); + g_print("Getting Metadata\n"); #endif #if 0 - g_print("Received metadata:%s\n",res->str); + g_print("Received metadata:%s\n", res->str); #endif - if (status == CURLE_OK) - { - split = g_strsplit(res->str, "\n", 20); - - for (i = 0; split && split[i]; i++) + if (status == CURLE_OK) { - if (g_str_has_prefix(split[i], "artist=")) - { - handle->lastfm_artist = g_strdup(split[i] + 7); + split = g_strsplit(res->str, "\n", 20); + + for (i = 0; split && split[i]; i++) + { + if (g_str_has_prefix(split[i], "artist=")) + { + handle->lastfm_artist = g_strdup(split[i] + 7); #ifdef DEBUG - g_print("Artist: %s\n", handle->lastfm_artist); + g_print("Artist: %s\n", handle->lastfm_artist); #endif - } - if (g_str_has_prefix(split[i], "track=")) + } + if (g_str_has_prefix(split[i], "track=")) { - handle->lastfm_title = g_strdup(split[i] + 6); + handle->lastfm_title = g_strdup(split[i] + 6); #ifdef DEBUG - g_print("Title: %s\n", handle->lastfm_title); + g_print("Title: %s\n", handle->lastfm_title); #endif - } + } - if (g_str_has_prefix(split[i], "album=")) - handle->lastfm_album = g_strdup(split[i] + 6); - if (g_str_has_prefix(split[i], "albumcover_medium=")) - handle->lastfm_cover = g_strdup(split[i] + 18); - if (g_str_has_prefix(split[i], "trackduration=")) - { handle->lastfm_duration = g_ascii_strtoull(g_strdup(split[i] + 14),NULL,10); + if (g_str_has_prefix(split[i], "album=")) + handle->lastfm_album = g_strdup(split[i] + 6); + if (g_str_has_prefix(split[i], "albumcover_medium=")) + handle->lastfm_cover = g_strdup(split[i] + 18); + if (g_str_has_prefix(split[i], "trackduration=")) + { + handle->lastfm_duration = g_ascii_strtoull(g_strdup(split[i] + 14), NULL, 10); #ifdef DEBUG - g_print("Duration:%d\n",handle->lastfm_duration ); + g_print("Duration:%d\n", handle->lastfm_duration); #endif - } - if (g_str_has_prefix(split[i], "trackprogress=")) - handle->lastfm_progress = g_ascii_strtoull(g_strdup(split[i] + 14),NULL,10); + } + if (g_str_has_prefix(split[i], "trackprogress=")) + handle->lastfm_progress = g_ascii_strtoull(g_strdup(split[i] + 14), NULL, 10); - if (g_str_has_prefix(split[i], "station=")) - { - handle->lastfm_station_name = g_strdup(split[i] + 8); + if (g_str_has_prefix(split[i], "station=")) + { + handle->lastfm_station_name = g_strdup(split[i] + 8); #ifdef DEBUG - g_print("Station Name: %s\n", handle->lastfm_station_name); + g_print("Station Name: %s\n", handle->lastfm_station_name); #endif + } } - } - g_strfreev(split); - } - g_string_erase(res, 0, -1); + g_strfreev(split); + } + g_string_erase(res, 0, -1); - int sleep_time; - if(handle->lastfm_progress==0) //if i don't know track duration i'm polling for metadata every 10 seconds - sleep_time=10; - else - sleep_time=handle->lastfm_duration - handle->lastfm_progress+3; + int sleep_time; + if (handle->lastfm_progress == 0) //if i don't know track duration i'm polling for metadata every 10 seconds + sleep_time = 10; + else + sleep_time = handle->lastfm_duration - handle->lastfm_progress + 3; #ifdef DEBUG - g_print("Sleeping for %d seconds\n",sleep_time); + g_print("Sleeping for %d seconds\n", sleep_time); #endif -sleep(sleep_time); -} - return NULL; //we'll never get here + sleep(sleep_time); + } + return NULL; //we'll never get here } VFSFile *lastfm_vfs_fopen_impl(const gchar * path, const gchar * mode) @@ -233,8 +234,8 @@ LastFM *handle; file = g_new0(VFSFile, 1); handle = g_new0(LastFM, 1); - - while ((LastFMGlobalData->lastfm_mp3_stream_url == NULL) && (LastFMGlobalData->login_count <= 3)) + + while ((LastFMGlobalData->lastfm_mp3_stream_url == NULL) && (LastFMGlobalData->login_count <= 3)) { printf("Login try count: %d\n", LastFMGlobalData->login_count++); lastfm_login(); @@ -250,14 +251,14 @@ handle->lastfm_station_name = g_strdup(LastFMGlobalData->lastfm_station_name); if (lastfm_adjust(path)) - g_thread_create(lastfm_get_metadata,handle, FALSE,NULL); + g_thread_create(lastfm_get_metadata, handle, FALSE, NULL); #ifdef DEBUG else g_print("Cannot tune to given channel\n"); - g_print("The metadata thread has just been created\n"); + g_print("The metadata thread has just been created\n"); #endif - + handle->proxy_fd = vfs_fopen(handle->lastfm_mp3_stream_url, mode); file->handle = handle; @@ -347,20 +348,20 @@ g_print("Interesting metadata:\n"); if (handle->lastfm_station_name != NULL) - g_print("%s\n",handle->lastfm_station_name); + g_print("%s\n", handle->lastfm_station_name); if (handle->lastfm_artist != NULL) - g_print("%s\n",handle->lastfm_artist); + g_print("%s\n", handle->lastfm_artist); if (handle->lastfm_title != NULL) - g_print("%s\n",handle->lastfm_title); + g_print("%s\n", handle->lastfm_title); g_print("%ul\n\n", handle->lastfm_duration); #endif - if (!g_ascii_strncasecmp(field, "stream-name",12) && (handle->lastfm_station_name != NULL)) + if (!g_ascii_strncasecmp(field, "stream-name", 12) && (handle->lastfm_station_name != NULL)) return g_strdup(handle->lastfm_station_name); - if (!g_ascii_strncasecmp(field, "track-name",11) && (handle->lastfm_title != NULL) && (handle->lastfm_artist != NULL)) + if (!g_ascii_strncasecmp(field, "track-name", 11) && (handle->lastfm_title != NULL) && (handle->lastfm_artist != NULL)) return g_strdup_printf("%s - %s", handle->lastfm_artist, handle->lastfm_title); return NULL;
--- a/src/lastfm/lastfm.h Thu May 10 17:48:34 2007 -0700 +++ b/src/lastfm/lastfm.h Thu May 10 21:43:57 2007 -0700 @@ -15,7 +15,8 @@ gchar *lastfm_title; gchar *lastfm_album; gchar *lastfm_cover; - unsigned lastfm_duration; + unsigned int lastfm_duration; + unsigned int lastfm_progress; int login_count; } LastFM; @@ -45,7 +46,7 @@ gchar *lastfm_vfs_metadata_impl(VFSFile * file, const gchar * field); -static gboolean lastfm_get_metadata(LastFM * handle); +static gpointer lastfm_get_metadata(LastFM * handle); static gboolean lastfm_login(void);