File tree Expand file tree Collapse file tree 1 file changed +10
-32
lines changed
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube Expand file tree Collapse file tree 1 file changed +10
-32
lines changed Original file line number Diff line number Diff line change @@ -316,38 +316,16 @@ public static int parseDurationString(@Nonnull final String input)
316316 ? input .split (":" )
317317 : input .split ("\\ ." );
318318
319- String days = "0" ;
320- String hours = "0" ;
321- String minutes = "0" ;
322- final String seconds ;
323-
324- switch (splitInput .length ) {
325- case 4 :
326- days = splitInput [0 ];
327- hours = splitInput [1 ];
328- minutes = splitInput [2 ];
329- seconds = splitInput [3 ];
330- break ;
331- case 3 :
332- hours = splitInput [0 ];
333- minutes = splitInput [1 ];
334- seconds = splitInput [2 ];
335- break ;
336- case 2 :
337- minutes = splitInput [0 ];
338- seconds = splitInput [1 ];
339- break ;
340- case 1 :
341- seconds = splitInput [0 ];
342- break ;
343- default :
344- throw new ParsingException ("Error duration string with unknown format: " + input );
345- }
346-
347- return ((convertDurationToInt (days ) * 24
348- + convertDurationToInt (hours )) * 60
349- + convertDurationToInt (minutes )) * 60
350- + convertDurationToInt (seconds );
319+ final int [] units = {24 , 60 , 60 , 1 };
320+ final int offset = units .length - splitInput .length ;
321+ if (offset < 0 ) {
322+ throw new ParsingException ("Error duration string with unknown format: " + input );
323+ }
324+ int duration = 0 ;
325+ for (int i = 0 ; i < splitInput .length ; i ++) {
326+ duration = units [i + offset ] * (duration + convertDurationToInt (splitInput [i ]));
327+ }
328+ return duration ;
351329 }
352330
353331 /**
You can’t perform that action at this time.
0 commit comments