Merge pull request #1801 from mfietz/issue/1800-parse-duration

Parse iTunes duration seconds as float
This commit is contained in:
Tom Hennen 2016-03-22 17:26:56 -04:00
commit 35a3734da8
2 changed files with 10 additions and 9 deletions

View File

@ -61,26 +61,26 @@ public class NSITunes extends Namespace {
state.getFeed().setAuthor(author);
}
} else if (DURATION.equals(localName)) {
String duration = state.getContentBuf().toString();
if(TextUtils.isEmpty(duration)) {
String durationStr = state.getContentBuf().toString();
if(TextUtils.isEmpty(durationStr)) {
return;
}
String[] parts = duration.trim().split(":");
String[] parts = durationStr.trim().split(":");
try {
int durationMs = 0;
if (parts.length == 2) {
durationMs += TimeUnit.MINUTES.toMillis(Long.parseLong(parts[0])) +
TimeUnit.SECONDS.toMillis(Long.parseLong(parts[1]));
TimeUnit.SECONDS.toMillis((long)Float.parseFloat(parts[1]));
} else if (parts.length >= 3) {
durationMs += TimeUnit.HOURS.toMillis(Long.parseLong(parts[0])) +
TimeUnit.MINUTES.toMillis(Long.parseLong(parts[1])) +
TimeUnit.SECONDS.toMillis(Long.parseLong(parts[2]));
TimeUnit.SECONDS.toMillis((long)Float.parseFloat(parts[2]));
} else {
return;
}
state.getTempObjects().put(DURATION, durationMs);
} catch (NumberFormatException e) {
Log.e(NSTAG, Log.getStackTraceString(e));
Log.e(NSTAG, "Duration \"" + durationStr + "\" could not be parsed");
}
} else if (SUBTITLE.equals(localName)) {
String subtitle = state.getContentBuf().toString();

View File

@ -40,10 +40,11 @@ public class NSMedia extends Namespace {
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
url != null && validType) {
long size = 0;
String sizeStr = attributes.getValue(SIZE);
try {
size = Long.parseLong(attributes.getValue(SIZE));
size = Long.parseLong(sizeStr);
} catch (NumberFormatException e) {
Log.e(TAG, "Length attribute could not be parsed.");
Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
}
int durationMs = 0;
@ -53,7 +54,7 @@ public class NSMedia extends Namespace {
long duration = Long.parseLong(durationStr);
durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
} catch (NumberFormatException e) {
Log.e(TAG, "Duration attribute could not be parsed");
Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
}
}
FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);