getLanguageInfo returns Locale instead of String

so that java can automatically translate with Locale.getDisplayLanguage(), instead of always having English name of the language
This commit is contained in:
B0pol 2020-01-25 13:16:42 +01:00
parent 341372c0d0
commit e392b6c68f
7 changed files with 33 additions and 16 deletions

View File

@ -18,6 +18,7 @@ import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class MediaCCCStreamExtractor extends StreamExtractor {
@ -248,8 +249,8 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
}
@Override
public String getLanguageInfo() throws ParsingException {
return "";
public Locale getLanguageInfo() throws ParsingException {
return null;
}
@Nonnull

View File

@ -6,6 +6,7 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.MediaFormat;
@ -391,7 +392,11 @@ public class PeertubeStreamExtractor extends StreamExtractor {
}
@Override
public String getLanguageInfo() throws ParsingException {
return JsonUtils.getString(json, "language.label");
public Locale getLanguageInfo() throws ParsingException {
try {
return new Locale(JsonUtils.getString(json, "language.id"));
} catch (ParsingException e) {
return null;
}
}
}

View File

@ -20,6 +20,7 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class SoundcloudStreamExtractor extends StreamExtractor {
private JsonObject track;
@ -276,8 +277,8 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
}
@Override
public String getLanguageInfo() throws ParsingException {
return "";
public Locale getLanguageInfo() throws ParsingException {
return null;
}
@Nonnull

View File

@ -1157,8 +1157,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
}
@Override
public String getLanguageInfo() throws ParsingException {
return "";
public Locale getLanguageInfo() throws ParsingException {
return null;
}
@Nonnull

View File

@ -35,6 +35,7 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
/**
* Scrapes information from a video/audio streaming service (eg, YouTube).
@ -390,13 +391,15 @@ public abstract class StreamExtractor extends Extractor {
public abstract String getLicence() throws ParsingException;
/**
* The language of the stream.
* If the language is not available you can simply return an empty string.
* @return the licence of the stream or an empty String.
* The locale language of the stream.
* If the language is not available you can simply return null.
* If the language is provided by a language code, you can return
* new Locale(language_code);
* @return the locale language of the stream or null.
* @throws ParsingException
*/
@Nonnull
public abstract String getLanguageInfo() throws ParsingException;
@Nullable
public abstract Locale getLanguageInfo() throws ParsingException;
/**
* The list of tags of the stream.

View File

@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/*
* Created by Christian Schabesberger on 26.08.15.
@ -349,8 +350,8 @@ public class StreamInfo extends Info {
private String privacy = "";
private String category = "";
private String licence = "";
private String language = "";
private String support = "";
private Locale language = null;
private List<String> tags = new ArrayList<>();
/**
@ -610,11 +611,11 @@ public class StreamInfo extends Info {
this.licence = str;
}
public String getLanguageInfo() {
public Locale getLanguageInfo() {
return this.language;
}
public void setLanguageInfo(String lang) {
public void setLanguageInfo(Locale lang) {
this.language = lang;
}

View File

@ -11,6 +11,7 @@ import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import org.junit.BeforeClass;
import org.junit.Ignore;
@ -154,4 +155,9 @@ public class PeertubeStreamExtractorDefaultTest {
supportInfoExtractor.fetchPage();
assertEquals("https://utip.io/chatsceptique", supportInfoExtractor.getSupportInfo());
}
@Test
public void testGetLanguageInformation() throws ParsingException {
assertEquals(new Locale("en"), extractor.getLanguageInfo());
}
}