add glyrc module

This commit is contained in:
zmike 2014-01-31 20:22:46 -05:00
parent 13f7f68e86
commit 9b501741de
3 changed files with 231 additions and 0 deletions

View File

@ -93,6 +93,16 @@ fi
want_glyr_gmpc=$have_esql
AM_CONDITIONAL([MOD_GLYR_GMPC], [test "x$want_glyr_gmpc" = "xyes"])
want_glyr=maybe
AC_ARG_ENABLE([module-glyr],
[AC_HELP_STRING([--disable-module-glyr], [disable glyr module. @<:@default=detect@:>@])],
[want_glyr=$enableval], [])
if test -n "$want_glyr" ; then
AC_CHECK_PROG([GLYR], [glyrc], [yes], [no])
want_glyr=$GLYR
fi
AM_CONDITIONAL([MOD_GLYR], [test "x$want_glyr" = "xyes"])
########################################
case "$host_os" in
@ -148,6 +158,7 @@ echo
cat << MODULES_EOF
Modules:
* glyr_gmpc...........: $want_glyr_gmpc
* glyr................: $want_glyr
MODULES_EOF
echo

View File

@ -30,3 +30,26 @@ src_modules_glyr_gmpc_la_LDFLAGS = -module -avoid-version
src_modules_glyr_gmpc_la_LIBTOOLFLAGS = --tag=disable-static
endif
if MOD_GLYR
mod_LTLIBRARIES += src/modules/glyr.la
src_modules_glyr_la_SOURCES = \
src/modules/glyr.c
src_modules_glyr_la_CPPFLAGS = \
$(AM_CFLAGS) \
$(mod_cppflags) \
@EFL_CFLAGS@ \
@ELM_CFLAGS@ \
-I$(top_srcdir)/src/bin \
-I$(top_builddir)
src_modules_glyr_la_LIBADD = \
@EFL_LIBS@ \
@ELM_LIBS@
src_modules_glyr_la_LDFLAGS = -module -avoid-version
src_modules_glyr_la_LIBTOOLFLAGS = --tag=disable-static
endif

197
src/modules/glyr.c Normal file
View File

@ -0,0 +1,197 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "empdd.h"
#include "empc.h"
#include <Ecore.h>
#include <Efreet.h>
#include <Elementary.h>
typedef enum
{
GLYR_TYPE_UNKNOWN,
GLYR_TYPE_LYRICS,
GLYR_TYPE_ALBUM_REVIEW,
GLYR_TYPE_ARTIST_PHOTO,
GLYR_TYPE_COVERART,
GLYR_TYPE_ARTIST_BIO,
GLYR_TYPE_SIMILAR_ARTIST,
GLYR_TYPE_SIMILAR_SONG,
GLYR_TYPE_ALBUMLIST,
GLYR_TYPE_TAG,
GLYR_TYPE_TAG_ARTIST,
GLYR_TYPE_TAG_ALBUM,
GLYR_TYPE_TAG_TITLE,
GLYR_TYPE_RELATION,
GLYR_TYPE_IMG_URL,
GLYR_TYPE_TXT_URL,
GLYR_TYPE_TRACK,
GLYR_TYPE_GUITARTABS,
GLYR_TYPE_BACKDROPS
} GLYR_DATA_TYPE;
typedef enum
{
GLYR_GET_UNKNOWN,
GLYR_GET_COVERART,
GLYR_GET_LYRICS,
GLYR_GET_ARTIST_PHOTOS,
GLYR_GET_ARTIST_BIO,
GLYR_GET_SIMILAR_ARTISTS,
GLYR_GET_SIMILAR_SONGS,
GLYR_GET_ALBUM_REVIEW,
GLYR_GET_TRACKLIST,
GLYR_GET_TAGS,
GLYR_GET_RELATIONS,
GLYR_GET_ALBUMLIST,
GLYR_GET_GUITARTABS,
GLYR_GET_BACKDROPS,
GLYR_GET_ANY
} GLYR_GET_TYPE;
static Eina_List *exes = NULL;
static Eina_List *handlers = NULL;
static char replace_chars[] =
{
' ',
'\t',
'\n',
'\\',
'\'',
'\"',
';',
'!',
'#',
'$',
'%',
'&',
'*',
'(',
')',
'[',
']',
'{',
'}',
'|',
'<',
'>',
'?',
0
};
static char *
_escape(const char *str)
{
Eina_Strbuf *buf;
const char *p;
char *ret;
if (!str) return NULL;
buf = eina_strbuf_new();
for (p = str; p[0]; p++)
{
const char *c;
for (c = replace_chars; c[0]; c++)
{
if (c[0] != p[0]) continue;
eina_strbuf_append_char(buf, '\\');
break;
}
eina_strbuf_append_char(buf, p[0]);
}
ret = eina_strbuf_string_steal(buf);
eina_strbuf_free(buf);
return ret;
}
static Eina_Bool
exe_data(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Data *ev)
{
Empc_Fetch_Request *req;
const char *tag;
Ecore_Exe_Event_Data_Line *el;
tag = ecore_exe_tag_get(ev->exe);
if ((!tag) || strcmp(tag, "glyr")) return ECORE_CALLBACK_RENEW;
req = ecore_exe_data_get(ev->exe);
for (el = ev->lines; el && el->line ; el++)
{
if (el->line[0] != 'h') continue;
if (strncmp(el->line, "http", 4)) continue;
elm_image_file_set(req->obj, el->line, NULL);
req->result(req, EINA_TRUE);
exes = eina_list_remove(exes, ev->exe);
break;
}
return ECORE_CALLBACK_DONE;
}
static Eina_Bool
exe_del(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Exe_Event_Del *ev)
{
Eina_List *l;
Empc_Fetch_Request *req;
const char *tag;
tag = ecore_exe_tag_get(ev->exe);
l = eina_list_data_find_list(exes, ev->exe);
if (!l) return (!tag) || strcmp(tag, "glyr");
req = ecore_exe_data_get(ev->exe);
exes = eina_list_remove_list(exes, l);
req->result(req, EINA_FALSE);
return ECORE_CALLBACK_DONE;
}
EAPI Eina_Bool
empc_module_metadata_fetch(const Empc_Fetch_Request *req)
{
char buf[4096];
char *artist, *album;
Ecore_Exe *exe;
artist = _escape(req->artist);
album = _escape(req->album);
if (album)
snprintf(buf, sizeof(buf), "glyrc cover -a %s -b %s -D -v1 --write /dev/null", artist, album);
else
snprintf(buf, sizeof(buf), "glyrc cover -a %s -D -v1 --write /dev/null", artist);
exe = ecore_exe_pipe_run(buf, ECORE_EXE_PIPE_ERROR | ECORE_EXE_PIPE_ERROR_LINE_BUFFERED, req);
ecore_exe_tag_set(exe, "glyr");
if (exe)
exes = eina_list_append(exes, exe);
return !!exe;
}
EAPI Empc_Module_Type
empc_module_type(void)
{
return EMPC_MODULE_TYPE_METADATA_IMAGE;
}
EAPI int
empc_module_priority(void)
{
return 50;
}
static Eina_Bool
glyr_init(void)
{
E_LIST_HANDLER_APPEND(handlers, ECORE_EXE_EVENT_ERROR, exe_data, NULL);
E_LIST_HANDLER_APPEND(handlers, ECORE_EXE_EVENT_DEL, exe_del, NULL);
return EINA_TRUE;
}
static void
glyr_shutdown(void)
{
E_FREE_LIST(handlers, ecore_event_handler_del);
E_FREE_LIST(exes, ecore_exe_free);
}
EINA_MODULE_INIT(glyr_init);
EINA_MODULE_SHUTDOWN(glyr_shutdown);