Merge pull request #971 from lrusso96/patch-1
[YouTube] Improve duration parsing
This commit is contained in:
commit
2211a24b69
|
@ -316,38 +316,16 @@ public final class YoutubeParsingHelper {
|
||||||
? input.split(":")
|
? input.split(":")
|
||||||
: input.split("\\.");
|
: input.split("\\.");
|
||||||
|
|
||||||
String days = "0";
|
final int[] units = {24, 60, 60, 1};
|
||||||
String hours = "0";
|
final int offset = units.length - splitInput.length;
|
||||||
String minutes = "0";
|
if (offset < 0) {
|
||||||
final String seconds;
|
throw new ParsingException("Error duration string with unknown format: " + input);
|
||||||
|
|
||||||
switch (splitInput.length) {
|
|
||||||
case 4:
|
|
||||||
days = splitInput[0];
|
|
||||||
hours = splitInput[1];
|
|
||||||
minutes = splitInput[2];
|
|
||||||
seconds = splitInput[3];
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
hours = splitInput[0];
|
|
||||||
minutes = splitInput[1];
|
|
||||||
seconds = splitInput[2];
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
minutes = splitInput[0];
|
|
||||||
seconds = splitInput[1];
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
seconds = splitInput[0];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ParsingException("Error duration string with unknown format: " + input);
|
|
||||||
}
|
}
|
||||||
|
int duration = 0;
|
||||||
return ((convertDurationToInt(days) * 24
|
for (int i = 0; i < splitInput.length; i++) {
|
||||||
+ convertDurationToInt(hours)) * 60
|
duration = units[i + offset] * (duration + convertDurationToInt(splitInput[i]));
|
||||||
+ convertDurationToInt(minutes)) * 60
|
}
|
||||||
+ convertDurationToInt(seconds);
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue