Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Glyr Version 0.4beta now ready. Mainly a bugfix release. See CHANGELO…

…G and TODO
  • Loading branch information...
commit f0870fba3e02db799ef2f0efcd5478b4b69e3bba 1 parent e5cf1ea
@sahib authored
View
20 CHANGELOG
@@ -0,0 +1,20 @@
+Hand written changelog of important changes.
+Use the github page to view the automated git generated brother.
+
+2011/03/07
+----------
++ Fixed lyrix.at parser (ctr was incremented always, not only on item found)
++ Speed up of cover and lyrics plugins (Up to 200%)
++ Fixed lyrics:magistrix plugin
++ Fixed lyrics:lyricswiki plugin
++ Fix of DynHelp
++ Fixed overall memory leaks
++ added finalize() call to cleanup plugins
+
+2011/03/09
+----------
++ Help text reacts now on "I DONT WANNA COLOR!"
++ added ability to stop searchengine by returning GLYRE_STOP_BY_CB in callback
++ Fixed a bug when using the google plugin and -D
++ Fixed google (and other) returning 404 Pages
+
View
24 README
@@ -1,3 +1,27 @@
+Glyr is both a library and a commandline tool to download various sorts of music related metadata.
+It was writte because the author was heavily annoyed by some musicplayers with broken or weird cover download.
+Therfore glyr can be used as a C library to provide routines to easily add features like cover/lyrics/photo download to your musicplayers.
+At the moment bindings are available for Ruby (and the wrapper class 'Glubyr'), but a SWIG interface file is provided which makes
+writing bindings for other scripting languages very ease.
+
+Glyr's feature in a nutshell are:
+ - download of coverart / lyrics / similiar artists / album reviews / band related photos / artist information
+ - Always having more than fallback, and a hit rate of approx. 97% for coverdownload
+ - Portable: Windows and Linux are supported (Developement on Linux), if you like to port glyr to Mac OSX please drop me a note,
+ There will be only minor to no changes on Mac OS X in the source..
+ - Fuzzy matching: Search providers with Levenshtein algorithm to eliminate typos
+ - Fast Download: libcurl is used internally, and sources are searched in parallel, unneeded data is not downloaded if possible.
+ - Almost no dependencies: Only libcurl.
+ - Download of a user defined amount of items, glyrc cover -a Foo -b Bar -n 30 loads 30 covers of 'Bar' by 'Foo'
+ - grouped download: Query providers by descending Accuray / Speed
+ - Optional download of images, URL is returned otherwise
+ - Uses prefereable Sources that provide a good API
+ - Check for duplicate URLs
+ - Licensed under the GPLv3
+
+glyrc is (note the 'c') the commandline interface to libglyr which can be used for example in bash scripts, or to tag your musicdb.
+The usage of the commandlin interface is descriped below... (also available via --usage)
+
USAGE:
glyrc GETTER [OPTIONS...]
View
32 TODO
@@ -1,16 +1,24 @@
+
+Ideas:
+------
+- Musicbrainz!
- type member in GlyMemcache
-- Order | apperance of groups
- + taking order from --from
- + adding intersection and negation
-
-- skip duplicate check option
-- memory leaks
-- making plugins that share code
+ - mostly implemented
+ - COVER_BACK, COVER_FRONT.. etc. still missing
+
- new plugins (wikipedia for ainfo - clementine)
- at least two more review plugins
+- colors for Win32
+- check header for content type..
+
+Missing:
+--------
- ainfo with correct formatting, perhaps also review
-- Increment version number to 0.5 :-)
-- --prefer=format option
-- Negate options
-- docu!
-- short help
+- More documentation!
+- short help (in work)
+- making plugins that share code (clean up the mess..)
+- Ensure legality (and add a legal note somewhere)
+- Check if min/max works correct
+- remove books (seperatze branch)
+- example.c
+- photos:google
View
BIN  bin/linux/glyrc
Binary file not shown
View
BIN  bin/linux/libglyr.so
Binary file not shown
View
5 lib/CMakeLists.txt
@@ -1,7 +1,7 @@
# configure
set( GLYR_VERSION_MAJOR "0")
-set( GLYR_VERSION_MINOR "2")
-set( GLYR_VERSION_NAME "Kleptomaniacal Magpie")
+set( GLYR_VERSION_MINOR "4beta")
+set( GLYR_VERSION_NAME "Larcenous Locust")
set( GLYR_COLORED_OUTPUT true)
configure_file (
@@ -10,7 +10,6 @@ configure_file (
)
ADD_DEFINITIONS( -ggdb3 -Wall )
-
ADD_LIBRARY(glyr SHARED ${LIB_SOURCE_LOCATIONS})
TARGET_LINK_LIBRARIES(glyr curl)
INSTALL(TARGETS glyr LIBRARY DESTINATION lib)
View
1  lib/ainfo.c
@@ -56,6 +56,7 @@ static GlyCacheList * ainfo_finalize(GlyCacheList * result, GlyQuery * settings)
if(settings->callback.download)
settings->callback.download(result->list[i],settings);
+ result->list[i]->type = TYPE_AINFO;
DL_add_to_list(r_list,DL_copy(result->list[i]));
}
return r_list;
View
127 lib/core.c
@@ -159,7 +159,7 @@ static size_t DL_buffer(void *puffer, size_t size, size_t nmemb, void *cache)
if(mem->dsrc != NULL && strstr(mem->data,mem->dsrc))
{
- puts("Found endmark..");
+ // Stop download now, as we appear to have everything
return 0;
}
}
@@ -208,7 +208,8 @@ GlyMemCache* DL_init(void)
cache->size = 0;
cache->data = NULL;
cache->dsrc = NULL;
- cache->error = 0;
+ cache->error = ALL_OK;
+ cache->type = TYPE_NOIDEA;
}
else
{
@@ -225,6 +226,7 @@ GlyCacheList * DL_new_lst(void)
if(c != NULL)
{
c->size = 0;
+ c->usersig = GLYRE_OK;
c->list = calloc(1,sizeof(GlyMemCache*));
if(!c->list)
{
@@ -297,6 +299,13 @@ void DL_free_container(GlyCacheList * c)
/*--------------------------------------------------------*/
+// Check header - This currently not used
+size_t internal_header_function( void *ptr, size_t size, size_t nmemb, void *userdata)
+{
+ glyr_message(-1,NULL,stderr,"Header:\n%s\n",(char*)ptr);
+ return size * nmemb;
+}
+
// Init an easyhandler with all relevant options
static void DL_setopt(CURL *eh, GlyMemCache * cache, const char * url, GlyQuery * s, void * magic_private_ptr, long timeout)
{
@@ -321,6 +330,10 @@ static void DL_setopt(CURL *eh, GlyMemCache * cache, const char * url, GlyQuery
curl_easy_setopt(eh, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(eh, CURLOPT_MAXREDIRS, s->redirects);
+ // Do not download 404 pages
+ curl_easy_setopt(eh, CURLOPT_FAILONERROR, 1L);
+ // curl_easy_setopt(eh, CURLOPT_HEADERFUNCTION, internal_header_function);
+
// Discogs equires gzip compression
curl_easy_setopt(eh, CURLOPT_ENCODING,"gzip");
@@ -394,6 +407,9 @@ bool continue_search(int iter, GlyQuery * s)
int flag_double_urls(GlyCacheList * result, GlyQuery * s)
{
+ if(s->duplcheck == false)
+ return 0;
+
size_t i = 0, dp = 0;
for(i = 0; i < result->size; i++)
{
@@ -426,6 +442,9 @@ int flag_double_urls(GlyCacheList * result, GlyQuery * s)
int flag_blacklisted_urls(GlyCacheList * result, const char ** URLblacklist, GlyQuery * s)
{
+ if(s->duplcheck == false)
+ return 0;
+
size_t i = 0, ctr = 0;
for(i = 0; i < result->size; i++)
{
@@ -485,9 +504,9 @@ GlyMemCache * download_single(const char* url, GlyQuery * s, const char * end)
res = curl_easy_perform(curl);
// Better check again
- if(res != CURLE_OK)
+ if(res != CURLE_OK && res != CURLE_WRITE_ERROR)
{
- glyr_message(-1,NULL,stderr,C_"\n:: %s\n", curl_easy_strerror(res));
+ glyr_message(-1,NULL,stderr,C_"\n:: %s [E:%d]\n", curl_easy_strerror(res),res);
DL_free(dldata);
dldata = NULL;
}
@@ -566,16 +585,20 @@ GlyCacheList * invoke(cb_object *oblist, long CNT, long parallel, long timeout,
for (Counter = 0; Counter < CNT; Counter++)
{
char * track = oblist[Counter].url;
- oblist[Counter].url = prepare_url(oblist[Counter].url,oblist[Counter].s->artist,oblist[Counter].s->album,oblist[Counter].s->title);
+ oblist[Counter].url = prepare_url(oblist[Counter].url,oblist[Counter].s->artist,oblist[Counter].s->album,oblist[Counter].s->title);
oblist[Counter].cache = handle_init(cm,&oblist[Counter],s,timeout);
- if(track) free(track);
-
- if(oblist[Counter].cache == NULL)
+ if(track)
+ {
+ free(track);
+ track = NULL;
+ }
+ if(oblist[Counter].cache == NULL || oblist[Counter].url == NULL)
{
glyr_message(-1,NULL,stderr,"[Internal Error:] Empty callback or empty url!\n");
glyr_message(-1,NULL,stderr,"[Internal Error:] Call your local C-h4x0r!\n");
return NULL;
}
+
}
// counter of plugins tried
@@ -648,7 +671,7 @@ GlyCacheList * invoke(cb_object *oblist, long CNT, long parallel, long timeout,
glyr_message(2,s,stderr,"Query: %s",capo->plug->color);
}
- if(capo && capo->cache && capo->cache->data && msg->data.result == CURLE_OK)
+ if(capo && capo->cache && capo->cache->data && (msg->data.result == CURLE_OK || msg->data.result == CURLE_WRITE_ERROR))
{
// Here is where the actual callback shall be executed
if(capo->parser_callback)
@@ -673,19 +696,23 @@ GlyCacheList * invoke(cb_object *oblist, long CNT, long parallel, long timeout,
result_lst = DL_new_lst();
}
- // push all pointers from sublist to resultlist
- DL_push_sublist(result_lst,cl);
-
- // free the old container
- DL_free_container(cl);
glyr_message(3,s,stderr,"Tried sources: %d (of max. %d) | Buffers in line: %d\n",n_sources,s->number,result_lst->size);
// Are we finally done?
- if(n_sources >= CNT || (!capo->batch ? s->number <= s->itemctr : s->number <= result_lst->size))
+ if((capo->batch && cl->usersig == GLYRE_STOP_BY_CB) ||n_sources >= CNT || (!capo->batch ? s->number <= s->itemctr : s->number <= result_lst->size))
{
do_exit = true;
}
+
+ if((capo->batch && cl->usersig == GLYRE_OK) || !capo->batch)
+ {
+ // push all pointers from sublist to resultlist
+ DL_push_sublist(result_lst,cl);
+ }
+
+ // free the old container
+ DL_free_container(cl);
}
else if(!capo->batch)
{
@@ -725,6 +752,11 @@ GlyCacheList * invoke(cb_object *oblist, long CNT, long parallel, long timeout,
const char * curl_err = curl_easy_strerror(msg->data.result);
glyr_message(1,s,stderr,"%s - [%d]\n",curl_err ? curl_err : "Unknown Error",msg->data.result);
}
+ else
+ {
+ ALIGN(align_msg);
+ glyr_message(2,s,stderr,C_R"failed.\n"C_);
+ }
curl_multi_remove_handle(cm,e);
if(capo->url)
@@ -754,25 +786,25 @@ GlyCacheList * invoke(cb_object *oblist, long CNT, long parallel, long timeout,
// erase "downloading [.] message"
if(oblist[0].batch) glyr_message(2,s,stderr,"%-25c\n",1);
-
- // Job done - clean up what we did to the memory..
- size_t I = 0;
- for(; I < Counter; I++)
+ int I = 0;
+ for(I = 0; I < Counter; I++)
{
DL_free(oblist[I].cache);
+ oblist[I].cache = NULL;
- // Free handle
if(oblist[I].handle != NULL)
+ {
curl_easy_cleanup(oblist[I].handle);
-
+ oblist[I].handle = NULL;
+ }
// Free the prepared URL
if(oblist[I].url != NULL)
+ {
free(oblist[I].url);
-
- // erase everything
+ oblist[I].url = NULL;
+ }
memset(&oblist[I],0,sizeof(cb_object));
}
-
curl_multi_cleanup(cm);
return result_lst;
}
@@ -788,6 +820,7 @@ void plugin_init(cb_object *ref, const char *url, GlyCacheList * (callback)(cb_o
ref->batch = batch;
ref->endmark = endmark;
ref->s = s;
+ ref->handle = NULL;
}
/*--------------------------------------------------------*/
@@ -805,11 +838,9 @@ GlyCacheList * register_and_execute(GlyQuery * query, GlyCacheList * (*finalizer
// A container storing all URLs that specified plugins need to work
// (They are downlaoded by invoke() and made available to the plugin via a cb_oject called 'capo')
- cb_object *URLContainer = NULL;
-
+ cb_object *URLContainer = NULL;
GlyCacheList * resultList = NULL;
-
// Now jsut register all Plugins that are there
// This is for simplicity reasons, and does not take
// away any ressources...
@@ -839,18 +870,16 @@ GlyCacheList * register_and_execute(GlyQuery * query, GlyCacheList * (*finalizer
if(pList[iter].plug.free_url)
{
free(pUrl);
+ pUrl = NULL;
}
// Make sure we don't use $iter as URLContainer iterator (creepy consequences if URLCallbacks returns NULL)
plugCtr++;
}
}
-
if(plugCtr != 0)
{
// Internal Order in whic we visit groups
int GIDArray[] = {GRP_SAFE, GRP_FAST, GRP_USFE, GRP_SPCL, GRP_SLOW, -666 /* Negative evil */};
- char * nList[] = {GRPN_SAFE, GRPN_FAST,GRPN_USFE, GRPN_SPCL, GRPN_SLOW, (char*)-666 };
-
// Mark a plugin if visited if it's in multiple groups
bool * visitList = calloc(plugCtr,sizeof(char));
if(visitList == NULL)
@@ -881,7 +910,7 @@ GlyCacheList * register_and_execute(GlyQuery * query, GlyCacheList * (*finalizer
if(invCtr > 0)
{
- const char * group_name = (query->groupedDL) ? nList[iter] : "all";
+ const char * group_name = (query->groupedDL) ? grp_id_to_name(GIDArray[iter]) : "all";
glyr_message(2,query,stderr,"Invoking group "C_Y"%s"C_":\n",group_name);
// Get the items from invoke()
@@ -901,17 +930,33 @@ GlyCacheList * register_and_execute(GlyQuery * query, GlyCacheList * (*finalizer
DL_push_sublist(resultList,subList);
DL_free_container(subList);
}
+ DL_free_lst(dlData);
}
}
free(invokeList);
invokeList = NULL;
}
+ // Free URLs that have been allocated, but not used
+ int I = 0;
+ for(I = 0; I < plugCtr; I++)
+ {
+ if(visitList[I]==false && URLContainer[I].url)
+ {
+ free(URLContainer[I].url);
+ URLContainer[I].url = NULL;
+ }
+ }
free(visitList);
visitList = NULL;
+
}
- else glyr_message(2,query,stderr,"Sorry. No Plugin were registered, so nothing was downloaded... :(\n");
+ else glyr_message(2,query,stderr,"Sorry. No Plugin were registered, so nothing was downloaded... :(\n");
+
+ // allow plugins to cleanup
+ finalizer(NULL,query);
+ // Free the Container.
if(URLContainer != NULL) free(URLContainer);
return resultList;
}
@@ -926,3 +971,21 @@ GlyPlugin * copy_table(const GlyPlugin * o, size_t size)
}
/*--------------------------------------------------------*/
+
+const char * grp_id_to_name(int id)
+{
+ switch(id)
+ {
+ case GRP_SAFE: return GRPN_SAFE;
+ case GRP_USFE: return GRPN_USFE;
+ case GRP_FAST: return GRPN_FAST;
+ case GRP_SLOW: return GRPN_SLOW;
+ case GRP_SPCL: return GRPN_SPCL;
+ case GRP_NONE: return GRPN_NONE;
+ case GRP_ALL: return GRPN_ALL;
+ default: return NULL;
+ }
+ return NULL;
+}
+
+/*--------------------------------------------------------*/
View
3  lib/core.h
@@ -102,4 +102,7 @@ int glyr_message(int v, GlyQuery * s, FILE * stream, const char * fmt, ...);
int flag_double_urls(GlyCacheList * result, GlyQuery * s);
int flag_blacklisted_urls(GlyCacheList * result, const char ** URLblacklist, GlyQuery * s);
+// ....
+const char * grp_id_to_name(int id);
+
#endif
View
23 lib/cover.c
@@ -48,10 +48,10 @@ GlyPlugin cover_providers[] =
{"amazon", "a", C_Y"amazon", false, {cover_amazon_parse, cover_amazon_url, NULL, false}, GRP_SAFE | GRP_FAST},
{"lyricswiki", "w", C_C"lyricswiki", false, {cover_lyricswiki_parse, cover_lyricswiki_url, NULL, false}, GRP_SAFE | GRP_FAST},
{"google", "g", GOOGLE_COLOR, false, {cover_google_parse, cover_google_url, NULL, true }, GRP_USFE | GRP_FAST},
- {"albumart", "b", C_R"albumart", false, {cover_albumart_parse, cover_albumart_url, NULL, false}, GRP_USFE | GRP_FAST},
+ {"albumart", "b", C_R"albumart", false, {cover_albumart_parse, cover_albumart_url, "<div id=\"pagination\"", false}, GRP_USFE | GRP_FAST},
{"discogs", "d", C_"disc"C_Y"o"C_"gs", false, {cover_discogs_parse, cover_discogs_url, NULL, false}, GRP_USFE | GRP_SLOW},
{"allmusic", "m", C_"all"C_C"music", false, {cover_allmusic_parse, cover_allmusic_url, NULL, false}, GRP_SPCL | GRP_SLOW},
- {"coverhunt", "c", C_G"coverhunt", false, {cover_coverhunt_parse, cover_coverhunt_url, NULL, false}, GRP_SPCL | GRP_FAST},
+ {"coverhunt", "c", C_G"coverhunt", false, {cover_coverhunt_parse, cover_coverhunt_url, "<div id=\"footer\">", false}, GRP_SPCL | GRP_FAST},
// {"allcdcovers","o", ALLCDCOVERSC, false, {cover_allcdcovers_parse, cover_allcdcovers_url,NULL, false}, GRP_USFE | GRP_SLOW},
{ NULL, NULL, NULL, false, {NULL, NULL, NULL, false}, GRP_NONE | GRP_NONE},
};
@@ -78,13 +78,18 @@ static GlyCacheList * cover_callback(cb_object * capo)
// the downloaded cache, and add the source url
GlyCacheList * ls = DL_new_lst();
GlyMemCache * dl = DL_copy(capo->cache);
+
if(dl)
{
dl->dsrc = strdup(capo->url);
+ if(dl->type == TYPE_NOIDEA)
+ dl->type = TYPE_COVER;
// call user defined callback
if(capo->s->callback.download)
- capo->s->callback.download(dl,capo->s);
+ {
+ ls->usersig = capo->s->callback.download(dl,capo->s);
+ }
DL_add_to_list(ls,dl);
}
@@ -99,6 +104,13 @@ const char * URLblacklist[] =
static GlyCacheList * cover_finalize(GlyCacheList * result, GlyQuery * settings)
{
+ // Only NULL when finalizing()
+ if(result == NULL)
+ {
+ glyr_message(2,settings,stderr,C_R"* "C_"Got in total %d images!\n",settings->itemctr);
+ return NULL;
+ }
+
GlyCacheList * dl_list = NULL;
if(result)
{
@@ -125,7 +137,10 @@ static GlyCacheList * cover_finalize(GlyCacheList * result, GlyQuery * settings)
}
dl_list = invoke(urlplug_list,ctr,settings->parallel,settings->timeout * ctr, settings);
- glyr_message(2,settings,stderr,C_G"* "C_"Succesfully downloaded %d image.\n",dl_list->size);
+ if(dl_list != NULL)
+ {
+ glyr_message(2,settings,stderr,C_G"* "C_"Succesfully downloaded %d image.\n",dl_list->size);
+ }
free(urlplug_list);
}
}
View
1  lib/cover/allcdcovers.c
@@ -47,6 +47,7 @@ static GlyMemCache * get_cover_page(const char * url, GlyQuery * s)
{
GlyMemCache * rt = NULL;
GlyMemCache * dl = download_single(url,s,NULL);
+
if(dl != NULL)
{
char * dl_link = strstr(dl->data,DOWNLOAD_BEGIN);
View
19 lib/cover/allmusic_com.c
@@ -59,11 +59,19 @@ GlyMemCache * parse_cover_page(GlyMemCache * dl)
if(img_begin != NULL)
{
char * img_url = copy_value(img_begin + strlen(IMG_BEGIN), strstr(img_begin,IMG_ENDIN));
- if(img_url != NULL && strcmp(img_url,"/img/pages/site/icons/no_cover_200.gif"))
+ if(img_url != NULL)
{
- rc = DL_init();
- rc->data = img_url;
- rc->size = strlen(img_url);
+ if(strcmp(img_url,"/img/pages/site/icons/no_cover_200.gif"))
+ {
+ rc = DL_init();
+ rc->data = img_url;
+ rc->size = strlen(img_url);
+ }
+ else
+ {
+ free(img_url);
+ img_url=NULL;
+ }
}
}
}
@@ -80,6 +88,7 @@ GlyCacheList * cover_allmusic_parse(cb_object * capo)
DL_add_to_list(r_list, result);
return r_list;
}
+
char * search_begin = NULL;
if( (search_begin = strstr(capo->cache->data, SEARCH_TREE_BEGIN)) == NULL)
{
@@ -107,7 +116,7 @@ GlyCacheList * cover_allmusic_parse(cb_object * capo)
ascii_strdown_modify(orig_artist,-1);
if(levenshtein_strcmp(orig_artist,artist) <= LV_MAX)
{
- GlyMemCache * dl = download_single(url,capo->s,NULL);
+ GlyMemCache * dl = download_single(url,capo->s,"<div class=\"artist\">");
if(dl != NULL)
{
GlyMemCache * result = parse_cover_page(dl);
View
2  lib/cover/coverhunt.c
@@ -90,7 +90,7 @@ GlyCacheList * cover_coverhunt_parse(cb_object *capo)
char * real_url = strdup_printf("http://www.coverhunt.com/go/%s",go_url);
if(real_url)
{
- GlyMemCache * search_buf = download_single(real_url,capo->s,NULL);
+ GlyMemCache * search_buf = download_single(real_url,capo->s,"<div id=\"right\">");
if(search_buf)
{
char * artwork = strstr(search_buf->data, "<div class=\"artwork\">");
View
3  lib/cover/discogs.c
@@ -97,7 +97,8 @@ GlyCacheList * cover_discogs_parse(cb_object * capo)
char *release_url = strdup_printf("http://www.discogs.com/release/%s?f=xml&api_key="API_KEY,release_ID);
if(release_url)
{
- GlyMemCache * tmp_cache = download_single(release_url,capo->s,NULL);
+ // Only download till artists tag.
+ GlyMemCache * tmp_cache = download_single(release_url,capo->s,"<artists>");
if(tmp_cache && tmp_cache->data && tmp_cache->size)
{
// Parsing the image url from here on
View
47 lib/glyr.c
@@ -48,18 +48,18 @@ static void glyr_register_group(GlyPlugin * providers, enum GLYR_GROUPS GIDmask,
// The rest is done for you quite automagically.
GlyPlugin getwd_commands [] =
{
- {"cover" , "c", (char*)GET_COVER, false},
- {"lyrics", "l", (char*)GET_LYRIC, false},
- {"photos", "p", (char*)GET_PHOTO, false},
- {"ainfo", "a", (char*)GET_AINFO, false},
- {"similiar","s", (char*)GET_SIMILIAR, false},
- {"review", "r", (char*)GET_REVIEW, false},
+ {"cover" , "c", (char*)GET_COVER, false, {NULL, NULL, NULL, false}, GRP_NONE},
+ {"lyrics", "l", (char*)GET_LYRIC, false, {NULL, NULL, NULL, false}, GRP_NONE},
+ {"photos", "p", (char*)GET_PHOTO, false, {NULL, NULL, NULL, false}, GRP_NONE},
+ {"ainfo", "a", (char*)GET_AINFO, false, {NULL, NULL, NULL, false}, GRP_NONE},
+ {"similiar","s", (char*)GET_SIMILIAR, false, {NULL, NULL, NULL, false}, GRP_NONE},
+ {"review", "r", (char*)GET_REVIEW, false, {NULL, NULL, NULL, false}, GRP_NONE},
#ifdef USE_BOOKS
/* Books was developed for private use */
/* You can enable it by defining USE_BOOKS */
- {"books", "b", (char*)GET_BOOKS, false},
+ {"books", "b", (char*)GET_BOOKS, false, {NULL, NULL, NULL, false}, GRP_NONE},
#endif
- {NULL, NULL, NULL, 42}
+ {NULL, NULL, NULL, 42, {NULL, NULL, NULL, false}, GRP_NONE}
};
/*-----------------------------------------------*/
@@ -74,7 +74,7 @@ const char * Gly_version(void)
/*-----------------------------------------------*/
// Seperate method because va_arg struggles with function pointers
-int GlyOpt_dlcallback(GlyQuery * settings, void (*dl_cb)(GlyMemCache *, GlyQuery *), void * userp)
+int GlyOpt_dlcallback(GlyQuery * settings, int (*dl_cb)(GlyMemCache *, GlyQuery *), void * userp)
{
if(settings)
{
@@ -259,6 +259,15 @@ int GlyOpt_plugmax(GlyQuery * s, int plugmax)
/*-----------------------------------------------*/
+int GlyOpt_duplcheck(GlyQuery * s, bool duplcheck)
+{
+ if(s == NULL) return GLYRE_EMPTY_STRUCT;
+ s->duplcheck = duplcheck;
+ return GLYRE_OK;
+}
+
+/*-----------------------------------------------*/
+
int GlyOpt_groupedDL(GlyQuery * s, bool groupedDL)
{
if(s == NULL) return GLYRE_EMPTY_STRUCT;
@@ -287,6 +296,13 @@ GlyMemCache * Gly_clist_at(GlyCacheList * clist, int iter)
}
/*-----------------------------------------------*/
+
+const char * Gly_groupname_by_id(int ID)
+{
+ return grp_id_to_name(ID);
+}
+
+/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/
@@ -312,6 +328,7 @@ static void set_query_on_defaults(GlyQuery * glyrs)
glyrs->callback.download = NULL;
glyrs->callback.user_pointer = NULL;
glyrs->itemctr = 0;
+ glyrs->duplcheck = DEFAULT_DUPLCHECK;
memset(glyrs->info,0,sizeof(const char * ) * PTR_SPACE);
}
@@ -605,27 +622,27 @@ static int glyr_parse_from(const char * arg, GlyQuery * settings)
c_arg++;
}
- if(!strcasecmp(c_arg,GRPN_ALL))
+ if(!strcasecmp(c_arg, grp_id_to_name(GRP_ALL)))
{
glyr_register_group(what_pair,GRP_ALL,value);
}
- else if(!strcasecmp(c_arg,GRPN_SAFE))
+ else if(!strcasecmp(c_arg, grp_id_to_name(GRP_SAFE)))
{
glyr_register_group(what_pair, GRP_SAFE,value);
}
- else if(!strcasecmp(c_arg,GRPN_USFE))
+ else if(!strcasecmp(c_arg, grp_id_to_name(GRP_USFE)))
{
glyr_register_group(what_pair, GRP_USFE,value);
}
- else if(!strcasecmp(c_arg,GRPN_SPCL))
+ else if(!strcasecmp(c_arg, grp_id_to_name(GRP_SPCL)))
{
glyr_register_group(what_pair, GRP_SPCL,value);
}
- else if(!strcasecmp(c_arg,GRPN_FAST))
+ else if(!strcasecmp(c_arg, grp_id_to_name(GRP_FAST)))
{
glyr_register_group(what_pair,GRP_FAST,value);
}
- else if(!strcasecmp(c_arg,GRPN_SLOW))
+ else if(!strcasecmp(c_arg, grp_id_to_name(GRP_SLOW)))
{
glyr_register_group(what_pair,GRP_SLOW,value);
}
View
15 lib/glyr.h
@@ -26,22 +26,12 @@
// all structs used by glyr are here
#include "types.h"
-enum GLYR_ERROR
-{
- GLYRE_OK, // everything is fine
- GLYRE_BAD_OPTION, // you passed a bad option to Gly_setopt()
- GLYRE_BAD_VALUE, // Invalid value in va_list
- GLYRE_EMPTY_STRUCT, // you passed an empty struct to Gly_setopt()
- GLYRE_NO_PROVIDER, // setttings->provider == NULL
- GLYRE_UNKNOWN_GET // settings->type is not valid
-};
#ifdef __cplusplus
extern "C"
{
#endif
typedef void (*callback_t) (void *user_data, const char *other_data);
- void anvoke(callback_t callback, void *user_data, const char *other_data);
// the actual main of glyr
GlyCacheList * Gly_get(GlyQuery * settings, int * error);
@@ -60,7 +50,7 @@ extern "C"
GlyMemCache * Gly_new_cache(void);
/* Gly_opt_* methods */
- int GlyOpt_dlcallback(GlyQuery * settings, void (*dl_cb)(GlyMemCache *, GlyQuery *), void * userp);
+ int GlyOpt_dlcallback(GlyQuery * settings, int (*dl_cb)(GlyMemCache *, GlyQuery *), void * userp);
int GlyOpt_type(GlyQuery * s, int type);
int GlyOpt_artist(GlyQuery * s, char * artist);
int GlyOpt_album(GlyQuery * s, char * album);
@@ -95,6 +85,9 @@ extern "C"
// write binary file, this is for use in language bindings mainly, which partly can't easily write them themself
int Gly_write_binary_file(const char * path, GlyMemCache * data, const char * save_dir, const char * type, GlyQuery *s);
+ // Returns the actual name of the group pointed by ID
+ const char * Gly_groupname_by_id(int ID);
+
#ifdef _cplusplus
}
#endif
View
20 lib/lyrics.c
@@ -37,19 +37,24 @@
#include "lyrics/lyrdb.h"
#include "lyrics/metrolyrics.h"
+#define LATE "<div id='d_navigation'"
+#define DIRE "<!-- google_ad_section_start(weight=ignore) -->"
+#define VIPE "</td></tr></table>"
+#define DARE "<div class=\"note\">"
+
// Add your's here
GlyPlugin lyric_providers[] =
{
// full name key coloredname use? parser callback geturl callback free url?
{"lyricswiki", "w", "lyricswiki", false, {lyrics_lyricswiki_parse, lyrics_lyricswiki_url, NULL, false}, GRP_SAFE | GRP_FAST},
{"lyr.db", "d", "lyr.db", false, {lyrics_lyrdb_parse, lyrics_lyrdb_url, NULL, false}, GRP_SAFE | GRP_FAST},
- {"lyrix.at", "a", "lyrix.at", false, {lyrics_lyrixat_parse, lyrics_lyrixat_url, NULL, false}, GRP_SAFE | GRP_FAST},
- {"magistrix", "x", "magistrix", false, {lyrics_magistrix_parse, lyrics_magistrix_url, NULL, false}, GRP_SAFE | GRP_FAST},
- {"directlyrics","i", "directlyrics",false, {lyrics_directlyrics_parse,lyrics_directlyrics_url,NULL, true }, GRP_SAFE | GRP_FAST},
- {"lyricsvip", "v", "lyricsvip", false, {lyrics_lyricsvip_parse, lyrics_lyricsvip_url, NULL, true }, GRP_SAFE | GRP_FAST},
- {"songlyrics", "s", "songlyrics", false, {lyrics_songlyrics_parse, lyrics_songlyrics_url, NULL, true }, GRP_SAFE | GRP_FAST},
- {"darklyrics", "y", "darklyrics", false, {lyrics_darklyrics_parse, lyrics_darklyrics_url, NULL, false}, GRP_SAFE | GRP_FAST},
- {"metrolyrics", "m", "metrolyrics", false, {lyrics_metrolyrics_parse, lyrics_metrolyrics_url, NULL, false}, GRP_SAFE | GRP_FAST},
+ {"lyrix.at", "a", "lyrix.at", false, {lyrics_lyrixat_parse, lyrics_lyrixat_url, LATE, false}, GRP_SAFE | GRP_SLOW},
+ {"magistrix", "x", "magistrix", false, {lyrics_magistrix_parse, lyrics_magistrix_url, NULL, false}, GRP_USFE | GRP_FAST},
+ {"directlyrics","i", "directlyrics",false, {lyrics_directlyrics_parse,lyrics_directlyrics_url,DIRE, true }, GRP_SAFE | GRP_FAST},
+ {"lyricsvip", "v", "lyricsvip", false, {lyrics_lyricsvip_parse, lyrics_lyricsvip_url, VIPE, true }, GRP_USFE | GRP_FAST},
+ {"songlyrics", "s", "songlyrics", false, {lyrics_songlyrics_parse, lyrics_songlyrics_url, NULL, true }, GRP_SPCL | GRP_SLOW},
+ {"darklyrics", "y", "darklyrics", false, {lyrics_darklyrics_parse, lyrics_darklyrics_url, DARE, false}, GRP_SAFE | GRP_FAST},
+ {"metrolyrics", "m", "metrolyrics", false, {lyrics_metrolyrics_parse, lyrics_metrolyrics_url, NULL, false}, GRP_SPCL | GRP_SLOW},
{ NULL, NULL, NULL, false, {NULL, NULL, NULL, false}, GRP_NONE | GRP_NONE}
};
@@ -71,6 +76,7 @@ static GlyCacheList * lyrics_finalize(GlyCacheList * result, GlyQuery * settings
dl->data = beautify_lyrics(result->list[i]->data);
dl->size = strlen(dl->data);
dl->dsrc = strdup(result->list[i]->dsrc);
+ dl->type = TYPE_LYRICS;
// call user defined callback
if(settings->callback.download)
View
2  lib/lyrics/lyricswiki.c
@@ -119,7 +119,7 @@ GlyCacheList * lyrics_lyricswiki_parse(cb_object * capo)
}
endTag=NULL;
}
- result = DL_error(NO_ENDIN_TAG);
+ else result = DL_error(NO_ENDIN_TAG);
find=NULL;
}
else result = DL_error(NO_BEGIN_TAG);
View
21 lib/lyrics/lyrix_at.c
@@ -44,12 +44,11 @@ const char * lyrics_lyrixat_url(GlyQuery * settings)
GlyCacheList * lyrics_lyrixat_parse(cb_object * capo)
{
/* lyrix.at does not offer any webservice -> use the searchfield to get some results */
- GlyMemCache * result = NULL;
GlyCacheList * r_list = NULL;
-
char * search_begin_tag = capo->cache->data;
- int ctr = 0;
- while( (search_begin_tag = strstr(search_begin_tag+1,SEARCH_START_TAG)) && !result && MAX_TRIES >= ctr++ && continue_search(ctr,capo->s))
+ int ctr = 0, urlc = 0;
+
+ while( (search_begin_tag = strstr(search_begin_tag+1,SEARCH_START_TAG)) && MAX_TRIES >= ctr++ && continue_search(urlc,capo->s))
{
char * url_tag = search_begin_tag;
size_t toggle = 1,i;
@@ -65,7 +64,6 @@ GlyCacheList * lyrics_lyrixat_parse(cb_object * capo)
char * title_end = strstr(title_tag,"<");
if(title_end)
{
-
char * title = copy_value(title_tag + strlen(URL_TAG_ENDIN),title_end);
if(title)
{
@@ -77,7 +75,7 @@ GlyCacheList * lyrics_lyrixat_parse(cb_object * capo)
char * url = strdup_printf("http://lyrix.at/de%s",url_part);
if(url)
{
- GlyMemCache * lyrcache = download_single(url,capo->s,NULL);
+ GlyMemCache * lyrcache = download_single(url,capo->s,"<!-- eBay Relevance Ad -->");
if(lyrcache)
{
char * lyr_begin = strstr(lyrcache->data,LYRIC_BEGIN);
@@ -89,10 +87,14 @@ GlyCacheList * lyrics_lyrixat_parse(cb_object * capo)
char * lyrics = copy_value(lyr_begin,lyr_endin);
if(lyrics)
{
- result = DL_init();
+ GlyMemCache * result = DL_init();
result->data = strreplace(lyrics,"<br />","");
result->size = strlen(lyrics);
result->dsrc = strdup(url);
+
+ if(!r_list) r_list = DL_new_lst();
+ DL_add_to_list(r_list,result);
+ urlc++;
}
free(lyrics);
}
@@ -112,10 +114,5 @@ GlyCacheList * lyrics_lyrixat_parse(cb_object * capo)
}
}
}
- if(result)
- {
- r_list = DL_new_lst();
- DL_add_to_list(r_list,result);
- }
return r_list;
}
View
29 lib/lyrics/magistrix.c
@@ -34,7 +34,7 @@ const char * lyrics_magistrix_url(GlyQuery * settings)
return MG_URL;
}
-GlyMemCache * parse_lyric_page(const char * buffer)
+static GlyMemCache * parse_lyric_page(const char * buffer)
{
GlyMemCache * result = NULL;
if(buffer)
@@ -81,29 +81,30 @@ static bool approve_content(char * content, const char * compare)
#define TITLE_BEGIN "\" class=\"lyricIcon bgMove\">"
#define URL_BEGIN "<a href=\""
#define SEARCH_END "</a>"
-#define MAX_TRIES 5
+#define MAX_TRIES 7
GlyCacheList * lyrics_magistrix_parse (cb_object * capo)
{
- GlyMemCache * result=NULL;
GlyCacheList * r_list=NULL;
-
if( strstr(capo->cache->data,"<div class='empty_collection'>") == NULL) // No songtext page?
{
if( strstr(capo->cache->data,"<title>Songtext-Suche</title>") == NULL) // Are we not on the search result page?
{
- result = parse_lyric_page(capo->cache->data);
+ GlyMemCache * result = parse_lyric_page(capo->cache->data);
if(result)
{
result->dsrc = strdup(capo->url);
+ if(!r_list) r_list = DL_new_lst();
+ DL_add_to_list(r_list,result);
}
}
else
{
char * node = capo->cache->data;
- int ctr = 0;
- while( (node = strstr(node+1,"<tr class='topLine'>")) && !result && MAX_TRIES >= ctr++ && continue_search(ctr,capo->s))
+ int ctr = 0, urlc = 0;
+ while( (node = strstr(node+1,"<tr class='topLine'>")) && MAX_TRIES >= ctr && continue_search(urlc,capo->s))
{
+ ctr++;
char * artist = copy_value(strstr(node,ARTIST_BEGIN)+strlen(ARTIST_BEGIN),strstr(node,"</a>"));
if(artist)
{
@@ -129,16 +130,21 @@ GlyCacheList * lyrics_magistrix_parse (cb_object * capo)
char * dl_url = strdup_printf("www.magistrix.de%s",url);
if(dl_url)
{
- GlyMemCache * dl_cache = download_single(dl_url,capo->s,NULL);
+ // We don't need the ugly comments
+ GlyMemCache * dl_cache = download_single(dl_url,capo->s,"<div class='comments'");
if(dl_cache)
{
- result = parse_lyric_page(dl_cache->data);
+ GlyMemCache * result = parse_lyric_page(dl_cache->data);
if(result)
{
+ urlc++;
result->dsrc = strdup(dl_url);
+ if(!r_list) r_list = DL_new_lst();
+ DL_add_to_list(r_list,result);
}
DL_free(dl_cache);
}
+ free(dl_url);
}
free(url);
}
@@ -154,10 +160,5 @@ GlyCacheList * lyrics_magistrix_parse (cb_object * capo)
}
}
}
- if(result)
- {
- r_list = DL_new_lst();
- DL_add_to_list(r_list,result);
- }
return r_list;
}
View
11 lib/lyrics/metrolyrics.c
@@ -95,9 +95,7 @@ static bool approve_content(char * content, const char * compare)
GlyCacheList * lyrics_metrolyrics_parse(cb_object * capo)
{
- GlyMemCache * result = NULL;
GlyCacheList * r_list = NULL;
-
char * root = strstr(capo->cache->data,ROOT_NODE);
if(root)
{
@@ -125,10 +123,12 @@ GlyCacheList * lyrics_metrolyrics_parse(cb_object * capo)
GlyMemCache * dl_cache = download_single(dl_url,capo->s,NULL);
if(dl_cache)
{
- result = parse_lyrics_page(dl_cache->data);
+ GlyMemCache * result = parse_lyrics_page(dl_cache->data);
if(result)
{
result->dsrc = strdup(dl_url);
+ if(!r_list) r_list = DL_new_lst();
+ DL_add_to_list(r_list,result);
}
DL_free(dl_cache);
}
@@ -150,10 +150,5 @@ GlyCacheList * lyrics_metrolyrics_parse(cb_object * capo)
if(node > dist) break;
}
}
- if(result)
- {
- r_list = DL_new_lst();
- DL_add_to_list(r_list,result);
- }
return r_list;
}
View
1  lib/lyrics/songlyrics.c
@@ -61,6 +61,7 @@ GlyCacheList * lyrics_songlyrics_parse(cb_object * capo)
GlyMemCache * result = NULL;
GlyCacheList * r_list = NULL;
char * find_tag, * find_end;
+
if( (find_tag = strstr(capo->cache->data,"<p id=\"songLyricsDiv\"")) != NULL)
{
if( (find_tag = strstr(find_tag,"&#")) != NULL)
View
13 lib/photos.c
@@ -43,18 +43,20 @@ GlyPlugin * glyr_get_photo_providers(void)
return copy_table(photos_providers,sizeof(photos_providers));
}
-static GlyCacheList * cover_callback(cb_object * capo)
+static GlyCacheList * photo_callback(cb_object * capo)
{
GlyCacheList * ls = DL_new_lst();
GlyMemCache * dl = DL_copy(capo->cache);
if(dl)
{
dl->dsrc = strdup(capo->url);
+ dl->type = TYPE_PHOTOS;
// call user defined callback
if(capo->s->callback.download)
- capo->s->callback.download(dl,capo->s);
-
+ {
+ ls->usersig = capo->s->callback.download(dl,capo->s);
+ }
DL_add_to_list(ls,dl);
}
return ls;
@@ -62,6 +64,8 @@ static GlyCacheList * cover_callback(cb_object * capo)
static GlyCacheList * photo_finalize(GlyCacheList * result, GlyQuery * settings)
{
+ if(!result) return NULL;
+
GlyCacheList * dl_list = NULL;
if(result)
{
@@ -78,13 +82,14 @@ static GlyCacheList * photo_finalize(GlyCacheList * result, GlyQuery * settings)
{
if(result->list[i] && result->list[i]->data && result->list[i]->error == ALL_OK)
{
- plugin_init(&urlplug_list[ctr], result->list[i]->data, cover_callback, settings, NULL, NULL, true);
+ plugin_init(&urlplug_list[ctr], result->list[i]->data, photo_callback, settings, NULL, NULL, true);
ctr++;
}
if(result->list[i]->data)
{
free(result->list[i]->data);
+ result->list[i]->data = NULL;
}
}
dl_list = invoke(urlplug_list,i,settings->parallel,settings->timeout * i, settings);
View
6 lib/review.c
@@ -33,7 +33,7 @@
GlyPlugin review_providers[] =
{
// full name key coloredname use? parser callback geturl callback free url?
- {"allmusic", "m", C_"all"C_C"music", false, {review_allmusic_parse, review_allmusic_url, NULL, false}, GRP_SAFE | GRP_FAST},
+ {"allmusic", "m", C_"all"C_C"music", false, {review_allmusic_parse, review_allmusic_url, "<div id=\"right-sidebar\">", false}, GRP_SAFE | GRP_FAST},
{ NULL, NULL, NULL, false, {NULL, NULL, NULL, false}, GRP_NONE | GRP_NONE},
};
@@ -53,8 +53,10 @@ static GlyCacheList * review_finalize(GlyCacheList * result, GlyQuery * settings
{
// call user defined callback
if(settings->callback.download)
+ {
settings->callback.download(result->list[i],settings);
-
+ }
+ result->list[i]->type = TYPE_REVIEW;
DL_add_to_list(r_list,DL_copy(result->list[i]));
}
return r_list;
View
3  lib/review/allmusic_com.c
@@ -90,6 +90,7 @@ GlyCacheList * review_allmusic_parse(cb_object * capo)
DL_add_to_list(r_list, result);
return r_list;
}
+
char * search_begin = NULL;
if( (search_begin = strstr(capo->cache->data, SEARCH_TREE_BEGIN)) == NULL)
{
@@ -120,7 +121,7 @@ GlyCacheList * review_allmusic_parse(cb_object * capo)
char * review_url = strdup_printf("%s/review",url);
if(review_url)
{
- GlyMemCache * dl = download_single(review_url,capo->s,NULL);
+ GlyMemCache * dl = download_single(review_url,capo->s,"<div id=\"tracks\">");
if(dl != NULL)
{
GlyMemCache * result = parse_text(dl);
View
1  lib/similiar.c
@@ -55,6 +55,7 @@ static GlyCacheList * similiar_finalize(GlyCacheList * result, GlyQuery * settin
if(settings->callback.download)
settings->callback.download(result->list[i],settings);
+ result->list[i]->type = TYPE_SIMILIAR;
DL_add_to_list(r_list,DL_copy(result->list[i]));
}
return r_list;
View
17 lib/stringop.c
@@ -867,13 +867,16 @@ char * copy_value(const char * begin, const char * end)
if(begin && end)
{
size_t length = end - begin;
- char * buffer = malloc(length+1);
- if(buffer)
- {
- strncpy(buffer,begin,length);
- buffer[length] = '\0';
- }
- return buffer;
+ if(length >= 0)
+ {
+ char * buffer = malloc(length+1);
+ if(buffer)
+ {
+ strncpy(buffer,begin,length);
+ buffer[length] = '\0';
+ }
+ return buffer;
+ }
}
return NULL;
}
View
34 lib/types.h
@@ -62,11 +62,12 @@
#define DEFAULT_CMAXSIZE -1
#define DEFAULT_VERBOSITY 2
#define DEFAULT_NUMBER 1
-#define DEFAULT_PLUGMAX 10
+#define DEFAULT_PLUGMAX -1
#define DEFAULT_LANG "en"
#define DEFAULT_DOWNLOAD true
#define DEFAULT_GROUPEDL true
#define DEFAULT_FROM_ARGUMENT_DELIM ";"
+#define DEFAULT_DUPLCHECK true
#define PTR_SPACE 10
@@ -91,6 +92,17 @@ enum GLYR_GROUPS
GRP_ALL = 1 << 5 /* All! */
};
+enum GLYR_ERROR
+{
+ GLYRE_OK, // everything is fine
+ GLYRE_BAD_OPTION, // you passed a bad option to Gly_setopt()
+ GLYRE_BAD_VALUE, // Invalid value in va_list
+ GLYRE_EMPTY_STRUCT, // you passed an empty struct to Gly_setopt()
+ GLYRE_NO_PROVIDER, // setttings->provider == NULL
+ GLYRE_UNKNOWN_GET, // settings->type is not valid
+ GLYRE_STOP_BY_CB // Callback returned stop signal.
+};
+
/* Group names */
#define GRPN_NONE "none"
#define GRPN_SAFE "safe"
@@ -115,6 +127,7 @@ typedef struct GlyMemCache
size_t size; // Size of data
char *dsrc; // Source of data
int error; // error code - internal use only
+ int type; // type of metadata
} GlyMemCache;
// list of GlyMemCaches
@@ -122,6 +135,7 @@ typedef struct GlyCacheList
{
GlyMemCache ** list;
size_t size;
+ int usersig;
} GlyCacheList;
typedef struct GlyQuery
@@ -168,6 +182,9 @@ typedef struct GlyQuery
// or all in parallel? (faster, but less accurate)
bool groupedDL;
+ // Check for bad data?
+ bool duplcheck;
+
// language settings (for amazon / google / last.fm)
char * lang;
@@ -176,7 +193,7 @@ typedef struct GlyQuery
struct callback
{
- void (* download)(GlyMemCache * dl, struct GlyQuery * s);
+ int (* download)(GlyMemCache * dl, struct GlyQuery * s);
void * user_pointer;
} callback;
@@ -215,8 +232,19 @@ enum GLYR_GET_TYPES
GET_AINFO,
GET_SIMILIAR,
GET_REVIEW,
- GET_BOOKS,
+ GET_BOOKS, // This should be removed
GET_UNSURE
};
+enum GLYR_DATA_TYPE
+{
+ TYPE_NOIDEA,
+ TYPE_LYRICS,
+ TYPE_REVIEW,
+ TYPE_PHOTOS,
+ TYPE_COVER,
+ TYPE_AINFO,
+ TYPE_SIMILIAR
+};
+
#endif
View
474 src/main.c
@@ -44,12 +44,13 @@ const char * default_path = ".";
// --------------------------------------------------------- //
/* --------------------------------------------------------- */
-static void print_version(void)
+static void print_version(GlyQuery * s)
{
- glyr_message(-1,NULL,stdout, C_G"%s\n\n"C_,Gly_version());
- glyr_message(-1,NULL,stderr, C_"This is still beta software, expect quite a lot bugs.\n");
- glyr_message(-1,NULL,stderr, C_"Email bugs to <sahib@online.de> or use the bugtracker\n"
- C_"at https://github.com/sahib/glyr/issues - Thank you! \n");
+ glyr_message(-1,s,stdout, C_G"%s\n\n"C_,Gly_version());
+ glyr_message(-1,s,stderr, C_"This is still beta software, expect quite a lot bugs.\n");
+ glyr_message(-1,s,stderr, C_"Email bugs to <sahib@online.de> or use the bugtracker\n"
+ C_"at https://github.com/sahib/glyr/issues - Thank you! \n");
+
exit(0);
}
@@ -57,216 +58,189 @@ static void print_version(void)
// --------------------------------------------------------- //
/* --------------------------------------------------------- */
-const char * next_group(GlyPlugin * table, int s)
-{
- int i;
- for(i = s; table[i].name; i++)
- {
- if(!table[i].key)
- return table[i].name;
- }
- return NULL;
-}
-
#define _S "\t"
-static void list_provider_at_id(int id, int min_align)
+static void list_provider_at_id(int id, int min_align,GlyQuery * s)
{
GlyPlugin * cp = Gly_get_provider_by_id(id);
- const char * c_group = next_group(cp,0);
if(cp != NULL)
{
- size_t i = 0;
- size_t max_align = min_align;
-
- for(i = 0; cp[i].name; i++)
- {
- if(cp[i].key)
- {
- // align text. Help texts are sooo boring :-)
- size_t x = 0;
- size_t name_len = strlen(cp[i].name);
- if(name_len >= max_align)
- {
- max_align = name_len + 1;
- }
-
- size_t align = max_align - name_len;
-
- glyr_message(-1,NULL,stdout,_S"- "C_G"%s"C_,cp[i].name);
- for(x = 0; x < align; x++)
- {
- glyr_message(-1,NULL,stdout," ");
- }
- glyr_message(-1,NULL,stdout,"["C_R"%s"C_"]"C_,cp[i].key);
-
- if(id != -1)
- {
- glyr_message(-1,NULL,stdout," in group "C_Y"all"C_","C_Y"%s"C_,c_group);
- }
- glyr_message(-1,NULL,stdout,"\n");
- }
- else
- {
- c_group = next_group(cp,i+1);
- }
- }
- free(cp);
+ int i = 0;
+ for(i = 0; cp[i].name != NULL; i++)
+ {
+ int align = min_align - strlen(cp[i].name);
+ int a = 0;
+ glyr_message(-1,s,stdout,C_G _S"%s"C_,cp[i].name);
+ for(a = 0; a < align; a++)
+ glyr_message(-1,s,stdout," ");
+
+ glyr_message(-1,s,stdout,C_" ["C_R"%s"C_"]%s",cp[i].key, (id == -1) ? "" : " in groups "C_Y"all"C_);
+ int b = 1, j = 0;
+ for(b = 1, j = 0; b <= GRP_ALL; j++)
+ {
+ if(b & cp[i].gid)
+ {
+ glyr_message(-1,s,stdout,C_","C_Y"%s",Gly_groupname_by_id(b));
+ }
+ b <<= 1;
+ }
+ glyr_message(-1,s,stdout,"\n");
+ }
+ free(cp);
}
}
-static void usage(void)
+static void usage(GlyQuery * s)
{
- glyr_message(-1,NULL,stdout,C_B"USAGE:\n"C_ _S"glyrc "C_Y"GETTER"C_" [OPTIONS...]\n\n");
- glyr_message(-1,NULL,stdout,"glyrc downloads variouse sorts of musicrelated metadata.\n");
- glyr_message(-1,NULL,stdout,C_Y"GETTER"C_" is the type of metadata to download, it must be one of: \n");
-
- list_provider_at_id(-1, 10);
+ glyr_message(-1,s,stdout,C_B"USAGE:\n"C_ _S"glyrc "C_Y"GETTER"C_" [OPTIONS...]\n\n");
+ glyr_message(-1,s,stdout,"glyrc downloads variouse sorts of musicrelated metadata.\n");
+ glyr_message(-1,s,stdout,C_Y"GETTER"C_" is the type of metadata to download, it must be one of: \n");
+ list_provider_at_id(-1, 10,s);
#define GET_C C_G
#define OPT_C C_C
#define OPT_A OPT_C"\n "
- glyr_message(-1,NULL,stdout,"\nThe getter has to be always the very first argument given, and may require other arguments\n");
- glyr_message(-1,NULL,stdout,"A short note to the terminology: a provider is a source glyrc may download data from.\n");
- glyr_message(-1,NULL,stdout,"A group is a collection of providers, each getter has at least the groups all,safe and unsafe,\n");
- glyr_message(-1,NULL,stdout,"Please note that providers and groups may differ heavily from getter to getter!\n");
- glyr_message(-1,NULL,stdout,"you can modify glyrc's providerlist by passing the names (or their shortcuts) to --from.\n");
- glyr_message(-1,NULL,stdout,"To find out what getter needs what argument see below: ("OPT_C"-n"C_" is the max number of items)\n");
- glyr_message(-1,NULL,stdout,C_B"\nCOVER\n"C_);
- glyr_message(-1,NULL,stdout,_S"Download "OPT_C"-n"C_" albumart images of the artist and album specified with "OPT_C"-a and -b\n"C_);
- glyr_message(-1,NULL,stdout,_S"The filetype of the image is unspecified (as libglyr often could only vaguely guess)\n");
- glyr_message(-1,NULL,stdout,_S"and may be determinded by its header; glyrc saves it as '.img in all cases.'\n");
- glyr_message(-1,NULL,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
- list_provider_at_id(GET_COVER,12);
- glyr_message(-1,NULL,stdout,C_B"LYRICS\n"C_);
- glyr_message(-1,NULL,stdout,_S"Download "OPT_C"-n"C_" lyrics of the artist and title specified with "OPT_C"-a"C_" and "OPT_C"-t\n"C_);
- glyr_message(-1,NULL,stdout,_S"The album ("OPT_C"-b"C_") is optional and may be used by some plugins.\n");
- glyr_message(-1,NULL,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
- list_provider_at_id(GET_LYRIC,13);
- glyr_message(-1,NULL,stdout,C_B"PHOTOS\n"C_);
- glyr_message(-1,NULL,stdout,_S"Download "OPT_C"-n"C_" photos that are related to the artist given by "OPT_C"-a"C_".\n");
- glyr_message(-1,NULL,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
- list_provider_at_id(GET_PHOTO,12);
- glyr_message(-1,NULL,stdout,C_B"AINFO\n"C_);
- glyr_message(-1,NULL,stdout,_S"Download "OPT_C"-n"C_" artist descriptions of the artist given by "OPT_C"-a"C_".\n");
- glyr_message(-1,NULL,stdout,_S"Apart from the name, a similiarity rating from 0.0 to 1.0, a URL to last.fm page\n");
- glyr_message(-1,NULL,stdout,_S"and a bunch of URLs to images of the similiar artist in ascending size.\n");
- glyr_message(-1,NULL,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
- list_provider_at_id(GET_AINFO,12);
- glyr_message(-1,NULL,stdout,C_B"\nSIMILIAR\n"C_);
- glyr_message(-1,NULL,stdout,_S"Download "OPT_C"-n"C_" information about similiar artist to the one given with -a "OPT_C"-a"C_".\n");
- glyr_message(-1,NULL,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
- list_provider_at_id(GET_SIMILIAR,12);
- glyr_message(-1,NULL,stdout,C_B"\nGENERAL OPTIONS\n"C_);
- glyr_message(-1,NULL,stdout,OPT_A"-f --from <prov>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Set the sources (providers) you want to query.\n");
- glyr_message(-1,NULL,stdout,_S"The string you have to provide cotains the names of the providers or a group\n");
- glyr_message(-1,NULL,stdout,_S"(or their shortcuts), seperated by a \"%s\" and prepended by a + or -,\n", DEFAULT_FROM_ARGUMENT_DELIM);
- glyr_message(-1,NULL,stdout,_S"which adds or deletes this source to/from the current state.\n");
- glyr_message(-1,NULL,stdout,_S"An example would be: \"+all%s-special%s+d\"\n",DEFAULT_FROM_ARGUMENT_DELIM,DEFAULT_FROM_ARGUMENT_DELIM );
- glyr_message(-1,NULL,stdout,_S _S "+all : adds everything.\n");
- glyr_message(-1,NULL,stdout,_S _S "-special : subtract the members of group 'special'.\n");
- glyr_message(-1,NULL,stdout,_S _S "+d : add the provider 'd' (discogs, see above)\n");
- glyr_message(-1,NULL,stdout,OPT_A"-n --number <int>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Maximum number of items a getter may download.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %d.\n", DEFAULT_NUMBER);
- glyr_message(-1,NULL,stdout,OPT_A"-x --plugmax <int>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Maximum number of items a plugin may download.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %d.\n", DEFAULT_PLUGMAX);
- glyr_message(-1,NULL,stdout,OPT_A"-u --update\n"C_);
- glyr_message(-1,NULL,stdout,_S"Update file even if already present.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %s.\n",update ? "true" : "false");
- glyr_message(-1,NULL,stdout,OPT_A"-d --nodownload\n"C_);
- glyr_message(-1,NULL,stdout,_S"Do not download final result, only print URL.\n");
- glyr_message(-1,NULL,stdout,_S"This only works for images, as lyrics and ainfo do not neccesarely have a concrete URL.\n");
- glyr_message(-1,NULL,stdout,_S"Use this to turn glyrc into some sort of music-metadate search engine.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %s.\n",DEFAULT_DOWNLOAD ? "true" : "false");
- glyr_message(-1,NULL,stdout,OPT_A"-w --write <dir>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Write all files to the directory <dir>\n");
- glyr_message(-1,NULL,stdout,_S"The filenames itself is determined by the artist,album, title depending on <GET>, see the also the FILES section.\n");
- glyr_message(-1,NULL,stdout,_S"The special value \"stdout\" will print the data directly to stdout, \"stderr\" to stderr\n"_S"and \"null\" will print nothing.\n");
- glyr_message(-1,NULL,stdout,_S"Default is '%s'\n",default_path);
- glyr_message(-1,NULL,stdout,C_B"\nLIBCURL OPTIONS\n"C_);
- glyr_message(-1,NULL,stdout,OPT_A"-p --parallel <int>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Download max. <int> files in parallel if there's more than one to download.\n");
- glyr_message(-1,NULL,stdout,_S"This is useful for downloading photos in line; Default is %d.\n", DEFAULT_PARALLEL);
- glyr_message(-1,NULL,stdout,OPT_A"-r --redirects <int>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Allow max. <int> redirects. This is only used for Amazon and you should never need to use it.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %d.\n", DEFAULT_REDIRECTS);
- glyr_message(-1,NULL,stdout,OPT_A"-m --timeout <int>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Maximum number of <int> seconds to wait before cancelling a download.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %d.\n", DEFAULT_TIMEOUT);
- glyr_message(-1,NULL,stdout,C_B"\nMISC OPTIONS\n"C_);
- glyr_message(-1,NULL,stdout,OPT_A"-V --version\n"C_);
- glyr_message(-1,NULL,stdout,_S"Print version string and exit.\n");
- glyr_message(-1,NULL,stdout,OPT_A"-h --help\n"C_);
- glyr_message(-1,NULL,stdout,_S"Print this help and exit.\n");
- glyr_message(-1,NULL,stdout,OPT_A"-c --color\n"C_);
- glyr_message(-1,NULL,stdout,_S"Enables colored console output (Unix only).\n");
- glyr_message(-1,NULL,stdout,_S"Default is %s.\n", PRT_COLOR ? "true" : "false");
- glyr_message(-1,NULL,stdout,OPT_A"-v --verbosity <int>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Level of verbosity:\n");
- glyr_message(-1,NULL,stdout,_S _S"-v0: Print nothing but fatal errors.\n");
- glyr_message(-1,NULL,stdout,_S _S"-v1: Print only basic information.\n");
- glyr_message(-1,NULL,stdout,_S _S"-v2: Print informative output. (default)\n");
- glyr_message(-1,NULL,stdout,_S _S"-v3: Enable debugging messages.\n");
- glyr_message(-1,NULL,stdout,_S _S"-v4: Enable libcurl-debugging messages.\n");
- glyr_message(-1,NULL,stdout,C_B"\nPLUGIN OPTIONS\n"C_);
- glyr_message(-1,NULL,stdout,OPT_A"-a --artist <string>; -b --album <string>; -t --title <string>\n"C_);
- glyr_message(-1,NULL,stdout,_S"Depending on the getter you have to provide information on what to search.\n");
- glyr_message(-1,NULL,stdout,_S"Please refer to the getter description to find what argument is needed for what getter.\n");
- glyr_message(-1,NULL,stdout,OPT_A"-i --minsize\n"C_);
- glyr_message(-1,NULL,stdout,_S"For cover only: The minimum size a coverimage may have\n");
- glyr_message(-1,NULL,stdout,_S"A value of -1 will disable the sizecheck.\n");
- glyr_message(-1,NULL,stdout,_S"Note that this value is only a 'suggestion' for libglyr,\n");
- glyr_message(-1,NULL,stdout,_S"but it should work in 95%% of all cases.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %d.\n",DEFAULT_CMINSIZE);
- glyr_message(-1,NULL,stdout,OPT_A"-e --maxsize\n"C_);
- glyr_message(-1,NULL,stdout,_S"For cover only: The maximum size a coverimage may have (see above)\n");
- glyr_message(-1,NULL,stdout,_S"A value of -1 will disable the sizecheck.\n");
- glyr_message(-1,NULL,stdout,_S"Default is %d.\n",DEFAULT_CMAXSIZE);
- glyr_message(-1,NULL,stdout,OPT_A"-l --lang <l>\n"C_);
- glyr_message(-1,NULL,stdout,_S"For cover:\n"_S _S"decides which amazon / google server is queried,\n"_S _S"what may have impact on search results.\n\n");
- glyr_message(-1,NULL,stdout,_S"For ainfo's last.fm plugin:\n"_S _S"Decide in which language results are returned.\n\n");
- glyr_message(-1,NULL,stdout,_S"The language is given by ISO 639-1 codes;\n");
- glyr_message(-1,NULL,stdout,_S"Examples are: us,ca,uk,fr,de,jp\n");
- glyr_message(-1,NULL,stdout,C_B"\nEXAMPLES\n"C_);
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc cover -a Equilibrium -b \"Turis Fratyr\"\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# Download the cover art of the album 'Turis Fratyr' by the band equilibrium,\n");
- glyr_message(-1,NULL,stdout,_S _S"# save it to Equilibrium_Turis+Fratyr_0.img\n");
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc cover -a Equilibrium -b Rekreatur -n 5 -i 100 -e 250 --from \"amazon\"\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# Download 5x (different) images of 'Rekreatur',\n");
- glyr_message(-1,NULL,stdout,_S _S"# with the dimensions in between 100x100 and 250x250 from amazon\n");
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc lyrics -a Equilibrium -t \"Blut im Auge\"\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# Download lyrics of the Song \"Blut im Auge\" by Equilibrium,\n");
- glyr_message(-1,NULL,stdout,_S _S"# show it in stdout, and write it to Equilibrium_Blut+im+Auge_0.lyrics\n");
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc ainfo -a \"Justin Bieber\"\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# This produces nothing interesting (but hopefully a Segfault).\n");
- glyr_message(-1,NULL,stdout,_S _S"# If not it will print all the things you always wanted to know about Justin Bieber.\n");
- glyr_message(-1,NULL,stdout,_S _S"# (In german Language)\n");
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc photos -a \"Die Apokalyptischen Reiter\" -v0 -n 5\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# Downloads 5 photos showing the band \"Die Apokalyptischen Reiter\"\n");
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc review -a \"Equilibrium\" -b \"Sagas\" -w stdout -v0\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# Dumps the review of Equilibrium Sagas to stdout\n");
- glyr_message(-1,NULL,stdout,_S C_Y"glyrc similiar -a \"Equilibrium\" -w stdout -v0 -n 5\n"C_);
- glyr_message(-1,NULL,stdout,_S _S"# Show the 5 most similiar artist to Equilibrium (according to last.fm...)\n");
- glyr_message(-1,NULL,stdout,_S _S"# Every set includes the name, matchrate (from 0.0 to 1.0),\n");
- glyr_message(-1,NULL,stdout,_S _S"# a link to the last.fm page, and a link to a pressphoto (different sizes)\n");
- glyr_message(-1,NULL,stdout,C_B"\nFILES\n"C_);
- glyr_message(-1,NULL,stdout,_S"Everything is stored in a file with the pattern $save_dir/$artist_($album|$title)_suffix.type\n");
- glyr_message(-1,NULL,stdout,_S"Spaces and Slashes in artist/album/title are escaped with a '+'. ($num is the itemcounter)\n");
- glyr_message(-1,NULL,stdout,_S _S"$dir/$artist_$album_cover_$num.jpg\n");
- glyr_message(-1,NULL,stdout,_S _S"$dir/$artist_$title_lyrics_$num.txt\n");
- glyr_message(-1,NULL,stdout,_S _S"$dir/$artist_photos_$num.jpg\n");
- glyr_message(-1,NULL,stdout,_S _S"$dir/$artist_ainfo_$num.txt\n");
- glyr_message(-1,NULL,stdout,_S _S"$dir/$artist_similiar_$num.txt\n");
- glyr_message(-1,NULL,stdout,_S _S"$dir/$artist_$album_review_$num.txt\n");
- glyr_message(-1,NULL,stdout,C_B"\nAUTHOR\n"C_);
- glyr_message(-1,NULL,stdout,_S"See the AUTHORS file that comes in glyr's distribution.\n");
- glyr_message(-1,NULL,stdout,_S"See also COPYING to know about your rights.\n");
- glyr_message(-1,NULL,stdout,_S"\n");
-
- print_version();
+ glyr_message(-1,s,stdout,"\nThe getter has to be always the very first argument given, and may require other arguments\n");
+ glyr_message(-1,s,stdout,"A short note to the terminology: a provider is a source glyrc may download data from.\n");
+ glyr_message(-1,s,stdout,"A group is a collection of providers, each getter has at least the groups all,safe and unsafe,\n");
+ glyr_message(-1,s,stdout,"Please note that providers and groups may differ heavily from getter to getter!\n");
+ glyr_message(-1,s,stdout,"you can modify glyrc's providerlist by passing the names (or their shortcuts) to --from.\n");
+ glyr_message(-1,s,stdout,"To find out what getter needs what argument see below: ("OPT_C"-n"C_" is the max number of items)\n");
+ glyr_message(-1,s,stdout,C_B"\nCOVER\n"C_);
+ glyr_message(-1,s,stdout,_S"Download "OPT_C"-n"C_" albumart images of the artist and album specified with "OPT_C"-a and -b\n"C_);
+ glyr_message(-1,s,stdout,_S"The filetype of the image is unspecified (as libglyr often could only vaguely guess)\n");
+ glyr_message(-1,s,stdout,_S"and may be determinded by its header; glyrc saves it as '.img in all cases.'\n");
+ glyr_message(-1,s,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
+ list_provider_at_id(GET_COVER,12,s);
+ glyr_message(-1,s,stdout,C_B"LYRICS\n"C_);
+ glyr_message(-1,s,stdout,_S"Download "OPT_C"-n"C_" lyrics of the artist and title specified with "OPT_C"-a"C_" and "OPT_C"-t\n"C_);
+ glyr_message(-1,s,stdout,_S"The album ("OPT_C"-b"C_") is optional and may be used by some plugins.\n");
+ glyr_message(-1,s,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
+ list_provider_at_id(GET_LYRIC,13,s);
+ glyr_message(-1,s,stdout,C_B"PHOTOS\n"C_);
+ glyr_message(-1,s,stdout,_S"Download "OPT_C"-n"C_" photos that are related to the artist given by "OPT_C"-a"C_".\n");
+ glyr_message(-1,s,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
+ list_provider_at_id(GET_PHOTO,12,s);
+ glyr_message(-1,s,stdout,C_B"AINFO\n"C_);
+ glyr_message(-1,s,stdout,_S"Download "OPT_C"-n"C_" artist descriptions of the artist given by "OPT_C"-a"C_".\n");
+ glyr_message(-1,s,stdout,_S"Apart from the name, a similiarity rating from 0.0 to 1.0, a URL to last.fm page\n");
+ glyr_message(-1,s,stdout,_S"and a bunch of URLs to images of the similiar artist in ascending size.\n");
+ glyr_message(-1,s,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
+ list_provider_at_id(GET_AINFO,12,s);
+ glyr_message(-1,s,stdout,C_B"\nSIMILIAR\n"C_);
+ glyr_message(-1,s,stdout,_S"Download "OPT_C"-n"C_" information about similiar artist to the one given with -a "OPT_C"-a"C_".\n");
+ glyr_message(-1,s,stdout,_S"Currently "OPT_C"--from"C_" takes the following strings here:\n\n");
+ list_provider_at_id(GET_SIMILIAR,12,s);
+ glyr_message(-1,s,stdout,C_B"\nGENERAL OPTIONS\n"C_);
+ glyr_message(-1,s,stdout,OPT_A"-f --from <prov>\n"C_);
+ glyr_message(-1,s,stdout,_S"Set the sources (providers) you want to query.\n");
+ glyr_message(-1,s,stdout,_S"The string you have to provide cotains the names of the providers or a group\n");
+ glyr_message(-1,s,stdout,_S"(or their shortcuts), seperated by a \"%s\" and prepended by a + or -,\n", DEFAULT_FROM_ARGUMENT_DELIM);
+ glyr_message(-1,s,stdout,_S"which adds or deletes this source to/from the current state.\n");
+ glyr_message(-1,s,stdout,_S"An example would be: \"+all%s-special%s+d\"\n",DEFAULT_FROM_ARGUMENT_DELIM,DEFAULT_FROM_ARGUMENT_DELIM );
+ glyr_message(-1,s,stdout,_S _S "+all : adds everything.\n");
+ glyr_message(-1,s,stdout,_S _S "-special : subtract the members of group 'special'.\n");
+ glyr_message(-1,s,stdout,_S _S "+d : add the provider 'd' (discogs, see above)\n");
+ glyr_message(-1,s,stdout,OPT_A"-n --number <int>\n"C_);
+ glyr_message(-1,s,stdout,_S"Maximum number of items a getter may download.\n");
+ glyr_message(-1,s,stdout,_S"Default is %d.\n", DEFAULT_NUMBER);
+ glyr_message(-1,s,stdout,OPT_A"-x --plugmax <int>\n"C_);
+ glyr_message(-1,s,stdout,_S"Maximum number of items a plugin may download.\n");
+ glyr_message(-1,s,stdout,_S"Default is %d.\n", DEFAULT_PLUGMAX);
+ glyr_message(-1,s,stdout,OPT_A"-u --update\n"C_);
+ glyr_message(-1,s,stdout,_S"Update file even if already present.\n");
+ glyr_message(-1,s,stdout,_S"Default is %s.\n",update ? "true" : "false");
+ glyr_message(-1,s,stdout,OPT_A"-d --nodownload\n"C_);
+ glyr_message(-1,s,stdout,_S"Do not download final result, only print URL.\n");
+ glyr_message(-1,s,stdout,_S"This only works for images, as lyrics and ainfo do not neccesarely have a concrete URL.\n");
+ glyr_message(-1,s,stdout,_S"Use this to turn glyrc into some sort of music-metadate search engine.\n");
+ glyr_message(-1,s,stdout,_S"Default is %s.\n",DEFAULT_DOWNLOAD ? "true" : "false");
+ glyr_message(-1,s,stdout,OPT_A"-w --write <dir>\n"C_);
+ glyr_message(-1,s,stdout,_S"Write all files to the directory <dir>\n");
+ glyr_message(-1,s,stdout,_S"The filenames itself is determined by the artist,album, title depending on <GET>, see the also the FILES section.\n");
+ glyr_message(-1,s,stdout,_S"The special value \"stdout\" will print the data directly to stdout, \"stderr\" to stderr\n"_S"and \"null\" will print nothing.\n");
+ glyr_message(-1,s,stdout,_S"Default is '%s'\n",default_path);
+ glyr_message(-1,s,stdout,C_B"\nLIBCURL OPTIONS\n"C_);
+ glyr_message(-1,s,stdout,OPT_A"-p --parallel <int>\n"C_);
+ glyr_message(-1,s,stdout,_S"Download max. <int> files in parallel if there's more than one to download.\n");
+ glyr_message(-1,s,stdout,_S"This is useful for downloading photos in line; Default is %d.\n", DEFAULT_PARALLEL);
+ glyr_message(-1,s,stdout,OPT_A"-r --redirects <int>\n"C_);
+ glyr_message(-1,s,stdout,_S"Allow max. <int> redirects. This is only used for Amazon and you should never need to use it.\n");
+ glyr_message(-1,s,stdout,_S"Default is %d.\n", DEFAULT_REDIRECTS);
+ glyr_message(-1,s,stdout,OPT_A"-m --timeout <int>\n"C_);
+ glyr_message(-1,s,stdout,_S"Maximum number of <int> seconds to wait before cancelling a download.\n");
+ glyr_message(-1,s,stdout,_S"Default is %d.\n", DEFAULT_TIMEOUT);
+ glyr_message(-1,s,stdout,C_B"\nMISC OPTIONS\n"C_);
+ glyr_message(-1,s,stdout,OPT_A"-V --version\n"C_);
+ glyr_message(-1,s,stdout,_S"Print version string and exit.\n");
+ glyr_message(-1,s,stdout,OPT_A"-h --help\n"C_);
+ glyr_message(-1,s,stdout,_S"Print this help and exit.\n");
+ glyr_message(-1,s,stdout,OPT_A"-c --color\n"C_);
+ glyr_message(-1,s,stdout,_S"Enables colored console output (Unix only).\n");
+ glyr_message(-1,s,stdout,_S"Default is %s.\n", PRT_COLOR ? "true" : "false");
+ glyr_message(-1,s,stdout,OPT_A"-v --verbosity <int>\n"C_);
+ glyr_message(-1,s,stdout,_S"Level of verbosity:\n");
+ glyr_message(-1,s,stdout,_S _S"-v0: Print nothing but fatal errors.\n");
+ glyr_message(-1,s,stdout,_S _S"-v1: Print only basic information.\n");
+ glyr_message(-1,s,stdout,_S _S"-v2: Print informative output. (default)\n");
+ glyr_message(-1,s,stdout,_S _S"-v3: Enable debugging messages.\n");
+ glyr_message(-1,s,stdout,_S _S"-v4: Enable libcurl-debugging messages.\n");
+ glyr_message(-1,s,stdout,C_B"\nPLUGIN OPTIONS\n"C_);
+ glyr_message(-1,s,stdout,OPT_A"-a --artist <string>; -b --album <string>; -t --title <string>\n"C_);
+ glyr_message(-1,s,stdout,_S"Depending on the getter you have to provide information on what to search.\n");
+ glyr_message(-1,s,stdout,_S"Please refer to the getter description to find what argument is needed for what getter.\n");
+ glyr_message(-1,s,stdout,OPT_A"-i --minsize\n"C_);
+ glyr_message(-1,s,stdout,_S"For cover only: The minimum size a coverimage may have\n");
+ glyr_message(-1,s,stdout,_S"A value of -1 will disable the sizecheck.\n");
+ glyr_message(-1,s,stdout,_S"Note that this value is only a 'suggestion' for libglyr,\n");
+ glyr_message(-1,s,stdout,_S"but it should work in 95%% of all cases.\n");
+ glyr_message(-1,s,stdout,_S"Default is %d.\n",DEFAULT_CMINSIZE);
+ glyr_message(-1,s,stdout,OPT_A"-e --maxsize\n"C_);
+ glyr_message(-1,s,stdout,_S"For cover only: The maximum size a coverimage may have (see above)\n");
+ glyr_message(-1,s,stdout,_S"A value of -1 will disable the sizecheck.\n");
+ glyr_message(-1,s,stdout,_S"Default is %d.\n",DEFAULT_CMAXSIZE);
+ glyr_message(-1,s,stdout,OPT_A"-l --lang <l>\n"C_);
+ glyr_message(-1,s,stdout,_S"For cover:\n"_S _S"decides which amazon / google server is queried,\n"_S _S"what may have impact on search results.\n\n");
+ glyr_message(-1,s,stdout,_S"For ainfo's last.fm plugin:\n"_S _S"Decide in which language results are returned.\n\n");
+ glyr_message(-1,s,stdout,_S"The language is given by ISO 639-1 codes;\n");
+ glyr_message(-1,s,stdout,_S"Examples are: us,ca,uk,fr,de,jp\n");
+ glyr_message(-1,s,stdout,C_B"\nEXAMPLES\n"C_);
+ glyr_message(-1,s,stdout,_S C_Y"glyrc cover -a Equilibrium -b \"Turis Fratyr\"\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# Download the cover art of the album 'Turis Fratyr' by the band equilibrium,\n");
+ glyr_message(-1,s,stdout,_S _S"# save it to Equilibrium_Turis+Fratyr_0.img\n");
+ glyr_message(-1,s,stdout,_S C_Y"glyrc cover -a Equilibrium -b Rekreatur -n 5 -i 100 -e 250 --from \"amazon\"\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# Download 5x (different) images of 'Rekreatur',\n");
+ glyr_message(-1,s,stdout,_S _S"# with the dimensions in between 100x100 and 250x250 from amazon\n");
+ glyr_message(-1,s,stdout,_S C_Y"glyrc lyrics -a Equilibrium -t \"Blut im Auge\"\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# Download lyrics of the Song \"Blut im Auge\" by Equilibrium,\n");
+ glyr_message(-1,s,stdout,_S _S"# show it in stdout, and write it to Equilibrium_Blut+im+Auge_0.lyrics\n");
+ glyr_message(-1,s,stdout,_S C_Y"glyrc ainfo -a \"Justin Bieber\"\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# This produces nothing interesting (but hopefully a Segfault).\n");
+ glyr_message(-1,s,stdout,_S _S"# If not it will print all the things you always wanted to know about Justin Bieber.\n");
+ glyr_message(-1,s,stdout,_S _S"# (In german Language)\n");
+ glyr_message(-1,s,stdout,_S C_Y"glyrc photos -a \"Die Apokalyptischen Reiter\" -v0 -n 5\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# Downloads 5 photos showing the band \"Die Apokalyptischen Reiter\"\n");
+ glyr_message(-1,s,stdout,_S C_Y"glyrc review -a \"Equilibrium\" -b \"Sagas\" -w stdout -v0\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# Dumps the review of Equilibrium Sagas to stdout\n");
+ glyr_message(-1,s,stdout,_S C_Y"glyrc similiar -a \"Equilibrium\" -w stdout -v0 -n 5\n"C_);
+ glyr_message(-1,s,stdout,_S _S"# Show the 5 most similiar artist to Equilibrium (according to last.fm...)\n");
+ glyr_message(-1,s,stdout,_S _S"# Every set includes the name, matchrate (from 0.0 to 1.0),\n");
+ glyr_message(-1,s,stdout,_S _S"# a link to the last.fm page, and a link to a pressphoto (different sizes)\n");
+ glyr_message(-1,s,stdout,C_B"\nFILES\n"C_);
+ glyr_message(-1,s,stdout,_S"Everything is stored in a file with the pattern $save_dir/$artist_($album|$title)_suffix.type\n");
+ glyr_message(-1,s,stdout,_S"Spaces and Slashes in artist/album/title are escaped with a '+'. ($num is the itemcounter)\n");
+ glyr_message(-1,s,stdout,_S _S"$dir/$artist_$album_cover_$num.jpg\n");
+ glyr_message(-1,s,stdout,_S _S"$dir/$artist_$title_lyrics_$num.txt\n");
+ glyr_message(-1,s,stdout,_S _S"$dir/$artist_photos_$num.jpg\n");
+ glyr_message(-1,s,stdout,_S _S"$dir/$artist_ainfo_$num.txt\n");
+ glyr_message(-1,s,stdout,_S _S"$dir/$artist_similiar_$num.txt\n");
+ glyr_message(-1,s,stdout,_S _S"$dir/$artist_$album_review_$num.txt\n");
+ glyr_message(-1,s,stdout,C_B"\nAUTHOR\n"C_);
+ glyr_message(-1,s,stdout,_S"See the AUTHORS file that comes in glyr's distribution.\n");
+ glyr_message(-1,s,stdout,_S"See also COPYING to know about your rights.\n");
+ glyr_message(-1,s,stdout,_S"\n");
+
+ print_version(s);
exit(0);
}
#undef S
@@ -305,7 +279,7 @@ static bool set_get_type(GlyQuery * s, const char * arg)
glyr_message(2,s,stderr,"Avaliable getters are: \n");
glyr_message(2,s,stderr,"---------------------- \n");
- list_provider_at_id(-1,7);
+ list_provider_at_id(-1,7,s);
bool dym = false;
for(i = 0; plist[i].name; i++)
@@ -360,7 +334,7 @@ static void search_similiar_providers(const char * providers, GlyQuery * s)
{
if(dym)
{
- glyr_message(2,s,stderr,"Did you mean");
+ glyr_message(2,s,stderr,C_R"* "C_"Did you mean");
}
glyr_message(2,s,stderr,"%s "C_G"%s"C_" ",dym?"":" or",plist[j].name);
@@ -375,7 +349,7 @@ static void search_similiar_providers(const char * providers, GlyQuery * s)
}
glyr_message(2,s,stderr,"Must be one of:\n");
- list_provider_at_id(s->type,15);
+ list_provider_at_id(s->type,15,s);
glyr_message(2,s,stderr,"\n");
free(plist);
@@ -446,37 +420,40 @@ static bool check_if_dir(const char * path)
}
-void help_short(void)
+void help_short(GlyQuery * s)
{
- glyr_message(-1,NULL,stderr,"Usage: "
- "glyrc [GETTER] (options)\n[GETTER] must be one of:\n");
+ glyr_message(-1,s,stderr,"Usage: "
+ "glyrc [GETTER] (options)\n\n[GETTER] must be one of:\n");
- list_provider_at_id(-1,10);
+ list_provider_at_id(-1,10,s);
+ glyr_message(-1,s,stderr,"\nIf you're viewing this helptext the first time,\n"
+ "you probably want to view --usage, which has more details & examples\n");
+
#define IN "\t"
- glyr_message(-1,NULL,stderr,"\n\nOPTIONS:\n"
- IN"-f|--from\n"
- IN"-w|--write\n"
- IN"-p|--parallel\n"
- IN"-r|--redirects\n"
- IN"-m|--timeout\n"
- IN"-x|--plugmax\n"
- IN"-v|--verbosity\n"
- IN"-u|--update\n"
- IN"-U|--skip-update\n"
- IN"-h|--help\n"
- IN"-H|--usage\n"
- IN"-V|--version\n"
- IN"-c|--color\n"
- IN"-C|--skip-color\n"
- IN"-d|--download\n"
- IN"-D|--skip-download\n"
- IN"-g|--groups\n"
- IN"-G|--skip-groups\n"
- IN"-a|--artist\n"
- IN"-b|--album\n"
- IN"-t|--title\n"
- "\nRefer to --usage for more detailed explanation.\n"
+ glyr_message(-1,s,stderr,"\n\nOPTIONS:\n"
+ IN"-f --from <s> Providers from where to get metadata. Refer to the list in --usage.\n"
+ IN"-w --write <d> Write metadata to <d>, special values stdout, stderr and null are supported\n"
+ IN"-p --parallel <i> Integer. Define the number of downloads that may be performed in parallel.\n"
+ IN"-r --redirects Integer. Define the number of redirects that are allowed.\n"
+ IN"-m --timeout Integer. Define the maximum number in seconds after which a download is cancelled.\n"
+ IN"-x --plugmax Integer. Maximum number od download a plugin may deliever. Use to make results more vary.\n"
+ IN"-v --verbosity Integer. Set verbosity from 0 to 4. See --usage for details.\n"
+ IN"-u --update Also download metadata if files are already in path (given by -w or '.')\n"
+ IN"-U --skip-update Do not download data if already present.\n"
+ IN"-h --help This text you unlucky wanderer are viewing.\n"
+ IN"-H --usage A more detailed version of this text.\n"
+ IN"-V --version Print the version string.\n"
+ IN"-c --color Enable colored output (Unix only)\n"
+ IN"-C --skip-color Disable colored output. (Unix only)\n"
+ IN"-d --download Download Images.\n"
+ IN"-D --skip-download Don't download images, but return the URLs to them (act like a search engine)\n"
+ IN"-g --groups Enable grouped download (Slower but more accurate, as quality > speed)\n"
+ IN"-G --skip-groups Query all providers at once. (Faster but may deliever weird results)\n"
+ IN"-a --artist Artist name (Used by all plugins)\n"
+ IN"-b --album Album name (Used by cover,review,lyrics)\n"
+ IN"-t --title Songname (used mainly by lyrics)\n"
+ "\n"
);
exit(EXIT_FAILURE);
@@ -500,7 +477,7 @@ static char ** parse_commandline_general(int argc, char * const * argv, GlyQuery
{"update", no_argument, 0, 'u'},
{"skip-update", no_argument, 0, 'U'},
{"help", no_argument, 0, 'h'},
- {"usage", no_argument, 0, 'H'},
+ {"usage", no_argument, 0, 'H'},
{"version", no_argument, 0, 'V'},
{"color", no_argument, 0, 'c'},
{"skip-color", no_argument, 0, 'C'},
@@ -522,7 +499,7 @@ static char ** parse_commandline_general(int argc, char * const * argv, GlyQuery
while (true)
{
int option_index = 0;
- c = getopt_long(argc, argv, "uUVhcCdDgGf:w:p:r:m:x:v:a:b:t:i:e:n:l:",long_options, &option_index);
+ c = getopt_long(argc, argv, "uUVhHcCdDgGf:w:p:r:m:x:v:a:b:t:i:e:n:l:",long_options, &option_index);
// own error report
opterr = 0;
@@ -619,15 +596,15 @@ static char ** parse_commandline_general(int argc, char * const * argv, GlyQuery
break;
case 'V':
- print_version();
+ print_version(glyrs);
break;
case 'h':
- help_short();
+ help_short(glyrs);
break;
case 'H':
- usage();
+ usage(glyrs);
break;
case 'c':
GlyOpt_color(glyrs,true);
@@ -858,13 +835,16 @@ char * get_path_by_type(GlyQuery * s, const char * sd, int iter)
// --------------------------------------------------------- //
/* --------------------------------------------------------- */
-static void cb(GlyMemCache * c, GlyQuery * s)
+static int cb(GlyMemCache * c, GlyQuery * s)
{
// This is just to demonstrate the callback option.
// Put anything in here that you want to be executed when
// a cache is 'ready' (i.e. ready for return)
// See the glyr_set_dl_callback for more info
// a custom pointer is in s->user_pointer
+
+ // return GLYRE_STOP_BY_CB;
+ return GLYRE_OK;
}
int main(int argc, char * argv[])
@@ -980,9 +960,25 @@ int main(int argc, char * argv[])
}
else if(argc >= 2 && !strcmp(argv[1],"-V"))
{
- print_version();
+ print_version(NULL);
+ }
+ else if(argc >= 2 && (!strcmp(argv[1],"-C") || !strcmp(argv[1],"-CH")))
+ {
+ GlyQuery tmp;
+ tmp.color_output = false;
+ usage(&tmp);
+ }
+ else if(argc >= 2 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-ch")))
+ {
+ help_short(NULL);
+ }
+ else if(argc >= 2 && (!strcmp(argv[1],"-C") || !strcmp(argv[1],"-Ch")))
+ {
+ GlyQuery tmp;
+ tmp.color_output = false;
+ help_short(&tmp);
}
- else usage();
+ else usage(NULL);
// byebye
return result;
Please sign in to comment.
Something went wrong with that request. Please try again.