Esempio n. 1
0
void build_queries(GlyrQuery * one, GlyrQuery * two, GlyrQuery * three)
{
    glyr_query_init(one);
    glyr_query_init(two);
    glyr_query_init(three);

    glyr_opt_artist(one,"Diablo Swing Orchestra");
    glyr_opt_title (one,"Balrog Boogie");
    glyr_opt_type  (one, GLYR_GET_LYRICS);

    glyr_opt_artist(two, "Farin Urlaub");
    glyr_opt_download(two,FALSE);
    glyr_opt_type  (two, GLYR_GET_ARTIST_PHOTOS);

    glyr_opt_artist(three, "Knorkator");
    glyr_opt_type  (three, GLYR_GET_ARTIST_PHOTOS);
}
static void moose_metadata_query_init(MooseMetadataQuery *self) {
    MooseMetadataQueryPrivate *priv = moose_metadata_query_get_instance_private(self);
    glyr_query_init(&priv->query);
    glyr_opt_qsratio(&priv->query, 1.0);
    glyr_opt_parallel(&priv->query, 4);
    glyr_opt_timeout(&priv->query, 5.0);
    glyr_opt_useragent(&priv->query,
                       "Moose/0.0.1 +(https://github.com/studentkittens/moosecat)");
}
Esempio n. 3
0
END_TEST

//--------------------

START_TEST (test_sorted_rating)
{
    const int N = 10;

    GlyrDatabase * db = setup_db();

    GlyrQuery q;
    glyr_query_init (&q);
    setup (&q,GLYR_GET_LYRICS,N);

    for (int i = 0; i < N; ++i)
    {
        int rate = (i / 2) + 1;

        GlyrMemCache * ct = glyr_cache_new();
        fail_if (ct == NULL);

        glyr_cache_set_data (ct,g_strdup_printf ("MyLyrics %d",i),-1);
        ct->dsrc = g_strdup ("http://MyLyrics.com");
        ct->rating = rate;
        glyr_db_insert (db,&q,ct);

        glyr_cache_free (ct);
    }

    fail_unless (count_db_items (db) == N);

    GlyrMemCache * list = glyr_db_lookup (db,&q);
    GlyrMemCache * iter = list;
    fail_if (list == NULL);

    double last_timestamp = DBL_MAX;
    int last_rating = INT_MAX;
    while (iter)
    {
        glyr_cache_print (iter);
        fail_unless (last_rating >= iter->rating);
        if (last_rating == iter->rating)
            fail_unless (last_timestamp >= iter->timestamp);

        last_timestamp = iter->timestamp;
        last_rating = iter->rating;
        iter = iter->next;
    }

    glyr_free_list (list);
}
void
pragha_songinfo_plugin_get_info_to_dialog (PraghaSongInfoPlugin *plugin,
                                           GLYR_GET_TYPE        type,
                                           const gchar          *artist,
                                           const gchar          *title)
{
	PraghaApplication *pragha;
	GtkWidget *window;
	GlyrDatabase *cache_db;
	glyr_struct *glyr_info;

	glyr_info = g_slice_new0 (glyr_struct);

	glyr_query_init (&glyr_info->query);
	glyr_opt_type (&glyr_info->query, type);

	switch (type) {
		case GLYR_GET_ARTIST_BIO:
			glyr_opt_artist(&glyr_info->query, artist);

			glyr_opt_lang (&glyr_info->query, "auto");
			glyr_opt_lang_aware_only (&glyr_info->query, TRUE);
			break;
		case GLYR_GET_LYRICS:
			glyr_opt_artist(&glyr_info->query, artist);
			glyr_opt_title(&glyr_info->query, title);
			break;
		default:
			break;
	}

	cache_db = pragha_songinfo_plugin_get_cache (plugin);

	glyr_opt_lookup_db (&glyr_info->query, cache_db);
	glyr_opt_db_autowrite (&glyr_info->query, TRUE);

	glyr_info->plugin = plugin;

	pragha = pragha_songinfo_plugin_get_application (plugin);
	window = pragha_application_get_window (pragha);
	set_watch_cursor (window);

	pragha_async_launch (get_related_info_idle_func,
	                     glyr_finished_thread_update,
	                     glyr_info);
}
Esempio n. 5
0
END_TEST

//--------------------

/* Write artist|album|title, select only artist|title */
START_TEST (test_intelligent_lookup)
{
    GlyrDatabase * db = setup_db();

    GlyrQuery alt;
    glyr_query_init (&alt);

    gchar * artist = "Аркона";
    gchar * album  = "Ot Serdca k Nebu";
    gchar * title  = "Pokrovy Nebesnogo Startsa (Shrouds Of Celestial Sage)";

    glyr_opt_artist (&alt,artist);
    glyr_opt_album (&alt,album );
    glyr_opt_title (&alt,title );
    glyr_opt_type  (&alt,GLYR_GET_LYRICS);

    GlyrMemCache * subject = glyr_cache_new();
    glyr_cache_set_data (subject,g_strdup ("These are lyrics. Really."),-1);

    glyr_db_insert (db,&alt,subject);

    GlyrMemCache * one = glyr_db_lookup (db,&alt);
    fail_if (one == NULL,NULL);
    fail_if (memcmp (one->md5sum,subject->md5sum,16) != 0, NULL);
    glyr_cache_free (one);

    alt.album = NULL;
    GlyrMemCache * two = glyr_db_lookup (db,&alt);
    fail_if (two == NULL,NULL);
    fail_if (memcmp (two->md5sum,subject->md5sum,16) != 0, NULL);
    glyr_cache_free (two);

    fail_unless (count_db_items (db) == 1,NULL);
    int deleted = glyr_db_delete (db,&alt);
    fail_unless (deleted == 1,NULL);
    fail_unless (count_db_items (db) == 0,NULL);

    glyr_query_destroy (&alt);
    glyr_db_destroy (db);
}
Esempio n. 6
0
File: simple.c Progetto: sahib/glyr
int main (void)
{
    /* Init this thing, the only two methods not being threadsafe */
    glyr_init();
    /* Also clear ressources on exit */
    atexit (glyr_cleanup);

    /* This struct is used to store all settings you do via glyr_opt_* */
    GlyrQuery q;
    /* We also should set it to standard values */
    glyr_query_init (&q);

    /* We want lyrics, well, I want. */
    glyr_opt_type (&q,GLYR_GET_LYRICS);

    /* Set random artist/title -  you could also omit the album line */
    glyr_opt_artist (&q, (char*) "Die Ärzte");
    glyr_opt_album (&q, (char*) "Die Bestie in Menschengestalt");
    glyr_opt_title (&q, (char*) "FaFaFa");

    /* If any error occured it will be saved here, or GLYRE_OK */
    /* You could have also passed a NULL pointer to glyr_get() if you're not interested in this */
    GLYR_ERROR err;

    /* Now get the job done! The 3rd  */
    GlyrMemCache * head = glyr_get (&q,&err,NULL);

    /* The results are stored in the GlyrMemCache struct -
       you are most likely only interested in the fields data, size and type*/
    if (head != NULL)
    {
        /* head contains also a pointer to the next element, you can use it therefore as linkedlist */
        //        puts(head->data);
        glyr_cache_print (head);

        /* We have to free it again also, you can pass ANY pointer of the list, it works in both directions */
        glyr_free_list (head);
    }

    /* glyr_query_init  may allocate memory - free it. */
    glyr_query_destroy (&q);
    return err;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    /* You need to call this before anything happens */
    glyr_init();
    atexit(glyr_cleanup);

    /* Initialize a new query (this may allocate memory) */
    GlyrQuery q;
    glyr_query_init(&q);

    /* Say we want a Songtext */
    GLYR_GET_TYPE type = GLYR_GET_LYRICS;
    glyr_opt_type(&q, type);

    /* Set at least the required fields to your needs        *
     * For lyrics those are 'artist' and 'title', ('album')  *
     * is strictly optional and may be used by a few plugins */
    glyr_opt_artist(&q, (char *) "Die Apokalyptischen Reiter");
    glyr_opt_album(&q, (char *) "Riders on the Storm");
    glyr_opt_title(&q, (char *) "Friede sei mit dir");

    /* Execute a func when getting one item */
    int this_be_my_counter = 0;
    glyr_opt_dlcallback(&q, funny_callback, &this_be_my_counter);

    /* For the start: Enable verbosity */
    glyr_opt_verbosity(&q, 2);

    /* Download 5 (or less) items */
    glyr_opt_number(&q, 5);

    /* Just search, without downloading items */
    glyr_opt_download(&q, 0);

    /* Call the most important command: GET!
     * This returned a list of (GlyrMemCache *)s
     * Each containing ONE item. (i.e. a songtext)
     */
    GLYR_ERROR err;
    GlyrMemCache *it = glyr_get(&q, &err, NULL);

    if(err != GLYRE_OK) {
        fprintf(stderr, "E:%s\n", glyr_strerror(err));
    }

    /* Now iterate through it... */
    if(it != NULL) {
        GlyrMemCache *start = it;

        int counter = 0;
        while(it != NULL) {
            /* This has the same effect as in the callback,
             * Just that it's executed just once after all DL is done.
             * Commented out, as this would print it twice
             * */
            print_item(it, counter);

            /* Every cache has a link to the next and prev one (or NULL respectively) */
            it = it->next;
            ++counter;
        }

        /* The contents of it are dynamically allocated. */
        /* So better free them if you're not keen on memoryleaks */
        glyr_free_list(start);
    }
    /* Destroy query (reset to default values and free dyn memory) */
    /* You could start right off to use this query in another glyr_get */
    glyr_query_destroy(&q);
    return EXIT_SUCCESS;
}