[xiph-commits] r13544 - in trunk/ezstream: doc src

moritz at svn.xiph.org moritz at svn.xiph.org
Mon Aug 13 20:43:35 PDT 2007


Author: moritz
Date: 2007-08-13 20:43:35 -0700 (Mon, 13 Aug 2007)
New Revision: 13544

Modified:
   trunk/ezstream/doc/ezstream.1.in
   trunk/ezstream/src/ezstream.c
   trunk/ezstream/src/metadata.c
   trunk/ezstream/src/metadata.h
Log:
Ticket #1225, reported by matpoc at lenta dot ru: Looks like there's demand
for normalizing metadata strings, which -- I assume -- is due to strange
(MP3) encoders that do weird things. Well, why not. It's not too intrusive,
and disabled by default. Enable string normalization with the new -n command
line parameter.


Modified: trunk/ezstream/doc/ezstream.1.in
===================================================================
--- trunk/ezstream/doc/ezstream.1.in	2007-08-14 03:33:12 UTC (rev 13543)
+++ trunk/ezstream/doc/ezstream.1.in	2007-08-14 03:43:35 UTC (rev 13544)
@@ -12,7 +12,7 @@
 .Sh SYNOPSIS
 .Nm
 .Bk -words
-.Op Fl hqVv
+.Op Fl hnqVv
 .Op Fl c Ar configfile
 .Ek
 .Sh DESCRIPTION
@@ -36,6 +36,8 @@
 .It Fl h
 Print a summary of available command line parameters with short descriptions
 and exit.
+.It Fl n
+Normalize metadata strings by removing excess whitespaces.
 .It Fl q
 Be more quiet.
 Suppress the output that external programs send to standard error.

Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c	2007-08-14 03:33:12 UTC (rev 13543)
+++ trunk/ezstream/src/ezstream.c	2007-08-14 03:43:35 UTC (rev 13544)
@@ -74,6 +74,7 @@
 char			*__progname;
 #endif /* HAVE___PROGNAME */
 
+int			 nFlag;
 int			 qFlag;
 int			 vFlag;
 int			 metadataFromProgram;
@@ -445,7 +446,7 @@
 	metadata_t	*mdata;
 
 	if (metadataFromProgram) {
-		if ((mdata = metadata_program(fileName)) == NULL)
+		if ((mdata = metadata_program(fileName, nFlag)) == NULL)
 			return (NULL);
 
 		if (!metadata_program_update(mdata, METADATA_ALL)) {
@@ -453,7 +454,7 @@
 			return (NULL);
 		}
 	} else {
-		if ((mdata = metadata_file(fileName)) == NULL)
+		if ((mdata = metadata_file(fileName, nFlag)) == NULL)
 			return (NULL);
 
 		if (!metadata_file_update(mdata)) {
@@ -1018,7 +1019,7 @@
 void
 usage(void)
 {
-	printf("usage: %s [-hqVv] [-c configfile]\n", __progname);
+	printf("usage: %s [-hnqVv] [-c configfile]\n", __progname);
 }
 
 void
@@ -1027,6 +1028,7 @@
 	printf("\n");
 	printf("  -c configfile  use XML configuration in configfile\n");
 	printf("  -h             display this additional help and exit\n");
+	printf("  -n             normalize metadata strings\n");
 	printf("  -q             suppress STDERR output from external en-/decoders\n");
 	printf("  -V             print the version number and exit\n");
 	printf("  -v             verbose output (use twice for more effect)\n");
@@ -1061,10 +1063,11 @@
 	__progname = getProgname(argv[0]);
 	pezConfig = getEZConfig();
 
+	nFlag = 0;
 	qFlag = 0;
 	vFlag = 0;
 
-	while ((c = getopt(argc, argv, "c:hqVv")) != -1) {
+	while ((c = getopt(argc, argv, "c:hnqVv")) != -1) {
 		switch (c) {
 		case 'c':
 			if (configFile != NULL) {
@@ -1078,6 +1081,9 @@
 			usage();
 			usageHelp();
 			return (ez_shutdown(0));
+		case 'n':
+			nFlag = 1;
+			break;
 		case 'q':
 			qFlag = 1;
 			break;

Modified: trunk/ezstream/src/metadata.c
===================================================================
--- trunk/ezstream/src/metadata.c	2007-08-14 03:33:12 UTC (rev 13543)
+++ trunk/ezstream/src/metadata.c	2007-08-14 03:43:35 UTC (rev 13544)
@@ -54,6 +54,7 @@
 	char	*artist;
 	char	*title;
 	int	 songLen;
+	int	 normalize;
 	int	 program;
 };
 
@@ -74,6 +75,7 @@
 void		metadata_get_extension(char *, size_t, const char *);
 char *		metadata_get_name(const char *);
 void		metadata_process_md(metadata_t *);
+void		metadata_normalize_string(char **);
 
 metadata_t *
 metadata_create(const char *filename)
@@ -324,10 +326,47 @@
 
 	if (md->string == NULL)
 		md->string = metadata_assemble_string(md);
+
+	if (md->normalize) {
+		metadata_normalize_string(&md->string);
+		metadata_normalize_string(&md->artist);
+		metadata_normalize_string(&md->title);
+	}
 }
 
+void
+metadata_normalize_string(char **s)
+{
+	char	*str, *cp, *tmpstr, *tp;
+	int	 is_space;
+
+	if (s == NULL || (str = *s) == NULL || strlen(str) == 0)
+		return;
+
+	tmpstr = xcalloc(strlen(str) + 1, sizeof(char));
+
+	tp = tmpstr;
+	is_space = 1;
+	for (cp = str; *cp != '\0'; cp++) {
+		if (*cp == ' ') {
+			if (!is_space && strlen(tmpstr) > 0 &&
+			    tmpstr[strlen(tmpstr) - 1] != ' ')
+				*tp++ = ' ';
+			is_space = 1;
+		} else {
+			*tp++ = *cp;
+			is_space = 0;
+		}
+	}
+	if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr) - 1] == ' ')
+		tmpstr[strlen(tmpstr) - 1] = '\0';
+
+	xfree(str);
+	*s = xrealloc(tmpstr, strlen(tmpstr) + 1, sizeof (char));
+}
+
 metadata_t *
-metadata_file(const char *filename)
+metadata_file(const char *filename, int normalize)
 {
 	metadata_t	*md;
 
@@ -343,11 +382,13 @@
 		return (NULL);
 	}
 
+	md->normalize = normalize;
+
 	return (md);
 }
 
 metadata_t *
-metadata_program(const char *program)
+metadata_program(const char *program, int normalize)
 {
 	metadata_t	*md;
 #ifdef HAVE_STAT
@@ -392,6 +433,8 @@
 	fclose(filep);
 #endif /* HAVE_STAT */
 
+	md->normalize = normalize;
+
 	return (md);
 }
 
@@ -560,6 +603,12 @@
 		abort();
 	}
 
+	if (md->normalize) {
+		metadata_normalize_string(&md->string);
+		metadata_normalize_string(&md->artist);
+		metadata_normalize_string(&md->title);
+	}
+
 	return (1);
 }
 

Modified: trunk/ezstream/src/metadata.h
===================================================================
--- trunk/ezstream/src/metadata.h	2007-08-14 03:33:12 UTC (rev 13543)
+++ trunk/ezstream/src/metadata.h	2007-08-14 03:43:35 UTC (rev 13544)
@@ -33,7 +33,8 @@
  * success, or NULL on failure. The returned handle is "branded" for reading
  * metadata from media files.
  */
-metadata_t *	metadata_file(const char * /* filename */);
+metadata_t *	metadata_file(const char * /* filename */,
+			      int /* normalize strings */);
 
 /*
  * Create a metadata handle that is "branded" for acquiring metadata from an
@@ -52,7 +53,8 @@
  *     metadata, or an empty string if no artist information is available.
  *   - Return at most METADATA_MAX characters, or the result will be truncated.
  */
-metadata_t *	metadata_program(const char * /* program name */);
+metadata_t *	metadata_program(const char * /* program name */,
+				 int /* normalize strings */);
 
 /*
  * Free all memory used by a metadata handle that has been created with



More information about the commits mailing list