Commit 6dbc1f1a authored by Ziirish's avatar Ziirish

- new cid_cover_lookup function to locate covers by reading directories content

- cleaning a few pieces of code
parent 2f31b315
......@@ -152,7 +152,7 @@ cid_stop_measure_timer (CidMeasure *pMeasureTimer)
_cid_pause_measure_timer (pMeasureTimer);
cid_debug ("***on attend que le thread termine...(%d)", g_atomic_int_get (&pMeasureTimer->iThreadIsRunning));
//cid_debug ("***on attend que le thread termine...(%d)", g_atomic_int_get (&pMeasureTimer->iThreadIsRunning));
while (g_atomic_int_get (&pMeasureTimer->iThreadIsRunning) == 1)
{
cpt++;
......@@ -164,7 +164,7 @@ cid_stop_measure_timer (CidMeasure *pMeasureTimer)
g_usleep (10);
}
///gtk_main_iteration ();
cid_debug ("***temine.");
//cid_debug ("***temine.");
}
void
......
......@@ -9,6 +9,7 @@
*/
//#include "cid-constantes.h"
#include "cid-callbacks.h"
#include "cid-cover.h"
#include "cid-struct.h"
#include "cid-messages.h"
......@@ -25,26 +26,33 @@ gchar *TAB_IMAGE_SIZES[] = {"large","extralarge"};
#ifdef LIBXML_READER_ENABLED
gboolean
cid_get_xml_file (const gchar *artist, const gchar *album)
cid_get_xml_file (const gchar *artist,
const gchar *album)
{
if (g_file_test (DEFAULT_DOWNLOADED_IMAGE_LOCATION, G_FILE_TEST_EXISTS))
{
cid_remove_file (DEFAULT_DOWNLOADED_IMAGE_LOCATION);
}
if (g_strcasecmp("Unknown",artist)==0 || g_strcasecmp("Unknown",album)==0 ||
g_strcasecmp("Inconnu",artist)==0 || g_strcasecmp("Inconnu",album)==0)
if (g_strcasecmp("Unknown",artist)==0
|| g_strcasecmp("Unknown",album)==0
|| g_strcasecmp("Inconnu",artist)==0
|| g_strcasecmp("Inconnu",album)==0)
{
return FALSE;
}
gchar *cURLBegin = g_strdup_printf("%s%s&api_key=%s",LAST_API_URL,LAST_ALBUM,LAST_ID_KEY);
gchar *cURLBegin = g_strdup_printf("%s%s&api_key=%s",
LAST_API_URL,LAST_ALBUM,
LAST_ID_KEY);
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 *cURLArgs = g_strdup_printf ("&artist=%s&album=%s", cArtistClean, cAlbumClean);
gchar *cURLArgs = g_strdup_printf ("&artist=%s&album=%s",
cArtistClean,
cAlbumClean);
gchar *cURLFull = g_strdup_printf ("%s%s", cURLBegin, cURLArgs);
g_free (cURLArgs);
g_free (cArtistClean);
......@@ -62,8 +70,9 @@ cid_get_xml_file (const gchar *artist, const gchar *album)
if (rename (DEFAULT_XML_LOCATION".tmp",DEFAULT_XML_LOCATION) == -1)
{
cid_warning ("Cannot rename '%s' to '%s'", DEFAULT_XML_LOCATION".tmp",
DEFAULT_XML_LOCATION);
cid_warning ("Cannot rename '%s' to '%s'",
DEFAULT_XML_LOCATION".tmp",
DEFAULT_XML_LOCATION);
}
g_free (cTmpFilePath);
......@@ -75,7 +84,8 @@ cid_get_xml_file (const gchar *artist, const gchar *album)
#else
gboolean
cid_get_xml_file (const gchar *artist, const gchar *album)
cid_get_xml_file (const gchar *artist,
const gchar *album)
{
return FALSE;
}
......@@ -83,7 +93,7 @@ cid_get_xml_file (const gchar *artist, const gchar *album)
#endif
gboolean
cid_download_missing_cover (const gchar *cURL/*, const gchar *cDestPath*/)
cid_download_missing_cover (const gchar *cURL)
{
CURL *handle = curl_easy_init ();
curl_easy_setopt(handle, CURLOPT_URL, cURL);
......@@ -98,8 +108,9 @@ cid_download_missing_cover (const gchar *cURL/*, const gchar *cDestPath*/)
if (rename (DEFAULT_DOWNLOADED_IMAGE_LOCATION".tmp",DEFAULT_DOWNLOADED_IMAGE_LOCATION) == -1)
{
cid_warning ("Cannot rename '%s' to '%s'",DEFAULT_DOWNLOADED_IMAGE_LOCATION".tmp",
DEFAULT_DOWNLOADED_IMAGE_LOCATION);
cid_warning ("Cannot rename '%s' to '%s'",
DEFAULT_DOWNLOADED_IMAGE_LOCATION".tmp",
DEFAULT_DOWNLOADED_IMAGE_LOCATION);
}
return TRUE;
......@@ -112,7 +123,10 @@ cid_download_missing_cover (const gchar *cURL/*, const gchar *cDestPath*/)
* @param imageSize Taille de l'image que l'on souhaite
*/
void
cid_search_xml_xpath (const char *filename, gchar **cValue, const gchar*xpath, ...)
cid_search_xml_xpath (const char *filename,
gchar **cValue,
const gchar*xpath,
...)
{
xmlDocPtr doc;
*cValue = NULL;
......@@ -173,8 +187,10 @@ cid_search_xml_xpath (const char *filename, gchar **cValue, const gchar*xpath, .
}
gchar *
cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
const gchar *cArtist, const gchar *cAlbum)
cid_db_store_cover (CidMainContainer **pCid,
const gchar *cCoverPath,
const gchar *cArtist,
const gchar *cAlbum)
{
g_return_val_if_fail (cCoverPath != NULL
&& cArtist != NULL
......@@ -186,10 +202,16 @@ cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
CidMainContainer *cid = *pCid;
GKeyFile *pKeyFile;
CURL *handle = curl_easy_init();
gchar *cKey = g_strdup_printf ("%s_%s", curl_easy_escape (handle, cArtist, 0),
curl_easy_escape (handle, cAlbum, 0));
gchar *cKey = g_strdup_printf ("%s_%s", curl_easy_escape (handle,
cArtist,
0),
curl_easy_escape (handle,
cAlbum,
0));
curl_easy_cleanup (handle);
gchar *cDBFile = g_strdup_printf ("%s/%s", cid->config->cDLPath, CID_COVER_DB);
gchar *cDBFile = g_strdup_printf ("%s/%s",
cid->config->cDLPath,
CID_COVER_DB);
gchar *md5 = cid_md5sum (cCoverPath);
GKeyFileFlags flags;
GError *error = NULL;
......@@ -224,7 +246,9 @@ cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
cid_warning ("%s",error->message);
g_error_free (error);
}
gchar *cDestFile = g_strdup_printf ("%s/%s", cid->config->cDLPath, md5);
gchar *cDestFile = g_strdup_printf ("%s/%s",
cid->config->cDLPath,
md5);
cid_copy_file (cCoverPath, cDestFile);
cid_remove_file (cCoverPath);
g_key_file_set_value (pKeyFile, "DB", cKey, md5);
......@@ -238,7 +262,9 @@ cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
}
gchar *
cid_db_search_cover (CidMainContainer **pCid, const gchar *cArtist, const gchar *cAlbum)
cid_db_search_cover (CidMainContainer **pCid,
const gchar *cArtist,
const gchar *cAlbum)
{
g_return_val_if_fail (cArtist != NULL && cAlbum != NULL, NULL);
CidMainContainer *cid = *pCid;
......@@ -276,7 +302,9 @@ cid_db_search_cover (CidMainContainer **pCid, const gchar *cArtist, const gchar
}
if (cVal != NULL)
{
cCoverPath = g_strdup_printf ("%s/%s", cid->config->cDLPath, cVal);
cCoverPath = g_strdup_printf ("%s/%s",
cid->config->cDLPath,
cVal);
g_free (cVal);
}
......@@ -288,7 +316,46 @@ cid_db_search_cover (CidMainContainer **pCid, const gchar *cArtist, const gchar
}
gchar *
cid_cover_lookup (const gchar *cDir)
cid_cover_lookup (CidMainContainer **pCid,
const gchar *cArtist,
const gchar *cAlbum,
const gchar *cDir)
{
CidMainContainer *cid = *pCid;
gchar *cRes = NULL;
BEGIN_FOREACH_DT (cid->runtime->pCoversList)
g_free (cRes);
gchar *file = g_strdup (p_temp->content->string);
cid_substitute_user_params (&file);
if (*file == '/')
cRes = g_strdup (file);
else
cRes = g_strdup_printf ("%s/%s.jpg", cDir, file);
cid_debug (" test de %s\n", musicData.playing_cover);
if (g_file_test (cRes, G_FILE_TEST_EXISTS))
{
return cRes;
}
END_FOREACH_DT_NF
g_free (cRes);
cRes = cid_db_search_cover (pCid, cArtist, cAlbum);
if (cRes != NULL)
return cRes;
cid->runtime->iCheckIter = 0;
if (musicData.iSidCheckCover != 0)
{
g_source_remove (musicData.iSidCheckCover);
musicData.iSidCheckCover = 0;
}
cid_debug ("l'image n'existe pas encore => on boucle.\n");
musicData.iSidCheckCover =
g_timeout_add (1000,
(GSourceFunc) _check_cover_is_present,
pCid);
return NULL;
}
......@@ -62,7 +62,7 @@ gboolean cid_get_xml_file (const gchar *artist, const gchar *album);
* @param cDestPath Ou en enregistre la pochette telechargee.
* @return succes du telechargement.
*/
gboolean cid_download_missing_cover (const gchar *cURL/*, const gchar *cDestPath*/);
gboolean cid_download_missing_cover (const gchar *cURL);
/**
* On sauvegarde la pochette dans notre 'magazin'.
......@@ -71,18 +71,35 @@ gboolean cid_download_missing_cover (const gchar *cURL/*, const gchar *cDestPath
* @return URI de la pochette apres stockage dans notre
* 'magazin', NULL si stockage impossible.
*/
gchar *cid_db_store_cover (CidMainContainer **pCid,const gchar *cCoverPath,
const gchar *cArtist, const gchar *cAlbum);
gchar *cid_db_store_cover (CidMainContainer **pCid,
const gchar *cCoverPath,
const gchar *cArtist,
const gchar *cAlbum);
/**
* Recherche une pochette dans notre 'magazin'.
* @param pCid Structure de controle de cid.
* @param cArtist nom de l'artiste.
* @param cAlbum nom de l'album.
* @return URI complet de l'image, NULL si non toruve.
* @return URI complet de l'image, NULL si non toruvé.
*/
gchar *cid_db_search_cover (CidMainContainer **pCid, const gchar *cArtist,
const gchar *cAlbum);
gchar *cid_db_search_cover (CidMainContainer **pCid,
const gchar *cArtist,
const gchar *cAlbum);
/**
* Recherche une pochette sur la machine par analyse brute des fichiers.
* @param pCid Structure de controle de cid.
* @param cArtist nom de l'artiste.
* @param cAlbum nom de l'album.
* @param cDir répertoire dans lequel se trouve la musique en cours de
* lecture.
* @return URI complet de l'image, NULL si non trouvé.
*/
gchar *cid_cover_lookup (CidMainContainer **pCid,
const gchar *cArtist,
const gchar *cAlbum,
const gchar *cDir);
G_END_DECLS
#endif
......@@ -228,7 +228,7 @@ getSongInfos(void)
}
else
{
CidDataTable *p_tabFiles = cid_clone_datatable (cid->runtime->pCoversList);
//CidDataTable *p_tabFiles = cid_clone_datatable (cid->runtime->pCoversList);
//cid_create_datatable(G_TYPE_STRING,"cover","album","albumart",
// ".folder",".cover","folder","Cover","Folder",
// G_TYPE_INVALID);
......@@ -237,6 +237,7 @@ getSongInfos(void)
{
gchar *cSongDir = g_path_get_dirname (cSongPath);
g_free (cSongPath);
/*
musicData.playing_cover = g_strdup_printf ("%s/%s - %s.jpg", cSongDir, musicData.playing_artist, musicData.playing_album);
cid_debug (" test de %s\n", musicData.playing_cover);
BEGIN_FOREACH_DT(p_tabFiles)
......@@ -246,36 +247,53 @@ getSongInfos(void)
musicData.playing_cover = g_strdup_printf ("%s/%s.jpg", cSongDir, p_temp->content->string);
cid_debug (" test de %s\n", musicData.playing_cover);
END_FOREACH_DT
*/
if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
{
cid_debug (" test de %s (.gnome2)\n", musicData.playing_cover);
cid_debug (" test de %s (.gnome2)",
musicData.playing_cover);
g_free (musicData.playing_cover);
musicData.playing_cover = g_strdup_printf("%s/.gnome2/rhythmbox/covers/%s - %s.jpg", g_getenv("HOME"),musicData.playing_artist, musicData.playing_album);
musicData.playing_cover = g_strdup_printf("%s/.gnome2/rhythmbox/covers/%s - %s.jpg",
g_getenv("HOME"),
musicData.playing_artist,
musicData.playing_album);
}
if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
{
cid_debug (" test de %s (.cache)\n", musicData.playing_cover);
cid_debug (" test de %s (.cache)",
musicData.playing_cover);
g_free (musicData.playing_cover);
musicData.playing_cover = g_strdup_printf("%s/.cache/rhythmbox/covers/%s - %s.jpg", g_getenv("HOME"),musicData.playing_artist, musicData.playing_album);
musicData.playing_cover = g_strdup_printf("%s/.cache/rhythmbox/covers/%s - %s.jpg",
g_getenv("HOME"),
musicData.playing_artist,
musicData.playing_album);
}
g_free (cSongDir);
if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
{
gchar *cCoverSave = g_strdup (musicData.playing_cover);
g_free (musicData.playing_cover);
musicData.playing_cover = cid_db_search_cover (&cid, musicData.playing_artist, musicData.playing_album);
musicData.playing_cover =
cid_cover_lookup (&cid,
musicData.playing_artist,
musicData.playing_album,
cSongDir);
if (musicData.playing_cover == NULL)
{
musicData.playing_cover = g_strdup (cCoverSave);
/*
cid->runtime->iCheckIter = 0;
if (musicData.iSidCheckCover == 0)
{
cid_debug ("l'image n'existe pas encore => on boucle.\n");
musicData.iSidCheckCover = g_timeout_add (1 SECONDES, (GSourceFunc) _check_cover_is_present, &cid);
}
*/
}
g_free (cCoverSave);
}
g_free (cSongDir);
}
}
cid_message (" playing_cover <- %s\n", musicData.playing_cover);
......
......@@ -855,8 +855,8 @@ cid_create_sized_datatable_with_default_full (size_t iSize, GType iType, void *v
void
cid_str_replace_all (gchar **string, const gchar *sFrom, const gchar *sTo)
{
if (*string == NULL || sFrom == NULL || sTo == NULL)
return;
g_return_if_fail (*string != NULL && sFrom != NULL && sTo != NULL);
gchar **tmp = g_strsplit(*string,sFrom,0);
CidDataTable *t_temp = cid_datatable_new();
while (*tmp != NULL)
......
......@@ -314,6 +314,9 @@ p_temp=p_temp->next; \
} \
cid_free_datatable(&p_dt);
#define END_FOREACH_DT_NF \
p_temp=p_temp->next; \
}
G_END_DECLS
#endif
......@@ -45,8 +45,6 @@
CidMainContainer *cid;
int ret = CID_EXIT_SUCCESS;
static gchar *cLaunchCommand = NULL;
static void
cid_init (CidMainContainer *pCid)
{
......@@ -84,8 +82,6 @@ cid_intercept_signal (int number)
return;
}
cid_warning ("Attention : cid has crashed (%s).", strsignal(number));
//execl ("/bin/sh", "/bin/sh", "-c", cLaunchCommand, NULL); // on ne revient pas de cette fonction.
//cid_warning ("Sorry, couldn't restart cid");
fflush (stdout);
signal (number, SIG_DFL);
raise (number);
......@@ -160,12 +156,6 @@ cid_run_with_player (CidMainContainer **pCid)
static void
cid_set_signal_interception (struct sigaction *action)
{
/*
signal (SIGSEGV, cid_intercept_signal); // Segmentation violation
signal (SIGFPE, cid_intercept_signal); // Floating-point exception
signal (SIGILL, cid_intercept_signal); // Illegal instruction
signal (SIGABRT, cid_intercept_signal); // Abort
*/
(*action).sa_handler = cid_intercept_signal;
sigfillset (&((*action).sa_mask));
(*action).sa_flags = 0;
......@@ -199,10 +189,6 @@ cid_display_init(CidMainContainer **pCid, int *argc, char ***argv)
if (!cid->runtime->bRunning)
cid_exit (pCid, CID_GTK_ERROR,"Unable to load gtk context");
/* On intercepte les signaux */
// signal (SIGINT, cid_interrupt); // ctrl+c
// signal (SIGTERM, cid_interrupt);
if (cid->config->bSafeMode)
{
_cid_conf_panel(NULL,NULL);
......@@ -230,28 +216,18 @@ main ( int argc, char **argv )
{
struct sigaction action;
cid = g_malloc0 (sizeof(*cid));
cid->config = g_malloc0 (sizeof(*(cid->config)));
cid->runtime = g_malloc0 (sizeof(*(cid->runtime)));
cid->defaut = g_malloc0 (sizeof(*(cid->defaut)));
curl_global_init(CURL_GLOBAL_ALL);
int i;
GString *sCommandString = g_string_new (argv[0]);
for (i = 1; i < argc; i ++)
{
g_string_append_printf (sCommandString, " %s", argv[i]);
}
g_string_append_printf (sCommandString, " -s");
cLaunchCommand = sCommandString->str;
g_string_free (sCommandString, FALSE);
curl_global_init(CURL_GLOBAL_ALL);
cid_log_set_level(0);
cid_init(cid);
// On internationalise l'appli.
setlocale (LC_ALL,"");
bindtextdomain (CID_GETTEXT_PACKAGE, CID_LOCALE_DIR);
......
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