Skip to content

Introduction to libglyr

bugdone edited this page Sep 24, 2016 · 4 revisions

Probably you expect phrases like “It’s so easy!”
Yupp, it is easy.

This guide describes the API for C.
If you ever had to do with libcurl you might notice there are some very similar things here.
First of all we have a thing called a query, you set options in this query, like the Artist, Album, or the singers hair colour, and also the type of Metadata you want, like ‘coverart’. Then you give this query to glyr_get() and after some time you get back a list of caches.
Those caches are the resulting items you use in your application. Yupp, that easy.

Now, let’s see how this works in code:
  1. We should init the library first.
    glyr_init();
  2. Make sure we destroy it later.
    atexit(glyr_cleanup);
  3. Let’s make a new query:
    GlyrQuery my_query;
  4. Set it to sane defaults:
    glyr_query_init(&my_query);
  5. Say we want coverart.
    glyr_opt_type(&my_query,GLYR_GET_COVERART);
  6. Set the artist.
    glyr_opt_artist(&my_query,"Excrementory Grindfuckers");
  7. Set the album.
    glyr_opt_album(&my_query,"Guts, Gore & Grind");
  8. Now order your items.
    GlyrMemCache * list = glyr_get(&my_query,NULL,NULL);
  9. list is the head of a doubly linked list of caches
    Each cache has a data field, containing the data (here some unprintable image)
    Also, it has a pointer next, which (surprise) points to the next item in the list.
    We then can iterate over the results like this.
    GlyrMemCache * it = list; while(it != NULL) { printf("Image with size %d\n",it->size); it = it->next; }
  10. This will get you 0 or 1 image. Why? Because glyr_opt_number() was set to 1.
    Try to change it and run again.
  11. When done we should free the thing:
    glyr_free_list(list);
  12. And this query isn’t needed anymore. Free it:
    glyr_query_destroy(&my_query);

Notes
  1. Most of the time you will just use the glyr_opt methods.
  2. All default values for glyr_opt are #defined in types.h; Example: GLYR_DEFAULT_QSRATIO
  3. If you use libglyr in a musicplayer you want to run it in an own thread. Read on to see an example.
  4. Most of the default settings are sane. You’re only required to set artist/album/title and the type.

Links
That above was a full program using libglyr. The cool thing: Normally that’s all you need.
A similar simple version can be found here.
You can compile this via gcc simple.c -o simple -lglyr
If you’re done with this: Proceed with the next example.