Workaround for incorrect duration for "YT shorts" videos in channels
As a workaround 0 is returned as duration for such videos. See also https://github.com/TeamNewPipe/NewPipe/issues/8034
This commit is contained in:
parent
164e21b5af
commit
7598b40957
|
@ -219,10 +219,34 @@ public final class YoutubeParsingHelper {
|
|||
throw new ParsingException("Error duration string with unknown format: " + input);
|
||||
}
|
||||
|
||||
return ((Integer.parseInt(Utils.removeNonDigitCharacters(days)) * 24
|
||||
+ Integer.parseInt(Utils.removeNonDigitCharacters(hours))) * 60
|
||||
+ Integer.parseInt(Utils.removeNonDigitCharacters(minutes))) * 60
|
||||
+ Integer.parseInt(Utils.removeNonDigitCharacters(seconds));
|
||||
return ((convertDurationToInt(days) * 24
|
||||
+ convertDurationToInt(hours)) * 60
|
||||
+ convertDurationToInt(minutes)) * 60
|
||||
+ convertDurationToInt(seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to convert a duration string to an integer without throwing an exception.
|
||||
* <br/>
|
||||
* Helper method for {@link #parseDurationString(String)}.
|
||||
* <br/>
|
||||
* Note: This method is also used as a workaround for NewPipe#8034 (YT shorts no longer
|
||||
* display any duration in channels).
|
||||
*
|
||||
* @param input The string to process
|
||||
* @return The converted integer or 0 if the conversion failed.
|
||||
*/
|
||||
private static int convertDurationToInt(final String input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final String clearedInput = Utils.removeNonDigitCharacters(input);
|
||||
try {
|
||||
return Integer.parseInt(clearedInput);
|
||||
} catch (final NumberFormatException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -138,6 +138,11 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||
}
|
||||
}
|
||||
|
||||
// NewPipe#8034 - YT returns not a correct duration for "YT shorts" videos
|
||||
if ("SHORTS".equals(duration)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return YoutubeParsingHelper.parseDurationString(duration);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue