Commit 7ae38b1e authored by Ziirish's avatar Ziirish

new: support regex to clean album names while looking for a cover (ex: years/disk number)

parent 88a02a16
......@@ -21,7 +21,7 @@ AC_PROG_CC
AC_HEADER_STDC
# Checks for libraries.
PKG_CHECK_MODULES(PACKAGE, "gtk+-2.0 dbus-1 dbus-glib-1 libxml-2.0 gthread-2.0 libcurl libcrypto")
PKG_CHECK_MODULES(PACKAGE, "gtk+-2.0 dbus-1 dbus-glib-1 libxml-2.0 gthread-2.0 libcurl libcrypto x11 cairo")
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
......
......@@ -48,12 +48,18 @@ cid_get_xml_file (const gchar *artist,
gchar *cTmpFilePath = g_strdup (DEFAULT_XML_LOCATION);
CURL *handle = curl_easy_init();
gchar *cArtistClean = curl_easy_escape (handle, artist, 0);
gchar *cAlbumClean = curl_easy_escape (handle, album, 0);
gchar *cTmpArtist = g_strdup (artist);
gchar *cTmpAlbum = g_strdup (album);
cid_str_prepare (&cTmpArtist);
cid_str_prepare (&cTmpAlbum);
gchar *cArtistClean = curl_easy_escape (handle, cTmpArtist, 0);
gchar *cAlbumClean = curl_easy_escape (handle, cTmpAlbum, 0);
gchar *cURLArgs = g_strdup_printf ("&artist=%s&album=%s",
cArtistClean,
cAlbumClean);
gchar *cURLFull = g_strdup_printf ("%s%s", cURLBegin, cURLArgs);
g_free (cTmpArtist);
g_free (cTmpAlbum);
g_free (cURLArgs);
g_free (cArtistClean);
g_free (cAlbumClean);
......
......@@ -160,6 +160,7 @@ cid_substitute_user_params (gchar **cPath)
pData[1] = cPath;
cid_datatable_foreach (table, (CidDataAction) cid_proceed_substitute, pData);
cid_free_datatable (&table);
g_free (pData);
}
CidSubstitute *
......@@ -183,3 +184,57 @@ cid_free_substitute (CidSubstitute *pSub)
g_free (pSub->replacement);
g_free (pSub);
}
static void
cid_proceed_regex (gchar **cString, const gchar *regex, const gchar *replacement)
{
g_return_if_fail (*cString != NULL);
GError *error = NULL;
GRegex *reg = g_regex_new (regex,0,0,&error);
if (error != NULL)
{
fprintf (stderr,"g_regex_new error: %s\n",error->message);
g_error_free (error);
error = NULL;
g_regex_unref (reg);
return;
}
gchar *res = g_regex_replace (reg, *cString, -1, 0, replacement, 0, &error);
if (error != NULL)
{
fprintf (stderr,"g_regex_replace error: %s\n",error->message);
g_error_free (error);
error = NULL;
g_regex_unref (reg);
return;
}
g_free (*cString);
*cString = g_strdup (res);
g_free (res);
g_regex_unref (reg);
}
static void
cid_foreach_proceed_regex (CidDataCase *pCase, gpointer *pData)
{
cid_proceed_regex (pData[1],pCase->content->sub->regex,pCase->content->sub->replacement);
}
void
cid_str_prepare (gchar **cString)
{
CidDataTable *table = cid_create_datatable (CID_TYPE_SUBSTITUTE,
cid_new_substitute ("\\(.*\\)",""),
cid_new_substitute ("\\[.*\\]",""),
cid_new_substitute (" +"," "),
cid_new_substitute (" $",""),
G_TYPE_INVALID);
gpointer *pData = g_new0(gpointer, 2);
pData[0] = GINT_TO_POINTER(0);
pData[1] = cString;
cid_datatable_foreach (table, (CidDataAction) cid_foreach_proceed_regex, pData);
cid_free_datatable (&table);
g_free (pData);
}
......@@ -51,5 +51,11 @@ void cid_str_replace_all (gchar **string, const gchar *sFrom, const gchar *sTo);
void cid_str_replace_all_seq (gchar **string, gchar *seqFrom, gchar *seqTo);
/**
* Permet de préparer une chaîne pour la recherche sur Last.fm.
* @param cString chaîne à préparer.
*/
void cid_str_prepare (gchar **cString);
G_END_DECLS
#endif
......@@ -261,9 +261,9 @@ main ( int argc, char **argv )
/*
GError *error = NULL;
GMatchInfo *match_info;
GRegex *reg = g_regex_new ("%al",0,0,&error);
gchar *init = "blah %al bloh";
gchar *replacement = "blih";
GRegex *reg = g_regex_new ("(\\(|\\[).*(\\)|\\])",0,0,&error);
gchar *init = "blah (%al) bloh";
gchar *replacement = "";
if (error != NULL)
{
fprintf (stderr,"g_regex_new error: %s\n",error->message);
......@@ -318,7 +318,15 @@ main ( int argc, char **argv )
g_free (tmp);
}
*/
/*
gchar *init = g_strdup("blah %home% (toto) [tata] ");
fprintf (stdout,"before: '%s'\n",init);
cid_str_prepare (&init);
fprintf (stdout,"after: '%s'\n",init);
g_free (init);
*/
fprintf (stdout,"Bye !\n");
return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment