/recipes/xbmc/libcdio-0.81/libcdio-0.81-add-cdtextinfo.patch

https://github.com/SIFTeam/openembedded · Patch · 337 lines · 337 code · 0 blank · 0 comment · 0 complexity · 7d1dd4c24d38790636c3520033148b58 MD5 · raw file

  1. Index: libcdio-0.81/src/cdtextinfo.c
  2. ===================================================================
  3. --- libcdio-0.81/src/cdtextinfo.c
  4. +++ libcdio-0.81/src/cdtextinfo.c
  5. @@ -0,0 +1,372 @@
  6. +/*
  7. + This program is free software; you can redistribute it and/or modify
  8. + it under the terms of the GNU General Public License as published by
  9. + the Free Software Foundation; either version 2 of the License, or
  10. + (at your option) any later version.
  11. +
  12. + This program is distributed in the hope that it will be useful,
  13. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. + GNU General Public License for more details.
  16. +
  17. + You should have received a copy of the GNU General Public License
  18. + along with this program; if not, write to the Free Software
  19. + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. +
  21. + cdtextinfo, 2008-07-25 by fraxinas <andreas.frisch@multimedia-labs.de>
  22. +*/
  23. +
  24. +#include "config.h"
  25. +#include <stdio.h>
  26. +#include <stdlib.h>
  27. +#include <string.h>
  28. +#include <cddb/cddb.h>
  29. +#include <cdio/cdio.h>
  30. +#include <cdio/cdtext.h>
  31. +#include "cddb.h"
  32. +#include "getopt.h"
  33. +
  34. +struct opts_s
  35. +{
  36. + bool album;
  37. + bool listing;
  38. + bool cddb;
  39. + bool cdtext;
  40. + bool xml;
  41. +} options;
  42. +
  43. +/* Configuration option codes */
  44. +enum {
  45. + OP_HANDLED = 0,
  46. +
  47. + OP_CDDB_SERVER,
  48. + OP_CDDB_CACHE,
  49. + OP_CDDB_EMAIL,
  50. + OP_CDDB_NOCACHE,
  51. + OP_CDDB_TIMEOUT,
  52. +
  53. + OP_USAGE,
  54. +
  55. + /* These are the remaining configuration options */
  56. + OP_VERSION,
  57. +
  58. +};
  59. +
  60. +static bool parse_options (int argc, char *argv[])
  61. +{
  62. + int opt; /* used for argument parsing */
  63. +
  64. + const char* helpText =
  65. + "Usage: %s [OPTION...]\n"
  66. + " -a, --album Print audio CD album info\n"
  67. + " -l, --listing Print title info for all tracks\n"
  68. + " -T, --cdtext Use CD-Text\n"
  69. + " -D, --cddb Use CDDB\n"
  70. + " -x, --xml XML output\n"
  71. + "\n"
  72. + "CDDB options:\n"
  73. + " -P, --cddb-port=INT CDDB port number to use (default 8880)\n"
  74. + " --cddb-server=STRING CDDB server to contact for information\n"
  75. + " (default: freedb.freedb.org)\n"
  76. + " --cddb-cache=STRING Location of CDDB cache directory\n"
  77. + " (default ~/.cddbclient)\n"
  78. + " --cddb-email=STRING Email address to give CDDB server\n"
  79. + " (default me@dreambox)\n"
  80. + " --no-cddb-cache Disable caching of CDDB entries\n"
  81. + " locally (default caches)\n"
  82. + " --cddb-timeout=INT CDDB timeout value in seconds\n"
  83. + " (default 10 seconds)\n"
  84. + "\n"
  85. + "Help options:\n"
  86. + " -?, --help Show this help message\n"
  87. + " --usage Display brief usage message\n"
  88. + "\n"
  89. + "Example: %s -xalDT\n"
  90. + " Will query album info and track listing from both CD-Text and CDDB and display as XML\n";
  91. +
  92. + const char* usageText =
  93. + "Usage: %s [-a|--album] [-l|--listing]\n"
  94. + " [-T|--cdtext] [-D|--cddb] [-x|--xml]\n"
  95. + " [-P|--cddb-port INT] [--cddb-server=STRING]\n"
  96. + " [--cddb-cache=STRING] [--cddb-email=STRING]\n"
  97. + " [--no-cddb-cache] [--cddb-timeout=INT]\n"
  98. + " [-?|--help] [--usage]\n";
  99. +
  100. + const char* optionsString = "alTDP:x?";
  101. + struct option optionsTable[] = {
  102. + {"album", no_argument, NULL, 'a' },
  103. + {"listing", no_argument, NULL, 'l' },
  104. + {"cdtext", no_argument, NULL, 'T' },
  105. + {"cddb", no_argument, NULL, 'D' },
  106. + {"cddb-port", required_argument, NULL, 'P' },
  107. + {"cddb-server", required_argument, NULL, OP_CDDB_SERVER },
  108. + {"cddb-cache", required_argument, NULL, OP_CDDB_CACHE },
  109. + {"cddb-email", required_argument, NULL, OP_CDDB_EMAIL },
  110. + {"no-cddb-cache", no_argument, NULL, OP_CDDB_NOCACHE },
  111. + {"cddb-timeout", required_argument, NULL, OP_CDDB_TIMEOUT },
  112. + {"help", no_argument, NULL, '?' },
  113. + {"usage", no_argument, NULL, OP_USAGE },
  114. + { NULL, 0, NULL, 0 }
  115. + };
  116. +
  117. + while ((opt = getopt_long(argc, argv, optionsString, optionsTable, NULL)) >= 0) {
  118. + switch (opt) {
  119. + case 'a': options.album = true; break;
  120. + case 'l': options.listing = true; break;
  121. + case 'T': options.cdtext = true; break;
  122. + case 'D': options.cddb = true; break;
  123. + case 'x': options.xml = true; break;
  124. + case 'P': cddb_opts.port = atoi(optarg); break;
  125. + case OP_CDDB_SERVER: cddb_opts.server = strdup(optarg); break;
  126. + case OP_CDDB_CACHE: cddb_opts.cachedir = strdup(optarg); break;
  127. + case OP_CDDB_EMAIL: cddb_opts.email = strdup(optarg); break;
  128. + case OP_CDDB_NOCACHE: cddb_opts.disable_cache = 1; break;
  129. + case OP_CDDB_TIMEOUT: cddb_opts.timeout = atoi(optarg); break;
  130. + case '?':
  131. + fprintf(stdout, helpText, argv[0], argv[0]);
  132. + exit(0);
  133. + break;
  134. + case OP_USAGE:
  135. + fprintf(stderr, usageText, argv[0]);
  136. + exit(1);
  137. + break;
  138. + case 0:
  139. + break;
  140. + }
  141. + }
  142. + return true;
  143. +}
  144. +
  145. +static void cddb_errmsg(const char *msg)
  146. +{
  147. + if ( options.xml )
  148. + printf("<error msg=\"%s\" />\n", msg);
  149. + else
  150. + printf("%s\n", msg);
  151. +}
  152. +
  153. +int print_cddb_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track)
  154. +{
  155. + int i_cddb_matches = 0, i_cddb_currentmatch = 1;
  156. +
  157. + cddb_conn_t *p_conn = NULL;
  158. + cddb_disc_t *p_cddb_disc = NULL;
  159. +
  160. + if ( init_cddb(p_cdio, &p_conn, &p_cddb_disc, cddb_errmsg, i_first_track, i_tracks, &i_cddb_matches) )
  161. + {
  162. + while ( i_cddb_currentmatch <= i_cddb_matches )
  163. + {
  164. + cddb_read(p_conn, p_cddb_disc);
  165. +
  166. + if ( options.xml )
  167. + printf("\t<query source=\"CDDB\" match=\"%i\" num_matches=\"%i\">\n",i_cddb_currentmatch,i_cddb_matches);
  168. +
  169. + if (options.album)
  170. + {
  171. + if ( options.xml )
  172. + printf("\t\t<albuminfo>\n");
  173. +
  174. + if ( cddb_disc_get_title(p_cddb_disc) )
  175. + {
  176. + if ( options.xml )
  177. + printf("\t\t\t\t<title>%s</title>\n",cddb_disc_get_title(p_cddb_disc));
  178. + else
  179. + printf("TITLE:%s\n",cddb_disc_get_title(p_cddb_disc));
  180. + }
  181. + if ( cddb_disc_get_artist(p_cddb_disc) )
  182. + {
  183. + if ( options.xml )
  184. + printf("\t\t\t\t<artist>%s</artist>\n",cddb_disc_get_artist(p_cddb_disc));
  185. + else
  186. + printf("ARTIST:%s\n",cddb_disc_get_artist(p_cddb_disc));
  187. + }
  188. + if ( cddb_disc_get_genre(p_cddb_disc) )
  189. + {
  190. + if ( options.xml )
  191. + printf("\t\t\t\t<genre>%s</genre>\n",cddb_disc_get_genre(p_cddb_disc));
  192. + else
  193. + printf("GENRE:%s\n",cddb_disc_get_genre(p_cddb_disc));
  194. + }
  195. + if ( cddb_disc_get_category_str(p_cddb_disc) )
  196. + {
  197. + if ( options.xml )
  198. + printf("\t\t\t\t<category>%s</category>\n",cddb_disc_get_category_str(p_cddb_disc));
  199. + else
  200. + printf("CATEGORY:%s\n",cddb_disc_get_category_str(p_cddb_disc));
  201. + }
  202. + if ( cddb_disc_get_year(p_cddb_disc) )
  203. + {
  204. + if ( options.xml )
  205. + printf("\t\t\t\t<year>%i</year>\n",cddb_disc_get_year(p_cddb_disc));
  206. + else
  207. + printf("YEAR:%i\n",cddb_disc_get_year(p_cddb_disc));
  208. + }
  209. + if ( cddb_disc_get_ext_data(p_cddb_disc) )
  210. + {
  211. + if ( options.xml )
  212. + printf("\t\t\t\t<extra_data>%s</extra_data>\n",cddb_disc_get_ext_data(p_cddb_disc));
  213. + else
  214. + printf("EXTDATA:%s\n",cddb_disc_get_ext_data(p_cddb_disc));
  215. + }
  216. + if ( options.xml )
  217. + printf("\t\t</albuminfo>\n");
  218. + }
  219. + if (options.listing)
  220. + {
  221. + if ( options.xml )
  222. + printf("\t\t<tracklisting>\n");
  223. +
  224. + cddb_track_t *p_cddb_track = cddb_disc_get_track_first(p_cddb_disc);
  225. + while ( p_cddb_track != NULL )
  226. + {
  227. + if ( options.xml )
  228. + {
  229. + printf("\t\t\t\t<track number=\"%i\">\n",cddb_track_get_number(p_cddb_track));
  230. + if (cddb_track_get_length(p_cddb_track))
  231. + printf("\t\t\t\t\t\t<length>%i</length>\n",cddb_track_get_length(p_cddb_track));
  232. + if (cddb_track_get_title(p_cddb_track))
  233. + printf("\t\t\t\t\t\t<title>%s</title>\n",cddb_track_get_title(p_cddb_track));
  234. + if (cddb_track_get_artist(p_cddb_track))
  235. + printf("\t\t\t\t\t\t<artist>%s</artist>\n",cddb_track_get_artist(p_cddb_track));
  236. + if (cddb_track_get_ext_data(p_cddb_track))
  237. + printf("\t\t\t\t\t\t<extra_data>%s</extra_data>\n",cddb_track_get_ext_data(p_cddb_track));
  238. + printf("\t\t\t\t</track>\n");
  239. + }
  240. + else
  241. + printf("%i:%s\n",cddb_track_get_number(p_cddb_track),cddb_track_get_title(p_cddb_track));
  242. +
  243. + p_cddb_track = cddb_disc_get_track_next(p_cddb_disc);
  244. + }
  245. +
  246. + if ( options.xml )
  247. + printf("\t\t</tracklisting>\n");
  248. + }
  249. + if ( options.xml )
  250. + printf("\t</query>\n");
  251. +
  252. + cddb_query_next(p_conn, p_cddb_disc);
  253. + i_cddb_currentmatch++;
  254. + }
  255. + if ( i_cddb_currentmatch < 1 && options.xml )
  256. + printf("\t<query source=\"CDDB\" num_matches=\"%i\" />\n",i_cddb_matches);
  257. + }
  258. + cddb_disc_destroy(p_cddb_disc);
  259. + cddb_destroy(p_conn);
  260. + libcddb_shutdown();
  261. + return 0;
  262. +}
  263. +
  264. +int print_cdtext_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_track)
  265. +{
  266. + const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
  267. +
  268. + if ( cdtext == NULL || cdtext && !cdtext->field[9] )
  269. + {
  270. + if ( options.xml )
  271. + printf("\t<query source=\"CD-TEXT\" num_matches=\"0\" />\n");
  272. + return -1;
  273. + }
  274. +
  275. + if ( options.xml )
  276. + printf("\t<query source=\"CD-TEXT\" match=\"1\" num_matches=\"1\">\n");
  277. +
  278. + if ( options.album )
  279. + {
  280. + if ( options.xml )
  281. + printf("\t\t<albuminfo>\n");
  282. + cdtext_field_t i;
  283. + for (i=0; i < MAX_CDTEXT_FIELDS; i++)
  284. + {
  285. + if (cdtext->field[i])
  286. + {
  287. + if ( options.xml )
  288. + printf("\t\t\t\t<%s>%s</%s>\n",cdtext_field2str(i),cdtext->field[i],cdtext_field2str(i));
  289. + else
  290. + printf("%s:%s\n", cdtext_field2str(i), cdtext->field[i]);
  291. + }
  292. + }
  293. + if ( options.xml )
  294. + printf("\t\t</albuminfo>\n");
  295. + }
  296. +
  297. + if ( options.listing )
  298. + {
  299. + if ( options.xml )
  300. + printf("\t\t<tracklisting>\n");
  301. +
  302. + for ( ; i_track < i_tracks; i_track++ )
  303. + {
  304. + const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, i_track);
  305. + if (!cdtext)
  306. + continue;
  307. +
  308. + if ( options.xml )
  309. + {
  310. + printf("\t\t\t\t<track number=\"%i\">\n",i_track);
  311. +
  312. + cdtext_field_t i;
  313. + for (i=0; i < MAX_CDTEXT_FIELDS; i++)
  314. + {
  315. + if (cdtext->field[i])
  316. + {
  317. + if ( options.xml )
  318. + printf("\t\t\t\t\t\t<%s>%s</%s>\n",cdtext_field2str(i),cdtext->field[i],cdtext_field2str(i));
  319. + }
  320. + }
  321. + printf("\t\t\t\t</track>\n");
  322. + }
  323. +
  324. + else if (cdtext->field[9])
  325. + printf("%d:%s\n", i_track, cdtext->field[9]);
  326. + }
  327. +
  328. + if ( options.xml )
  329. + printf("\t\t</tracklisting>\n");
  330. + }
  331. +
  332. + if ( options.xml )
  333. + printf("\t</query>\n");
  334. +
  335. + return 0;
  336. +}
  337. +