23 if (stat (filename, &buf) == -1)
25 if (S_ISREG (buf.st_mode))
32 printf(
"\n\t*************** it2m: Usage ***************\nit2m itunes.xml dbpassword user databasename port\nit2m ([itunes.xml]|default='iTunes Music Library.xml') dbpassword \n\t[ user [(database|default='mythconverg')] [(port|default=3306)] ]\n* VerySimple Use : YourPassWord\n* Simple : YourItunesMusicLin.xml YourPassWord\n* Custom : YourItunesMusicLin.xml YourPassWord YouUser\n* Default : \"iTunes Music Library.xml\" YourPass root mythconverg 3306\n\ni2tm : writed by Sonique :: Cedric FERRY :: http://sonique54.free.fr.\n");
43 int rate = atoi(rating)/10;
44 int numplays = atoi(count);
46 char query [1024] =
"";
47 sprintf(query,
"UPDATE music_songs SET rating = %d, numplays = %d WHERE music_songs.artist_id IN (SELECT artist_id FROM music_artists WHERE artist_name LIKE \"%s%%\") AND music_songs.album_id IN (SELECT album_id FROM music_albums WHERE album_name LIKE \"%s%%\") AND music_songs.name LIKE \"%s%%\" ",rate, numplays, artname, albname, songname);
50 t=mysql_real_query(
mysql, query, strlen(query));
52 printf(
"UpdateMythConverg request error : %s \n", mysql_error(
mysql) );
54 if(mysql_affected_rows(
mysql) < 1){
56 printf(
"\t\t%s - %s - %s cannot be found OR already up to date.\n", artname, albname, songname);
59 printf(
"%s - %s - %s Have been UPDATED.\n",artname, albname, songname);
69 xmlDocPtr xmlperms_doc = NULL;
70 xmlXPathContextPtr xmlperms_context = NULL;
71 xmlXPathObjectPtr xmlobject;
73 const char path_template[] =
"/plist/dict/dict/dict/*";
78 fprintf (stderr,
"%s:%d File not found\n", __FILE__, __LINE__);
82 xmlperms_doc = xmlParseFile (filename);
85 fprintf (stderr,
"%s:%d Could not parse the document\n", __FILE__,__LINE__);
91 xmlperms_context = xmlXPathNewContext (xmlperms_doc);
93 xmlobject = xmlXPathEval (path_template, xmlperms_context);
96 char * albname = NULL;
97 char * artname = NULL;
99 char * songname = NULL;
103 if ( (xmlobject->type == XPATH_NODESET) &&
104 (xmlobject->nodesetval) ){
106 if (xmlobject->nodesetval->nodeNr){
107 xmlNodePtr node, node2;
110 for(i=0; i<xmlobject->nodesetval->nodeNr-1; i++){
112 node = xmlobject->nodesetval->nodeTab[i];
113 node2 = xmlobject->nodesetval->nodeTab[i+1];
114 xmlChar *pathact1 = xmlGetNodePath (node);
117 if( node->type == XML_ELEMENT_NODE &&
118 (xmlobject->nodesetval) &&
119 strcmp( node->name,
"key" ) == 0 ){
122 if( strcmp( (
char*)node->children->content,
"Track ID")==0 ){
135 if( strcmp( (
char*)node->children->content,
"Name")==0 ){
136 if(strcmp( node2->name,
"string") == 0) {
137 songname = strdup(node2->children->content);
141 if(strcmp((
char *) node->children->content,
"Album")==0 ) {
142 if(strcmp(node2->name,
"string") == 0){
143 albname = strdup(node2->children->content);
147 if(strcmp((
char *) node->children->content,
"Artist")==0 ){
148 if(strcmp(node2->name,
"string") == 0){
149 artname = strdup(node2->children->content);
153 if(strcmp((
char *) node->children->content,
"Play Count")==0 ){
154 if(strcmp(node2->name,
"integer") == 0){
155 count = strdup(node2->children->content);
159 if(strcmp((
char *) node->children->content,
"Rating")==0 ){
160 if(strcmp(node2->name,
"integer") == 0){
161 rating = strdup(node2->children->content);
166 if(rating != NULL && artname != NULL && albname != NULL && songname != NULL ){
168 if(count == NULL){ count = strdup(
"0"); }
194 xmlXPathFreeObject (xmlobject);
195 xmlXPathFreeContext (xmlperms_context);
214 mysql=mysql_init(NULL);
218 printf(
"Error : No such file to analyse, %s or iTunes Music Library.xml not found.\n\n", argv[0]);
222 file=strdup(argv[i]);
225 file=strdup(
"iTunes Music Library.xml");
232 printf(
"Error : You must specify the MySQL password.\n");
236 pass=strdup(argv[i]);
242 printf(
"* No user given in argument, root will be used.\n");
245 user=strdup(argv[i]);
251 printf(
"* No dbname given in argument, mythconverg will be used.\n");
252 dbname=strdup(
"mythconverg");
254 dbname=strdup(argv[i]);
261 printf(
"* No port given in argument, 3306 will be used.\n");
267 printf(
" Itunes Music File: %s \n Password: %s \n User: %s \n dbname: %s \n port: %d \n", file, pass, user, dbname, port);
271 if (!mysql_real_connect(
mysql,
"localhost",user,pass,dbname,port,NULL,0)) {
272 printf(
"Connection error : %s \n", mysql_error(
mysql) );
275 printf(
"MySQL aviable ...\n");
279 xmlDocPtr xmldoc = NULL;
280 xmldoc = xmlParseFile (file);
282 printf(
"%s isn't an XML file.\n",file);