diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2010-08-09 09:31:47 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2010-08-09 09:31:47 +0200 |
commit | d3cb0ea6f6ab7be363baf0d395fb4aee91457a85 (patch) | |
tree | bbaee2049b9c95c67158227139777ee11420db73 /src/lyrics.cpp | |
parent | 8b109d07366829550e02d43df14e8552b75c2af9 (diff) |
put CURL related functions into a separate file
Diffstat (limited to 'src/lyrics.cpp')
-rw-r--r-- | src/lyrics.cpp | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/lyrics.cpp b/src/lyrics.cpp index eacc20f0..fd4c976c 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -31,6 +31,7 @@ #include "browser.h" #include "charset.h" +#include "curl_handle.h" #include "global.h" #include "helpers.h" @@ -63,7 +64,6 @@ bool Lyrics::Ready = 0; #ifdef HAVE_PTHREAD_H pthread_t *Lyrics::Downloader = 0; -pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER; #endif // HAVE_PTHREAD_H #endif // HAVE_CURL_CURL_H @@ -211,27 +211,11 @@ void *Lyrics::Get(void *screen_void_ptr) std::string artist = locale_to_utf_cpy(screen->itsSong.GetArtist()); std::string title = locale_to_utf_cpy(screen->itsSong.GetTitle()); - char *c_artist = curl_easy_escape(0, artist.c_str(), artist.length()); - char *c_title = curl_easy_escape(0, title.c_str(), title.length()); - std::string url = my_lyrics->url; - Replace(url, "%artist%", c_artist); - Replace(url, "%title%", c_title); - - CURLcode code; - pthread_mutex_lock(&Global::CurlLock); - CURL *lyrics = curl_easy_init(); - curl_easy_setopt(lyrics, CURLOPT_URL, url.c_str()); - curl_easy_setopt(lyrics, CURLOPT_WRITEFUNCTION, write_data); - curl_easy_setopt(lyrics, CURLOPT_WRITEDATA, &result); - curl_easy_setopt(lyrics, CURLOPT_CONNECTTIMEOUT, 10); - curl_easy_setopt(lyrics, CURLOPT_NOSIGNAL, 1); - code = curl_easy_perform(lyrics); - curl_easy_cleanup(lyrics); - pthread_mutex_unlock(&Global::CurlLock); + Replace(url, "%artist%", Curl::escape(artist).c_str()); + Replace(url, "%title%", Curl::escape(title).c_str()); - curl_free(c_artist); - curl_free(c_title); + CURLcode code = Curl::perform(url, result); if (code != CURLE_OK) { @@ -372,7 +356,7 @@ const Lyrics::Plugin Lyrics::LyricsPlugin = LyricsPlugin_NotFound };*/ -bool Lyrics::Generic_NotFound(const std::string &s) +bool Lyrics::Generic_NotFound(const std::string &) { // it should never fail as open_tag and close_tag // are not present if lyrics are not found |