Handle iTunes single-number duration format

Apple says this [1] about the `<itunes:duration>` tag:

    If you specify a single number as a value (without colons), Apple
    Podcasts displays the value as seconds.

This commit makes it also handle this single-number format.

Closes: #3024

[1]: https://help.apple.com/itc/podcasts_connect/#/itcb54353390
This commit is contained in:
Anderson Mesquita 2019-05-04 13:10:23 -04:00
parent 9b41139709
commit fb3bfa9f80
2 changed files with 10 additions and 1 deletions

View File

@ -8,7 +8,9 @@ public class DurationParser {
public static long inMillis(String durationStr) throws NumberFormatException {
String[] parts = durationStr.trim().split(":");
if (parts.length == 2) {
if (parts.length == 1) {
return toMillis(parts[0]);
} else if (parts.length == 2) {
return toMillis("0", parts[0], parts[1]);
} else if (parts.length == 3) {
return toMillis(parts[0], parts[1], parts[2]);

View File

@ -16,6 +16,13 @@ public class DurationParserTest {
assertEquals(45 * seconds, duration);
}
@Test
public void testSingleNumberDurationInMillis() {
int twoHoursInSeconds = 2 * 60 * 60;
long duration = DurationParser.inMillis(String.valueOf(twoHoursInSeconds));
assertEquals(2 * hours, duration);
}
@Test
public void testMinuteSecondDurationInMillis() {
long duration = DurationParser.inMillis("05:10");