File: register_plugins.c

package info (click to toggle)
glyr 1.0.6+git20140423-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,724 kB
  • ctags: 1,275
  • sloc: ansic: 13,062; python: 1,052; ruby: 75; makefile: 15
file content (427 lines) | stat: -rw-r--r-- 15,695 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/***********************************************************
 * This file is part of glyr
 * + a command-line tool and library to download various sort of music related metadata.
 * + Copyright (C) [2011-2012]  [Christopher Pahl]
 * + Hosted at: https://github.com/sahib/glyr
 *
 * glyr is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * glyr is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with glyr. If not, see <http://www.gnu.org/licenses/>.
 **************************************************************/

/* register all plugins here */
#include "core.h"
#include "register_plugins.h"

/* Warning: All functions in here are _not_ threadsafe. */
static void get_list_from_type (MetaDataFetcher * fetch);
static void register_provider_plugins (void);
static void init_provider_list (void);

/* global provider plugin list */
GList * glyrMetaDataSourceList = NULL;

/* List of MetaDataFetchers */
GList * glyrMetaDataPluginList = NULL;


/* Externalized fetcher vars, add yours here  {{{ */
extern MetaDataFetcher glyrFetcher_cover;
extern MetaDataFetcher glyrFetcher_lyrics;
extern MetaDataFetcher glyrFetcher_artistphotos;
extern MetaDataFetcher glyrFetcher_artistbio;
extern MetaDataFetcher glyrFetcher_similar_artists;
extern MetaDataFetcher glyrFetcher_similar_song;
extern MetaDataFetcher glyrFetcher_review;
extern MetaDataFetcher glyrFetcher_albumlist;
extern MetaDataFetcher glyrFetcher_tags;
extern MetaDataFetcher glyrFetcher_relations;
extern MetaDataFetcher glyrFetcher_tracklist;
extern MetaDataFetcher glyrFetcher_guitartabs;
extern MetaDataFetcher glyrFetcher_backdrops;
/* }}} */

/* Externalized sourceprovider vars, add yours here {{{ */
extern MetaDataSource ainfo_lastfm_src;
extern MetaDataSource ainfo_lyricsreg_src;
extern MetaDataSource ainfo_bbcmusic_src;
extern MetaDataSource ainfo_echonest_src;
extern MetaDataSource albumlist_musicbrainz_src;
extern MetaDataSource cover_coverartarchive_src;
extern MetaDataSource cover_albumart_src;
extern MetaDataSource cover_amazon_src;
extern MetaDataSource cover_coverhunt_src;
extern MetaDataSource cover_discogs_src;
extern MetaDataSource cover_google_src;
extern MetaDataSource cover_lastfm_src;
extern MetaDataSource cover_jamendo_src;
extern MetaDataSource cover_lyricswiki_src;
extern MetaDataSource cover_rhapsody_src;
extern MetaDataSource cover_picsearch_src;
extern MetaDataSource cover_musicbrainz_src;
extern MetaDataSource cover_slothradio_src;
extern MetaDataSource lyrics_lipwalk_src;
extern MetaDataSource lyrics_lyrdb_src;
extern MetaDataSource lyrics_lyricsreg_src;
extern MetaDataSource lyrics_lyricstime_src;
extern MetaDataSource lyrics_lyricsvip_src;
extern MetaDataSource lyrics_lyricswiki_src;
extern MetaDataSource lyrics_lyrix_src;
extern MetaDataSource lyrics_magistrix_src;
//extern MetaDataSource lyrics_metrolyrics_src;
extern MetaDataSource lyrics_metallum_src;
extern MetaDataSource lyrics_elyrics_src;
extern MetaDataSource lyrics_chartlyrics_src;
extern MetaDataSource lyrics_vagalume_src;
extern MetaDataSource photos_flickr_src;
extern MetaDataSource photos_google_src;
extern MetaDataSource photos_lastfm_src;
extern MetaDataSource photos_singerpictures_src;
extern MetaDataSource photos_discogs_src;
extern MetaDataSource photos_rhapsody_src;
extern MetaDataSource photos_picsearch_src;
extern MetaDataSource photos_bbcmusic_src;
extern MetaDataSource relations_musicbrainz_src;
extern MetaDataSource review_amazon_src;
extern MetaDataSource review_echonest_src;
extern MetaDataSource review_metallum_src;
extern MetaDataSource similar_artist_lastfm_src;
extern MetaDataSource similar_song_lastfm_src;
extern MetaDataSource tags_musicbrainz_src;
extern MetaDataSource tracklist_musicbrainz_src;
//extern MetaDataSource guitartabs_guitaretab_src;
extern MetaDataSource guitartabs_chordie_src;
extern MetaDataSource backdrops_htbackdrops_src;

/* Special offline providers */
extern MetaDataSource local_provider_src;
extern MetaDataSource relations_generated_src;
extern MetaDataSource musictree_provider_src;
/* }}} */

// Disabled due to bad quality.
//extern MetaDataSource lyrics_darklyrics_src;
//extern MetaDataSource lyrics_directlyrics_src;
//extern MetaDataSource lyrics_songlyrics_src;
/////////////////////////////////

/* Get fetcher list */
GList * r_getFList (void)
{
    return glyrMetaDataPluginList;
}

/////////////////////////////////

/* Get Source list */
GList * r_getSList (void)
{
    return glyrMetaDataSourceList;
}

/////////////////////////////////

void plugin_add_to_list (GList ** list, void * data)
{
    if (list != NULL)
    {
        *list = g_list_prepend (*list,data);
    }
}

/////////////////////////////////

static void register_provider_plugins (void)
{
    plugin_add_to_list (&glyrMetaDataSourceList,&ainfo_lastfm_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&ainfo_lyricsreg_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&ainfo_bbcmusic_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&ainfo_echonest_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&albumlist_musicbrainz_src);

    // FIXME: Seems to be broken too. (serverside)
    //plugin_add_to_list(&glyrMetaDataSourceList,&cover_albumart_src);

    // FIXME: Silly amazon requires to be a Seller to use their API
    // plugin_add_to_list(&glyrMetaDataSourceList,&cover_amazon_src);

    // FIXME: Coverhunt seems to be down. Add again when up and running
    //plugin_add_to_list(&glyrMetaDataSourceList,&cover_coverhunt_src);


    // FIXME: No real data yet there.. adele:19 gives a correct mbid, but no results
    plugin_add_to_list(&glyrMetaDataSourceList,&cover_coverartarchive_src);

    plugin_add_to_list (&glyrMetaDataSourceList,&cover_discogs_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_google_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_lastfm_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_jamendo_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_lyricswiki_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_rhapsody_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_picsearch_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_musicbrainz_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&cover_slothradio_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lipwalk_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lyrdb_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lyricsreg_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lyricstime_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lyricsvip_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lyricswiki_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_lyrix_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_magistrix_src);
    //plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_metrolyrics_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_metallum_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_elyrics_src);
	plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_vagalume_src);

    // FIXME: Chartlyrics reacts very slowly, and often not at all
    // add again when running again ( :( - good api though)
    // 28.1.2012: Seems to be on again, API fails too often though still.
    plugin_add_to_list (&glyrMetaDataSourceList,&lyrics_chartlyrics_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_flickr_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_google_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_lastfm_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_discogs_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_singerpictures_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_rhapsody_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_picsearch_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&photos_bbcmusic_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&relations_musicbrainz_src);

    // FIXME: Silly amazon requires to be a Seller to use their API
    //plugin_add_to_list(&glyrMetaDataSourceList,&review_amazon_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&review_metallum_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&review_echonest_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&similar_artist_lastfm_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&similar_song_lastfm_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&tags_musicbrainz_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&tracklist_musicbrainz_src);
    // FIXME: Searchfunction of guitaretabs seems to be broken
    //plugin_add_to_list(&glyrMetaDataSourceList,&guitartabs_guitaretab_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&guitartabs_chordie_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&backdrops_htbackdrops_src);

    /* Special offline providers */
    plugin_add_to_list (&glyrMetaDataSourceList,&relations_generated_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&local_provider_src);
    plugin_add_to_list (&glyrMetaDataSourceList,&musictree_provider_src);
}

/////////////////////////////////

/* Just presort a bit, so we don't need to shuffle the plugins always *
 * This has no actual practical use, it's just that pretty plugins are listed
 * first in outputs. Actual sorting is not threadsafe!
 */
static gint compare_by_priority (gconstpointer a, gconstpointer b)
{
    const MetaDataSource * sa = a;
    const MetaDataSource * sb = b;
    return (sa != NULL && sb != NULL) ?
           (sa->quality * sa->speed -
            sb->quality * sb->speed
           ) : 0;
}

/////////////////////////////////

static void get_list_from_type (MetaDataFetcher * fetch)
{
    GList * src;
    for (src = glyrMetaDataSourceList; src; src = src->next)
    {
        MetaDataSource * item = src->data;
        if (item && (fetch->type == item->type || item->type == GLYR_GET_ANY) )
        {
            fetch->provider = g_list_prepend (fetch->provider,item);
            if (item->data_type == GLYR_TYPE_UNKNOWN)
            {
                item->data_type = fetch->default_data_type;
            }
        }

    }
    fetch->provider = g_list_sort (fetch->provider,compare_by_priority);

}

/////////////////////////////////

static void init_provider_list (void)
{
    for (GList * fetch = glyrMetaDataPluginList; fetch; fetch = fetch->next)
        get_list_from_type ( (MetaDataFetcher *) (fetch->data) );
}

/////////////////////////////////

/* Register fetchers */
void register_fetcher_plugins (void)
{
    /* add yours here */
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_cover);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_lyrics);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_artistphotos);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_artistbio);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_similar_artists);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_similar_song);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_review);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_albumlist);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_tags);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_relations);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_tracklist);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_guitartabs);
    plugin_add_to_list (&glyrMetaDataPluginList,&glyrFetcher_backdrops);

    glyrMetaDataPluginList = g_list_reverse (glyrMetaDataPluginList);

    /* call init() */
    for (GList * elem = glyrMetaDataPluginList; elem; elem = elem->next)
    {
        MetaDataFetcher * fetch = elem->data;
        if (fetch->init != NULL)
        {
            fetch->init();
        }
    }

    /* le plugins */
    register_provider_plugins();

    init_provider_list();
}

/////////////////////////////////

/* Unregister 'em again */
void unregister_fetcher_plugins (void)
{
    /* Destroy all fetchers */
    if (glyrMetaDataPluginList)
    {
        GList * elem;
        for (elem = glyrMetaDataPluginList; elem != NULL; elem = elem->next)
        {
            MetaDataFetcher * item = elem->data;
            if (item->destroy != NULL)
            {
                item->destroy();
            }
            g_list_free (item->provider);
            item->provider = NULL;
        }
        g_list_free (glyrMetaDataPluginList);
        glyrMetaDataPluginList = NULL;
    }

    /* Also kill others */
    if (!glyrMetaDataSourceList)
    {
        g_list_free (glyrMetaDataSourceList);
        glyrMetaDataSourceList = NULL;
    }
}

/////////////////////////////////

GlyrFetcherInfo * get_plugin_info (void)
{
    GlyrFetcherInfo * head = NULL;
    GlyrFetcherInfo * prev_fetcher = NULL;
    for (GList * elem0 = r_getFList(); elem0; elem0 = elem0->next)
    {
        MetaDataFetcher * fetch = elem0->data;
        GlyrFetcherInfo  * finfo = g_malloc0 (sizeof (GlyrFetcherInfo) );

        GlyrSourceInfo * prev_source = NULL;
        for (GList * elem1 = r_getSList(); elem1; elem1 = elem1->next)
        {
            MetaDataSource * source = elem1->data;
            if (source && source->type == fetch->type)
            {
                GlyrSourceInfo  * sinfos = g_malloc0 (sizeof (GlyrSourceInfo) );

                sinfos->quality = source->quality;
                sinfos->speed   = source->speed;
                sinfos->key     = source->key;
                sinfos->type    = source->type;
                sinfos->lang_aware = source->lang_aware;
                sinfos->name    = g_strdup (source->name);

                if (prev_source != NULL)
                {
                    prev_source->next = sinfos;
                    sinfos->prev = prev_source;
                }
                else
                {
                    finfo->head = sinfos;
                }
                prev_source = sinfos;
            }
        }

        if (prev_fetcher != NULL)
        {
            prev_fetcher->next = finfo;
            finfo->prev = prev_fetcher;
        }
        else
        {
            head = finfo;
        }

        prev_fetcher = finfo;

        finfo->name = g_strdup (fetch->name);
        finfo->type = fetch->type;
        finfo->reqs = fetch->reqs;
    }
    return head;
}

/////////////////////////////////

static void free_single_item (GlyrFetcherInfo * info)
{
    if (info != NULL)
    {
        GlyrSourceInfo * elem = info->head;
        while (elem != NULL)
        {
            GlyrSourceInfo * to_delete = elem;
            elem = elem->next;

            g_free (to_delete->name);
            g_free (to_delete);
        }
        g_free ( (gchar*) info->name);
        info->name = NULL;
    }
    g_free (info);
}

/////////////////////////////////

void free_plugin_info (GlyrFetcherInfo * infos)
{
    if (infos != NULL)
    {
        GlyrFetcherInfo * fetch = infos;
        while (fetch != NULL)
        {
            GlyrFetcherInfo * to_delete = fetch;
            fetch = fetch->next;
            free_single_item (to_delete);
        }
    }
}