Playlist.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package convert_rhythmbox_player_to_sandisk;
  2. // To get the playlist name and type from the file name
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5. public class Playlist {
  6. protected String filename; // full playlist filename
  7. protected String path; // directory that holds playlist
  8. protected String name; // e.g., Anime, Favorites, Rap
  9. protected String type; // rhythmbox or sandisk
  10. public Playlist(String filename, String path) {
  11. this.filename = filename;
  12. this.path = path;
  13. type = this.getPlaylistTypeFromFilename();
  14. name = this.getPlaylistNameFromFilename();
  15. }
  16. public String getName() { return name; }
  17. protected String getAbsolutePath() {
  18. return path + filename;
  19. }
  20. protected String getPlaylistTypeFromFilename() {
  21. // To determine the pattern to match
  22. Pattern playlistTypePattern = Pattern.compile("(rhythmbox|sandisk)");
  23. // To Find the match in the filename
  24. Matcher playlistTypeMatcher = playlistTypePattern.matcher(filename);
  25. // If matches are found return the first one; if not, return null.
  26. while ( playlistTypeMatcher.find() ) {
  27. return playlistTypeMatcher.group(1);
  28. }
  29. return null;
  30. }
  31. protected String getPlaylistNameFromFilename() {
  32. // To determine the pattern to match
  33. Pattern playlistNamePattern = Pattern.compile("(\\w+)_" + type + ".m3u");
  34. // To Find the match in the filename
  35. Matcher playlistNameMatcher = playlistNamePattern.matcher(filename);
  36. // If matches are found return the first one; if not, return null.
  37. while ( playlistNameMatcher.find() ) {
  38. return playlistNameMatcher.group(1);
  39. }
  40. return null;
  41. }
  42. }