hythmbox-2.98/plugins/audioscrobbler/rb-audioscrobbler-service.c

No issues found

  1 /*
  2  * rb-audioscrobbler-service.c
  3  *
  4  * Copyright (C) 2010 Jamie Nicol <jamie@thenicols.net>
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as published by
  8  * the Free Software Foundation; either version 2, or (at your option)
  9  * any later version.
 10  *
 11  * The Rhythmbox authors hereby grant permission for non-GPL compatible
 12  * GStreamer plugins to be used and distributed together with GStreamer
 13  * and Rhythmbox. This permission is above and beyond the permissions granted
 14  * by the GPL license by which Rhythmbox is covered. If you modify this code
 15  * you may extend this exception to your version of the code, but you are not
 16  * obligated to do so. If you do not wish to do so, delete this exception
 17  * statement from your version.
 18  *
 19  * This program is distributed in the hope that it will be useful,
 20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 22  * GNU General Public License for more details.
 23  *
 24  * You should have received a copy of the GNU General Public License
 25  * along with this program; if not, write to the Free Software
 26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 27  */
 28 
 29 #include "rb-audioscrobbler-service.h"
 30 
 31 /* Last.fm details */
 32 #define LASTFM_NAME "Last.fm"
 33 #define LASTFM_AUTH_URL "http://www.last.fm/api/auth/"
 34 #define LASTFM_SCROBBLER_URL "http://post.audioscrobbler.com/"
 35 #define LASTFM_API_URL "http://ws.audioscrobbler.com/2.0/"
 36 #define LASTFM_OLD_RADIO_API_URL "http://ws.audioscrobbler.com/"
 37 /* this API key belongs to Jamie Nicol <jamie@thenicols.net>
 38    generated May 2010 for use in the audioscrobbler plugin */
 39 #define LASTFM_API_KEY "0337ff3c59299b6a31d75164041860b6"
 40 #define LASTFM_API_SECRET "776c85a04a445efa8f9ed7705473c606"
 41 
 42 #define LIBREFM_NAME "Libre.fm"
 43 #define LIBREFM_AUTH_URL "http://alpha.libre.fm/api/auth/"
 44 #define LIBREFM_SCROBBLER_URL "http://turtle.libre.fm/"
 45 #define LIBREFM_API_URL "http://alpha.libre.fm/2.0/"
 46 #define LIBREFM_API_KEY "a string 32 characters in length"
 47 #define LIBREFM_API_SECRET "a string 32 characters in length"
 48 
 49 struct _RBAudioscrobblerServicePrivate {
 50 	char *name;
 51 	char *auth_url;
 52 	char *scrobbler_url;
 53 	char *api_url;
 54 	char *old_radio_api_url;
 55 	char *api_key;
 56 	char *api_secret;
 57 };
 58 
 59 #define RB_AUDIOSCROBBLER_SERVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_AUDIOSCROBBLER_SERVICE, RBAudioscrobblerServicePrivate))
 60 
 61 static void rb_audioscrobbler_service_finalize (GObject *object);
 62 static void rb_audioscrobbler_service_get_property (GObject *object,
 63                                                     guint prop_id,
 64                                                     GValue *value,
 65                                                     GParamSpec *pspec);
 66 static void rb_audioscrobbler_service_set_property (GObject *object,
 67                                                     guint prop_id,
 68                                                     const GValue *value,
 69                                                     GParamSpec *pspec);
 70 
 71 enum
 72 {
 73 	PROP_0,
 74 	PROP_NAME,
 75 	PROP_AUTH_URL,
 76 	PROP_SCROBBLER_URL,
 77 	PROP_API_URL,
 78 	PROP_OLD_RADIO_API_URL,
 79 	PROP_API_KEY,
 80 	PROP_API_SECRET,
 81 };
 82 
 83 G_DEFINE_DYNAMIC_TYPE (RBAudioscrobblerService, rb_audioscrobbler_service, G_TYPE_OBJECT)
 84 
 85 RBAudioscrobblerService *
 86 rb_audioscrobbler_service_new_lastfm (void)
 87 {
 88 	/* create a Last.fm service */
 89 	return g_object_new (RB_TYPE_AUDIOSCROBBLER_SERVICE,
 90 	                     "name", LASTFM_NAME,
 91 	                     "auth-url", LASTFM_AUTH_URL,
 92 	                     "scrobbler-url", LASTFM_SCROBBLER_URL,
 93 	                     "api-url", LASTFM_API_URL,
 94 	                     "old-radio-api-url", LASTFM_OLD_RADIO_API_URL,
 95 	                     "api-key", LASTFM_API_KEY,
 96 	                     "api-secret", LASTFM_API_SECRET,
 97 	                     NULL);
 98 }
 99 
100 RBAudioscrobblerService *
101 rb_audioscrobbler_service_new_librefm (void)
102 {
103 	/* create a Libre.fm service */
104 	return g_object_new (RB_TYPE_AUDIOSCROBBLER_SERVICE,
105 	                     "name", LIBREFM_NAME,
106 	                     "auth-url", LIBREFM_AUTH_URL,
107 	                     "scrobbler-url", LIBREFM_SCROBBLER_URL,
108 	                     "api-url", LIBREFM_API_URL,
109 	                     "api-key", LIBREFM_API_KEY,
110 	                     "api-secret", LIBREFM_API_SECRET,
111 	                     NULL);
112 }
113 
114 static void
115 rb_audioscrobbler_service_class_init (RBAudioscrobblerServiceClass *klass)
116 {
117 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
118 
119 	object_class->finalize = rb_audioscrobbler_service_finalize;
120 	object_class->get_property = rb_audioscrobbler_service_get_property;
121 	object_class->set_property = rb_audioscrobbler_service_set_property;
122 
123 	g_object_class_install_property (object_class,
124 	                                 PROP_NAME,
125 	                                 g_param_spec_string ("name",
126 	                                                      "Name",
127 	                                                      "Name of the service",
128 	                                                      NULL,
129                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
130 
131 	g_object_class_install_property (object_class,
132 	                                 PROP_AUTH_URL,
133 	                                 g_param_spec_string ("auth-url",
134 	                                                      "Authentication URL",
135 	                                                      "URL user should be taken to for authentication",
136 	                                                      NULL,
137                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
138 
139 	g_object_class_install_property (object_class,
140 	                                 PROP_SCROBBLER_URL,
141 	                                 g_param_spec_string ("scrobbler-url",
142 	                                                      "Scrobbler URL",
143 	                                                      "URL scrobbler sessions should be made with",
144 	                                                      NULL,
145                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
146 
147 	g_object_class_install_property (object_class,
148 	                                 PROP_API_URL,
149 	                                 g_param_spec_string ("api-url",
150 	                                                      "API URL",
151 	                                                      "URL API requests should be sent to",
152 	                                                      NULL,
153                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
154 
155 	g_object_class_install_property (object_class,
156 	                                 PROP_OLD_RADIO_API_URL,
157 	                                 g_param_spec_string ("old-radio-api-url",
158 	                                                      "Old Radio API URL",
159 	                                                      "URL that radio requests using the old API should be sent to",
160 	                                                      NULL,
161                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
162 
163 	g_object_class_install_property (object_class,
164 	                                 PROP_API_KEY,
165 	                                 g_param_spec_string ("api-key",
166 	                                                      "API Key",
167 	                                                      "API key",
168 	                                                      NULL,
169                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
170 
171 	g_object_class_install_property (object_class,
172 	                                 PROP_API_SECRET,
173 	                                 g_param_spec_string ("api-secret",
174 	                                                      "API Secret",
175 	                                                      "API secret",
176 	                                                      NULL,
177                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
178 
179 	g_type_class_add_private (klass, sizeof (RBAudioscrobblerServicePrivate));
180 }
181 
182 static void
183 rb_audioscrobbler_service_class_finalize (RBAudioscrobblerServiceClass *klass)
184 {
185 }
186 
187 static void
188 rb_audioscrobbler_service_init (RBAudioscrobblerService *service)
189 {
190 	service->priv = RB_AUDIOSCROBBLER_SERVICE_GET_PRIVATE (service);
191 }
192 
193 static void
194 rb_audioscrobbler_service_finalize (GObject *object)
195 {
196 	RBAudioscrobblerService *service = RB_AUDIOSCROBBLER_SERVICE (object);
197 
198 	g_free (service->priv->name);
199 	g_free (service->priv->auth_url);
200 	g_free (service->priv->scrobbler_url);
201 	g_free (service->priv->api_url);
202 	g_free (service->priv->old_radio_api_url);
203 	g_free (service->priv->api_key);
204 	g_free (service->priv->api_secret);
205 
206 	G_OBJECT_CLASS (rb_audioscrobbler_service_parent_class)->finalize (object);
207 }
208 
209 static void
210 rb_audioscrobbler_service_get_property (GObject *object,
211                                         guint prop_id,
212                                         GValue *value,
213                                         GParamSpec *pspec)
214 {
215 	RBAudioscrobblerService *service = RB_AUDIOSCROBBLER_SERVICE (object);
216 
217 	switch (prop_id) {
218 	case PROP_NAME:
219 		g_value_set_string (value, rb_audioscrobbler_service_get_name (service));
220 		break;
221 	case PROP_AUTH_URL:
222 		g_value_set_string (value, rb_audioscrobbler_service_get_auth_url (service));
223 		break;
224 	case PROP_SCROBBLER_URL:
225 		g_value_set_string (value, rb_audioscrobbler_service_get_scrobbler_url (service));
226 		break;
227 	case PROP_API_URL:
228 		g_value_set_string (value, rb_audioscrobbler_service_get_api_url (service));
229 		break;
230 	case PROP_OLD_RADIO_API_URL:
231 		g_value_set_string (value, rb_audioscrobbler_service_get_old_radio_api_url (service));
232 		break;
233 	case PROP_API_KEY:
234 		g_value_set_string (value, rb_audioscrobbler_service_get_api_key (service));
235 		break;
236 	case PROP_API_SECRET:
237 		g_value_set_string (value, rb_audioscrobbler_service_get_api_secret (service));
238 		break;
239 	default:
240 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
241 		break;
242 	}
243 }
244 
245 static void
246 rb_audioscrobbler_service_set_property (GObject *object,
247                                         guint prop_id,
248                                         const GValue *value,
249                                         GParamSpec *pspec)
250 {
251 	RBAudioscrobblerService *service = RB_AUDIOSCROBBLER_SERVICE (object);
252 
253 	switch (prop_id) {
254 	case PROP_NAME:
255 		g_free (service->priv->name);
256 		service->priv->name = g_value_dup_string (value);
257 		break;
258 	case PROP_AUTH_URL:
259 		g_free (service->priv->auth_url);
260 		service->priv->auth_url = g_value_dup_string (value);
261 		break;
262 	case PROP_SCROBBLER_URL:
263 		g_free (service->priv->scrobbler_url);
264 		service->priv->scrobbler_url = g_value_dup_string (value);
265 		break;
266 	case PROP_API_URL:
267 		g_free (service->priv->api_url);
268 		service->priv->api_url = g_value_dup_string (value);
269 		break;
270 	case PROP_OLD_RADIO_API_URL:
271 		g_free (service->priv->old_radio_api_url);
272 		service->priv->old_radio_api_url = g_value_dup_string (value);
273 		break;
274 	case PROP_API_KEY:
275 		g_free (service->priv->api_key);
276 		service->priv->api_key = g_value_dup_string (value);
277 		break;
278 	case PROP_API_SECRET:
279 		g_free (service->priv->api_secret);
280 		service->priv->api_secret = g_value_dup_string (value);
281 		break;
282 	default:
283 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
284 		break;
285 	}
286 }
287 
288 const char *
289 rb_audioscrobbler_service_get_name (RBAudioscrobblerService *service)
290 {
291 	return service->priv->name;
292 }
293 
294 const char *
295 rb_audioscrobbler_service_get_auth_url (RBAudioscrobblerService *service)
296 {
297 	return service->priv->auth_url;
298 }
299 
300 const char *
301 rb_audioscrobbler_service_get_scrobbler_url (RBAudioscrobblerService *service)
302 {
303 	return service->priv->scrobbler_url;
304 }
305 
306 const char *
307 rb_audioscrobbler_service_get_api_url (RBAudioscrobblerService *service)
308 {
309 	return service->priv->api_url;
310 }
311 
312 const char *
313 rb_audioscrobbler_service_get_old_radio_api_url (RBAudioscrobblerService *service)
314 {
315 	return service->priv->old_radio_api_url;
316 }
317 
318 const char *
319 rb_audioscrobbler_service_get_api_key (RBAudioscrobblerService *service)
320 {
321 	return service->priv->api_key;
322 }
323 
324 const char *
325 rb_audioscrobbler_service_get_api_secret (RBAudioscrobblerService *service)
326 {
327 	return service->priv->api_secret;
328 }
329 
330 void
331 _rb_audioscrobbler_service_register_type (GTypeModule *module)
332 {
333 	rb_audioscrobbler_service_register_type (module);
334 }