From d79e20340cfea7d7a96b2e40487c0f069491d25c Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 17 Mar 2022 16:14:58 +0100 Subject: [PATCH] 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 --- .../schabi/newpipe/extractor/Extractor.java | 36 ++++-- .../org/schabi/newpipe/extractor/Info.java | 27 +++-- .../schabi/newpipe/extractor/InfoItem.java | 7 +- .../newpipe/extractor/InfoItemsCollector.java | 13 +- .../newpipe/extractor/ListExtractor.java | 18 ++- .../schabi/newpipe/extractor/ListInfo.java | 22 ++-- .../schabi/newpipe/extractor/MediaFormat.java | 36 +++--- .../schabi/newpipe/extractor/MetaInfo.java | 6 +- .../org/schabi/newpipe/extractor/NewPipe.java | 45 +++---- .../org/schabi/newpipe/extractor/Page.java | 7 +- .../newpipe/extractor/StreamingService.java | 112 ++++++++++-------- 11 files changed, 191 insertions(+), 138 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java index 9389e255..523b548b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -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.
- * 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 diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java index 3a1980b5..78a15553 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -17,7 +17,8 @@ public abstract class Info implements Serializable { */ private final String id; /** - * Different than the {@link #originalUrl} in the sense that it may be set as a cleaned url. + * Different than the {@link #originalUrl} in the sense that it may 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 errors = new ArrayList<>(); - public void addError(Throwable throwable) { + public void addError(final Throwable throwable) { this.errors.add(throwable); } - public void addAllErrors(Collection errors) { - this.errors.addAll(errors); + public void addAllErrors(final Collection 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() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java index aead6c7f..cbcab0a5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java @@ -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; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java index 1fd4b28a..b0ac2e14 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java @@ -29,7 +29,8 @@ import java.util.List; * along with NewPipe. If not, see . */ -public abstract class InfoItemsCollector implements Collector { +public abstract class InfoItemsCollector + implements Collector { private final List itemList = new ArrayList<>(); private final List errors = new ArrayList<>(); @@ -77,7 +78,7 @@ public abstract class InfoItemsCollector the info item type this list extractor provides */ public abstract class ListExtractor extends Extractor { /** @@ -30,7 +31,7 @@ public abstract class ListExtractor 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 extends Extractor { * @return a {@link InfoItemsPage} corresponding to the requested page * @see InfoItemsPage#getNextPage() */ - public abstract InfoItemsPage getPage(final Page page) throws IOException, ExtractionException; + public abstract InfoItemsPage getPage(Page page) throws IOException, ExtractionException; + @Nonnull @Override public ListLinkHandler getLinkHandler() { return (ListLinkHandler) super.getLinkHandler(); @@ -64,15 +66,17 @@ public abstract class ListExtractor 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 the info item type that this page is supposed to store and provide */ public static class InfoItemsPage { private static final InfoItemsPage EMPTY = - new InfoItemsPage<>(Collections.emptyList(), null, Collections.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 InfoItemsPage emptyPage() { //noinspection unchecked @@ -97,11 +101,13 @@ public abstract class ListExtractor extends Extractor { */ private final List errors; - public InfoItemsPage(InfoItemsCollector collector, Page nextPage) { + public InfoItemsPage(final InfoItemsCollector collector, final Page nextPage) { this(collector.getItems(), nextPage, collector.getErrors()); } - public InfoItemsPage(List itemsList, Page nextPage, List errors) { + public InfoItemsPage(final List itemsList, + final Page nextPage, + final List errors) { this.itemsList = itemsList; this.nextPage = nextPage; this.errors = errors; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java index c06c24c4..8e383f3e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java @@ -10,19 +10,21 @@ public abstract class ListInfo extends Info { private final List contentFilters; private final String sortFilter; - public ListInfo(int serviceId, - String id, - String url, - String originalUrl, - String name, - List contentFilter, - String sortFilter) { + public ListInfo(final int serviceId, + final String id, + final String url, + final String originalUrl, + final String name, + final List 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 extends Info { return relatedItems; } - public void setRelatedItems(List relatedItems) { + public void setRelatedItems(final List relatedItems) { this.relatedItems = relatedItems; } @@ -44,7 +46,7 @@ public abstract class ListInfo extends Info { return nextPage; } - public void setNextPage(Page page) { + public void setNextPage(final Page page) { this.nextPage = page; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java index 6936568a..71948470 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java @@ -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; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/MetaInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/MetaInfo.java index da9928e8..79e2650d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/MetaInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/MetaInfo.java @@ -16,8 +16,10 @@ public class MetaInfo implements Serializable { private List urls = new ArrayList<>(); private List urlTexts = new ArrayList<>(); - public MetaInfo(@Nonnull final String title, @Nonnull final Description content, - @Nonnull final List urls, @Nonnull final List urlTexts) { + public MetaInfo(@Nonnull final String title, + @Nonnull final Description content, + @Nonnull final List urls, + @Nonnull final List urlTexts) { this.title = title; this.content = content; this.urls = urls; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java b/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java index cdd53684..767a2e64 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java @@ -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 ""; @@ -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; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Page.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Page.java index 5f49cb2c..e1b19e7f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Page.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Page.java @@ -17,8 +17,11 @@ public class Page implements Serializable { @Nullable private final byte[] body; - public Page(final String url, final String id, final List ids, - final Map cookies, @Nullable final byte[] body) { + public Page(final String url, + final String id, + final List ids, + final Map cookies, + @Nullable final byte[] body) { this.url = url; this.id = id; this.ids = ids; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index dcde0aff..94b8ba2d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -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 mediaCapabilities) { + public ServiceInfo(final String name, final List 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 - * ServiceList. + * 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 capabilities) { + public StreamingService(final int id, + final String name, + final List 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. *

* 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 contentFilter, - String sortFilter) throws ExtractionException { + public SearchExtractor getSearchExtractor(final String query, + final List contentFilter, + final String sortFilter) throws ExtractionException { return getSearchExtractor(getSearchQHFactory() .fromQuery(query, contentFilter, sortFilter)); } - public ChannelExtractor getChannelExtractor(String id, - List contentFilter, - String sortFilter) throws ExtractionException { + public ChannelExtractor getChannelExtractor(final String id, + final List contentFilter, + final String sortFilter) + throws ExtractionException { return getChannelExtractor(getChannelLHFactory() .fromQuery(id, contentFilter, sortFilter)); } - public PlaylistExtractor getPlaylistExtractor(String id, - List contentFilter, - String sortFilter) throws ExtractionException { + public PlaylistExtractor getPlaylistExtractor(final String id, + final List 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: *

    *
  • Check if the exactly localization is supported by this service.
  • - *
  • If not, check if a less specific localization is available, using only the language code.
  • + *
  • If not, check if a less specific localization is available, using only the language + * code.
  • *
  • Fallback to the {@link Localization#DEFAULT default} localization.
  • *
*/ @@ -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: *
    *
  • Check if the country is supported by this service.
  • *
  • If not, fallback to the {@link ContentCountry#DEFAULT default} country.
  • @@ -361,14 +371,15 @@ public abstract class StreamingService { } /** - * Get an instance of the time ago parser using the patterns related to the passed localization.
    - *
    - * 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. + *

    + * 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 + "\")"); } }