Throw ParsingException instead of IllegalArg

This commit is contained in:
Stypox 2024-03-29 13:41:23 +01:00
parent 7408173246
commit 23fc7aa209
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 9 additions and 12 deletions

View File

@ -131,7 +131,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
// Don't set the audio language in this case
if (language != null && !language.contains("-")) {
builder.setAudioLocale(LocaleCompat.forLanguageTag(language).orElseThrow(() ->
new ExtractionException(
new ParsingException(
"Cannot convert this language to a locale: " + language)
));
}

View File

@ -190,7 +190,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
try { // Premiered 20 hours ago
final TimeAgoParser timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(
Localization.fromLocalizationCode("en").get());
new Localization("en"));
final OffsetDateTime parsedTime = timeAgoParser.parse(time).offsetDateTime();
return DateTimeFormatter.ISO_LOCAL_DATE.format(parsedTime);
} catch (final Exception ignored) {
@ -1378,13 +1378,9 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final int audioTrackIdLastLocaleCharacter = audioTrackId.indexOf(".");
if (audioTrackIdLastLocaleCharacter != -1) {
// Audio tracks IDs are in the form LANGUAGE_CODE.TRACK_NUMBER
@Nullable final Locale locale =
LocaleCompat.forLanguageTag(
audioTrackId.substring(0, audioTrackIdLastLocaleCharacter
)).orElse(null);
if (locale != null) {
itagItem.setAudioLocale(locale);
}
LocaleCompat.forLanguageTag(
audioTrackId.substring(0, audioTrackIdLastLocaleCharacter)
).ifPresent(itagItem::setAudioLocale);
}
itagItem.setAudioTrackType(YoutubeParsingHelper.extractAudioTrackType(streamUrl));
}

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.extractor.stream;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
import org.schabi.newpipe.extractor.utils.LocaleCompat;
@ -170,7 +171,7 @@ public final class SubtitlesStream extends Stream {
* not set, or have been set as {@code null}
*/
@Nonnull
public SubtitlesStream build() {
public SubtitlesStream build() throws ParsingException {
if (content == null) {
throw new IllegalStateException("No valid content was specified. Please specify a "
+ "valid one with setContent.");
@ -229,10 +230,10 @@ public final class SubtitlesStream extends Stream {
@Nonnull final DeliveryMethod deliveryMethod,
@Nonnull final String languageCode,
final boolean autoGenerated,
@Nullable final String manifestUrl) {
@Nullable final String manifestUrl) throws ParsingException {
super(id, content, isUrl, mediaFormat, deliveryMethod, manifestUrl);
this.locale = LocaleCompat.forLanguageTag(languageCode).orElseThrow(
() -> new IllegalArgumentException(
() -> new ParsingException(
"not a valid locale language code: " + languageCode));
this.code = languageCode;
this.format = mediaFormat;