/usr/share/doc/libglyr-doc/examples/rating.c is in libglyr-doc 1.0.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /***********************************************************
* 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/>.
**************************************************************/
#include <time.h>
#include <stdio.h>
#include "../../lib/glyr.h"
#include "../../lib/cache.h"
/* Short example to show a more obscure feature of caching:
* Every cache has a field called 'rating' - see below:
*
* Execute this example twice (./bin/rating [how_many_items]:
* 1) First time some URLs will be found in the web.
* A random rating is applied to each, and they're written to the DB.
* 2) The second run will get the URLs from the cache instead. Sorted by rating,
* and if two have the same rating the last added will be the first (sorted by timestamp).
* Newly found (== not yet cached items) are always at the very end of the list.
* 3) will yield the same result as 2)
* 4) 'rm /tmp/metadata.db' to start again.
*/
int main (int argc, const char *argv[])
{
int amount_to_get = (argc > 1) ? strtol (argv[1],NULL,10) : 3;
GLYR_ERROR err;
glyr_init();
atexit (glyr_cleanup);
srand (time (NULL) );
GlyrDatabase * db = glyr_db_init ("/tmp");
if (db != NULL)
{
GlyrQuery q;
glyr_query_init (&q);
glyr_opt_artist (&q,"Die Apokalyptischen Reiter");
glyr_opt_type (&q,GLYR_GET_ARTIST_PHOTOS);
glyr_opt_download (&q,false);
glyr_opt_number (&q,amount_to_get);
glyr_opt_lookup_db (&q,db);
/* Say, we want to manage the writing part ourself */
glyr_opt_db_autowrite (&q,false);
/* Now either get me some from the web or the db */
GlyrMemCache * list = glyr_get (&q,&err,NULL);
if (err != GLYRE_OK)
{
fprintf (stderr,"Error occured: %s\n",glyr_strerror (err) );
}
if (list != NULL)
{
for (GlyrMemCache * cache = list; cache; cache = cache->next)
{
puts ("-----------------");
glyr_cache_print (cache);
puts ("-----------------");
/* Give it some rating if not already cached */
if (cache->cached == false)
{
cache->rating = rand() % 100;
glyr_db_insert (db,&q,cache);
}
}
glyr_free_list (list);
}
glyr_query_destroy (&q);
glyr_db_destroy (db);
}
return EXIT_SUCCESS;
}
|