Fix checkstyle issues in root package extractor/
Note: not all issues were fixed because MediaFormat and ServiceList use a specific formatting that makes sense for them
This commit is contained in:
parent
ca7c63f273
commit
d79e20340c
11 changed files with 191 additions and 138 deletions
|
@ -10,13 +10,15 @@ import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class Extractor {
|
public abstract class Extractor {
|
||||||
/**
|
/**
|
||||||
* {@link StreamingService} currently related to this extractor.<br>
|
* {@link StreamingService} currently related to this extractor.<br>
|
||||||
* Useful for getting other things from a service (like the url handlers for cleaning/accepting/get id from urls).
|
* Useful for getting other things from a service (like the url handlers for
|
||||||
|
* cleaning/accepting/get id from urls).
|
||||||
*/
|
*/
|
||||||
private final StreamingService service;
|
private final StreamingService service;
|
||||||
private final LinkHandler linkHandler;
|
private final LinkHandler linkHandler;
|
||||||
|
@ -27,16 +29,18 @@ public abstract class Extractor {
|
||||||
private ContentCountry forcedContentCountry = null;
|
private ContentCountry forcedContentCountry = null;
|
||||||
|
|
||||||
private boolean pageFetched = false;
|
private boolean pageFetched = false;
|
||||||
private final Downloader downloader;
|
// called like this to prevent checkstyle errors about "hiding a field"
|
||||||
|
private final Downloader theDownloader;
|
||||||
|
|
||||||
public Extractor(final StreamingService service, final LinkHandler linkHandler) {
|
public Extractor(final StreamingService service, final LinkHandler linkHandler) {
|
||||||
this.service = Objects.requireNonNull(service, "service is null");
|
this.service = Objects.requireNonNull(service, "service is null");
|
||||||
this.linkHandler = Objects.requireNonNull(linkHandler, "LinkHandler is null");
|
this.linkHandler = Objects.requireNonNull(linkHandler, "LinkHandler is null");
|
||||||
this.downloader = Objects.requireNonNull(NewPipe.getDownloader(), "downloader is null");
|
this.theDownloader = Objects.requireNonNull(NewPipe.getDownloader(), "downloader is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The {@link LinkHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler).
|
* @return The {@link LinkHandler} of the current extractor object (e.g. a ChannelExtractor
|
||||||
|
* should return a channel url handler).
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public LinkHandler getLinkHandler() {
|
public LinkHandler getLinkHandler() {
|
||||||
|
@ -50,13 +54,17 @@ public abstract class Extractor {
|
||||||
* @throws ExtractionException if the pages content is not understood
|
* @throws ExtractionException if the pages content is not understood
|
||||||
*/
|
*/
|
||||||
public void fetchPage() throws IOException, ExtractionException {
|
public void fetchPage() throws IOException, ExtractionException {
|
||||||
if (pageFetched) return;
|
if (pageFetched) {
|
||||||
onFetchPage(downloader);
|
return;
|
||||||
|
}
|
||||||
|
onFetchPage(theDownloader);
|
||||||
pageFetched = true;
|
pageFetched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertPageFetched() {
|
protected void assertPageFetched() {
|
||||||
if (!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
|
if (!pageFetched) {
|
||||||
|
throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isPageFetched() {
|
protected boolean isPageFetched() {
|
||||||
|
@ -66,11 +74,12 @@ public abstract class Extractor {
|
||||||
/**
|
/**
|
||||||
* Fetch the current page.
|
* Fetch the current page.
|
||||||
*
|
*
|
||||||
* @param downloader the download to use
|
* @param downloader the downloader to use
|
||||||
* @throws IOException if the page can not be loaded
|
* @throws IOException if the page can not be loaded
|
||||||
* @throws ExtractionException if the pages content is not understood
|
* @throws ExtractionException if the pages content is not understood
|
||||||
*/
|
*/
|
||||||
public abstract void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException;
|
public abstract void onFetchPage(@Nonnull Downloader downloader)
|
||||||
|
throws IOException, ExtractionException;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getId() throws ParsingException {
|
public String getId() throws ParsingException {
|
||||||
|
@ -111,18 +120,18 @@ public abstract class Extractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Downloader getDownloader() {
|
public Downloader getDownloader() {
|
||||||
return downloader;
|
return theDownloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Localization
|
// Localization
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public void forceLocalization(Localization localization) {
|
public void forceLocalization(final Localization localization) {
|
||||||
this.forcedLocalization = localization;
|
this.forcedLocalization = localization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forceContentCountry(ContentCountry contentCountry) {
|
public void forceContentCountry(final ContentCountry contentCountry) {
|
||||||
this.forcedContentCountry = contentCountry;
|
this.forcedContentCountry = contentCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +142,8 @@ public abstract class Extractor {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ContentCountry getExtractorContentCountry() {
|
public ContentCountry getExtractorContentCountry() {
|
||||||
return forcedContentCountry == null ? getService().getContentCountry() : forcedContentCountry;
|
return forcedContentCountry == null ? getService().getContentCountry()
|
||||||
|
: forcedContentCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
@ -17,7 +17,8 @@ public abstract class Info implements Serializable {
|
||||||
*/
|
*/
|
||||||
private final String id;
|
private final String id;
|
||||||
/**
|
/**
|
||||||
* Different than the {@link #originalUrl} in the sense that it <i>may</i> be set as a cleaned url.
|
* Different than the {@link #originalUrl} in the sense that it <i>may</i> be set as a cleaned
|
||||||
|
* url.
|
||||||
*
|
*
|
||||||
* @see LinkHandler#getUrl()
|
* @see LinkHandler#getUrl()
|
||||||
* @see Extractor#getOriginalUrl()
|
* @see Extractor#getOriginalUrl()
|
||||||
|
@ -33,15 +34,19 @@ public abstract class Info implements Serializable {
|
||||||
|
|
||||||
private final List<Throwable> errors = new ArrayList<>();
|
private final List<Throwable> errors = new ArrayList<>();
|
||||||
|
|
||||||
public void addError(Throwable throwable) {
|
public void addError(final Throwable throwable) {
|
||||||
this.errors.add(throwable);
|
this.errors.add(throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAllErrors(Collection<Throwable> errors) {
|
public void addAllErrors(final Collection<Throwable> throwables) {
|
||||||
this.errors.addAll(errors);
|
this.errors.addAll(throwables);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Info(int serviceId, String id, String url, String originalUrl, String name) {
|
public Info(final int serviceId,
|
||||||
|
final String id,
|
||||||
|
final String url,
|
||||||
|
final String originalUrl,
|
||||||
|
final String name) {
|
||||||
this.serviceId = serviceId;
|
this.serviceId = serviceId;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -49,7 +54,7 @@ public abstract class Info implements Serializable {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Info(int serviceId, LinkHandler linkHandler, String name) {
|
public Info(final int serviceId, final LinkHandler linkHandler, final String name) {
|
||||||
this(serviceId,
|
this(serviceId,
|
||||||
linkHandler.getId(),
|
linkHandler.getId(),
|
||||||
linkHandler.getUrl(),
|
linkHandler.getUrl(),
|
||||||
|
@ -59,14 +64,16 @@ public abstract class Info implements Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final String ifDifferentString = !url.equals(originalUrl) ? " (originalUrl=\"" + originalUrl + "\")" : "";
|
final String ifDifferentString
|
||||||
return getClass().getSimpleName() + "[url=\"" + url + "\"" + ifDifferentString + ", name=\"" + name + "\"]";
|
= url.equals(originalUrl) ? "" : " (originalUrl=\"" + originalUrl + "\")";
|
||||||
|
return getClass().getSimpleName() + "[url=\"" + url + "\"" + ifDifferentString
|
||||||
|
+ ", name=\"" + name + "\"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if you use an api and want to handle the website url
|
// if you use an api and want to handle the website url
|
||||||
// overriding original url is essential
|
// overriding original url is essential
|
||||||
public void setOriginalUrl(String url) {
|
public void setOriginalUrl(final String originalUrl) {
|
||||||
originalUrl = url;
|
this.originalUrl = originalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getServiceId() {
|
public int getServiceId() {
|
||||||
|
|
|
@ -29,7 +29,10 @@ public abstract class InfoItem implements Serializable {
|
||||||
private final String name;
|
private final String name;
|
||||||
private String thumbnailUrl;
|
private String thumbnailUrl;
|
||||||
|
|
||||||
public InfoItem(InfoType infoType, int serviceId, String url, String name) {
|
public InfoItem(final InfoType infoType,
|
||||||
|
final int serviceId,
|
||||||
|
final String url,
|
||||||
|
final String name) {
|
||||||
this.infoType = infoType;
|
this.infoType = infoType;
|
||||||
this.serviceId = serviceId;
|
this.serviceId = serviceId;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -52,7 +55,7 @@ public abstract class InfoItem implements Serializable {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThumbnailUrl(String thumbnailUrl) {
|
public void setThumbnailUrl(final String thumbnailUrl) {
|
||||||
this.thumbnailUrl = thumbnailUrl;
|
this.thumbnailUrl = thumbnailUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ import java.util.List;
|
||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemExtractor> implements Collector<I, E> {
|
public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemExtractor>
|
||||||
|
implements Collector<I, E> {
|
||||||
|
|
||||||
private final List<I> itemList = new ArrayList<>();
|
private final List<I> itemList = new ArrayList<>();
|
||||||
private final List<Throwable> errors = new ArrayList<>();
|
private final List<Throwable> errors = new ArrayList<>();
|
||||||
|
@ -77,7 +78,7 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
||||||
* Add an error
|
* Add an error
|
||||||
* @param error the error
|
* @param error the error
|
||||||
*/
|
*/
|
||||||
protected void addError(Exception error) {
|
protected void addError(final Exception error) {
|
||||||
errors.add(error);
|
errors.add(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
||||||
* Add an item
|
* Add an item
|
||||||
* @param item the item
|
* @param item the item
|
||||||
*/
|
*/
|
||||||
protected void addItem(I item) {
|
protected void addItem(final I item) {
|
||||||
itemList.add(item);
|
itemList.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +99,12 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commit(E extractor) {
|
public void commit(final E extractor) {
|
||||||
try {
|
try {
|
||||||
addItem(extract(extractor));
|
addItem(extract(extractor));
|
||||||
} catch (FoundAdException ae) {
|
} catch (final FoundAdException ae) {
|
||||||
// found an ad. Maybe a debug line could be placed here
|
// found an ad. Maybe a debug line could be placed here
|
||||||
} catch (ParsingException e) {
|
} catch (final ParsingException e) {
|
||||||
addError(e);
|
addError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class to extractors that have a list (e.g. playlists, users).
|
* Base class to extractors that have a list (e.g. playlists, users).
|
||||||
|
* @param <R> the info item type this list extractor provides
|
||||||
*/
|
*/
|
||||||
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +31,7 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
||||||
*/
|
*/
|
||||||
public static final long ITEM_COUNT_MORE_THAN_100 = -3;
|
public static final long ITEM_COUNT_MORE_THAN_100 = -3;
|
||||||
|
|
||||||
public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
public ListExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +51,9 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
||||||
* @return a {@link InfoItemsPage} corresponding to the requested page
|
* @return a {@link InfoItemsPage} corresponding to the requested page
|
||||||
* @see InfoItemsPage#getNextPage()
|
* @see InfoItemsPage#getNextPage()
|
||||||
*/
|
*/
|
||||||
public abstract InfoItemsPage<R> getPage(final Page page) throws IOException, ExtractionException;
|
public abstract InfoItemsPage<R> getPage(Page page) throws IOException, ExtractionException;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandler getLinkHandler() {
|
public ListLinkHandler getLinkHandler() {
|
||||||
return (ListLinkHandler) super.getLinkHandler();
|
return (ListLinkHandler) super.getLinkHandler();
|
||||||
|
@ -64,15 +66,17 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
||||||
/**
|
/**
|
||||||
* A class that is used to wrap a list of gathered items and eventual errors, it
|
* A class that is used to wrap a list of gathered items and eventual errors, it
|
||||||
* also contains a field that points to the next available page ({@link #nextPage}).
|
* also contains a field that points to the next available page ({@link #nextPage}).
|
||||||
|
* @param <T> the info item type that this page is supposed to store and provide
|
||||||
*/
|
*/
|
||||||
public static class InfoItemsPage<T extends InfoItem> {
|
public static class InfoItemsPage<T extends InfoItem> {
|
||||||
private static final InfoItemsPage<InfoItem> EMPTY =
|
private static final InfoItemsPage<InfoItem> EMPTY =
|
||||||
new InfoItemsPage<>(Collections.<InfoItem>emptyList(), null, Collections.<Throwable>emptyList());
|
new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenient method that returns a representation of an empty page.
|
* A convenient method that returns a representation of an empty page.
|
||||||
*
|
*
|
||||||
* @return a type-safe page with the list of items and errors empty and the nextPage set to {@code null}.
|
* @return a type-safe page with the list of items and errors empty and the nextPage set to
|
||||||
|
* {@code null}.
|
||||||
*/
|
*/
|
||||||
public static <T extends InfoItem> InfoItemsPage<T> emptyPage() {
|
public static <T extends InfoItem> InfoItemsPage<T> emptyPage() {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
|
@ -97,11 +101,13 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
||||||
*/
|
*/
|
||||||
private final List<Throwable> errors;
|
private final List<Throwable> errors;
|
||||||
|
|
||||||
public InfoItemsPage(InfoItemsCollector<T, ?> collector, Page nextPage) {
|
public InfoItemsPage(final InfoItemsCollector<T, ?> collector, final Page nextPage) {
|
||||||
this(collector.getItems(), nextPage, collector.getErrors());
|
this(collector.getItems(), nextPage, collector.getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InfoItemsPage(List<T> itemsList, Page nextPage, List<Throwable> errors) {
|
public InfoItemsPage(final List<T> itemsList,
|
||||||
|
final Page nextPage,
|
||||||
|
final List<Throwable> errors) {
|
||||||
this.itemsList = itemsList;
|
this.itemsList = itemsList;
|
||||||
this.nextPage = nextPage;
|
this.nextPage = nextPage;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
|
|
|
@ -10,19 +10,21 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
|
||||||
private final List<String> contentFilters;
|
private final List<String> contentFilters;
|
||||||
private final String sortFilter;
|
private final String sortFilter;
|
||||||
|
|
||||||
public ListInfo(int serviceId,
|
public ListInfo(final int serviceId,
|
||||||
String id,
|
final String id,
|
||||||
String url,
|
final String url,
|
||||||
String originalUrl,
|
final String originalUrl,
|
||||||
String name,
|
final String name,
|
||||||
List<String> contentFilter,
|
final List<String> contentFilter,
|
||||||
String sortFilter) {
|
final String sortFilter) {
|
||||||
super(serviceId, id, url, originalUrl, name);
|
super(serviceId, id, url, originalUrl, name);
|
||||||
this.contentFilters = contentFilter;
|
this.contentFilters = contentFilter;
|
||||||
this.sortFilter = sortFilter;
|
this.sortFilter = sortFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
|
public ListInfo(final int serviceId,
|
||||||
|
final ListLinkHandler listUrlIdHandler,
|
||||||
|
final String name) {
|
||||||
super(serviceId, listUrlIdHandler, name);
|
super(serviceId, listUrlIdHandler, name);
|
||||||
this.contentFilters = listUrlIdHandler.getContentFilters();
|
this.contentFilters = listUrlIdHandler.getContentFilters();
|
||||||
this.sortFilter = listUrlIdHandler.getSortFilter();
|
this.sortFilter = listUrlIdHandler.getSortFilter();
|
||||||
|
@ -32,7 +34,7 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
|
||||||
return relatedItems;
|
return relatedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRelatedItems(List<T> relatedItems) {
|
public void setRelatedItems(final List<T> relatedItems) {
|
||||||
this.relatedItems = relatedItems;
|
this.relatedItems = relatedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +46,7 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
|
||||||
return nextPage;
|
return nextPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextPage(Page page) {
|
public void setNextPage(final Page page) {
|
||||||
this.nextPage = page;
|
this.nextPage = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,32 +27,34 @@ package org.schabi.newpipe.extractor;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public enum MediaFormat {
|
public enum MediaFormat {
|
||||||
|
// @formatter:off
|
||||||
//video and audio combined formats
|
//video and audio combined formats
|
||||||
// id name suffix mime type
|
// id name suffix mimeType
|
||||||
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
||||||
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
|
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
|
||||||
WEBM (0x20, "WebM", "webm", "video/webm"),
|
WEBM (0x20, "WebM", "webm", "video/webm"),
|
||||||
// audio formats
|
// audio formats
|
||||||
M4A (0x100, "m4a", "m4a", "audio/mp4"),
|
M4A (0x100, "m4a", "m4a", "audio/mp4"),
|
||||||
WEBMA (0x200, "WebM", "webm", "audio/webm"),
|
WEBMA (0x200, "WebM", "webm", "audio/webm"),
|
||||||
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
|
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
|
||||||
OPUS (0x400, "opus", "opus", "audio/opus"),
|
OPUS (0x400, "opus", "opus", "audio/opus"),
|
||||||
OGG (0x500, "ogg", "ogg", "audio/ogg"),
|
OGG (0x500, "ogg", "ogg", "audio/ogg"),
|
||||||
WEBMA_OPUS (0x200, "WebM Opus", "webm", "audio/webm"),
|
WEBMA_OPUS(0x200, "WebM Opus", "webm", "audio/webm"),
|
||||||
// subtitles formats
|
// subtitles formats
|
||||||
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
|
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
|
||||||
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
|
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
|
||||||
TRANSCRIPT1 (0x3000, "TranScript v1", "srv1", "text/xml"),
|
TRANSCRIPT1(0x3000, "TranScript v1", "srv1", "text/xml"),
|
||||||
TRANSCRIPT2 (0x4000, "TranScript v2", "srv2", "text/xml"),
|
TRANSCRIPT2(0x4000, "TranScript v2", "srv2", "text/xml"),
|
||||||
TRANSCRIPT3 (0x5000, "TranScript v3", "srv3", "text/xml"),
|
TRANSCRIPT3(0x5000, "TranScript v3", "srv3", "text/xml"),
|
||||||
SRT (0x6000, "SubRip file format", "srt", "text/srt");
|
SRT (0x6000, "SubRip file format", "srt", "text/srt");
|
||||||
|
// @formatter:on
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String suffix;
|
public final String suffix;
|
||||||
public final String mimeType;
|
public final String mimeType;
|
||||||
|
|
||||||
MediaFormat(int id, String name, String suffix, String mimeType) {
|
MediaFormat(final int id, final String name, final String suffix, final String mimeType) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.suffix = suffix;
|
this.suffix = suffix;
|
||||||
|
|
|
@ -16,8 +16,10 @@ public class MetaInfo implements Serializable {
|
||||||
private List<URL> urls = new ArrayList<>();
|
private List<URL> urls = new ArrayList<>();
|
||||||
private List<String> urlTexts = new ArrayList<>();
|
private List<String> urlTexts = new ArrayList<>();
|
||||||
|
|
||||||
public MetaInfo(@Nonnull final String title, @Nonnull final Description content,
|
public MetaInfo(@Nonnull final String title,
|
||||||
@Nonnull final List<URL> urls, @Nonnull final List<String> urlTexts) {
|
@Nonnull final Description content,
|
||||||
|
@Nonnull final List<URL> urls,
|
||||||
|
@Nonnull final List<String> urlTexts) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.urls = urls;
|
this.urls = urls;
|
||||||
|
|
|
@ -32,7 +32,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* Provides access to streaming services supported by NewPipe.
|
* Provides access to streaming services supported by NewPipe.
|
||||||
*/
|
*/
|
||||||
public class NewPipe {
|
public final class NewPipe {
|
||||||
private static Downloader downloader;
|
private static Downloader downloader;
|
||||||
private static Localization preferredLocalization;
|
private static Localization preferredLocalization;
|
||||||
private static ContentCountry preferredContentCountry;
|
private static ContentCountry preferredContentCountry;
|
||||||
|
@ -40,19 +40,20 @@ public class NewPipe {
|
||||||
private NewPipe() {
|
private NewPipe() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(Downloader d) {
|
public static void init(final Downloader d) {
|
||||||
downloader = d;
|
downloader = d;
|
||||||
preferredLocalization = Localization.DEFAULT;
|
preferredLocalization = Localization.DEFAULT;
|
||||||
preferredContentCountry = ContentCountry.DEFAULT;
|
preferredContentCountry = ContentCountry.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(Downloader d, Localization l) {
|
public static void init(final Downloader d, final Localization l) {
|
||||||
downloader = d;
|
downloader = d;
|
||||||
preferredLocalization = l;
|
preferredLocalization = l;
|
||||||
preferredContentCountry = l.getCountryCode().isEmpty() ? ContentCountry.DEFAULT : new ContentCountry(l.getCountryCode());
|
preferredContentCountry = l.getCountryCode().isEmpty()
|
||||||
|
? ContentCountry.DEFAULT : new ContentCountry(l.getCountryCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(Downloader d, Localization l, ContentCountry c) {
|
public static void init(final Downloader d, final Localization l, final ContentCountry c) {
|
||||||
downloader = d;
|
downloader = d;
|
||||||
preferredLocalization = l;
|
preferredLocalization = l;
|
||||||
preferredContentCountry = c;
|
preferredContentCountry = c;
|
||||||
|
@ -88,8 +89,8 @@ public class NewPipe {
|
||||||
throw new ExtractionException("There's no service with the name = \"" + serviceName + "\"");
|
throw new ExtractionException("There's no service with the name = \"" + serviceName + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StreamingService getServiceByUrl(String url) throws ExtractionException {
|
public static StreamingService getServiceByUrl(final String url) throws ExtractionException {
|
||||||
for (StreamingService service : ServiceList.all()) {
|
for (final StreamingService service : ServiceList.all()) {
|
||||||
if (service.getLinkTypeByUrl(url) != StreamingService.LinkType.NONE) {
|
if (service.getLinkTypeByUrl(url) != StreamingService.LinkType.NONE) {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
@ -97,18 +98,18 @@ public class NewPipe {
|
||||||
throw new ExtractionException("No service can handle the url = \"" + url + "\"");
|
throw new ExtractionException("No service can handle the url = \"" + url + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getIdOfService(String serviceName) {
|
public static int getIdOfService(final String serviceName) {
|
||||||
try {
|
try {
|
||||||
return getService(serviceName).getServiceId();
|
return getService(serviceName).getServiceId();
|
||||||
} catch (ExtractionException ignored) {
|
} catch (final ExtractionException ignored) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNameOfService(int id) {
|
public static String getNameOfService(final int id) {
|
||||||
try {
|
try {
|
||||||
return getService(id).getServiceInfo().getName();
|
return getService(id).getServiceInfo().getName();
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
System.err.println("Service id not known");
|
System.err.println("Service id not known");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return "<unknown>";
|
return "<unknown>";
|
||||||
|
@ -119,19 +120,21 @@ public class NewPipe {
|
||||||
// Localization
|
// Localization
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public static void setupLocalization(Localization preferredLocalization) {
|
public static void setupLocalization(final Localization thePreferredLocalization) {
|
||||||
setupLocalization(preferredLocalization, null);
|
setupLocalization(thePreferredLocalization, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setupLocalization(Localization preferredLocalization, @Nullable ContentCountry preferredContentCountry) {
|
public static void setupLocalization(
|
||||||
NewPipe.preferredLocalization = preferredLocalization;
|
final Localization thePreferredLocalization,
|
||||||
|
@Nullable final ContentCountry thePreferredContentCountry) {
|
||||||
|
NewPipe.preferredLocalization = thePreferredLocalization;
|
||||||
|
|
||||||
if (preferredContentCountry != null) {
|
if (thePreferredContentCountry != null) {
|
||||||
NewPipe.preferredContentCountry = preferredContentCountry;
|
NewPipe.preferredContentCountry = thePreferredContentCountry;
|
||||||
} else {
|
} else {
|
||||||
NewPipe.preferredContentCountry = preferredLocalization.getCountryCode().isEmpty()
|
NewPipe.preferredContentCountry = thePreferredLocalization.getCountryCode().isEmpty()
|
||||||
? ContentCountry.DEFAULT
|
? ContentCountry.DEFAULT
|
||||||
: new ContentCountry(preferredLocalization.getCountryCode());
|
: new ContentCountry(thePreferredLocalization.getCountryCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +143,7 @@ public class NewPipe {
|
||||||
return preferredLocalization == null ? Localization.DEFAULT : preferredLocalization;
|
return preferredLocalization == null ? Localization.DEFAULT : preferredLocalization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPreferredLocalization(Localization preferredLocalization) {
|
public static void setPreferredLocalization(final Localization preferredLocalization) {
|
||||||
NewPipe.preferredLocalization = preferredLocalization;
|
NewPipe.preferredLocalization = preferredLocalization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +152,7 @@ public class NewPipe {
|
||||||
return preferredContentCountry == null ? ContentCountry.DEFAULT : preferredContentCountry;
|
return preferredContentCountry == null ? ContentCountry.DEFAULT : preferredContentCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPreferredContentCountry(ContentCountry preferredContentCountry) {
|
public static void setPreferredContentCountry(final ContentCountry preferredContentCountry) {
|
||||||
NewPipe.preferredContentCountry = preferredContentCountry;
|
NewPipe.preferredContentCountry = preferredContentCountry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,11 @@ public class Page implements Serializable {
|
||||||
@Nullable
|
@Nullable
|
||||||
private final byte[] body;
|
private final byte[] body;
|
||||||
|
|
||||||
public Page(final String url, final String id, final List<String> ids,
|
public Page(final String url,
|
||||||
final Map<String, String> cookies, @Nullable final byte[] body) {
|
final String id,
|
||||||
|
final List<String> ids,
|
||||||
|
final Map<String, String> cookies,
|
||||||
|
@Nullable final byte[] body) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.ids = ids;
|
this.ids = ids;
|
||||||
|
|
|
@ -6,7 +6,12 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.feed.FeedExtractor;
|
import org.schabi.newpipe.extractor.feed.FeedExtractor;
|
||||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.*;
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||||
import org.schabi.newpipe.extractor.localization.Localization;
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
|
@ -55,7 +60,7 @@ public abstract class StreamingService {
|
||||||
* @param name the name of the service
|
* @param name the name of the service
|
||||||
* @param mediaCapabilities the type of media this service can handle
|
* @param mediaCapabilities the type of media this service can handle
|
||||||
*/
|
*/
|
||||||
public ServiceInfo(String name, List<MediaCapability> mediaCapabilities) {
|
public ServiceInfo(final String name, final List<MediaCapability> mediaCapabilities) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.mediaCapabilities = Collections.unmodifiableList(mediaCapabilities);
|
this.mediaCapabilities = Collections.unmodifiableList(mediaCapabilities);
|
||||||
}
|
}
|
||||||
|
@ -74,8 +79,8 @@ public abstract class StreamingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LinkType will be used to determine which type of URL you are handling, and therefore which part
|
* LinkType will be used to determine which type of URL you are handling, and therefore which
|
||||||
* of NewPipe should handle a certain URL.
|
* part of NewPipe should handle a certain URL.
|
||||||
*/
|
*/
|
||||||
public enum LinkType {
|
public enum LinkType {
|
||||||
NONE,
|
NONE,
|
||||||
|
@ -90,14 +95,15 @@ public abstract class StreamingService {
|
||||||
/**
|
/**
|
||||||
* Creates a new Streaming service.
|
* Creates a new Streaming service.
|
||||||
* If you Implement one do not set id within your implementation of this extractor, instead
|
* If you Implement one do not set id within your implementation of this extractor, instead
|
||||||
* set the id when you put the extractor into
|
* set the id when you put the extractor into {@link ServiceList}
|
||||||
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/ServiceList.html">ServiceList</a>.
|
|
||||||
* All other parameters can be set directly from the overriding constructor.
|
* All other parameters can be set directly from the overriding constructor.
|
||||||
* @param id the number of the service to identify him within the NewPipe frontend
|
* @param id the number of the service to identify him within the NewPipe frontend
|
||||||
* @param name the name of the service
|
* @param name the name of the service
|
||||||
* @param capabilities the type of media this service can handle
|
* @param capabilities the type of media this service can handle
|
||||||
*/
|
*/
|
||||||
public StreamingService(int id, String name, List<ServiceInfo.MediaCapability> capabilities) {
|
public StreamingService(final int id,
|
||||||
|
final String name,
|
||||||
|
final List<ServiceInfo.MediaCapability> capabilities) {
|
||||||
this.serviceId = id;
|
this.serviceId = id;
|
||||||
this.serviceInfo = new ServiceInfo(name, capabilities);
|
this.serviceInfo = new ServiceInfo(name, capabilities);
|
||||||
}
|
}
|
||||||
|
@ -172,22 +178,21 @@ public abstract class StreamingService {
|
||||||
public abstract SubscriptionExtractor getSubscriptionExtractor();
|
public abstract SubscriptionExtractor getSubscriptionExtractor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method decides which strategy will be chosen to fetch the feed. In YouTube, for example, a separate feed
|
* This method decides which strategy will be chosen to fetch the feed. In YouTube, for example,
|
||||||
* exists which is lightweight and made specifically to be used like this.
|
* a separate feed exists which is lightweight and made specifically to be used like this.
|
||||||
* <p>
|
* <p>
|
||||||
* In services which there's no other way to retrieve them, null should be returned.
|
* In services which there's no other way to retrieve them, null should be returned.
|
||||||
*
|
*
|
||||||
* @return a {@link FeedExtractor} instance or null.
|
* @return a {@link FeedExtractor} instance or null.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public FeedExtractor getFeedExtractor(String url) throws ExtractionException {
|
public FeedExtractor getFeedExtractor(final String url) throws ExtractionException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must create a new instance of a KioskList implementation.
|
* Must create a new instance of a KioskList implementation.
|
||||||
* @return a new KioskList instance
|
* @return a new KioskList instance
|
||||||
* @throws ExtractionException
|
|
||||||
*/
|
*/
|
||||||
public abstract KioskList getKioskList() throws ExtractionException;
|
public abstract KioskList getKioskList() throws ExtractionException;
|
||||||
|
|
||||||
|
@ -195,49 +200,52 @@ public abstract class StreamingService {
|
||||||
* Must create a new instance of a ChannelExtractor implementation.
|
* Must create a new instance of a ChannelExtractor implementation.
|
||||||
* @param linkHandler is pointing to the channel which should be handled by this new instance.
|
* @param linkHandler is pointing to the channel which should be handled by this new instance.
|
||||||
* @return a new ChannelExtractor
|
* @return a new ChannelExtractor
|
||||||
* @throws ExtractionException
|
|
||||||
*/
|
*/
|
||||||
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) throws ExtractionException;
|
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler)
|
||||||
|
throws ExtractionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must crete a new instance of a PlaylistExtractor implementation.
|
* Must crete a new instance of a PlaylistExtractor implementation.
|
||||||
* @param linkHandler is pointing to the playlist which should be handled by this new instance.
|
* @param linkHandler is pointing to the playlist which should be handled by this new instance.
|
||||||
* @return a new PlaylistExtractor
|
* @return a new PlaylistExtractor
|
||||||
* @throws ExtractionException
|
|
||||||
*/
|
*/
|
||||||
public abstract PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) throws ExtractionException;
|
public abstract PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler)
|
||||||
|
throws ExtractionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must create a new instance of a StreamExtractor implementation.
|
* Must create a new instance of a StreamExtractor implementation.
|
||||||
* @param linkHandler is pointing to the stream which should be handled by this new instance.
|
* @param linkHandler is pointing to the stream which should be handled by this new instance.
|
||||||
* @return a new StreamExtractor
|
* @return a new StreamExtractor
|
||||||
* @throws ExtractionException
|
|
||||||
*/
|
*/
|
||||||
public abstract StreamExtractor getStreamExtractor(LinkHandler linkHandler) throws ExtractionException;
|
public abstract StreamExtractor getStreamExtractor(LinkHandler linkHandler)
|
||||||
|
throws ExtractionException;
|
||||||
|
|
||||||
public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler) throws ExtractionException;
|
public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
|
||||||
|
throws ExtractionException;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Extractors without link handler
|
// Extractors without link handler
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public SearchExtractor getSearchExtractor(String query,
|
public SearchExtractor getSearchExtractor(final String query,
|
||||||
List<String> contentFilter,
|
final List<String> contentFilter,
|
||||||
String sortFilter) throws ExtractionException {
|
final String sortFilter) throws ExtractionException {
|
||||||
return getSearchExtractor(getSearchQHFactory()
|
return getSearchExtractor(getSearchQHFactory()
|
||||||
.fromQuery(query, contentFilter, sortFilter));
|
.fromQuery(query, contentFilter, sortFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelExtractor getChannelExtractor(String id,
|
public ChannelExtractor getChannelExtractor(final String id,
|
||||||
List<String> contentFilter,
|
final List<String> contentFilter,
|
||||||
String sortFilter) throws ExtractionException {
|
final String sortFilter)
|
||||||
|
throws ExtractionException {
|
||||||
return getChannelExtractor(getChannelLHFactory()
|
return getChannelExtractor(getChannelLHFactory()
|
||||||
.fromQuery(id, contentFilter, sortFilter));
|
.fromQuery(id, contentFilter, sortFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaylistExtractor getPlaylistExtractor(String id,
|
public PlaylistExtractor getPlaylistExtractor(final String id,
|
||||||
List<String> contentFilter,
|
final List<String> contentFilter,
|
||||||
String sortFilter) throws ExtractionException {
|
final String sortFilter)
|
||||||
|
throws ExtractionException {
|
||||||
return getPlaylistExtractor(getPlaylistLHFactory()
|
return getPlaylistExtractor(getPlaylistLHFactory()
|
||||||
.fromQuery(id, contentFilter, sortFilter));
|
.fromQuery(id, contentFilter, sortFilter));
|
||||||
}
|
}
|
||||||
|
@ -246,28 +254,28 @@ public abstract class StreamingService {
|
||||||
// Short extractors overloads
|
// Short extractors overloads
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public SearchExtractor getSearchExtractor(String query) throws ExtractionException {
|
public SearchExtractor getSearchExtractor(final String query) throws ExtractionException {
|
||||||
return getSearchExtractor(getSearchQHFactory().fromQuery(query));
|
return getSearchExtractor(getSearchQHFactory().fromQuery(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelExtractor getChannelExtractor(String url) throws ExtractionException {
|
public ChannelExtractor getChannelExtractor(final String url) throws ExtractionException {
|
||||||
return getChannelExtractor(getChannelLHFactory().fromUrl(url));
|
return getChannelExtractor(getChannelLHFactory().fromUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException {
|
public PlaylistExtractor getPlaylistExtractor(final String url) throws ExtractionException {
|
||||||
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url));
|
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamExtractor getStreamExtractor(String url) throws ExtractionException {
|
public StreamExtractor getStreamExtractor(final String url) throws ExtractionException {
|
||||||
return getStreamExtractor(getStreamLHFactory().fromUrl(url));
|
return getStreamExtractor(getStreamLHFactory().fromUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommentsExtractor getCommentsExtractor(String url) throws ExtractionException {
|
public CommentsExtractor getCommentsExtractor(final String url) throws ExtractionException {
|
||||||
ListLinkHandlerFactory llhf = getCommentsLHFactory();
|
final ListLinkHandlerFactory listLinkHandlerFactory = getCommentsLHFactory();
|
||||||
if (llhf == null) {
|
if (listLinkHandlerFactory == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return getCommentsExtractor(llhf.fromUrl(url));
|
return getCommentsExtractor(listLinkHandlerFactory.fromUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -320,7 +328,8 @@ public abstract class StreamingService {
|
||||||
* the user prefer (using {@link NewPipe#getPreferredLocalization()}), then it will:
|
* the user prefer (using {@link NewPipe#getPreferredLocalization()}), then it will:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Check if the exactly localization is supported by this service.</li>
|
* <li>Check if the exactly localization is supported by this service.</li>
|
||||||
* <li>If not, check if a less specific localization is available, using only the language code.</li>
|
* <li>If not, check if a less specific localization is available, using only the language
|
||||||
|
* code.</li>
|
||||||
* <li>Fallback to the {@link Localization#DEFAULT default} localization.</li>
|
* <li>Fallback to the {@link Localization#DEFAULT default} localization.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
|
@ -333,8 +342,9 @@ public abstract class StreamingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to the first supported language that matches the preferred language
|
// Fallback to the first supported language that matches the preferred language
|
||||||
for (Localization supportedLanguage : getSupportedLocalizations()) {
|
for (final Localization supportedLanguage : getSupportedLocalizations()) {
|
||||||
if (supportedLanguage.getLanguageCode().equals(preferredLocalization.getLanguageCode())) {
|
if (supportedLanguage.getLanguageCode()
|
||||||
|
.equals(preferredLocalization.getLanguageCode())) {
|
||||||
return supportedLanguage;
|
return supportedLanguage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,8 +353,8 @@ public abstract class StreamingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the country that should be used to fetch content in this service. It will get which country
|
* Returns the country that should be used to fetch content in this service. It will get which
|
||||||
* the user prefer (using {@link NewPipe#getPreferredContentCountry()}), then it will:
|
* country the user prefer (using {@link NewPipe#getPreferredContentCountry()}), then it will:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Check if the country is supported by this service.</li>
|
* <li>Check if the country is supported by this service.</li>
|
||||||
* <li>If not, fallback to the {@link ContentCountry#DEFAULT default} country.</li>
|
* <li>If not, fallback to the {@link ContentCountry#DEFAULT default} country.</li>
|
||||||
|
@ -361,14 +371,15 @@ public abstract class StreamingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instance of the time ago parser using the patterns related to the passed localization.<br>
|
* Get an instance of the time ago parser using the patterns related to the passed localization.
|
||||||
* <br>
|
* <br><br>
|
||||||
* Just like {@link #getLocalization()}, it will also try to fallback to a less specific localization if
|
* Just like {@link #getLocalization()}, it will also try to fallback to a less specific
|
||||||
* the exact one is not available/supported.
|
* localization if the exact one is not available/supported.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if the localization is not supported (parsing patterns are not present).
|
* @throws IllegalArgumentException if the localization is not supported (parsing patterns are
|
||||||
|
* not present).
|
||||||
*/
|
*/
|
||||||
public TimeAgoParser getTimeAgoParser(Localization localization) {
|
public TimeAgoParser getTimeAgoParser(final Localization localization) {
|
||||||
final TimeAgoParser targetParser = TimeAgoPatternsManager.getTimeAgoParserFor(localization);
|
final TimeAgoParser targetParser = TimeAgoPatternsManager.getTimeAgoParserFor(localization);
|
||||||
|
|
||||||
if (targetParser != null) {
|
if (targetParser != null) {
|
||||||
|
@ -376,15 +387,18 @@ public abstract class StreamingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!localization.getCountryCode().isEmpty()) {
|
if (!localization.getCountryCode().isEmpty()) {
|
||||||
final Localization lessSpecificLocalization = new Localization(localization.getLanguageCode());
|
final Localization lessSpecificLocalization
|
||||||
final TimeAgoParser lessSpecificParser = TimeAgoPatternsManager.getTimeAgoParserFor(lessSpecificLocalization);
|
= new Localization(localization.getLanguageCode());
|
||||||
|
final TimeAgoParser lessSpecificParser
|
||||||
|
= TimeAgoPatternsManager.getTimeAgoParserFor(lessSpecificLocalization);
|
||||||
|
|
||||||
if (lessSpecificParser != null) {
|
if (lessSpecificParser != null) {
|
||||||
return lessSpecificParser;
|
return lessSpecificParser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("Localization is not supported (\"" + localization.toString() + "\")");
|
throw new IllegalArgumentException(
|
||||||
|
"Localization is not supported (\"" + localization + "\")");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue