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.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Extractor {
|
||||
/**
|
||||
* {@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 LinkHandler linkHandler;
|
||||
|
@ -27,16 +29,18 @@ public abstract class Extractor {
|
|||
private ContentCountry forcedContentCountry = null;
|
||||
|
||||
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) {
|
||||
this.service = Objects.requireNonNull(service, "service 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
|
||||
public LinkHandler getLinkHandler() {
|
||||
|
@ -50,13 +54,17 @@ public abstract class Extractor {
|
|||
* @throws ExtractionException if the pages content is not understood
|
||||
*/
|
||||
public void fetchPage() throws IOException, ExtractionException {
|
||||
if (pageFetched) return;
|
||||
onFetchPage(downloader);
|
||||
if (pageFetched) {
|
||||
return;
|
||||
}
|
||||
onFetchPage(theDownloader);
|
||||
pageFetched = true;
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -66,11 +74,12 @@ public abstract class Extractor {
|
|||
/**
|
||||
* 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 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
|
||||
public String getId() throws ParsingException {
|
||||
|
@ -111,18 +120,18 @@ public abstract class Extractor {
|
|||
}
|
||||
|
||||
public Downloader getDownloader() {
|
||||
return downloader;
|
||||
return theDownloader;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Localization
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public void forceLocalization(Localization localization) {
|
||||
public void forceLocalization(final Localization localization) {
|
||||
this.forcedLocalization = localization;
|
||||
}
|
||||
|
||||
public void forceContentCountry(ContentCountry contentCountry) {
|
||||
public void forceContentCountry(final ContentCountry contentCountry) {
|
||||
this.forcedContentCountry = contentCountry;
|
||||
}
|
||||
|
||||
|
@ -133,7 +142,8 @@ public abstract class Extractor {
|
|||
|
||||
@Nonnull
|
||||
public ContentCountry getExtractorContentCountry() {
|
||||
return forcedContentCountry == null ? getService().getContentCountry() : forcedContentCountry;
|
||||
return forcedContentCountry == null ? getService().getContentCountry()
|
||||
: forcedContentCountry;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -17,7 +17,8 @@ public abstract class Info implements Serializable {
|
|||
*/
|
||||
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 Extractor#getOriginalUrl()
|
||||
|
@ -33,15 +34,19 @@ public abstract class Info implements Serializable {
|
|||
|
||||
private final List<Throwable> errors = new ArrayList<>();
|
||||
|
||||
public void addError(Throwable throwable) {
|
||||
public void addError(final Throwable throwable) {
|
||||
this.errors.add(throwable);
|
||||
}
|
||||
|
||||
public void addAllErrors(Collection<Throwable> errors) {
|
||||
this.errors.addAll(errors);
|
||||
public void addAllErrors(final Collection<Throwable> throwables) {
|
||||
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.id = id;
|
||||
this.url = url;
|
||||
|
@ -49,7 +54,7 @@ public abstract class Info implements Serializable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public Info(int serviceId, LinkHandler linkHandler, String name) {
|
||||
public Info(final int serviceId, final LinkHandler linkHandler, final String name) {
|
||||
this(serviceId,
|
||||
linkHandler.getId(),
|
||||
linkHandler.getUrl(),
|
||||
|
@ -59,14 +64,16 @@ public abstract class Info implements Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
final String ifDifferentString = !url.equals(originalUrl) ? " (originalUrl=\"" + originalUrl + "\")" : "";
|
||||
return getClass().getSimpleName() + "[url=\"" + url + "\"" + ifDifferentString + ", name=\"" + name + "\"]";
|
||||
final String ifDifferentString
|
||||
= 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
|
||||
// overriding original url is essential
|
||||
public void setOriginalUrl(String url) {
|
||||
originalUrl = url;
|
||||
public void setOriginalUrl(final String originalUrl) {
|
||||
this.originalUrl = originalUrl;
|
||||
}
|
||||
|
||||
public int getServiceId() {
|
||||
|
|
|
@ -29,7 +29,10 @@ public abstract class InfoItem implements Serializable {
|
|||
private final String name;
|
||||
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.serviceId = serviceId;
|
||||
this.url = url;
|
||||
|
@ -52,7 +55,7 @@ public abstract class InfoItem implements Serializable {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void setThumbnailUrl(String thumbnailUrl) {
|
||||
public void setThumbnailUrl(final String thumbnailUrl) {
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ import java.util.List;
|
|||
* 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<Throwable> errors = new ArrayList<>();
|
||||
|
@ -77,7 +78,7 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
|||
* Add an error
|
||||
* @param error the error
|
||||
*/
|
||||
protected void addError(Exception error) {
|
||||
protected void addError(final Exception error) {
|
||||
errors.add(error);
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
|||
* Add an item
|
||||
* @param item the item
|
||||
*/
|
||||
protected void addItem(I item) {
|
||||
protected void addItem(final I item) {
|
||||
itemList.add(item);
|
||||
}
|
||||
|
||||
|
@ -98,12 +99,12 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
|||
}
|
||||
|
||||
@Override
|
||||
public void commit(E extractor) {
|
||||
public void commit(final E extractor) {
|
||||
try {
|
||||
addItem(extract(extractor));
|
||||
} catch (FoundAdException ae) {
|
||||
} catch (final FoundAdException ae) {
|
||||
// found an ad. Maybe a debug line could be placed here
|
||||
} catch (ParsingException e) {
|
||||
} catch (final ParsingException e) {
|
||||
addError(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.annotation.Nonnull;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
/**
|
||||
|
@ -30,7 +31,7 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -50,8 +51,9 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
|||
* @return a {@link InfoItemsPage} corresponding to the requested page
|
||||
* @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
|
||||
public ListLinkHandler 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
|
||||
* 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> {
|
||||
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.
|
||||
*
|
||||
* @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() {
|
||||
//noinspection unchecked
|
||||
|
@ -97,11 +101,13 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
|||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
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.nextPage = nextPage;
|
||||
this.errors = errors;
|
||||
|
|
|
@ -10,19 +10,21 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
|
|||
private final List<String> contentFilters;
|
||||
private final String sortFilter;
|
||||
|
||||
public ListInfo(int serviceId,
|
||||
String id,
|
||||
String url,
|
||||
String originalUrl,
|
||||
String name,
|
||||
List<String> contentFilter,
|
||||
String sortFilter) {
|
||||
public ListInfo(final int serviceId,
|
||||
final String id,
|
||||
final String url,
|
||||
final String originalUrl,
|
||||
final String name,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter) {
|
||||
super(serviceId, id, url, originalUrl, name);
|
||||
this.contentFilters = contentFilter;
|
||||
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);
|
||||
this.contentFilters = listUrlIdHandler.getContentFilters();
|
||||
this.sortFilter = listUrlIdHandler.getSortFilter();
|
||||
|
@ -32,7 +34,7 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
|
|||
return relatedItems;
|
||||
}
|
||||
|
||||
public void setRelatedItems(List<T> relatedItems) {
|
||||
public void setRelatedItems(final List<T> relatedItems) {
|
||||
this.relatedItems = relatedItems;
|
||||
}
|
||||
|
||||
|
@ -44,7 +46,7 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
|
|||
return nextPage;
|
||||
}
|
||||
|
||||
public void setNextPage(Page page) {
|
||||
public void setNextPage(final Page page) {
|
||||
this.nextPage = page;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,32 +27,34 @@ package org.schabi.newpipe.extractor;
|
|||
*/
|
||||
|
||||
public enum MediaFormat {
|
||||
// @formatter:off
|
||||
//video and audio combined formats
|
||||
// id name suffix mime type
|
||||
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
||||
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
|
||||
WEBM (0x20, "WebM", "webm", "video/webm"),
|
||||
// id name suffix mimeType
|
||||
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
||||
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
|
||||
WEBM (0x20, "WebM", "webm", "video/webm"),
|
||||
// audio formats
|
||||
M4A (0x100, "m4a", "m4a", "audio/mp4"),
|
||||
WEBMA (0x200, "WebM", "webm", "audio/webm"),
|
||||
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
|
||||
OPUS (0x400, "opus", "opus", "audio/opus"),
|
||||
OGG (0x500, "ogg", "ogg", "audio/ogg"),
|
||||
WEBMA_OPUS (0x200, "WebM Opus", "webm", "audio/webm"),
|
||||
M4A (0x100, "m4a", "m4a", "audio/mp4"),
|
||||
WEBMA (0x200, "WebM", "webm", "audio/webm"),
|
||||
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
|
||||
OPUS (0x400, "opus", "opus", "audio/opus"),
|
||||
OGG (0x500, "ogg", "ogg", "audio/ogg"),
|
||||
WEBMA_OPUS(0x200, "WebM Opus", "webm", "audio/webm"),
|
||||
// subtitles formats
|
||||
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
|
||||
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
|
||||
TRANSCRIPT1 (0x3000, "TranScript v1", "srv1", "text/xml"),
|
||||
TRANSCRIPT2 (0x4000, "TranScript v2", "srv2", "text/xml"),
|
||||
TRANSCRIPT3 (0x5000, "TranScript v3", "srv3", "text/xml"),
|
||||
SRT (0x6000, "SubRip file format", "srt", "text/srt");
|
||||
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
|
||||
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
|
||||
TRANSCRIPT1(0x3000, "TranScript v1", "srv1", "text/xml"),
|
||||
TRANSCRIPT2(0x4000, "TranScript v2", "srv2", "text/xml"),
|
||||
TRANSCRIPT3(0x5000, "TranScript v3", "srv3", "text/xml"),
|
||||
SRT (0x6000, "SubRip file format", "srt", "text/srt");
|
||||
// @formatter:on
|
||||
|
||||
public final int id;
|
||||
public final String name;
|
||||
public final String suffix;
|
||||
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.name = name;
|
||||
this.suffix = suffix;
|
||||
|
|
|
@ -16,8 +16,10 @@ public class MetaInfo implements Serializable {
|
|||
private List<URL> urls = new ArrayList<>();
|
||||
private List<String> urlTexts = new ArrayList<>();
|
||||
|
||||
public MetaInfo(@Nonnull final String title, @Nonnull final Description content,
|
||||
@Nonnull final List<URL> urls, @Nonnull final List<String> urlTexts) {
|
||||
public MetaInfo(@Nonnull final String title,
|
||||
@Nonnull final Description content,
|
||||
@Nonnull final List<URL> urls,
|
||||
@Nonnull final List<String> urlTexts) {
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.urls = urls;
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.List;
|
|||
/**
|
||||
* Provides access to streaming services supported by NewPipe.
|
||||
*/
|
||||
public class NewPipe {
|
||||
public final class NewPipe {
|
||||
private static Downloader downloader;
|
||||
private static Localization preferredLocalization;
|
||||
private static ContentCountry preferredContentCountry;
|
||||
|
@ -40,19 +40,20 @@ public class NewPipe {
|
|||
private NewPipe() {
|
||||
}
|
||||
|
||||
public static void init(Downloader d) {
|
||||
public static void init(final Downloader d) {
|
||||
downloader = d;
|
||||
preferredLocalization = Localization.DEFAULT;
|
||||
preferredContentCountry = ContentCountry.DEFAULT;
|
||||
}
|
||||
|
||||
public static void init(Downloader d, Localization l) {
|
||||
public static void init(final Downloader d, final Localization l) {
|
||||
downloader = d;
|
||||
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;
|
||||
preferredLocalization = l;
|
||||
preferredContentCountry = c;
|
||||
|
@ -88,8 +89,8 @@ public class NewPipe {
|
|||
throw new ExtractionException("There's no service with the name = \"" + serviceName + "\"");
|
||||
}
|
||||
|
||||
public static StreamingService getServiceByUrl(String url) throws ExtractionException {
|
||||
for (StreamingService service : ServiceList.all()) {
|
||||
public static StreamingService getServiceByUrl(final String url) throws ExtractionException {
|
||||
for (final StreamingService service : ServiceList.all()) {
|
||||
if (service.getLinkTypeByUrl(url) != StreamingService.LinkType.NONE) {
|
||||
return service;
|
||||
}
|
||||
|
@ -97,18 +98,18 @@ public class NewPipe {
|
|||
throw new ExtractionException("No service can handle the url = \"" + url + "\"");
|
||||
}
|
||||
|
||||
public static int getIdOfService(String serviceName) {
|
||||
public static int getIdOfService(final String serviceName) {
|
||||
try {
|
||||
return getService(serviceName).getServiceId();
|
||||
} catch (ExtractionException ignored) {
|
||||
} catch (final ExtractionException ignored) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getNameOfService(int id) {
|
||||
public static String getNameOfService(final int id) {
|
||||
try {
|
||||
return getService(id).getServiceInfo().getName();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
System.err.println("Service id not known");
|
||||
e.printStackTrace();
|
||||
return "<unknown>";
|
||||
|
@ -119,19 +120,21 @@ public class NewPipe {
|
|||
// Localization
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public static void setupLocalization(Localization preferredLocalization) {
|
||||
setupLocalization(preferredLocalization, null);
|
||||
public static void setupLocalization(final Localization thePreferredLocalization) {
|
||||
setupLocalization(thePreferredLocalization, null);
|
||||
}
|
||||
|
||||
public static void setupLocalization(Localization preferredLocalization, @Nullable ContentCountry preferredContentCountry) {
|
||||
NewPipe.preferredLocalization = preferredLocalization;
|
||||
public static void setupLocalization(
|
||||
final Localization thePreferredLocalization,
|
||||
@Nullable final ContentCountry thePreferredContentCountry) {
|
||||
NewPipe.preferredLocalization = thePreferredLocalization;
|
||||
|
||||
if (preferredContentCountry != null) {
|
||||
NewPipe.preferredContentCountry = preferredContentCountry;
|
||||
if (thePreferredContentCountry != null) {
|
||||
NewPipe.preferredContentCountry = thePreferredContentCountry;
|
||||
} else {
|
||||
NewPipe.preferredContentCountry = preferredLocalization.getCountryCode().isEmpty()
|
||||
NewPipe.preferredContentCountry = thePreferredLocalization.getCountryCode().isEmpty()
|
||||
? ContentCountry.DEFAULT
|
||||
: new ContentCountry(preferredLocalization.getCountryCode());
|
||||
: new ContentCountry(thePreferredLocalization.getCountryCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +143,7 @@ public class NewPipe {
|
|||
return preferredLocalization == null ? Localization.DEFAULT : preferredLocalization;
|
||||
}
|
||||
|
||||
public static void setPreferredLocalization(Localization preferredLocalization) {
|
||||
public static void setPreferredLocalization(final Localization preferredLocalization) {
|
||||
NewPipe.preferredLocalization = preferredLocalization;
|
||||
}
|
||||
|
||||
|
@ -149,7 +152,7 @@ public class NewPipe {
|
|||
return preferredContentCountry == null ? ContentCountry.DEFAULT : preferredContentCountry;
|
||||
}
|
||||
|
||||
public static void setPreferredContentCountry(ContentCountry preferredContentCountry) {
|
||||
public static void setPreferredContentCountry(final ContentCountry preferredContentCountry) {
|
||||
NewPipe.preferredContentCountry = preferredContentCountry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,11 @@ public class Page implements Serializable {
|
|||
@Nullable
|
||||
private final byte[] body;
|
||||
|
||||
public Page(final String url, final String id, final List<String> ids,
|
||||
final Map<String, String> cookies, @Nullable final byte[] body) {
|
||||
public Page(final String url,
|
||||
final String id,
|
||||
final List<String> ids,
|
||||
final Map<String, String> cookies,
|
||||
@Nullable final byte[] body) {
|
||||
this.url = url;
|
||||
this.id = id;
|
||||
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.feed.FeedExtractor;
|
||||
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.Localization;
|
||||
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||
|
@ -55,7 +60,7 @@ public abstract class StreamingService {
|
|||
* @param name the name of the service
|
||||
* @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.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
|
||||
* of NewPipe should handle a certain URL.
|
||||
* LinkType will be used to determine which type of URL you are handling, and therefore which
|
||||
* part of NewPipe should handle a certain URL.
|
||||
*/
|
||||
public enum LinkType {
|
||||
NONE,
|
||||
|
@ -90,14 +95,15 @@ public abstract class StreamingService {
|
|||
/**
|
||||
* Creates a new Streaming service.
|
||||
* If you Implement one do not set id within your implementation of this extractor, instead
|
||||
* set the id when you put the extractor into
|
||||
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/ServiceList.html">ServiceList</a>.
|
||||
* set the id when you put the extractor into {@link ServiceList}
|
||||
* 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 name the name of the service
|
||||
* @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.serviceInfo = new ServiceInfo(name, capabilities);
|
||||
}
|
||||
|
@ -172,22 +178,21 @@ public abstract class StreamingService {
|
|||
public abstract SubscriptionExtractor getSubscriptionExtractor();
|
||||
|
||||
/**
|
||||
* This method decides which strategy will be chosen to fetch the feed. In YouTube, for example, a separate feed
|
||||
* exists which is lightweight and made specifically to be used like this.
|
||||
* This method decides which strategy will be chosen to fetch the feed. In YouTube, for example,
|
||||
* a separate feed exists which is lightweight and made specifically to be used like this.
|
||||
* <p>
|
||||
* In services which there's no other way to retrieve them, null should be returned.
|
||||
*
|
||||
* @return a {@link FeedExtractor} instance or null.
|
||||
*/
|
||||
@Nullable
|
||||
public FeedExtractor getFeedExtractor(String url) throws ExtractionException {
|
||||
public FeedExtractor getFeedExtractor(final String url) throws ExtractionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must create a new instance of a KioskList implementation.
|
||||
* @return a new KioskList instance
|
||||
* @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.
|
||||
* @param linkHandler is pointing to the channel which should be handled by this new instance.
|
||||
* @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.
|
||||
* @param linkHandler is pointing to the playlist which should be handled by this new instance.
|
||||
* @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.
|
||||
* @param linkHandler is pointing to the stream which should be handled by this new instance.
|
||||
* @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
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public SearchExtractor getSearchExtractor(String query,
|
||||
List<String> contentFilter,
|
||||
String sortFilter) throws ExtractionException {
|
||||
public SearchExtractor getSearchExtractor(final String query,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter) throws ExtractionException {
|
||||
return getSearchExtractor(getSearchQHFactory()
|
||||
.fromQuery(query, contentFilter, sortFilter));
|
||||
}
|
||||
|
||||
public ChannelExtractor getChannelExtractor(String id,
|
||||
List<String> contentFilter,
|
||||
String sortFilter) throws ExtractionException {
|
||||
public ChannelExtractor getChannelExtractor(final String id,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter)
|
||||
throws ExtractionException {
|
||||
return getChannelExtractor(getChannelLHFactory()
|
||||
.fromQuery(id, contentFilter, sortFilter));
|
||||
}
|
||||
|
||||
public PlaylistExtractor getPlaylistExtractor(String id,
|
||||
List<String> contentFilter,
|
||||
String sortFilter) throws ExtractionException {
|
||||
public PlaylistExtractor getPlaylistExtractor(final String id,
|
||||
final List<String> contentFilter,
|
||||
final String sortFilter)
|
||||
throws ExtractionException {
|
||||
return getPlaylistExtractor(getPlaylistLHFactory()
|
||||
.fromQuery(id, contentFilter, sortFilter));
|
||||
}
|
||||
|
@ -246,28 +254,28 @@ public abstract class StreamingService {
|
|||
// Short extractors overloads
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public SearchExtractor getSearchExtractor(String query) throws ExtractionException {
|
||||
public SearchExtractor getSearchExtractor(final String query) throws ExtractionException {
|
||||
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));
|
||||
}
|
||||
|
||||
public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException {
|
||||
public PlaylistExtractor getPlaylistExtractor(final String url) throws ExtractionException {
|
||||
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));
|
||||
}
|
||||
|
||||
public CommentsExtractor getCommentsExtractor(String url) throws ExtractionException {
|
||||
ListLinkHandlerFactory llhf = getCommentsLHFactory();
|
||||
if (llhf == null) {
|
||||
public CommentsExtractor getCommentsExtractor(final String url) throws ExtractionException {
|
||||
final ListLinkHandlerFactory listLinkHandlerFactory = getCommentsLHFactory();
|
||||
if (listLinkHandlerFactory == 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:
|
||||
* <ul>
|
||||
* <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>
|
||||
* </ul>
|
||||
*/
|
||||
|
@ -333,8 +342,9 @@ public abstract class StreamingService {
|
|||
}
|
||||
|
||||
// Fallback to the first supported language that matches the preferred language
|
||||
for (Localization supportedLanguage : getSupportedLocalizations()) {
|
||||
if (supportedLanguage.getLanguageCode().equals(preferredLocalization.getLanguageCode())) {
|
||||
for (final Localization supportedLanguage : getSupportedLocalizations()) {
|
||||
if (supportedLanguage.getLanguageCode()
|
||||
.equals(preferredLocalization.getLanguageCode())) {
|
||||
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
|
||||
* the user prefer (using {@link NewPipe#getPreferredContentCountry()}), then it will:
|
||||
* Returns the country that should be used to fetch content in this service. It will get which
|
||||
* country the user prefer (using {@link NewPipe#getPreferredContentCountry()}), then it will:
|
||||
* <ul>
|
||||
* <li>Check if the country is supported by this service.</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>
|
||||
* <br>
|
||||
* Just like {@link #getLocalization()}, it will also try to fallback to a less specific localization if
|
||||
* the exact one is not available/supported.
|
||||
* Get an instance of the time ago parser using the patterns related to the passed localization.
|
||||
* <br><br>
|
||||
* Just like {@link #getLocalization()}, it will also try to fallback to a less specific
|
||||
* 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);
|
||||
|
||||
if (targetParser != null) {
|
||||
|
@ -376,15 +387,18 @@ public abstract class StreamingService {
|
|||
}
|
||||
|
||||
if (!localization.getCountryCode().isEmpty()) {
|
||||
final Localization lessSpecificLocalization = new Localization(localization.getLanguageCode());
|
||||
final TimeAgoParser lessSpecificParser = TimeAgoPatternsManager.getTimeAgoParserFor(lessSpecificLocalization);
|
||||
final Localization lessSpecificLocalization
|
||||
= new Localization(localization.getLanguageCode());
|
||||
final TimeAgoParser lessSpecificParser
|
||||
= TimeAgoPatternsManager.getTimeAgoParserFor(lessSpecificLocalization);
|
||||
|
||||
if (lessSpecificParser != null) {
|
||||
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