[Schmitzm-commits] r2366 - in trunk: schmitzm-core/src/test/java/de/schmitzm/lang schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Jul 19 15:23:06 CEST 2013
Author: mojays
Date: 2013-07-19 15:23:06 +0200 (Fri, 19 Jul 2013)
New Revision: 2366
Modified:
trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
Log:
ID3TagUtil: method to clean artist name
Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java 2013-07-19 11:04:44 UTC (rev 2365)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java 2013-07-19 13:23:06 UTC (rev 2366)
@@ -257,7 +257,7 @@
@Ignore
@Test
- public void testRegex() {
+ public void testRegexGenre() {
final String[] text = new String[] { "(18)Industrial", "(18)", "(18) ","Industrial","(18)Industrial(19)","()Industrial(19)" };
final Pattern p = Pattern.compile("(\\(([\\d]+)\\))?(.*)");
@@ -272,4 +272,22 @@
}
}
+
+ @Ignore
+ @Test
+ public void testRegexArtist() {
+ final String[] text = new String[] { "Depeche Mode", "Depeche Mode(18)", "Depeche Mode (18) ","18","(18)Industrial(19)", "Depeche Mode (2-18) " };
+ final Pattern p = Pattern.compile("([^\\(\\)]*)(\\(([\\d\\-]+)\\))?");
+
+ for (String t : text) {
+ System.out.println("=== '"+t+"' ===");
+ Matcher m = p.matcher(t);
+ if ( m.find() ) {
+ for (int i=1; i<=m.groupCount(); i++)
+ System.out.println("Group "+i+": '"+m.group(i)+"'");
+ }
+ System.out.println();
+ }
+
+ }
}
\ No newline at end of file
Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java 2013-07-19 11:04:44 UTC (rev 2365)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java 2013-07-19 13:23:06 UTC (rev 2366)
@@ -78,6 +78,12 @@
*/
public static final Pattern GENRE_PATTERN = Pattern.compile("(\\(([\\d]+)\\))?(.*)");
+ /**
+ * In very old ID3TagEdit version (with only ID3v1.0) the track number was
+ * stored in brackets after artist name. This pattern can be
+ * used to parse the artist name and track number from combined string.
+ */
+ public static final Pattern ARTIST_PATTERN = Pattern.compile("([^\\(\\)]*)(\\(([\\d\\-]+)\\))?");
/** Contains all available ID3 v1 genres as array. */
public static final Genre[] ALL_GENRE_ID3V1;
@@ -251,6 +257,27 @@
/**
+ * Eliminate possible track number from artist name (used in ID3v1.0 in very old
+ * ID3TagEdit version).
+ * @param artistName artist name
+ */
+ public static String cleanArtistName(String artistNameStr) {
+ if ( StringUtils.isBlank(artistNameStr) )
+ return null;
+
+ Matcher m = ARTIST_PATTERN.matcher(artistNameStr);
+ if ( !m.find() )
+ return artistNameStr;
+
+ String artistName = StringUtils.trimToNull(m.group(1));
+ String trackNo = StringUtils.trimToEmpty(m.group(3));
+
+ return artistName;
+ }
+
+
+
+ /**
* Returns the year from {@link ID3V2Tag}.
* @return {@code null} if there is no such information (instead of
* {@link ID3Exception})
More information about the Schmitzm-commits
mailing list