Mercurial > audlegacy-plugins
annotate src/lastfm/lastfm.c @ 1018:3484d9da7f7c trunk
[svn] - make metadata display in Audacious again.
author | nenolod |
---|---|
date | Fri, 11 May 2007 09:48:31 -0700 |
parents | 2f0b7056f354 |
children | 47db8268cb7b |
rev | line source |
---|---|
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
1 /* Audacious |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
2 * Copyright (c) 2007 Cristi Magherusan |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
3 * |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
7 * (at your option) any later version. |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
8 * |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
12 * GNU General Public License for more details. |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
13 * |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
17 */ |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
18 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
19 #include <audacious/vfs.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
20 #include <audacious/plugin.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
21 #include <audacious/configdb.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
22 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
23 #include <curl/curl.h> |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
24 #include <glib.h> |
982 | 25 #include "lastfm.h" |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
26 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
27 GThread *metadata_thread = NULL; |
976 | 28 LastFM *LastFMGlobalData; |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
29 /*this keeps the login data in a global place since |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
30 * we cannot login on every fopen call* if anyone |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
31 * has a better solution to this any hint is welcome */ |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
32 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
33 static size_t lastfm_store_res(void *ptr, size_t size, size_t nmemb, void *udata) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
34 { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
35 GString *data = (GString *) udata; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
36 g_string_append_len(data, ptr, nmemb); |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
37 return size * nmemb; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
38 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
39 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
40 gint get_data_from_url(gchar buf[4096], GString * res) |
1008 | 41 { |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
42 CURL *curl = curl_easy_init(); |
1008 | 43 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); |
44 curl_easy_setopt(curl, CURLOPT_USERAGENT, "Audacious"); | |
45 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, lastfm_store_res); | |
46 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | |
47 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); | |
48 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, LASTFM_CURL_TIMEOUT); | |
49 curl_easy_setopt(curl, CURLOPT_URL, buf); | |
50 curl_easy_setopt(curl, CURLOPT_WRITEDATA, res); | |
51 gint status = curl_easy_perform(curl); | |
52 curl_easy_cleanup(curl); | |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
53 return status; |
1008 | 54 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
55 |
982 | 56 static gboolean lastfm_login(void) |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
57 { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
58 /*gets the session ID in lastfm_session_id and returns the URL to be played |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
59 * read http://gabistapler.de/blog/index.php?/archives/268-Play-last.fm-streams-without-the-player.html for more info |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
60 */ |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
61 gint status, i; |
975 | 62 gchar buf[4096], **split = NULL; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
63 GString *res = g_string_new(NULL); |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
64 ConfigDb *cfgfile = NULL; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
65 char *username = NULL, *password = NULL; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
66 if ((cfgfile = bmp_cfg_db_open()) != NULL) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
67 { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
68 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "username", &username); |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
69 bmp_cfg_db_get_string(cfgfile, "audioscrobbler", "password", &password); |
976 | 70 g_free(cfgfile); |
71 } | |
72 if (username != NULL && password != NULL) | |
73 { | |
975 | 74 snprintf(buf, sizeof(buf), LASTFM_HANDSHAKE_URL, username, password); |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
75 g_free(password); |
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
76 g_free(username); |
976 | 77 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
78 else |
975 | 79 return FALSE; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
80 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
81 status = get_data_from_url(buf, res); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
82 |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
83 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
84 g_print("URL:%s\n", buf); |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
85 g_print("Downloaded data:%s\n", res->str); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
86 #endif |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
87 if (status == CURLE_OK) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
88 { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
89 split = g_strsplit(res->str, "\n", 7); |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
90 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
91 for (i = 0; split && split[i]; i++) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
92 { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
93 if (g_str_has_prefix(split[i], "session=")) |
975 | 94 LastFMGlobalData->lastfm_session_id = g_strndup(split[i] + 8, 32); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
95 else if (g_str_has_prefix(split[i], "stream_url=")) |
975 | 96 LastFMGlobalData->lastfm_mp3_stream_url = g_strdup(split[i] + 11); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
97 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
98 } |
976 | 99 else |
100 return FALSE; | |
975 | 101 |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
102 g_strfreev(split); |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
103 g_string_erase(res, 0, -1); |
976 | 104 return (gboolean) TRUE; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
105 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
106 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
107 static gboolean lastfm_adjust(const gchar * url) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
108 { |
975 | 109 int status, i; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
110 gchar tmp[4096], **split = NULL; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
111 gboolean ret = FALSE; |
975 | 112 GString *res = g_string_new(NULL); |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
113 |
976 | 114 if (LastFMGlobalData->lastfm_session_id == NULL) |
115 return FALSE; | |
116 snprintf(tmp, sizeof(tmp), LASTFM_ADJUST_URL, LastFMGlobalData->lastfm_session_id, url); | |
1008 | 117 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
118 status = get_data_from_url(tmp, res); |
1008 | 119 |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
120 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
121 g_print("Adjust received data:%s\n", res->str); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
122 #endif |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
123 if (status == CURLE_OK) |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
124 { |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
125 split = g_strsplit(res->str, "\n", 3); |
975 | 126 |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
127 for (i = 0; split && split[i]; i++) |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
128 { |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
129 if (g_str_has_prefix(split[i], "response=OK")) |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
130 ret = TRUE; |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
131 if (g_str_has_prefix(split[i], "stationname=")) |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
132 { |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
133 LastFMGlobalData->lastfm_station_name = g_strdup(split[i] + 12); |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
134 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
135 g_print("StationnName:%s\n", LastFMGlobalData->lastfm_station_name); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
136 #endif |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
137 } |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
138 } |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
139 g_strfreev(split); |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
140 } |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
141 g_string_erase(res, 0, -1); |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
142 |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
143 return ret; |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
144 } |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
145 static void *lastfm_get_metadata(LastFM * handle) |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
146 { |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
147 |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
148 gint status, i; |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
149 gchar tmp[4096], **split = NULL; |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
150 GString *res = g_string_new(NULL); |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
151 |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
152 if (handle->lastfm_session_id == NULL) |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
153 return NULL; |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
154 snprintf(tmp, sizeof(tmp), LASTFM_METADATA_URL, handle->lastfm_session_id); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
155 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
156 gboolean opened_file = TRUE; |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
157 while (opened_file) |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
158 { |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
159 handle->lastfm_duration = 0; |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
160 handle->lastfm_progress = 0; |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
161 status = get_data_from_url(tmp, res); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
162 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
163 g_print("Getting Metadata\n"); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
164 #endif |
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
165 #if 0 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
166 g_print("Received metadata:%s\n", res->str); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
167 #endif |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
168 if (status == CURLE_OK) |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
169 { |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
170 split = g_strsplit(res->str, "\n", 20); |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
171 |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
172 for (i = 0; split && split[i]; i++) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
173 { |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
174 if (g_str_has_prefix(split[i], "artist=")) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
175 { |
1018 | 176 if (handle->lastfm_artist) g_free(handle->lastfm_artist); |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
177 handle->lastfm_artist = g_strdup(split[i] + 7); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
178 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
179 g_print("Artist: %s\n", handle->lastfm_artist); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
180 #endif |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
181 } |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
182 if (g_str_has_prefix(split[i], "track=")) |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
183 { |
1018 | 184 if (handle->lastfm_title) g_free(handle->lastfm_title); |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
185 handle->lastfm_title = g_strdup(split[i] + 6); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
186 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
187 g_print("Title: %s\n", handle->lastfm_title); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
188 #endif |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
189 } |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
190 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
191 if (g_str_has_prefix(split[i], "album=")) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
192 handle->lastfm_album = g_strdup(split[i] + 6); |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
193 if (g_str_has_prefix(split[i], "albumcover_medium=")) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
194 handle->lastfm_cover = g_strdup(split[i] + 18); |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
195 if (g_str_has_prefix(split[i], "trackduration=")) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
196 { |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
197 handle->lastfm_duration = g_ascii_strtoull(g_strdup(split[i] + 14), NULL, 10); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
198 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
199 g_print("Duration:%d\n", handle->lastfm_duration); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
200 #endif |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
201 } |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
202 if (g_str_has_prefix(split[i], "trackprogress=")) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
203 handle->lastfm_progress = g_ascii_strtoull(g_strdup(split[i] + 14), NULL, 10); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
204 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
205 if (g_str_has_prefix(split[i], "station=")) |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
206 { |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
207 handle->lastfm_station_name = g_strdup(split[i] + 8); |
1009
f30aaf18916a
[svn] added primitive metadata handling (just gets printed in the terminal)
majeru
parents:
1008
diff
changeset
|
208 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
209 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
|
210 #endif |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
211 } |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
212 } |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
213 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
214 g_strfreev(split); |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
215 } |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
216 g_string_erase(res, 0, -1); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
217 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
218 int sleep_time; |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
219 if (handle->lastfm_progress == 0) //if i don't know track duration i'm polling for metadata every 10 seconds |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
220 sleep_time = 10; |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
221 else |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
222 sleep_time = handle->lastfm_duration - handle->lastfm_progress + 3; |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
223 #ifdef DEBUG |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
224 g_print("Sleeping for %d seconds\n", sleep_time); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
225 #endif |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
226 |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
227 sleep(sleep_time); |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
228 if (handle->proxy_fd == NULL) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
229 opened_file = FALSE; |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
230 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
231 |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
232 #ifdef DEBUG |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
233 g_print("Exiting a thread\n"); |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
234 #endif |
1016 | 235 metadata_thread = NULL; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
236 return NULL; |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
237 } |
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
238 |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
239 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
|
240 { |
1018 | 241 static GThread *th; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
242 VFSFile *file; |
975 | 243 LastFM *handle; |
976 | 244 file = g_new0(VFSFile, 1); |
975 | 245 handle = g_new0(LastFM, 1); |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
246 |
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
247 while ((LastFMGlobalData->lastfm_mp3_stream_url == NULL) && (LastFMGlobalData->login_count <= 3)) |
976 | 248 { |
249 printf("Login try count: %d\n", LastFMGlobalData->login_count++); | |
250 lastfm_login(); | |
251 if (LastFMGlobalData->lastfm_mp3_stream_url == NULL) | |
252 sleep(5); | |
253 } | |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
254 |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
255 if (LastFMGlobalData->lastfm_mp3_stream_url == NULL) |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
256 return NULL; |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
257 |
976 | 258 handle->lastfm_mp3_stream_url = g_strdup(LastFMGlobalData->lastfm_mp3_stream_url); |
259 handle->lastfm_session_id = g_strdup(LastFMGlobalData->lastfm_session_id); | |
260 handle->lastfm_station_name = g_strdup(LastFMGlobalData->lastfm_station_name); | |
261 | |
1018 | 262 if (lastfm_adjust(path)) |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
263 { |
1018 | 264 if ((th = g_thread_create(lastfm_get_metadata, handle, FALSE, NULL)) == NULL) |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
265 { |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
266 #ifdef DEBUG |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
267 g_print("Error creating metadata thread!!!\n"); |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
268 #endif |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
269 return NULL; |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
270 } |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
271 else |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
272 #ifdef DEBUG |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
273 g_print("The metadata thread has just been created\n"); |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
274 #endif |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
275 } |
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
276 #ifdef DEBUG |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
277 else |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
278 g_print("Cannot tune to given channel\n"); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
279 #endif |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
280 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
281 handle->proxy_fd = vfs_fopen(handle->lastfm_mp3_stream_url, mode); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
282 file->handle = handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
283 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
284 return file; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
285 } |
976 | 286 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
287 gint lastfm_vfs_fclose_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
288 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
289 gint ret = 0; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
290 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
291 if (file == NULL) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
292 return -1; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
293 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
294 LastFM *handle = file->handle; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
295 ret = vfs_fclose(handle->proxy_fd); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
296 if (!ret) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
297 handle->proxy_fd = NULL; |
975 | 298 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
299 return ret; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
300 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
301 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
302 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
|
303 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
304 LastFM *handle = file->handle; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
305 size_t ret = vfs_fread(ptr, size, nmemb, handle->proxy_fd); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
306 return ret; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
307 } |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
308 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
309 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
|
310 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
311 return -1; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
312 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
313 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
314 gint lastfm_vfs_getc_impl(VFSFile * stream) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
315 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
316 LastFM *handle = stream->handle; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
317 return vfs_getc(handle->proxy_fd); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
318 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
319 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
320 gint lastfm_vfs_ungetc_impl(gint c, VFSFile * stream) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
321 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
322 LastFM *handle = stream->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
323 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
324 return vfs_ungetc(c, handle->proxy_fd); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
325 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
326 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
327 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
|
328 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
329 return -1; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
330 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
331 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
332 void lastfm_vfs_rewind_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
333 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
334 return; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
335 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
336 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
337 glong lastfm_vfs_ftell_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
338 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
339 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
340 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
341 return vfs_ftell(handle->proxy_fd); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
342 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
343 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
344 gboolean lastfm_vfs_feof_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
345 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
346 LastFM *handle = file->handle; |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
347 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
348 return vfs_feof(handle->proxy_fd); |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
349 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
350 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
351 gint lastfm_vfs_truncate_impl(VFSFile * file, glong size) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
352 { |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
353 return -1; |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
354 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
355 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
356 off_t lastfm_vfs_fsize_impl(VFSFile * file) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
357 { |
1017
2f0b7056f354
[svn] - returning -1 is invalid here for fsize(). make metadata display in Audacious.
nenolod
parents:
1016
diff
changeset
|
358 return 0; |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
359 } |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
360 |
1014
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
361 gchar *lastfm_vfs_metadata_impl(VFSFile * file, const gchar * field) |
af586df84c9b
[svn] - lets avoid spawning >1 threads for metadata
nenolod
parents:
1013
diff
changeset
|
362 { |
976 | 363 LastFM *handle = file->handle; |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
364 |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
365 #ifdef DEBUG |
1018 | 366 g_print("Interesting metadata (want: %s):\n", field); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
367 |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
368 if (handle->lastfm_station_name != NULL) |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
369 g_print("%s\n", handle->lastfm_station_name); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
370 |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
371 if (handle->lastfm_artist != NULL) |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
372 g_print("%s\n", handle->lastfm_artist); |
975 | 373 |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
374 if (handle->lastfm_title != NULL) |
1010
8bad1b46ef78
[svn] - make this compile again and indent properly
nenolod
parents:
1009
diff
changeset
|
375 g_print("%s\n", handle->lastfm_title); |
978
3513bc2fd738
[svn] got the metadata but couldnt make use of it yet
majeru
parents:
976
diff
changeset
|
376 |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
377 g_print("%u\n\n", handle->lastfm_duration); |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
378 #endif |
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
379 |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
380 if (!g_ascii_strncasecmp(field, "stream-name", 11) && (handle->lastfm_station_name != NULL)) |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
381 return g_strdup(handle->lastfm_station_name); |
1013
177d47add6dd
[svn] lastfn's metadata seems to wotk, but still it has some glitches
majeru
parents:
1010
diff
changeset
|
382 if (!g_ascii_strncasecmp(field, "track-name", 10) && (handle->lastfm_title != NULL) && (handle->lastfm_artist != NULL)) |
979
e31c4566feb6
[svn] - disable all use of puts() unless -DDEBUG is defined.
nenolod
parents:
978
diff
changeset
|
383 return g_strdup_printf("%s - %s", handle->lastfm_artist, handle->lastfm_title); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
384 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
385 return NULL; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
386 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
387 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
388 VFSConstructor lastfm_const = { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
389 "lastfm://", |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
390 lastfm_vfs_fopen_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
391 lastfm_vfs_fclose_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
392 lastfm_vfs_fread_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
393 lastfm_vfs_fwrite_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
394 lastfm_vfs_getc_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
395 lastfm_vfs_ungetc_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
396 lastfm_vfs_fseek_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
397 lastfm_vfs_rewind_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
398 lastfm_vfs_ftell_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
399 lastfm_vfs_feof_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
400 lastfm_vfs_truncate_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
401 lastfm_vfs_fsize_impl, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
402 lastfm_vfs_metadata_impl |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
403 }; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
404 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
405 static void init(void) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
406 { |
975 | 407 LastFMGlobalData = g_new0(LastFM, 1); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
408 vfs_register_transport(&lastfm_const); |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
409 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
410 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
411 static void cleanup(void) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
412 { |
976 | 413 g_free(LastFMGlobalData); |
972
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
414 } |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
415 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
416 LowlevelPlugin llp_lastfm = { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
417 NULL, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
418 NULL, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
419 "lastfm:// URI Transport", |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
420 init, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
421 cleanup, |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
422 }; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
423 |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
424 LowlevelPlugin *get_lplugin_info(void) |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
425 { |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
426 return &llp_lastfm; |
cf7021ca4e7b
[svn] Add lastfm:// transport, an abstract VFS class which derives from curl
nenolod
parents:
diff
changeset
|
427 } |