Mercurial > audlegacy-plugins
annotate src/lastfm/lastfm.c @ 2138:76f9a4168708
Fix linking with libaudid3tag
Linking with libaudid3tag from /usr/lib/audacious, add rpath (affected to tta,
shnplug and madplug plugins)
author | Vitaly Lipatov <lav@etersoft.ru> |
---|---|
date | Sat, 27 Oct 2007 19:34:46 -0500 |
parents | b8da6a0b0da2 |
children | 39398ff5e162 |
rev | line source |
---|---|
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
1 /* Audacious lastfm transport plugin |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
2 * Copyright (c) 2007 Cristi Măgherușan <majeru@gentoo.ro> |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
3 * All rights reserved. |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
4 * |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
5 * Redistribution and use in source and binary forms, with or without modification, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
6 * are permitted provided that the following conditions are met: |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
7 * |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
8 * Redistributions of source code must retain the above copyright notice, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
9 * this list of conditions and the following disclaimer. |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
10 * |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
11 * Redistributions in binary form must reproduce the above copyright notice, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
12 * this list of conditions and the following disclaimer in the documentation |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
13 * and/or other materials provided with the distribution. |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
14 * |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
15 * Neither the name of the author nor the names of its contributors may be |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
16 * used to endorse or promote products derived from this software without |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
17 * specific prior written permission. |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
18 * |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
29 */ |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
30 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
31 /* |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
32 * Current status and known issues: |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
33 * - Works fine ant is relatively stable |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
34 * - The adjust fails when having 2 or more opened streams at the same time. |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
35 * * It will randomly adjust to any one of them, because the playlist keeps |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
36 * pulling metadata |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
37 * - When the network is disconnected opening a new track freezes the player |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
38 * * This seems to recover after the connection is restablished |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
39 * * Ordinary mp3 streams seem to share this behavior. Didnt tested if others do. |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
40 */ |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
41 |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
42 #include <audacious/vfs.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
43 #include <audacious/plugin.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
44 #include <audacious/configdb.h> |
1161 | 45 #include <libmowgli/mowgli_global_storage.h> |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
46 #include <curl/curl.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
47 #include <glib.h> |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
48 #include <string.h> |
982 | 49 #include "lastfm.h" |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
50 #include <glib/gi18n.h> |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
51 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
52 #define DEBUG 1 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
53 |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
54 size_t lastfm_store_res(void *ptr, size_t size, size_t nmemb, void *udata) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
55 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
56 GString *data = (GString *) udata; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
57 g_string_append_len(data, ptr, nmemb); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
58 return size * nmemb; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
59 } |
1036 | 60 |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
61 |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
62 gchar** lastfm_get_data_from_uri(gchar *url) |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
63 { |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
64 gchar**result=NULL; |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
65 GString* res=g_string_new(NULL); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
66 gint i=0; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
67 CURL *curl = curl_easy_init(); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
68 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
69 curl_easy_setopt(curl, CURLOPT_USERAGENT, "Audacious"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
70 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, lastfm_store_res); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
71 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
72 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
73 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, LASTFM_CURL_TIMEOUT); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
74 curl_easy_setopt(curl, CURLOPT_URL, url); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
75 curl_easy_setopt(curl, CURLOPT_WRITEDATA, res); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
76 gint status = curl_easy_perform(curl); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
77 curl_easy_cleanup(curl); |
1394
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
78 /* g_print(res->str);*/ |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
79 if((status==CURLE_OK) && res && res->str) |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
80 result = g_strsplit(res->str, "\n", 20); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
81 g_string_erase(res, 0, -1); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
82 #if DEBUG |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
83 g_print("Opened URL: '%s'\n",url); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
84 g_print("LASTFM: (get_uri) received data ---------------\n"); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
85 for (i = 0; result && result[i]; i++) |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
86 g_print("%s\n",result[i]); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
87 g_print("LASTFM: (get_uri) data ended ---------------\n"); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
88 #endif |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
89 return result; |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
90 } |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
91 |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
92 |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
93 static void show_login_error_dialog(void) |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
94 { |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
95 const gchar *markup = |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
96 N_("<b><big>Couldn't initialize the last.fm radio plugin.</big></b>\n\n" |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
97 "Check if your Scrobbler's plugin login data is set up properly."); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
98 |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
99 GtkWidget *dialog = |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
100 gtk_message_dialog_new_with_markup(NULL, |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
101 GTK_DIALOG_DESTROY_WITH_PARENT, |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
102 GTK_MESSAGE_ERROR, |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
103 GTK_BUTTONS_OK, |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
104 _(markup)); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
105 gtk_dialog_run(GTK_DIALOG(dialog)); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
106 gtk_widget_destroy(dialog); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
107 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
108 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
109 gchar* lastfm_get_login_uri() /* reads the audioscrobbler login data from the config */ |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
110 { /* and then uses them to create a login URL*/ |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
111 ConfigDb *cfg = NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
112 gchar *buf=NULL, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
113 *username = NULL, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
114 *password = NULL; |
2124 | 115 if ((cfg = aud_cfg_db_open()) != NULL) |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
116 { |
2124 | 117 aud_cfg_db_get_string(cfg, "audioscrobbler","username", |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
118 &username); |
2124 | 119 aud_cfg_db_get_string(cfg, "audioscrobbler","password", |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
120 &password); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
121 g_free(cfg); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
122 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
123 if (username != NULL && password != NULL) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
124 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
125 buf=g_strdup_printf(LASTFM_HANDSHAKE_URL, username, password); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
126 g_free(password); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
127 g_free(username); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
128 return buf; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
129 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
130 else |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
131 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
132 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
133 g_print("LASTFM: (get_login_uri) Couldn't find the login data. Use the scrobbler plugin to set it up.\n"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
134 #endif |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
135 show_login_error_dialog(); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
136 return NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
137 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
138 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
139 |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
140 void lastfm_store(gchar * var_name, gchar * var) /*mowgli storage wrapper, for storing global data*/ |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
141 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
142 if (mowgli_global_storage_get(var_name)) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
143 mowgli_global_storage_free(var_name); |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
144 |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
145 mowgli_global_storage_put(var_name,var); |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
146 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
147 |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
148 int lastfm_login(void) /*gets the session ID and the mp3 stream URL and stores them. |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
149 It's called just on the first fopen, since it doesnt change (hopefully!!!)*/ |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
150 { |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
151 gint i, |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
152 ret=LASTFM_LOGIN_OK; /*suppose everything goes fine*/ |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
153 gchar **split = NULL; |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
154 if(login_url!=NULL) |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
155 g_free(login_url); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
156 login_url=lastfm_get_login_uri(); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
157 if(login_url==NULL) |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
158 return LASTFM_MISSING_LOGIN_DATA; |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
159 split = lastfm_get_data_from_uri(login_url); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
160 if (split) |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
161 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
162 for (i = 0; split && split[i]; i++) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
163 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
164 if (g_str_has_prefix(split[i], "session=")) |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
165 lastfm_store("lastfm_session_id",g_strndup(split[i] + 8, 32)); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
166 else if (g_str_has_prefix(split[i], "stream_url=")) |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
167 lastfm_store("lastfm_stream_uri" ,g_strdup(split[i] + 11)); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
168 } |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
169 ret = LASTFM_LOGIN_OK; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
170 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
171 else |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
172 ret = LASTFM_LOGIN_ERROR; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
173 g_strfreev(split); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
174 g_free(login_url); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
175 login_url=NULL; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
176 return ret; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
177 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
178 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
179 static gchar* parse(gchar* input_string,gchar* token) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
180 { |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
181 if (!g_str_has_prefix(input_string, token)) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
182 return NULL; |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
183 |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
184 return g_strdup(strchr(input_string, '=') + 1); |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
185 } |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
186 |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
187 static gpointer lastfm_adjust(gpointer uri) /*tunes into a channel*/ |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
188 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
189 gchar *fetch_url=NULL, |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
190 *session_id = g_strdup(mowgli_global_storage_get("lastfm_session_id")); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
191 if (!session_id) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
192 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
193 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
194 g_print("LASTFM: (adjust) Adjust failed! Session ID not set.\n"); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
195 #endif |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
196 return NULL ; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
197 } |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
198 fetch_url=g_strdup_printf(LASTFM_ADJUST_URL, session_id, (char*)uri); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
199 gchar** tmp = lastfm_get_data_from_uri(fetch_url); /*the output doesn't matter*/ |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
200 g_strfreev(tmp); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
201 g_free(fetch_url); |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
202 g_free(session_id); |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
203 return NULL ; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
204 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
205 |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
206 gboolean parse_metadata(LastFM * handle,gchar ** split) |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
207 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
208 int i; |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
209 |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
210 if(split == NULL) |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
211 return FALSE; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
212 if(g_str_has_prefix(split[0],"streaming=false")) |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
213 { |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
214 #if DEBUG |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
215 g_print("LASTFM: (parse) Metadata is not available\n"); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
216 #endif |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
217 return FALSE; |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
218 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
219 handle->lastfm_duration=0; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
220 handle->lastfm_progress=0; |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
221 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
222 if (handle->lastfm_artist) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
223 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
224 g_free(handle->lastfm_artist); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
225 handle->lastfm_artist=NULL; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
226 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
227 if (handle->lastfm_title) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
228 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
229 g_free(handle->lastfm_title); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
230 handle->lastfm_title=NULL; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
231 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
232 if (handle->lastfm_album) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
233 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
234 g_free(handle->lastfm_album); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
235 handle->lastfm_album=NULL; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
236 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
237 if (handle->lastfm_station_name) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
238 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
239 g_free(handle->lastfm_station_name); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
240 handle->lastfm_station_name=NULL; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
241 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
242 for (i = 0; split && split[i]; i++) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
243 { |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
244 if (g_str_has_prefix(split[i], "artist=")) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
245 handle->lastfm_artist = parse(split[i],"artist="); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
246 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
247 if (g_str_has_prefix(split[i], "track=")) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
248 handle->lastfm_title = parse(split[i],"track="); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
249 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
250 if (g_str_has_prefix(split[i], "album=")) |
1360
62ba1e18d1bb
mowgli-fied the data that will be used by the GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1358
diff
changeset
|
251 lastfm_store("lastfm_album", parse(split[i],"album=" )); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
252 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
253 if (g_str_has_prefix(split[i], "albumcover_medium=")) |
1360
62ba1e18d1bb
mowgli-fied the data that will be used by the GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1358
diff
changeset
|
254 lastfm_store("lastfm_cover", parse(split[i],"albumcover_medium=")); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
255 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
256 if (g_str_has_prefix(split[i], "station=")) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
257 handle->lastfm_station_name = parse(split[i],"station="); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
258 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
259 if (g_str_has_prefix(split[i], "trackduration=")) |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
260 handle->lastfm_duration = g_ascii_strtoull(g_strdup(split[i] + 14), NULL, 10); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
261 if (g_str_has_prefix(split[i], "trackprogress=")) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
262 handle->lastfm_progress = g_ascii_strtoull(g_strdup(split[i] + 14), NULL, 10); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
263 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
264 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
265 #if DEBUG |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
266 if(handle->lastfm_station_name!=NULL) |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
267 { |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
268 g_print("nLASTFM: (parse) Duration:%d\n", handle->lastfm_duration); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
269 g_print("LASTFM: (parse) Station Name: %s\n", handle->lastfm_station_name); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
270 } |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
271 #endif |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
272 return TRUE; |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
273 } |
1036 | 274 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
275 int fetch_metadata(LastFM * handle) |
1036 | 276 { |
1394
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
277 #if DEBUG |
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
278 g_print("LASTFM: (fetch) starting to fetch\n"); |
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
279 #endif |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
280 gchar *uri=NULL; |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
281 gint res=METADATA_FETCH_FAILED; |
1394
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
282 if(handle==NULL) |
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
283 return res; |
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
284 |
2e25c7a29ac2
fixed crashes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1392
diff
changeset
|
285 handle->lastfm_session_id=mowgli_global_storage_get("lastfm_session_id"); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
286 if (handle->lastfm_session_id == NULL) |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
287 return res; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
288 uri=g_strdup_printf(LASTFM_METADATA_URL, handle->lastfm_session_id); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
289 gchar**fetched_metadata =NULL; |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
290 fetched_metadata = lastfm_get_data_from_uri(uri); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
291 if(fetched_metadata != NULL) |
1036 | 292 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
293 if(parse_metadata( handle,fetched_metadata)) |
1036 | 294 { |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
295 g_strfreev(fetched_metadata); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
296 res=METADATA_FETCH_SUCCEEDED; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
297 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
298 g_print("LASTFM: (fetch) metadata was parsed ok\n"); |
1036 | 299 #endif |
300 } | |
301 | |
302 } | |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
303 return res; |
1036 | 304 } |
305 | |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
306 gpointer lastfm_metadata_thread_func(gpointer arg) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
307 { |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
308 gint sleep_duration=1, |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
309 previous_track_duration=-1, |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
310 count=1, |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
311 status=0, |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
312 err=0; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
313 gboolean track_end_expected=FALSE,track_beginning=TRUE; |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
1036
diff
changeset
|
314 LastFM *handle = (LastFM *)arg; |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
315 /*get it right after opened the stream, so it doesnt need the mutex */ |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
316 fetch_metadata(handle); |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
317 |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
318 /* metadata is fetched 1 second after the stream is opened, |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
319 * and again after 2 seconds. |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
320 * if metadata was fetched ok i'm waiting for |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
321 * track_length - fetch_duration - 10 seconds |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
322 * then start polling for new metadata each 2 seconds, until |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
323 * the track gets changed from the previous iteration |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
324 */ |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
325 do |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
326 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
327 if(count%sleep_duration==0) |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
328 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
329 g_mutex_lock(metadata_mutex); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
330 if(handle==NULL) |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
331 { |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
332 #if DEBUG |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
333 g_print("LASTFM: (thread) Exiting thread, ID = %p, thread's handle got freed\n", (void *)g_thread_self()); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
334 #endif |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
335 thread_count--; |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
336 return NULL; |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
337 } |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
338 if(t0->tv_usec==-1) |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
339 g_get_current_time (t0); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
340 #if DEBUG |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
341 g_print("LASTFM: (thread) Fetching metadata:\n"); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
342 #endif |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
343 status=fetch_metadata(handle); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
344 g_get_current_time (t1); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
345 if(status==METADATA_FETCH_SUCCEEDED) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
346 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
347 if(!track_end_expected) |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
348 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
349 if(track_beginning) |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
350 { /*first try after track has changed*/ |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
351 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
352 g_print("LASTFM: (thread) retrying in 2 seconds\n"); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
353 #endif |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
354 track_beginning=FALSE; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
355 sleep_duration=2; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
356 } |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
357 else |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
358 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
359 if(g_str_has_prefix(handle->lastfm_station_name, "Previewing 30-second clips")) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
360 handle->lastfm_duration=30; |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
361 sleep_duration=handle->lastfm_duration-(t1->tv_sec - t0->tv_sec)-6; |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
362 previous_track_duration=handle->lastfm_duration; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
363 count=err=0; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
364 track_end_expected=TRUE; /*then the track_end will follow*/ |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
365 track_beginning=TRUE; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
366 t0->tv_usec=-1; |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
367 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
368 g_print("LASTFM: (thread) second fetch after new track started, the next will follow in %d sec\n",sleep_duration); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
369 #endif |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
370 } |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
371 |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
372 } |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
373 else |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
374 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
375 /*if the track hasnt yet changed (two tracks are considered identical if they |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
376 * have the same length or the same title) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
377 */ |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
378 if(handle->lastfm_duration == previous_track_duration) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
379 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
380 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
381 g_print("LASTFM: (thread) it is the same track as before, waiting for new track to start\n"); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
382 #endif |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
383 sleep_duration=2; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
384 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
385 else |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
386 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
387 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
388 g_print("LASTFM: (thread) the track has changed\n"); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
389 #endif |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
390 track_end_expected=FALSE; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
391 sleep_duration=2; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
392 /*if(previous_track_title) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
393 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
394 g_free(previous_track_title); |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
395 previous_track_title=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
396 }*/ |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
397 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
398 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
399 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
400 g_print("LASTFM: (thread) Current thread, ID = %p\n", (void *)g_thread_self()); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
401 #endif |
1036 | 402 } |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
403 else |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
404 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
405 err++; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
406 sleep_duration<<=1; |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
407 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
408 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
409 g_print("LASTFM: (thread) Thread_count: %d\n",thread_count); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
410 g_print("LASTFM: (thread) sleepping for %d seconds. ",err? sleep_duration/2 :sleep_duration); |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
411 g_print("Track length = %d sec\n",handle->lastfm_duration); |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
412 #endif |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
413 g_mutex_unlock(metadata_mutex); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
414 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
415 sleep(1); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
416 count++; |
1036 | 417 } |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
418 while ((g_thread_self()==metadata_thread )&& (err<7)); |
1036 | 419 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
420 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
421 g_print("LASTFM: (thread) Exiting thread, ID = %p\n", (void *)g_thread_self()); |
1036 | 422 #endif |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
423 thread_count--; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
424 return NULL; |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
425 } |
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
426 |
1978 | 427 VFSFile *lastfm_aud_vfs_fopen_impl(const gchar * path, const gchar * mode) |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
428 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
429 VFSFile *file = g_new0(VFSFile, 1); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
430 LastFM *handle = g_new0(LastFM, 1); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
431 handle->lastfm_artist=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
432 handle->lastfm_title=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
433 handle->lastfm_album=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
434 handle->lastfm_session_id=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
435 handle->lastfm_mp3_stream_url=NULL; |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
436 handle->lastfm_station_name=g_strdup("Couldn't fetch metadata"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
437 int login_count = 0; |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
438 gchar * temp_path=g_strdup(path); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
439 if(!mowgli_global_storage_get("lastfm_session_id")) /*login only if really needed*/ |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
440 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
441 while((login_count++ <= 3)&&(lastfm_login()!= LASTFM_LOGIN_OK)) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
442 sleep(5); |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
443 if(login_count>3) |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
444 { |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
445 g_free(handle); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
446 g_free(file); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
447 return NULL; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
448 } |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
449 } |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
450 handle->lastfm_session_id = g_strdup(mowgli_global_storage_get("lastfm_session_id")); |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
451 handle->lastfm_mp3_stream_url = g_strdup(mowgli_global_storage_get("lastfm_stream_uri")); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
452 g_get_current_time(t0); |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
453 g_thread_create(lastfm_adjust,temp_path,FALSE,NULL); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
454 metadata_thread = g_thread_create(lastfm_metadata_thread_func, handle, FALSE, NULL); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
455 thread_count++; |
1978 | 456 handle->proxy_fd = aud_vfs_fopen(handle->lastfm_mp3_stream_url, mode); |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
457 file->handle = handle; |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
458 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
459 g_print("LASTFM: (fopen) Thread_count: %d\n",thread_count); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
460 #endif |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
461 return file; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
462 } |
976 | 463 |
1978 | 464 gint lastfm_aud_vfs_fclose_impl(VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
465 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
466 gint ret = 0; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
467 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
468 if (file == NULL) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
469 return -1; |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
470 if (file->handle) |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
471 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
472 g_mutex_lock(metadata_mutex); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
473 LastFM *handle = file->handle; |
1978 | 474 ret = aud_vfs_fclose(handle->proxy_fd); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
475 if (!ret) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
476 handle->proxy_fd = NULL; |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
477 g_free(handle); |
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
478 handle=NULL; |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
479 file->handle = NULL; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
480 g_mutex_unlock(metadata_mutex); |
1228
01efa0e5b554
file->handle should be cleared on close, otherwise it can lead to double free.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1223
diff
changeset
|
481 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
482 return ret; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
483 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
484 |
1978 | 485 size_t lastfm_aud_vfs_fread_impl(gpointer ptr, size_t size, size_t nmemb, VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
486 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
487 LastFM *handle = file->handle; |
1978 | 488 size_t ret = aud_vfs_fread(ptr, size, nmemb, handle->proxy_fd); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
489 return ret; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
490 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
491 |
1978 | 492 size_t lastfm_aud_vfs_fwrite_impl(gconstpointer ptr, size_t size, size_t nmemb, VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
493 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
494 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
495 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
496 |
1978 | 497 gint lastfm_aud_vfs_getc_impl(VFSFile * stream) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
498 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
499 LastFM *handle = stream->handle; |
1978 | 500 return aud_vfs_getc(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
501 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
502 |
1978 | 503 gint lastfm_aud_vfs_ungetc_impl(gint c, VFSFile * stream) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
504 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
505 LastFM *handle = stream->handle; |
1978 | 506 return aud_vfs_ungetc(c, handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
507 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
508 |
1978 | 509 gint lastfm_aud_vfs_fseek_impl(VFSFile * file, glong offset, gint whence) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
510 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
511 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
512 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
513 |
1978 | 514 void lastfm_aud_vfs_rewind_impl(VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
515 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
516 return; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
517 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
518 |
1978 | 519 glong lastfm_aud_vfs_ftell_impl(VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
520 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
521 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
522 |
1978 | 523 return aud_vfs_ftell(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
524 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
525 |
1978 | 526 gboolean lastfm_aud_vfs_feof_impl(VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
527 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
528 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
529 |
1978 | 530 return aud_vfs_feof(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
531 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
532 |
1978 | 533 gint lastfm_aud_vfs_truncate_impl(VFSFile * file, glong size) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
534 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
535 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
536 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
537 |
1978 | 538 off_t lastfm_aud_vfs_fsize_impl(VFSFile * file) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
539 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
540 return 0; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
541 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
542 |
1978 | 543 gchar *lastfm_aud_vfs_metadata_impl(VFSFile * file, const gchar * field) |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
544 { |
1358
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
545 LastFM * handle; |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
546 if(file->handle!= NULL) |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
547 handle = file->handle; |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
548 else |
d2050220659a
threadified the adjust and first metadata fetch, so now it should open a lot faster
Cristi Magherusan <majeru@atheme-project.org>
parents:
1335
diff
changeset
|
549 return NULL; |
1036 | 550 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
551 if (!g_ascii_strncasecmp(field, "stream-name", 11) && (handle->lastfm_station_name != NULL)) |
1221
619cd8c8def5
Prefix the station name with last.fm to denote that it's coming from last.fm.
William Pitcock <nenolod@atheme-project.org>
parents:
1220
diff
changeset
|
552 return g_strdup_printf("last.fm radio: %s", handle->lastfm_station_name); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
553 if (!g_ascii_strncasecmp(field, "track-name", 10) && (handle->lastfm_title != NULL) && (handle->lastfm_artist != NULL)) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
554 return g_strdup_printf("%s - %s", handle->lastfm_artist, handle->lastfm_title); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
555 if (!g_ascii_strncasecmp(field, "content-type", 12)) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
556 return g_strdup("audio/mpeg"); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
557 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
558 return NULL; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
559 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
560 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
561 VFSConstructor lastfm_const = { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
562 "lastfm://", |
1978 | 563 lastfm_aud_vfs_fopen_impl, |
564 lastfm_aud_vfs_fclose_impl, | |
565 lastfm_aud_vfs_fread_impl, | |
566 lastfm_aud_vfs_fwrite_impl, | |
567 lastfm_aud_vfs_getc_impl, | |
568 lastfm_aud_vfs_ungetc_impl, | |
569 lastfm_aud_vfs_fseek_impl, | |
570 lastfm_aud_vfs_rewind_impl, | |
571 lastfm_aud_vfs_ftell_impl, | |
572 lastfm_aud_vfs_feof_impl, | |
573 lastfm_aud_vfs_truncate_impl, | |
574 lastfm_aud_vfs_fsize_impl, | |
575 lastfm_aud_vfs_metadata_impl | |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
576 }; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
577 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
578 static void init(void) |
1036 | 579 { |
1978 | 580 aud_vfs_register_transport(&lastfm_const); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
581 if (!metadata_mutex) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
582 metadata_mutex = g_mutex_new (); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
583 t0=g_new0(GTimeVal,1); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
584 t1=g_new0(GTimeVal,1); |
1392
e6f5685f71a1
added an experimental GUI for Last.fm radio
Cristi Magherusan <majeru@atheme-project.org>
parents:
1360
diff
changeset
|
585 lastfm_store("lastfm_loaded","TRUE"); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
586 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
587 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
588 static void cleanup(void) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
589 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
590 g_mutex_free(metadata_mutex); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
591 mowgli_global_storage_free("lastfm_stream_uri"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
592 #if DEBUG |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
593 g_print("LASTFM: (cleanup) Cleanup finished\n"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
594 #endif |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
595 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
596 |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1394
diff
changeset
|
597 DECLARE_PLUGIN(lastfm, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL) |