Mercurial > audlegacy-plugins
diff src/streambrowser/streambrowser.c @ 2815:cc6f02424609
added initial support for xiph streaming directory; small bug fixes & code cleanups
| author | Calin Crisan ccrisan@gmail.com |
|---|---|
| date | Sun, 13 Jul 2008 04:00:04 +0300 |
| parents | 7977bdc02664 |
| children | 779125caa3ac |
line wrap: on
line diff
--- a/src/streambrowser/streambrowser.c Sat Jul 12 16:00:03 2008 +0200 +++ b/src/streambrowser/streambrowser.c Sun Jul 13 04:00:04 2008 +0300 @@ -25,6 +25,7 @@ #include "streambrowser.h" #include "streamdir.h" #include "shoutcast.h" +#include "xiph.h" #include "gui/streambrowser_win.h" #include "gui/about_win.h" @@ -139,6 +140,28 @@ return TRUE; } +gboolean mystrcasestr(const char *haystack, const char *needle) +{ + int len_h = strlen(haystack) + 1; + int len_n = strlen(needle) + 1; + int i; + + char *upper_h = malloc(len_h); + char *upper_n = malloc(len_n); + + for (i = 0; i < len_h; i++) + upper_h[i] = toupper(haystack[i]); + for (i = 0; i < len_n; i++) + upper_n[i] = toupper(needle[i]); + + char *p = strstr(upper_h, upper_n); + + free(upper_h); + free(upper_n); + + return (gboolean) p; +} + static void sb_init() { @@ -261,7 +284,7 @@ } else { g_mutex_lock(update_thread_mutex); - + /* do we have a running thread? */ if (update_thread_count > 0) { int i; @@ -320,11 +343,11 @@ { debug("entering update thread core\n"); - /* try to get the last item in the queue */ + /* try to get the last item in the queue, but don't remove it */ g_mutex_lock(update_thread_mutex); update_thread_data_t *data = NULL; if (update_thread_count > 0) { - data = g_queue_pop_head(update_thread_data_queue); + data = g_queue_peek_head(update_thread_data_queue); } g_mutex_unlock(update_thread_mutex); @@ -357,6 +380,19 @@ streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); gdk_threads_leave(); } + /* xiph */ + else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { + gdk_threads_enter(); + streambrowser_win_set_category_state(data->streamdir, data->category, TRUE); + gdk_threads_leave(); + + xiph_category_fetch(data->category); + + gdk_threads_enter(); + streambrowser_win_set_category(data->streamdir, data->category); + streambrowser_win_set_category_state(data->streamdir, data->category, FALSE); + gdk_threads_leave(); + } } /* update a streamdir */ else if (data->streamdir != NULL) { @@ -369,14 +405,30 @@ gdk_threads_leave(); } } + /* xiph */ + else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { + streamdir_t *streamdir = xiph_streamdir_fetch(); + if (streamdir != NULL) { + gdk_threads_enter(); + streambrowser_win_set_streamdir(streamdir, XIPH_ICON); + gdk_threads_leave(); + } + } } /* update all streamdirs */ else { /* shoutcast */ - streamdir_t *shoutcast_streamdir = shoutcast_streamdir_fetch(); - if (shoutcast_streamdir != NULL) { + streamdir_t *streamdir = shoutcast_streamdir_fetch(); + if (streamdir != NULL) { gdk_threads_enter(); - streambrowser_win_set_streamdir(shoutcast_streamdir, SHOUTCAST_ICON); + streambrowser_win_set_streamdir(streamdir, SHOUTCAST_ICON); + gdk_threads_leave(); + } + /* xiph */ + streamdir = xiph_streamdir_fetch(); + if (streamdir != NULL) { + gdk_threads_enter(); + streambrowser_win_set_streamdir(streamdir, XIPH_ICON); gdk_threads_leave(); } } @@ -384,6 +436,9 @@ g_free(data); g_mutex_lock(update_thread_mutex); + + /* remove the just processed data from the queue */ + g_queue_pop_head(update_thread_data_queue); update_thread_count--; /* try to get the last item in the queue */ @@ -401,14 +456,22 @@ static void streaminfo_add_to_playlist(streaminfo_t *streaminfo) { - debug("fetching stream playlist for station '%s' from '%s'\n", streaminfo->name, streaminfo->playlist_url); - if (!fetch_remote_to_local_file(streaminfo->playlist_url, PLAYLIST_TEMP_FILE)) { - failure("shoutcast: stream playlist '%s' could not be downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); - return; - } - debug("stream playlist '%s' successfuly downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); + if (strlen(streaminfo->playlist_url) > 0) { + debug("fetching stream playlist for station '%s' from '%s'\n", streaminfo->name, streaminfo->playlist_url); + if (!fetch_remote_to_local_file(streaminfo->playlist_url, PLAYLIST_TEMP_FILE)) { + failure("shoutcast: stream playlist '%s' could not be downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); + return; + } + debug("stream playlist '%s' successfuly downloaded to '%s'\n", streaminfo->playlist_url, PLAYLIST_TEMP_FILE); - aud_playlist_add_url(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); + aud_playlist_add(aud_playlist_get_active(), PLAYLIST_TEMP_FILE); + debug("stream playlist '%s' added\n", streaminfo->playlist_url); + } + + if (strlen(streaminfo->url) > 0) { + aud_playlist_add(aud_playlist_get_active(), streaminfo->url); + debug("stream '%s' added\n", streaminfo->url); + } } static void on_plugin_services_menu_item_click()
