Provide multiple phrases to parse each time unit using <plurals>.
This commit is contained in:
parent
9157f2d3f1
commit
3613072f38
|
@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
|||
import org.schabi.newpipe.extractor.stream.TimeAgoParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -39,7 +40,7 @@ import java.util.Map;
|
|||
|
||||
public class YoutubeService extends StreamingService {
|
||||
|
||||
private Map<TimeAgoParser.TimeAgoUnit, String[]> timeAgoParserPhrases;
|
||||
private Map<TimeAgoParser.TimeAgoUnit, Collection<String>> timeAgoParserPhrases;
|
||||
|
||||
public YoutubeService(int id, String name) {
|
||||
super(id, name);
|
||||
|
@ -109,7 +110,7 @@ public class YoutubeService extends StreamingService {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the phrases used to parse upload date in the format '2 days ago'.
|
||||
* Sets the phrases used to parse upload dates in the format '2 days ago'.
|
||||
* @param secondsPhrases How to recognize seconds
|
||||
* @param minutesPhrases How to recognize minutes
|
||||
* @param hoursPhrases How to recognize hours
|
||||
|
@ -118,10 +119,11 @@ public class YoutubeService extends StreamingService {
|
|||
* @param monthsPhrases How to recognize months
|
||||
* @param yearsPhrases How to recognize years
|
||||
*/
|
||||
public void setTimeAgoParserPhrases(String[] secondsPhrases, String[] minutesPhrases,
|
||||
String[] hoursPhrases, String[] daysPhrases,
|
||||
String[] weeksPhrases, String[] monthsPhrases,
|
||||
String[] yearsPhrases) {
|
||||
public void setTimeAgoParserPhrases(
|
||||
Collection<String> secondsPhrases, Collection<String> minutesPhrases,
|
||||
Collection<String> hoursPhrases, Collection<String> daysPhrases,
|
||||
Collection<String> weeksPhrases, Collection<String> monthsPhrases,
|
||||
Collection<String> yearsPhrases) {
|
||||
timeAgoParserPhrases = new EnumMap<>(TimeAgoParser.TimeAgoUnit.class);
|
||||
timeAgoParserPhrases.put(TimeAgoParser.TimeAgoUnit.SECONDS, secondsPhrases);
|
||||
timeAgoParserPhrases.put(TimeAgoParser.TimeAgoUnit.MINUTES, minutesPhrases);
|
||||
|
@ -130,7 +132,6 @@ public class YoutubeService extends StreamingService {
|
|||
timeAgoParserPhrases.put(TimeAgoParser.TimeAgoUnit.WEEKS, weeksPhrases);
|
||||
timeAgoParserPhrases.put(TimeAgoParser.TimeAgoUnit.MONTHS, monthsPhrases);
|
||||
timeAgoParserPhrases.put(TimeAgoParser.TimeAgoUnit.YEARS, yearsPhrases);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,8 @@ package org.schabi.newpipe.extractor.stream;
|
|||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -20,9 +22,10 @@ public class TimeAgoParser {
|
|||
* A set of english phrases that are contained in the time units.
|
||||
* (e.g. '7 minutes ago' contains 'min')
|
||||
*/
|
||||
public static Map<TimeAgoUnit, String[]> DEFAULT_AGO_PHRASES = new EnumMap<>(TimeAgoUnit.class);
|
||||
public static Map<TimeAgoUnit, Collection<String>> DEFAULT_AGO_PHRASES =
|
||||
new EnumMap<>(TimeAgoUnit.class);
|
||||
|
||||
private final Map<TimeAgoUnit, String[]> agoPhrases;
|
||||
private final Map<TimeAgoUnit, Collection<String>> agoPhrases;
|
||||
|
||||
private final Calendar consistentNow;
|
||||
|
||||
|
@ -33,7 +36,7 @@ public class TimeAgoParser {
|
|||
* </p>
|
||||
* @param agoPhrases A set of phrases how to recognize the time units in a given language.
|
||||
*/
|
||||
public TimeAgoParser(Map<TimeAgoUnit, String[]> agoPhrases) {
|
||||
public TimeAgoParser(Map<TimeAgoUnit, Collection<String>> agoPhrases) {
|
||||
this.agoPhrases = agoPhrases;
|
||||
consistentNow = Calendar.getInstance();
|
||||
}
|
||||
|
@ -130,13 +133,13 @@ public class TimeAgoParser {
|
|||
}
|
||||
|
||||
static {
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.SECONDS, new String[]{"sec"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.MINUTES, new String[]{"min"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.HOURS, new String[]{"hour"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.DAYS, new String[]{"day"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.WEEKS, new String[]{"week"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.MONTHS, new String[]{"month"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.YEARS, new String[]{"year"});
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.SECONDS, Collections.singleton("sec"));
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.MINUTES, Collections.singleton("min"));
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.HOURS, Collections.singleton("hour"));
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.DAYS, Collections.singleton("day"));
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.WEEKS, Collections.singleton("week"));
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.MONTHS, Collections.singleton("month"));
|
||||
DEFAULT_AGO_PHRASES.put(TimeAgoUnit.YEARS, Collections.singleton("year"));
|
||||
}
|
||||
|
||||
public enum TimeAgoUnit {
|
||||
|
|
Loading…
Reference in New Issue