Mercurial > audlegacy-plugins
annotate src/lastfm/lastfm.c @ 1335:59699988d194
fixed some issues, hopefully it won't crash that much anymore
author | Cristi Magherusan <majeru@atheme-project.org> |
---|---|
date | Sun, 22 Jul 2007 17:34:21 +0300 |
parents | 7184bbd63761 |
children | d2050220659a |
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" |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
50 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
51 #define DEBUG 1 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
52 |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
53 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
|
54 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
55 GString *data = (GString *) udata; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
56 g_string_append_len(data, ptr, nmemb); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
57 return size * nmemb; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
58 } |
1036 | 59 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
60 gint lastfm_get_data_from_uri(gchar *url, GString * result) |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
61 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
62 CURL *curl = curl_easy_init(); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
63 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
|
64 curl_easy_setopt(curl, CURLOPT_USERAGENT, "Audacious"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
65 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
|
66 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
|
67 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
68 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
|
69 curl_easy_setopt(curl, CURLOPT_URL, url); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
70 curl_easy_setopt(curl, CURLOPT_WRITEDATA, result); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
71 gint status = curl_easy_perform(curl); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
72 curl_easy_cleanup(curl); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
73 return status; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
74 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
75 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
76 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
|
77 { /* 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
|
78 ConfigDb *cfg = NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
79 gchar *buf=NULL, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
80 *username = NULL, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
81 *password = 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
|
82 if ((cfg = bmp_cfg_db_open()) != NULL) |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
83 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
84 bmp_cfg_db_get_string(cfg, "audioscrobbler","username", |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
85 &username); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
86 bmp_cfg_db_get_string(cfg, "audioscrobbler","password", |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
87 &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
|
88 g_free(cfg); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
89 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
90 if (username != NULL && password != NULL) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
91 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
92 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
|
93 g_free(password); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
94 g_free(username); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
95 return buf; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
96 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
97 else |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
98 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
99 #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
|
100 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
|
101 #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
|
102 return NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
103 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
104 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
105 |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
106 void lastfm_store(gchar *var_name,gchar* var) /*mowgli storage wrapper, for storing global data*/ |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
107 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
108 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
|
109 mowgli_global_storage_free(var_name); |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
110 |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
111 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
|
112 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
113 |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
114 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
|
115 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
|
116 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
117 gint status, i, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
118 ret=LASTFM_LOGIN_OK; /*suppose everything goes fine*/ |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
119 gchar *login_uri=NULL, |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
120 **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
|
121 GString *res; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
122 login_uri=lastfm_get_login_uri(); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
123 if(login_uri==NULL) |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
124 return LASTFM_MISSING_LOGIN_DATA; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
125 res = g_string_new(NULL); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
126 status = lastfm_get_data_from_uri(login_uri, res); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
127 #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
|
128 g_print("LASTFM: (login) Opened login URI: '%s'\n", login_uri); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
129 g_print("LASTFM: (login) Got following data: '%s'\n", res->str); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
130 #endif |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
131 if (status == CURLE_OK) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
132 { |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
133 split = g_strsplit(res->str, "\n", 20); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
134 for (i = 0; split && split[i]; i++) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
135 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
141 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
142 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
|
143 ret = LASTFM_LOGIN_ERROR; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
144 g_strfreev(split); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
145 g_string_erase(res, 0, -1); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
146 g_free(login_uri); |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
147 login_uri=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
|
148 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
|
149 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
150 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
151 static gchar* parse(gchar* input_string,gchar* token) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
152 { |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
153 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
|
154 return NULL; |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
155 |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
156 return g_strdup(strchr(input_string, '=') + 1); |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
157 } |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
158 |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
159 gint lastfm_adjust(LastFM * handle,const gchar * 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
|
160 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
161 gint status, i,ret = LASTFM_ADJUST_FAILED; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
162 gchar *fetch_url=NULL, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
163 *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
|
164 **split = NULL; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
165 GString *res; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
166 session_id=mowgli_global_storage_get("lastfm_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
|
167 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
|
168 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
169 #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
|
170 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
|
171 #endif |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
172 return LASTFM_SESSION_MISSING; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
173 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
174 fetch_url=g_strdup_printf(LASTFM_ADJUST_URL, session_id, uri); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
175 res= g_string_new(NULL); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
176 status = lastfm_get_data_from_uri(fetch_url, res); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
177 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
178 if (status == CURLE_OK) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
179 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
180 split = g_strsplit(res->str, "\n", 2); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
181 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
|
182 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
183 if (g_str_has_prefix(split[i], "response=OK")) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
184 ret = LASTFM_ADJUST_OK; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
185 } |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
186 #if DEBUG |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
187 g_print("LASTFM: (adjust) Adjust to '%s' has completed successfully.\n",uri); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
188 #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
|
189 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
190 g_string_erase(res, 0, -1); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
191 g_strfreev(split); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
192 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
|
193 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
194 |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
195 gboolean parse_metadata(LastFM * handle,GString * metadata_strings) |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
196 { |
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 int i; |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
198 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
199 if(metadata_strings == NULL) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
200 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
|
201 gchar **split = g_strsplit(metadata_strings->str, "\n", 20); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
202 if(g_str_has_prefix(split[0],"streaming=false")) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
203 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
|
204 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
|
205 handle->lastfm_progress=0; |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
206 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
207 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
|
208 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
209 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
|
210 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
|
211 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
212 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
|
213 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
214 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
|
215 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
|
216 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
217 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
|
218 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
219 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
|
220 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
|
221 } |
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_cover) |
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_cover); |
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_cover=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_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
|
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_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
|
230 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
|
231 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
232 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
|
233 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
234 |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
235 if (g_str_has_prefix(split[i], "streaming=false")) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
236 { |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
237 g_strfreev(split); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
238 g_string_erase(metadata_strings, 0, -1); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
239 #if DEBUG |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
240 g_print("LASTFM: (parse) Metadata is not available"); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
241 #endif |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
242 return FALSE; |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
243 } |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
244 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
245 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
|
246 handle->lastfm_artist = parse(split[i],"artist="); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
247 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
248 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
|
249 handle->lastfm_title = parse(split[i],"track="); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
250 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
251 if (g_str_has_prefix(split[i], "album=")) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
252 handle->lastfm_album = parse(split[i],"album=" ); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
253 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
254 if (g_str_has_prefix(split[i], "albumcover_medium=")) |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
255 handle->lastfm_cover = parse(split[i],"albumcover_medium="); |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
256 |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
257 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
|
258 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
|
259 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 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
|
264 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
265 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
266 #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
|
267 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
|
268 { |
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("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
|
270 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
|
271 } |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
272 #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
|
273 g_strfreev(split); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
274 g_string_erase(metadata_strings, 0, -1); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
275 return TRUE; |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
276 } |
1036 | 277 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
278 int fetch_metadata(LastFM * handle) |
1036 | 279 { |
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; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
281 gint status,res=METADATA_FETCH_FAILED; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
282 if(!handle) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
283 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
|
284 handle->lastfm_session_id=mowgli_global_storage_get("lastfm_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
|
285 if (handle->lastfm_session_id == NULL) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
286 return res; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
287 uri=g_strdup_printf(LASTFM_METADATA_URL, handle->lastfm_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
|
288 GString *fetched_metadata = g_string_new(NULL); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
289 status = lastfm_get_data_from_uri(uri, fetched_metadata); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
290 if (status == CURLE_OK) |
1036 | 291 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
292 #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
|
293 g_print("LASTFM: (fetch) ----Received metadata:----\n%s\n----END----\n", fetched_metadata->str); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
294 #endif |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
295 if(parse_metadata( handle,fetched_metadata)) |
1036 | 296 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
297 res=METADATA_FETCH_SUCCEEDED; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
298 #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
|
299 g_print("LASTFM: (fetch) metadata was parsed ok\n"); |
1036 | 300 #endif |
301 } | |
302 | |
303 } | |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
304 return res; |
1036 | 305 } |
306 | |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
307 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
|
308 { |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 LastFM *handle = (LastFM *)arg; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
316 /* 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
|
317 * 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
|
318 * 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
|
319 * 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
|
320 * 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
|
321 * 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
|
322 */ |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
323 do |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
324 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
325 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
|
326 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
327 if(t0->tv_usec==-1) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
328 g_get_current_time (t0); |
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) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
331 break; |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
332 #if DEBUG |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
333 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
|
334 #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
|
335 status=fetch_metadata(handle); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
340 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
|
341 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
342 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
|
343 { /*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
|
344 #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
|
345 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
|
346 #endif |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
347 track_beginning=FALSE; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
348 sleep_duration=2; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
349 } |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
350 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
|
351 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 count=err=0; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 #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
|
361 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
|
362 #endif |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
363 } |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
364 |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
365 } |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
366 else |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
367 { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
368 /*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
|
369 * 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
|
370 */ |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
371 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
|
372 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
373 #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
|
374 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
|
375 #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
|
376 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
|
377 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
378 else |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
379 { |
1239
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) 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
|
382 #endif |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
383 track_end_expected=FALSE; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
384 sleep_duration=2; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
385 /*if(previous_track_title) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
386 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
387 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
|
388 previous_track_title=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
389 }*/ |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
390 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
391 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
392 #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
|
393 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
|
394 #endif |
1036 | 395 } |
1231
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
396 else |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
397 { |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
398 err++; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
399 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
|
400 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
401 #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
|
402 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
|
403 g_print("LASTFM: (thread) sleepping for %d seconds. ",err? sleep_duration/2 :sleep_duration); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
404 |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
405 |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
406 if((handle!= NULL)) |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
407 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
|
408 #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
|
409 |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
410 } |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
411 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
|
412 count++; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
413 |
1036 | 414 } |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
415 while ((g_thread_self()==metadata_thread )&& (err<7) && (handle != NULL)); |
1036 | 416 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
417 #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
|
418 g_print("LASTFM: (thread) Exiting thread, ID = %p\n", (void *)g_thread_self()); |
1036 | 419 #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
|
420 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
|
421 return NULL; |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
422 } |
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
423 |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
424 VFSFile *lastfm_vfs_fopen_impl(const gchar * path, const gchar * mode) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
425 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
426 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
|
427 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
|
428 handle->lastfm_artist=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
429 handle->lastfm_title=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
430 handle->lastfm_album=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
431 handle->lastfm_cover=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
432 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
|
433 handle->lastfm_mp3_stream_url=NULL; |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
434 handle->lastfm_station_name=NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
435 int login_count = 0; |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
436 |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
437 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
|
438 { |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
439 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
|
440 sleep(5); |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
441 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
|
442 { |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
443 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
|
444 g_free(file); |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
445 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
|
446 } |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
447 } |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
448 handle->lastfm_mp3_stream_url = mowgli_global_storage_get("lastfm_stream_uri"); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
449 handle->proxy_fd = vfs_fopen(handle->lastfm_mp3_stream_url, mode); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
450 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
451 handle->lastfm_session_id = mowgli_global_storage_get("lastfm_session_id"); |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
452 lastfm_adjust(handle,path); |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
453 file->handle = handle; |
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
454 g_get_current_time(t0); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
455 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
|
456 thread_count++; |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
457 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
|
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 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
464 gint lastfm_vfs_fclose_impl(VFSFile * file) |
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; |
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
|
470 if (file->handle) { |
1335
59699988d194
fixed some issues, hopefully it won't crash that much anymore
Cristi Magherusan <majeru@atheme-project.org>
parents:
1299
diff
changeset
|
471 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
|
472 LastFM *handle = file->handle; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
473 ret = vfs_fclose(handle->proxy_fd); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
474 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
|
475 handle->proxy_fd = NULL; |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
476 g_free(handle); |
e2b45aa596ad
improved the metadata algorithm, but couldnt get rid of the crashes yet
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
477 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
|
478 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
|
479 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
480 return ret; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
481 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
482 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
483 size_t lastfm_vfs_fread_impl(gpointer ptr, size_t size, size_t nmemb, VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
484 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
485 LastFM *handle = file->handle; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
486 size_t ret = vfs_fread(ptr, size, nmemb, handle->proxy_fd); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
487 return ret; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
488 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
489 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
490 size_t lastfm_vfs_fwrite_impl(gconstpointer ptr, size_t size, size_t nmemb, VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
491 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
492 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
493 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
494 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
495 gint lastfm_vfs_getc_impl(VFSFile * stream) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
496 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
497 LastFM *handle = stream->handle; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
498 return vfs_getc(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
499 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
500 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
501 gint lastfm_vfs_ungetc_impl(gint c, VFSFile * stream) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
502 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
503 LastFM *handle = stream->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
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 return vfs_ungetc(c, handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
506 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
507 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
508 gint lastfm_vfs_fseek_impl(VFSFile * file, glong offset, gint whence) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
509 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
510 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
511 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
512 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
513 void lastfm_vfs_rewind_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
514 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
515 return; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
516 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
517 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
518 glong lastfm_vfs_ftell_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
519 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
520 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
521 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
522 return vfs_ftell(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
523 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
524 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
525 gboolean lastfm_vfs_feof_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
526 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
527 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
528 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
529 return vfs_feof(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
530 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
531 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
532 gint lastfm_vfs_truncate_impl(VFSFile * file, glong size) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
533 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
534 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
535 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
536 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
537 off_t lastfm_vfs_fsize_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
538 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
539 return 0; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
540 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
541 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
542 gchar *lastfm_vfs_metadata_impl(VFSFile * file, const gchar * field) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
543 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
544 LastFM *handle = file->handle; |
1036 | 545 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 return g_strdup("audio/mpeg"); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
552 |
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 return NULL; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
554 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
555 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
556 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
|
557 "lastfm://", |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
558 lastfm_vfs_fopen_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
559 lastfm_vfs_fclose_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
560 lastfm_vfs_fread_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
561 lastfm_vfs_fwrite_impl, |
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_vfs_getc_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
563 lastfm_vfs_ungetc_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
564 lastfm_vfs_fseek_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
565 lastfm_vfs_rewind_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
566 lastfm_vfs_ftell_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
567 lastfm_vfs_feof_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
568 lastfm_vfs_truncate_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
569 lastfm_vfs_fsize_impl, |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
570 lastfm_vfs_metadata_impl |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
571 }; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
572 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
573 static void init(void) |
1036 | 574 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
575 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
|
576 if (!metadata_mutex) |
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
577 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
|
578 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
|
579 t1=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
|
580 |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
581 |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
582 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
583 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
584 static void cleanup(void) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
585 { |
1239
8af27e02e7b7
fixed crashes when opening multiple tracks, optimized metadata thread
Cristi Magherusan <majeru@atheme-project.org>
parents:
1231
diff
changeset
|
586 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
|
587 mowgli_global_storage_free("lastfm_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
|
588 mowgli_global_storage_free("lastfm_stream_uri"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
589 #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
|
590 g_print("LASTFM: (cleanup) Cleanup finished\n"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
591 #endif |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
592 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
593 |
1182
8df9aab3897e
[svn] - Bleh, squash the evil warning! Must compile without warnings!
nazca
parents:
1161
diff
changeset
|
594 DECLARE_PLUGIN(lastfm, init, cleanup, NULL, NULL, NULL, NULL, NULL) |