annotate src/lastfm/lastfm.c @ 3173:3fd0d762371c

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