diff --git a/CHANGELOG b/CHANGELOG index a1c21e1..a319493 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -79,3 +79,7 @@ Found some time to work a bit here :-) For normal users: Well, the duplicate check is now as fast as rmlint :-P + getopt_long is now getopt_long_only (no --arguments, just -argument or -a) + removed call_direct. It's of no use. Not even for devs. + +2011/05/16 +---------- ++ removed wikipedia.c for ainfo - never worked. Better provide a link and (relation getter) and let the user render the site (too many information would get lost if glyr would need to parse it) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0562422..0e3cfdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,6 @@ SET(LIB_SOURCE_LOCATIONS "${DIR_ROOT}/md5.c" # extensions "${DIR_AINFO}/lastfm.c" - "${DIR_AINFO}/wikipedia.c" "${DIR_AINFO}/allmusic_com.c" "${DIR_AINFO}/lyricsreg.c" "${DIR_SIMILIAR}/lastfm.c" diff --git a/TODO b/TODO index 44367cc..5c547a7 100644 --- a/TODO +++ b/TODO @@ -1,16 +1,10 @@ -------- future - Take a random musicplayer project and devel a glyr-plugin (hi there gmpc..) -- cmake install -- done - cmake portable.. - docu ------- plans -- paths for tag/relations in glyrc -- default settings for getters (like number=-1 for track/albumlist) -- ainfo/wikipedia.c still not working - ------- urgent - test lyrics (klingeltöne... *chrm*) - rewrite of GUI in C and gtk3 (Modi get your ass here!) -- full amazon support +- full amazon support *sigh* - this API just sucks and is applied Brain-BDSM - update swig diff --git a/lib/ainfo.c b/lib/ainfo.c index 6a6d188..c205c10 100644 --- a/lib/ainfo.c +++ b/lib/ainfo.c @@ -28,7 +28,6 @@ #include "ainfo/lastfm.h" #include "ainfo/allmusic_com.h" -#include "ainfo/wikipedia.h" // currently disabled #include "ainfo/lyricsreg.h" #define WKED "
    " @@ -38,9 +37,8 @@ // Add your's here GlyPlugin ainfo_providers[] = { -// full name key coloredname use? parser callback geturl callback free url? + // full name key coloredname use? parser callback geturl callback free url? {"lastfm", "l", "last"C_R"."C_"fm", false, {ainfo_lastfm_parse, ainfo_lastfm_url, NULL, true }, GRP_SAFE | GRP_FAST}, -// {"wikipedia", "w", "wikipedia", false, {ainfo_wikipedia_parse, ainfo_wikipedia_url, WKED, false}, GRP_SAFE | GRP_FAST}, // not working yet. {"allmusic", "m", C_"all"C_C"music", false, {ainfo_allmusic_parse, ainfo_allmusic_url, NULL, false}, GRP_USFE | GRP_SLOW}, {"lyricsreg", "r", C_"lyricsreg", false, {ainfo_lyricsreg_parse, ainfo_lyricsreg_url, LGED, false}, GRP_USFE | GRP_FAST}, { NULL, NULL,NULL, false, {NULL, NULL, NULL, false}, GRP_NONE | GRP_NONE}, diff --git a/lib/ainfo/wikipedia.c b/lib/ainfo/wikipedia.c deleted file mode 100644 index c0a97fa..0000000 --- a/lib/ainfo/wikipedia.c +++ /dev/null @@ -1,40 +0,0 @@ -/*********************************************************** -* This file is part of glyr -* + a commnadline tool and library to download various sort of musicrelated metadata. -* + Copyright (C) [2011] [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 . -**************************************************************/ -#include -#include -#include - -#include "wikipedia.h" -#include "../core.h" -#include "../stringlib.h" - -const char * ainfo_wikipedia_url(GlyQuery * s) -{ - return strdup_printf("http://%s.wikipedia.org/wiki/%%artist%%_(Band)",s->lang); - -} - -GlyCacheList * ainfo_wikipedia_parse(cb_object * capo) -{ - char * txt_begin = strstr(capo->cache->data,"cache->size - (txt_begin - capo->cache->data),'<','>'); - puts(txt_begin); - return NULL; -} diff --git a/lib/ainfo/wikipedia.h b/lib/ainfo/wikipedia.h deleted file mode 100644 index 1b6f495..0000000 --- a/lib/ainfo/wikipedia.h +++ /dev/null @@ -1,27 +0,0 @@ -/*********************************************************** -* This file is part of glyr -* + a commnadline tool and library to download various sort of musicrelated metadata. -* + Copyright (C) [2011] [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 . -**************************************************************/ -#ifndef A_WIKIPEDIA_H -#define A_WIKIPEDIA_H - -#include "../core.h" -const char * ainfo_wikipedia_url(GlyQuery * s); -GlyCacheList * ainfo_wikipedia_parse(cb_object * capo ); - -#endif diff --git a/lib/glyr.c b/lib/glyr.c index 4d61848..c9f7275 100644 --- a/lib/glyr.c +++ b/lib/glyr.c @@ -236,7 +236,7 @@ int GlyOpt_lang(GlyQuery * s, char * langcode) int GlyOpt_number(GlyQuery * s, unsigned int num) { if(s == NULL) return GLYRE_EMPTY_STRUCT; - s->number = num == 0 ? UINT_MAX : num; + s->number = num == 0 ? INT_MAX : num; return GLYRE_OK; } diff --git a/lib/glyr.h b/lib/glyr.h index fa90386..fb619ea 100644 --- a/lib/glyr.h +++ b/lib/glyr.h @@ -39,7 +39,7 @@ extern "C" // Cleanup curl, libglyr does not use any global vars, // but libcurl does. That's the only reason why there is a init/cleanup: - // both aren't threadsafe. + // both aren't threadsafe. (It's safe to Init at programstart and to do atexit(Gly_cleanup)) void Gly_cleanup(void); // the actual main of glyr @@ -106,6 +106,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(GlyQuery * s, GlyMemCache * data, const char * path); + // Also include the translation API + #include "translate.h" + #ifdef _cplusplus } diff --git a/lib/translate.c b/lib/translate.c index a8b714f..b92aacc 100644 --- a/lib/translate.c +++ b/lib/translate.c @@ -14,8 +14,10 @@ #include "types.h" #include "core.h" +// Please use your own key if you copy this - it's free! #define GOOGLE_TRANSLATE_API_KEY "AIzaSyDzfBNb-W5G9pvZY6KGbEoRK4JvOIhUsjI" +/* Module prototypes */ static const char * gtrans_get_trans_url(const char * input, const char * from, const char * to); static const char * gtrans_get_detector_url(const char * input); static char * json_get_single_value(char * sval, size_t keylen); @@ -32,7 +34,7 @@ static const char * gtrans_get_trans_url(const char * input, const char * from, if(escape_input != NULL) { resultURL = strdup_printf("https://www.googleapis.com/language/translate/v2?key=%s%s%s&target=%s&prettyprint=true&q=%s", GOOGLE_TRANSLATE_API_KEY, - (from==NULL) ? "" : "&source=", // &source field can be omitted + (from==NULL) ? "" : "&source=", // &source field can be omitted, autodetect then. (from==NULL) ? "" : from, to,escape_input ); @@ -148,12 +150,16 @@ static char * gtrans_parse_detector_json(GlyMemCache * cache, float * correctnes #define BLOCK_BUF 500 #define NEWLINE_MARKUP "__" /* Modifies $to_translate with the translation */ -void Gly_translate_text(GlyQuery * s, GlyMemCache * to_translate) +void Gly_gtrans_translate(GlyQuery * s, GlyMemCache * to_translate) { char * concat_chain = NULL; char block_buf[BLOCK_BUF+2]; if(s && to_translate && s->gtrans.target) { + // so yesterday I translated an image. O RLY? + if(to_translate->is_image) + return; + // no need to translate, eh? if(s->gtrans.source && !strcmp(s->gtrans.target,s->gtrans.source)) return; @@ -243,7 +249,7 @@ void Gly_translate_text(GlyQuery * s, GlyMemCache * to_translate) /* ------------------------------------------------------------------- */ /* Ask google translator what language we are dealing with, NULL if unknown */ -char * Gly_lookup_language(GlyQuery * s, const char * snippet, float * correctness) +char * Gly_gtrans_lookup(GlyQuery * s, const char * snippet, float * correctness) { char * result_lang = NULL; if(s && snippet) { @@ -262,7 +268,7 @@ char * Gly_lookup_language(GlyQuery * s, const char * snippet, float * correctne /* ------------------------------------------------------------------- */ -char ** Gly_list_supported_languages(GlyQuery * s) +char ** Gly_gtrans_list(GlyQuery * s) { char ** result_list = NULL; if(s != NULL) { diff --git a/lib/translate.h b/lib/translate.h index d667c5e..e31ae53 100644 --- a/lib/translate.h +++ b/lib/translate.h @@ -1,9 +1,31 @@ #ifndef G_TRANSLATE_H #define G_TRANSLATE_H +// gtrans method family + #include "types.h" -void Gly_translate_text(GlyQuery * s, GlyMemCache * to_translate); -char * Gly_lookup_language(GlyQuery * s, const char * snippet, float * correctness); -char ** Gly_list_supported_languages(GlyQuery * s); +/* Takes the cache struct to_translate and translate the text according to the setting stored in the GlyQuery s * + It will be translated IF to_translate is not an image (is_image == false) and the targetlang != sourcelang, * + and both languages are valid. Note that the usage of these functions is restricted by google to a certain limit * + being at the moment at 100,000 chars per day and IP. + The buffer is directly modified so make copies before if you need. +*/ +void Gly_gtrans_translate(GlyQuery * s, GlyMemCache * to_translate); + +/* Ask google what language the snippet given as const char is written in * + Optionally you can give a float pointer where the probability of the * + result being correct is stored in, (from 0.0 to 1.0), long snippets * + usually give better results. The result is returned as newly allocated * + char * - free it. +*/ +char * Gly_gtrans_lookup(GlyQuery * s, const char * snippet, float * correctness); + +/* Queries google for a list of all supported languages * + Returned as a list of char pointers, free both the * + single strings and the return value. * + If you only want to know all languages: * + 'glyrc gtrans list' does the same. * +*/ +char ** Gly_gtrans_list(GlyQuery * s); #endif diff --git a/src/main.c b/src/main.c index 3947a1d..6842bd6 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,6 @@ #include #include "../lib/glyr.h" -#include "../lib/translate.h" #include "../lib/md5.h" // also includes glyr's stringlib @@ -509,18 +508,18 @@ static const char ** parse_commandline_general(int argc, char * const * argv, Gl {"plugmax", required_argument, 0, 'x'}, {"verbosity", required_argument, 0, 'v'}, {"update", no_argument, 0, 'u'}, - {"skip-update", no_argument, 0, 'U'}, + {"no-update", no_argument, 0, 'U'}, {"help", 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'}, + {"no-color", no_argument, 0, 'C'}, {"download", no_argument, 0, 'd'}, - {"skip-download", no_argument, 0, 'D'}, + {"no-download", no_argument, 0, 'D'}, {"groups", no_argument, 0, 'g'}, - {"skip-groups", no_argument, 0, 'G'}, + {"no-groups", no_argument, 0, 'G'}, {"twincheck", no_argument, 0, 'y'}, - {"skip-twincheck",no_argument, 0, 'Y'}, + {"no-twincheck", no_argument, 0, 'Y'}, // -- plugin specific -- // {"artist", required_argument, 0, 'a'}, {"album", required_argument, 0, 'b'}, @@ -1009,7 +1008,7 @@ static void make_translation_work(GlyQuery * s, GlyMemCache * to_translate) { if(s && to_translate && !to_translate->is_image && s->gtrans.target) { if(!s->gtrans.source || strcmp(s->gtrans.target,s->gtrans.source)) { - Gly_translate_text(s,to_translate); + Gly_gtrans_translate(s,to_translate); } else { glyr_message(1,s,stderr,"- The target lang is the same as the source lang - Ignore'd."); } @@ -1074,7 +1073,7 @@ static enum GLYR_ERROR callback(GlyMemCache * c, GlyQuery * s) static void print_suppported_languages(GlyQuery * s) { size_t i = 0; - char ** lang_list = Gly_list_supported_languages(s); + char ** lang_list = Gly_gtrans_list(s); // Print all in a calendarstyle format while(lang_list[i]) { @@ -1106,15 +1105,19 @@ int main(int argc, char * argv[]) signal(SIGSEGV, sig_handler); signal(SIGINT, sig_handler); - if(argc >= 3 && strcmp(argv[1],"gtrans") != 0) { - // make sure to init everything and destroy again - Gly_init(); - atexit(Gly_cleanup); + // make sure to init everything and destroy again + Gly_init(); + atexit(Gly_cleanup); + /* Go firth unless the user demeands translation */ + if(argc >= 3 && strcmp(argv[1],"gtrans") != 0) { + // The struct that control this beast GlyQuery my_query; - // glyr's control struct + + // set it on default values Gly_init_query(&my_query); + // Good enough for glyrc GlyOpt_verbosity(&my_query,2); // Set the type.. @@ -1130,8 +1133,9 @@ int main(int argc, char * argv[]) write_arg[1] = NULL; } + // Special cases if(my_query.type == GET_AINFO) - my_query.number *= 2; + GlyOpt_number(&my_query,my_query.number*2); // Check if files do already exist bool file_exist = false; @@ -1152,27 +1156,37 @@ int main(int argc, char * argv[]) } } - // Set (example) callback + if(my_query.type == GET_TRACKLIST) + GlyOpt_number(&my_query,0); + + if(my_query.type == GET_ALBUMLIST) + GlyOpt_number(&my_query,0); + + // Set the callback - it will do all the actual work int item_counter = 0; GlyOpt_dlcallback(&my_query, callback, &item_counter); + if(my_query.type != GET_UNSURE) { if(!file_exist) { + + // Get information about available getters command_copy = Gly_get_provider_by_id(GET_UNSURE); - // Now start searching... + // Now start searching! enum GLYR_ERROR get_error = GLYRE_OK; GlyCacheList * my_list= Gly_get(&my_query, &get_error); + // The struct needs to be free'd again if(command_copy) { free(command_copy); } if(my_list) { if(get_error == GLYRE_OK) { - // to be removed completely? /* This is the place where you would work with the cachelist * As the callback is used in glyrc this is just plain empty * Useful if you need to cache the data (e.g. for batch jobs * + Left only for the reader's informatiom, no functions here * */ } @@ -1185,6 +1199,7 @@ int main(int argc, char * argv[]) glyr_message(1,&my_query,stderr,C_B"*"C_" File(s) already exist. Use -u to update.\n"); } + // free pathes size_t x = 0; for( x = 0; write_arg[x]; x++) { free((char*)write_arg[x]); @@ -1197,7 +1212,7 @@ int main(int argc, char * argv[]) Gly_destroy_query( &my_query); } /* Translator mode - simple interface to google translator */ - } else if(argc >= 2 && !strcmp(argv[1],"gtrans")) { + } else if(argc >= 3 && !strcmp(argv[1],"gtrans")) { GlyQuery settings; Gly_init_query(&settings); GlyOpt_verbosity(&settings,2); @@ -1207,16 +1222,16 @@ int main(int argc, char * argv[]) print_suppported_languages(&settings); /* detect language snippet given as argument */ - } else if(!strcmp(argv[2],"detect") && argc >= 3) { + } else if(!strcmp(argv[2],"detect") && argc >= 4) { float correctness = 0.0; - char * lang_guess = Gly_lookup_language(&settings,argv[3],&correctness); + char * lang_guess = Gly_gtrans_lookup(&settings,argv[3],&correctness); if(lang_guess != NULL) { glyr_message(2,&settings,stdout,"%s (%3.2f%% probability)\n",lang_guess,correctness*100.0); free(lang_guess); } /* Translation */ - } else if(argc >= 3) { + } else if(argc >= 4) { GlyMemCache * buffer = Gly_new_cache(); if(buffer != NULL) { buffer->data = strdup(argv[2]); @@ -1229,12 +1244,17 @@ int main(int argc, char * argv[]) /* set target language */ GlyOpt_gtrans_target_lang(&settings,argv[4]); - Gly_translate_text(&settings,buffer); + Gly_gtrans_translate(&settings,buffer); glyr_message(2,&settings,stdout,"%s\n",buffer->data); /* all done - bye! */ Gly_free_cache(buffer); } + } else { /* usage */ + glyr_message(-1,NULL,stderr,"Usage:\n"); + glyr_message(-1,NULL,stderr," glyrc gtrans list\n"); + glyr_message(-1,NULL,stderr," glyrc gtrans [text] [sourcelang|auto] [targetlang]\n"); + glyr_message(-1,NULL,stderr," glyrc gtrans detect [text]\n\n"); } /* free all registers */