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 // Don't set the audio language in this case
if (language != null && !language.contains("-")) { if (language != null && !language.contains("-")) {
builder.setAudioLocale(LocaleCompat.forLanguageTag(language).orElseThrow(() -> builder.setAudioLocale(LocaleCompat.forLanguageTag(language).orElseThrow(() ->
new ExtractionException( new ParsingException(
"Cannot convert this language to a locale: " + language) "Cannot convert this language to a locale: " + language)
)); ));
} }

View File

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

View File

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