Results 1 to 5 of 5
  1. #1
    Fittersman is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default reverse string split

    Hey, I'm trying to make an MP3 tagging program but I'm having trouble coming up with an efficient and clean way to code the following.

    Basically what I want to do is if users have an MP3 file called something like "/home/fittersman/Music/Albums/U2/[2009] No Line On The Horizon/06 - Get On Your Boots.mp3" I want the user to be able to give me the structure of this file, so for this example it would be "/home/fittersman/Music/Albums/<artist>/[<year>] <album>/<track#> - <title>.mp3", then the program would be able to retrieve the artist, year, album, track#, and title from the filename.

    I can do everything except the code that actually compares the two strings and gets the data from the filename.

    Does anyone know of a good library or something that can help me with this?

    Thanks for any help.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,237
    Rep Power
    19

    Default

    Pattern and Matcher. Search the net for a regex tutorial.

    db

  3. #3
    Fittersman is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default

    Thank you for the response. I read through a couple java tutorials on regex but I'm not sure it's really what I'm looking for.

    From what I've been reading about regular expressions they mostly seem to be useful when you know what you are looking for. In my case, I have no idea what I'm looking for. All I know is what will be separating the strings I want.

    The way I'm understanding regular expressions, I would still need to have quite a large amount of if statements and possibly while loops so I would be able to tell which string I'm working with is for which MP3 property (because users are not always going to put the tags, enclosed in <>, in the same order).

    What I was more looking for was a library that would allow me to do something like this...

    Java Code:
      
    String structure = //user input, something like "/home/fittersman/Music/Albums/<artist>/[<year>] <album>/<track#> - <title>.mp3"
    structure = structure.replaceAll("<artist>", "$1");
    structure = structure.replaceAll("<title>", "$2");
    structure = structure.replaceAll("<year>", "$3");
    structure = structure.replaceAll("<album>", "$4");
    structure = structure.replaceAll("<track#>", "$5");
    structure = structure.replaceAll("<number>", "$6");
    This would result in a string such as "/home/fittersman/Music/Albums/$1/[$3] $4/$5 - $2.mp3" for structure.

    Then I could call the function against the filename of the MP3. (GETVALUES is the made-up function I'm looking for.)

    Java Code:
    String filename = MP3file.getfilename();
    VALUES = filename.GETVALUES(structure);
    Then I could just get the tags using the retrieved values:

    Java Code:
    String songArtist = VALUES.get($1);
    String songTitle = VALUES.get($2);
    String songYear = VALUES.get($3);
    //etc...
    Anyone know anything like this? I just feel like there is already a function that does something like this.

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    Can u use metadata from those mp3 files for this purpose?

    If answer is YES,
    this is one of solutions for you:

    ---

    MyID3: a Java ID3 Tag Library

    Place myid3.jar and download and place jakarta-regexp-1.5.jar
    on classpath

    Try some code:

    Java Code:
    import java.io.File;
    import java.io.IOException;
    
    import org.cmc.music.common.ID3ReadException;
    import org.cmc.music.metadata.MusicMetadataSet;
    import org.cmc.music.myid3.MyID3;
    import org.cmc.music.util.Debug;
    
    public class Mp3 {
    
    	public static void main(String[] args) throws ID3ReadException, IOException {
    		
    		String filePath = "C:\\workspace\\Sve\\src\\mart08\\Madonna-Give.mp3";
    
    		File src = new File(filePath);
    		
    		MusicMetadataSet src_set = new MyID3().read(src); // read metadata
    
    		if (src_set == null) // perhaps no metadata
    			System.out.println("no meta data");
    			
    		Debug.debug("src_set", src_set); // dump all info.
    		
    		System.out.println( src_set.toString() );
    		
    		
    		
    	}
    }


    You can get tags inside like:

    Java Code:
    ...
    src_set {ID3TagSet. 
    v1_raw: {ID3Tag. values: { Album: Hard Candy, Artist: Madonna, Genre: Pop, Genre Id: 13, Title: Give It 2 Me, Track Number: 3, Track Number Numeric: 3, Year: 2008 } }
    v2_raw: {ID3Tag. values: { Album: Hard Candy, Artist: Madonna, Genre: Pop, Genre Id: 13, Title: Give It 2 Me, Track Number: 3, Track Number Numeric: 3, Year: 2008 } }...
    ---

    hope that can help...

  5. #5
    Fittersman is offline Member
    Join Date
    Mar 2010
    Posts
    3
    Rep Power
    0

    Default

    I cannot. What I'm trying to do is create the tags, so I have to assume the tags (or metadata as you call it) are blank.

Similar Threads

  1. reverse a string with a while loop...
    By OptimusPrime in forum New To Java
    Replies: 9
    Last Post: 12-28-2009, 11:06 PM
  2. How to split a String using split function
    By Java Tip in forum java.lang
    Replies: 4
    Last Post: 04-17-2009, 08:27 PM
  3. Reverse a string not using the substring method
    By kathyla18 in forum New To Java
    Replies: 17
    Last Post: 04-08-2009, 04:08 AM
  4. Reverse and Replace a String in Linear Time
    By colin.cruise in forum New To Java
    Replies: 5
    Last Post: 07-01-2008, 09:02 PM
  5. How to split a String using split function
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •