Mercurial > audlegacy-plugins
annotate src/lastfm/lastfm.c @ 1223:a6e6b0ea4535
Add mimetype integration.
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Mon, 09 Jul 2007 05:02:56 -0500 |
parents | 619cd8c8def5 |
children | 01efa0e5b554 |
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 |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
2 * Copyright (c) 2007 Cristi Magherusan <majeru@gentoo.ro> |
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 /* |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
32 Current status and known issues: |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
33 - Works fine ant is relatively stable unless DEBUG is enabled (read below) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
34 - The adjust fails when having 2 or more opened streams at the same time. |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
35 * It will randomly adjust to any one of them, because the playlist keeps |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
36 pulling metadata |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
37 - When the network is disconnected opening a new track freezes the player |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
38 * This seems to recover after the connection is restablished |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
39 * Ordinary mp3 streams seem to share this behavior. Didnt tested if others do. |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
40 */ |
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 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
52 /*Caution!!! setting DEBUG to 1 is very likely to crash the player because the g_print-ed values |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
53 aren't checked of being !=NULL |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
54 */ |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
55 |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
56 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
|
57 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
58 GString *data = (GString *) udata; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
59 g_string_append_len(data, ptr, nmemb); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
60 return size * nmemb; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
61 } |
1036 | 62 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
63 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
|
64 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
65 CURL *curl = curl_easy_init(); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
66 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
|
67 curl_easy_setopt(curl, CURLOPT_USERAGENT, "Audacious"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
68 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
|
69 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
|
70 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
71 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
|
72 curl_easy_setopt(curl, CURLOPT_URL, url); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
73 curl_easy_setopt(curl, CURLOPT_WRITEDATA, result); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
74 gint status = curl_easy_perform(curl); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
75 curl_easy_cleanup(curl); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
76 return status; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
77 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
78 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
79 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
|
80 { /* 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
|
81 ConfigDb *cfg = NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
82 gchar *buf=NULL, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
83 *username = NULL, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
84 *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
|
85 if ((cfg = bmp_cfg_db_open()) != NULL) |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
86 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
87 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
|
88 &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
|
89 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
|
90 &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
|
91 g_free(cfg); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
92 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
93 if (username != NULL && password != NULL) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
94 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
95 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
|
96 g_free(password); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
97 g_free(username); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
98 return buf; |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
99 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
100 else |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
101 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
102 #if DEBUG |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
103 g_print("Couldn't find the login data. Use the scrobbler plugin to set it up.\n"); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
104 #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
|
105 return NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
106 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
107 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
108 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
109 void lastfm_store(gchar *var_name,gchar* var){ /*mowgli storage wrapper*/ |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
110 if (mowgli_global_storage_get(var_name)) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
111 mowgli_global_storage_free(var_name); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
112 |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
113 mowgli_global_storage_put(var_name,var); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
114 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
115 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
116 int lastfm_login(void) /*gets the session ID and the mp3 stream URL and stores them*/ |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
117 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
118 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
|
119 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
|
120 gchar *login_uri=NULL, |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
121 **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
|
122 GString *res; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
123 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
|
124 if(login_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
|
125 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
126 g_free(login_uri); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
127 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
|
128 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
129 res = g_string_new(NULL); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
130 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
|
131 #if DEBUG |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
132 g_print("Opened login URI: '%s'\n", login_uri); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
133 g_print("Got following data: '%s'\n", res->str); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
134 #endif |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
135 if (status == CURLE_OK) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
136 { |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
137 split = g_strsplit(res->str, "\n", 20); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
138 for (i = 0; split && split[i]; i++) |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
139 { |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
145 } |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
146 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
|
147 ret = LASTFM_LOGIN_ERROR; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
148 g_strfreev(split); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
149 g_string_erase(res, 0, -1); |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
150 g_free(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
|
151 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
|
152 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
153 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
154 static gchar* parse(gchar* input_string,gchar* token) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
155 { |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
156 if (!g_str_has_prefix(input_string, token)) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
157 return NULL; |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
158 |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
159 return g_strdup(strchr(input_string, '=') + 1); |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
160 } |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
161 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
162 gint lastfm_adjust(const gchar * uri) /*tunes into a channel*/ |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
163 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
164 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
|
165 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
|
166 *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 **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
|
168 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
|
169 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
|
170 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
|
171 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
172 #if DEBUG |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
173 g_print("Adjust failed! Session ID not set.\n"); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
174 #endif |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
175 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
|
176 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
177 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
|
178 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
|
179 status = lastfm_get_data_from_uri(fetch_url, res); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
180 #if 0 |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
181 g_print("\nAdjusting: \nSession ID:%s\n",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
|
182 g_print("Fetch URL:%s\n",fetch_url); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
183 g_print("Adjust OK, \nReceived data:\n%s\n", res->str); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
184 #endif |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
185 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
|
186 { |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
187 split = g_strsplit(res->str, "\n", 20); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
188 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
|
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 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
|
191 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
|
192 if (g_str_has_prefix(split[i], "url=")) |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
193 lastfm_store("lastfm_tuned_to_url", parse(split[i], "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
|
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 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
200 |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
201 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
|
202 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
203 int i; |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
204 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 handle->lastfm_progress=0; |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
212 |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
213 if (handle->lastfm_artist) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
214 g_free(handle->lastfm_artist); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
215 |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
216 if (handle->lastfm_title) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
217 g_free(handle->lastfm_title); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
218 |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
219 if (handle->lastfm_album) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
220 g_free(handle->lastfm_album); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
221 |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
222 if (handle->lastfm_cover) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
223 g_free(handle->lastfm_cover); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
224 |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
225 if (handle->lastfm_station_name) |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
226 g_free(handle->lastfm_station_name); |
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
227 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
228 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
|
229 { |
1219
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
230 if (g_str_has_prefix(split[i], "artist=")) |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
231 handle->lastfm_artist = parse(split[i],"artist="); |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
232 |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
233 if (g_str_has_prefix(split[i], "track=")) |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
234 handle->lastfm_title = parse(split[i],"track="); |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
235 |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
236 if (g_str_has_prefix(split[i], "album=")) |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
237 handle->lastfm_album = parse(split[i],"album=" ); |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
238 |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
239 if (g_str_has_prefix(split[i], "albumcover_medium=")) |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
240 handle->lastfm_cover = parse(split[i],"albumcover_medium="); |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
241 |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
242 if (g_str_has_prefix(split[i], "station=")) |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
243 handle->lastfm_station_name = parse(split[i],"station="); |
31c44eb25a4a
Fix more crashes and metadata.
William Pitcock <nenolod@atheme-project.org>
parents:
1218
diff
changeset
|
244 |
1218
cc4e03df48a3
Make things not crash.
William Pitcock <nenolod@atheme-project.org>
parents:
1217
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 handle->lastfm_progress = 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
|
249 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
250 #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
|
251 g_print("\nDuration:%d\n", handle->lastfm_duration); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
252 if(handle->lastfm_station_name!=NULL) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
253 g_print("Station Name: %s\n", handle->lastfm_station_name); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
254 #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
|
255 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
|
256 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
|
257 return TRUE; |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
258 } |
1036 | 259 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
260 int fetch_metadata(LastFM * handle) |
1036 | 261 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
262 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
|
263 gint status,res=METADATA_FETCH_FAILED; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 if (status == CURLE_OK) |
1036 | 271 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
272 #if DEBUG |
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_print("Received metadata:'%s'\n", fetched_metadata->str); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
274 #endif |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
275 if(parse_metadata( handle,fetched_metadata)) |
1036 | 276 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
277 res=METADATA_FETCH_SUCCEEDED; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
278 #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
|
279 g_print("metadata was parsed ok\n"); |
1036 | 280 #endif |
281 } | |
282 | |
283 } | |
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 return res; |
1036 | 285 } |
286 | |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
287 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
|
288 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
289 gint err=0, |
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
290 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
|
291 previous_track_duration=-1, |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
292 count=0, |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
293 status=0; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
294 gboolean track_end_expected=FALSE; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
295 gchar* previous_track_title=NULL; |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
1036
diff
changeset
|
296 LastFM *handle = (LastFM *)arg; |
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 // metadata is fetched 1 second after the stream is opened. |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
298 // if it's fetched ok i'm waiting for track_length-10 seconds |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
299 // then start polling for new metadata each 2 seconds, until |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
300 // the track gets changed from the previous iteration |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
301 do |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
302 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
303 sleep(1); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
304 count++; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
305 if(count%sleep_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
|
306 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
307 status=fetch_metadata(handle); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
308 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
|
309 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
310 if(!track_end_expected) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
311 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
312 sleep_duration=handle->lastfm_duration-10; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
313 previous_track_duration=handle->lastfm_duration; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
314 previous_track_title=g_strdup(handle->lastfm_title); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
315 track_end_expected=TRUE; /*then the track_end will follow*/ |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
316 count=err=0; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
317 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
318 else |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
319 { //two tracks are considered identical if they have the same length and the same title |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
320 if((handle->lastfm_duration == previous_track_duration)&& |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
321 g_str_has_prefix(handle->lastfm_title, previous_track_title)) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
322 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
323 sleep_duration=2; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
324 err++; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
325 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
326 else //the tracks are different so i'm at the beginning of a new one |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
327 { |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
328 track_end_expected=FALSE; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
329 g_free(previous_track_title); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
330 } |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
331 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
332 #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
|
333 g_print("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
|
334 #endif |
1036 | 335 } |
336 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
|
337 err+=5; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
338 } |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
339 #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
|
340 g_print("Thread_count: %d\n",thread_count); |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
341 #endif |
1036 | 342 } |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
343 while (err<=7 && (g_thread_self()==metadata_thread )); |
1036 | 344 |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
345 #if DEBUG |
1047 | 346 g_print("Exiting thread, ID = %p\n", (void *)g_thread_self()); |
1036 | 347 #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
|
348 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
|
349 return NULL; |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
350 } |
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
351 |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
352 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
|
353 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
354 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
|
355 LastFM *handle = g_new0(LastFM, 1); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
356 gchar* lastfm_uri=NULL; |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
357 int login_count = 0; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
358 while((login_count++ <= 3)&&(lastfm_login()!= LASTFM_LOGIN_OK)) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
359 sleep(5); |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
360 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
361 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
|
362 handle->lastfm_mp3_stream_url = mowgli_global_storage_get("lastfm_stream_uri"); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
363 lastfm_uri=mowgli_global_storage_get("lastfm_tuned_to_url"); |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
364 //only tune in if the existinfg uri is NULL or != our new one(from path) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
365 //adjust doesnt work as it should when having more than one lastfm stream opened at a time |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
366 if (!lastfm_uri || (!g_str_has_prefix(path,lastfm_uri)) ) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
367 if(!lastfm_adjust(path)==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
|
368 return NULL; |
1036 | 369 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
370 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
|
371 thread_count++; |
1036 | 372 handle->proxy_fd = vfs_fopen(handle->lastfm_mp3_stream_url, mode); |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
373 file->handle = handle; |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
374 return file; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
375 } |
976 | 376 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
377 gint lastfm_vfs_fclose_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
378 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
379 gint ret = 0; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
380 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
381 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
|
382 return -1; |
1036 | 383 LastFM *handle = file->handle; |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
384 ret = vfs_fclose(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
|
385 if (!ret) |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
386 handle->proxy_fd = NULL; |
1036 | 387 g_free(handle); |
388 handle=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
|
389 return ret; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
390 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
391 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
392 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
|
393 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
394 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
|
395 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
|
396 return ret; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
397 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
398 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
399 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
|
400 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
401 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
402 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
403 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
404 gint lastfm_vfs_getc_impl(VFSFile * stream) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
405 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
406 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
|
407 return vfs_getc(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
408 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
409 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
410 gint lastfm_vfs_ungetc_impl(gint c, VFSFile * stream) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
411 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
412 LastFM *handle = stream->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
413 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
414 return vfs_ungetc(c, handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
415 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
416 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
417 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
|
418 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
419 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
420 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
421 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
422 void lastfm_vfs_rewind_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
423 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
424 return; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
425 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
426 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
427 glong lastfm_vfs_ftell_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
428 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
429 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
430 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
431 return vfs_ftell(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
432 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
433 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
434 gboolean lastfm_vfs_feof_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
435 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
436 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
437 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
438 return vfs_feof(handle->proxy_fd); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
439 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
440 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
441 gint lastfm_vfs_truncate_impl(VFSFile * file, glong size) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
442 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
443 return -1; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
444 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
445 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
446 off_t lastfm_vfs_fsize_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
447 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
448 return 0; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
449 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
450 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
451 gchar *lastfm_vfs_metadata_impl(VFSFile * file, const gchar * field) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
452 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
453 LastFM *handle = file->handle; |
1036 | 454 |
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 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
|
456 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
|
457 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
|
458 return g_strdup_printf("%s - %s", handle->lastfm_artist, handle->lastfm_title); |
1223
a6e6b0ea4535
Add mimetype integration.
William Pitcock <nenolod@atheme-project.org>
parents:
1221
diff
changeset
|
459 if (!g_ascii_strncasecmp(field, "content-type", 12)) |
a6e6b0ea4535
Add mimetype integration.
William Pitcock <nenolod@atheme-project.org>
parents:
1221
diff
changeset
|
460 return g_strdup("audio/mpeg"); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
461 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
462 return NULL; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
463 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
464 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
465 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
|
466 "lastfm://", |
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 lastfm_vfs_metadata_impl |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
480 }; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
481 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
482 static void init(void) |
1036 | 483 { |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
484 vfs_register_transport(&lastfm_const); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
485 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
486 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
487 static void cleanup(void) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
488 { |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
489 |
1217
d4efe4889489
rendered the lastfm transport plugin stable again, preparing it for its GUI
Cristi Magherusan <majeru@atheme-project.org>
parents:
1200
diff
changeset
|
490 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
|
491 mowgli_global_storage_free("lastfm_stream_uri"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
492 #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
|
493 g_print ("Cleanup finished\n"); |
1200
0ae013f630fa
mowgli transition, and some fixes
Cristi Magherusan <majeru@atheme-project.org>
parents:
1182
diff
changeset
|
494 #endif |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
495 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
496 |
1182
8df9aab3897e
[svn] - Bleh, squash the evil warning! Must compile without warnings!
nazca
parents:
1161
diff
changeset
|
497 DECLARE_PLUGIN(lastfm, init, cleanup, NULL, NULL, NULL, NULL, NULL) |