diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java index 0a28d70b8..c5f6edcf7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java @@ -2,9 +2,6 @@ package org.schabi.newpipe.extractor.localization; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; @@ -14,6 +11,9 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + public class Localization implements Serializable { public static final Localization DEFAULT = new Localization("en", "GB"); @@ -38,19 +38,7 @@ public class Localization implements Serializable { * @param localizationCode a localization code, formatted like {@link #getLocalizationCode()} */ public static Localization fromLocalizationCode(final String localizationCode) { - final int indexSeparator = localizationCode.indexOf("-"); - - final String languageCode; - final String countryCode; - if (indexSeparator != -1) { - languageCode = localizationCode.substring(0, indexSeparator); - countryCode = localizationCode.substring(indexSeparator + 1); - } else { - languageCode = localizationCode; - countryCode = null; - } - - return new Localization(languageCode, countryCode); + return fromLocale(Locale.forLanguageTag(localizationCode)); } public Localization(@Nonnull final String languageCode, @Nullable final String countryCode) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java index 778a85c93..f9ef1f5fd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/SubtitlesStream.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.extractor.stream; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; + import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.services.youtube.ItagItem; @@ -230,26 +232,7 @@ public final class SubtitlesStream extends Stream { final boolean autoGenerated, @Nullable final String manifestUrl) { super(id, content, isUrl, mediaFormat, deliveryMethod, manifestUrl); - - /* - * Locale.forLanguageTag only for Android API >= 21 - * Locale.Builder only for Android API >= 21 - * Country codes doesn't work well without - */ - final String[] splits = languageCode.split("-"); - switch (splits.length) { - case 2: - this.locale = new Locale(splits[0], splits[1]); - break; - case 3: - // Complex variants don't work! - this.locale = new Locale(splits[0], splits[1], splits[2]); - break; - default: - this.locale = new Locale(splits[0]); - break; - } - + this.locale = Locale.forLanguageTag(languageCode); this.code = languageCode; this.format = mediaFormat; this.autoGenerated = autoGenerated;