From b6bb20380fe2ab87d0e1415cd02bf3f6f3f14196 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 19 Jan 2014 13:32:49 -0800 Subject: #253 Try to base query off of tags --- src/github/daneren2005/dsub/util/Util.java | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 05267699..e944f125 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -421,7 +421,14 @@ public final class Util { } public static String parseOfflineIDSearch(Context context, String id, String cacheLocation) { - String name = id.replace(cacheLocation, ""); + // Try to get this info based off of tags first + String name = parseOfflineIDSearch(id); + if(name != null) { + return name; + } + + // Otherwise go nuts trying to parse from file structure + name = id.replace(cacheLocation, ""); if(name.startsWith("/")) { name = name.substring(1); } @@ -458,6 +465,31 @@ public final class Util { return name; } + public static String parseOfflineIDSearch(String id) { + MusicDirectory.Entry entry = new MusicDirectory.Entry(); + File file = new File(id); + + if(file.exists()) { + entry.loadMetadata(file); + + if(entry.getArtist() != null) { + String title = file.getName(); + int index = title.lastIndexOf("."); + title = index == -1 ? title : title.substring(0, index); + title = title.substring(title.indexOf('-') + 1); + + String query = "artist:\"" + entry.getArtist() + "\"" + + " AND title:\"" + title + "\""; + + return query; + } else { + return null; + } + } else { + return null; + } + } + public static String getContentType(HttpEntity entity) { if (entity == null || entity.getContentType() == null) { return null; -- cgit v1.2.3