Fix checkstyle issues in subpackages with abstract classes

This commit is contained in:
Stypox 2022-03-17 14:47:08 +01:00 committed by litetex
parent e4951a0623
commit 8aba2b47b0
50 changed files with 903 additions and 781 deletions

View File

@ -50,7 +50,7 @@ public class MultiInfoItemsCollector extends InfoItemsCollector<InfoItem, InfoIt
private final ChannelInfoItemsCollector userCollector;
private final PlaylistInfoItemsCollector playlistCollector;
public MultiInfoItemsCollector(int serviceId) {
public MultiInfoItemsCollector(final int serviceId) {
super(serviceId);
streamCollector = new StreamInfoItemsCollector(serviceId);
userCollector = new ChannelInfoItemsCollector(serviceId);
@ -76,7 +76,7 @@ public class MultiInfoItemsCollector extends InfoItemsCollector<InfoItem, InfoIt
}
@Override
public InfoItem extract(InfoItemExtractor extractor) throws ParsingException {
public InfoItem extract(final InfoItemExtractor extractor) throws ParsingException {
// Use the corresponding collector for each item extractor type
if (extractor instanceof StreamInfoItemExtractor) {
return streamCollector.extract((StreamInfoItemExtractor) extractor);

View File

@ -30,7 +30,7 @@ public abstract class ChannelExtractor extends ListExtractor<StreamInfoItem> {
public static final long UNKNOWN_SUBSCRIBER_COUNT = -1;
public ChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
public ChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
super(service, linkHandler);
}

View File

@ -34,27 +34,36 @@ import java.io.IOException;
public class ChannelInfo extends ListInfo<StreamInfoItem> {
public ChannelInfo(int serviceId, String id, String url, String originalUrl, String name, ListLinkHandler listLinkHandler) {
super(serviceId, id, url, originalUrl, name, listLinkHandler.getContentFilters(), listLinkHandler.getSortFilter());
public ChannelInfo(final int serviceId,
final String id,
final String url,
final String originalUrl,
final String name,
final ListLinkHandler listLinkHandler) {
super(serviceId, id, url, originalUrl, name, listLinkHandler.getContentFilters(),
listLinkHandler.getSortFilter());
}
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
public static ChannelInfo getInfo(final String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static ChannelInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
ChannelExtractor extractor = service.getChannelExtractor(url);
public static ChannelInfo getInfo(final StreamingService service, final String url)
throws IOException, ExtractionException {
final ChannelExtractor extractor = service.getChannelExtractor(url);
extractor.fetchPage();
return getInfo(extractor);
}
public static InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
Page page) throws IOException, ExtractionException {
public static InfoItemsPage<StreamInfoItem> getMoreItems(final StreamingService service,
final String url,
final Page page)
throws IOException, ExtractionException {
return service.getChannelExtractor(url).getPage(page);
}
public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException {
public static ChannelInfo getInfo(final ChannelExtractor extractor)
throws IOException, ExtractionException {
final int serviceId = extractor.getServiceId();
final String id = extractor.getId();
@ -62,60 +71,62 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
final String originalUrl = extractor.getOriginalUrl();
final String name = extractor.getName();
final ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name, extractor.getLinkHandler());
final ChannelInfo info =
new ChannelInfo(serviceId, id, url, originalUrl, name, extractor.getLinkHandler());
try {
info.setAvatarUrl(extractor.getAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setFeedUrl(extractor.getFeedUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
final InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
final InfoItemsPage<StreamInfoItem> itemsPage =
ExtractorHelper.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(itemsPage.getItems());
info.setNextPage(itemsPage.getNextPage());
try {
info.setSubscriberCount(extractor.getSubscriberCount());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setDescription(extractor.getDescription());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setParentChannelName(extractor.getParentChannelName());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setParentChannelUrl(extractor.getParentChannelUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setVerified(extractor.isVerified());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
@ -137,7 +148,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return parentChannelName;
}
public void setParentChannelName(String parentChannelName) {
public void setParentChannelName(final String parentChannelName) {
this.parentChannelName = parentChannelName;
}
@ -145,7 +156,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return parentChannelUrl;
}
public void setParentChannelUrl(String parentChannelUrl) {
public void setParentChannelUrl(final String parentChannelUrl) {
this.parentChannelUrl = parentChannelUrl;
}
@ -153,7 +164,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return parentChannelAvatarUrl;
}
public void setParentChannelAvatarUrl(String parentChannelAvatarUrl) {
public void setParentChannelAvatarUrl(final String parentChannelAvatarUrl) {
this.parentChannelAvatarUrl = parentChannelAvatarUrl;
}
@ -161,7 +172,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
public void setAvatarUrl(final String avatarUrl) {
this.avatarUrl = avatarUrl;
}
@ -169,7 +180,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return bannerUrl;
}
public void setBannerUrl(String bannerUrl) {
public void setBannerUrl(final String bannerUrl) {
this.bannerUrl = bannerUrl;
}
@ -177,7 +188,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return feedUrl;
}
public void setFeedUrl(String feedUrl) {
public void setFeedUrl(final String feedUrl) {
this.feedUrl = feedUrl;
}
@ -185,7 +196,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return subscriberCount;
}
public void setSubscriberCount(long subscriberCount) {
public void setSubscriberCount(final long subscriberCount) {
this.subscriberCount = subscriberCount;
}
@ -193,7 +204,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return description;
}
public void setDescription(String description) {
public void setDescription(final String description) {
this.description = description;
}
@ -201,7 +212,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return donationLinks;
}
public void setDonationLinks(String[] donationLinks) {
public void setDonationLinks(final String[] donationLinks) {
this.donationLinks = donationLinks;
}
@ -209,7 +220,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
return verified;
}
public void setVerified(boolean verified) {
public void setVerified(final boolean verified) {
this.verified = verified;
}
}

View File

@ -29,7 +29,7 @@ public class ChannelInfoItem extends InfoItem {
private long streamCount = -1;
private boolean verified = false;
public ChannelInfoItem(int serviceId, String url, String name) {
public ChannelInfoItem(final int serviceId, final String url, final String name) {
super(InfoType.CHANNEL, serviceId, url, name);
}
@ -37,7 +37,7 @@ public class ChannelInfoItem extends InfoItem {
return description;
}
public void setDescription(String description) {
public void setDescription(final String description) {
this.description = description;
}
@ -45,23 +45,23 @@ public class ChannelInfoItem extends InfoItem {
return subscriberCount;
}
public void setSubscriberCount(long subscriber_count) {
this.subscriberCount = subscriber_count;
public void setSubscriberCount(final long subscriberCount) {
this.subscriberCount = subscriberCount;
}
public long getStreamCount() {
return streamCount;
}
public void setStreamCount(long stream_count) {
this.streamCount = stream_count;
public void setStreamCount(final long streamCount) {
this.streamCount = streamCount;
}
public boolean isVerified() {
return verified;
}
public void setVerified(boolean verified) {
public void setVerified(final boolean verified) {
this.verified = verified;
}
}

View File

@ -23,45 +23,42 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class ChannelInfoItemsCollector extends InfoItemsCollector<ChannelInfoItem, ChannelInfoItemExtractor> {
public ChannelInfoItemsCollector(int serviceId) {
public final class ChannelInfoItemsCollector
extends InfoItemsCollector<ChannelInfoItem, ChannelInfoItemExtractor> {
public ChannelInfoItemsCollector(final int serviceId) {
super(serviceId);
}
@Override
public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws ParsingException {
// important information
int serviceId = getServiceId();
String name = extractor.getName();
String url = extractor.getUrl();
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, url, name);
public ChannelInfoItem extract(final ChannelInfoItemExtractor extractor)
throws ParsingException {
final ChannelInfoItem resultItem = new ChannelInfoItem(
getServiceId(), extractor.getUrl(), extractor.getName());
// optional information
try {
resultItem.setSubscriberCount(extractor.getSubscriberCount());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setStreamCount(extractor.getStreamCount());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setDescription(extractor.getDescription());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setVerified(extractor.isVerified());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}

View File

@ -11,7 +11,7 @@ import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException;
public class CommentsInfo extends ListInfo<CommentsInfoItem> {
public final class CommentsInfo extends ListInfo<CommentsInfoItem> {
private CommentsInfo(
final int serviceId,
@ -56,7 +56,8 @@ public class CommentsInfo extends ListInfo<CommentsInfoItem> {
public static InfoItemsPage<CommentsInfoItem> getMoreItems(
final CommentsInfo commentsInfo,
final Page page) throws ExtractionException, IOException {
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo.getUrl(), page);
return getMoreItems(NewPipe.getService(commentsInfo.getServiceId()), commentsInfo.getUrl(),
page);
}
public static InfoItemsPage<CommentsInfoItem> getMoreItems(
@ -86,7 +87,7 @@ public class CommentsInfo extends ListInfo<CommentsInfoItem> {
/**
* @apiNote Warning: This method is experimental and may get removed in a future release.
* @return <code>true</code> if the comments are disabled otherwise <code>false</code> (default)
* @return {@code true} if the comments are disabled otherwise {@code false} (default)
* @see CommentsExtractor#isCommentsDisabled()
*/
public boolean isCommentsDisabled() {
@ -95,7 +96,7 @@ public class CommentsInfo extends ListInfo<CommentsInfoItem> {
/**
* @apiNote Warning: This method is experimental and may get removed in a future release.
* @param commentsDisabled <code>true</code> if the comments are disabled otherwise <code>false</code>
* @param commentsDisabled {@code true} if the comments are disabled otherwise {@code false}
*/
public void setCommentsDisabled(final boolean commentsDisabled) {
this.commentsDisabled = commentsDisabled;

View File

@ -28,7 +28,7 @@ public class CommentsInfoItem extends InfoItem {
public static final int NO_LIKE_COUNT = -1;
public static final int NO_STREAM_POSITION = -1;
public CommentsInfoItem(int serviceId, String url, String name) {
public CommentsInfoItem(final int serviceId, final String url, final String name) {
super(InfoType.COMMENT, serviceId, url, name);
}
@ -36,7 +36,7 @@ public class CommentsInfoItem extends InfoItem {
return commentId;
}
public void setCommentId(String commentId) {
public void setCommentId(final String commentId) {
this.commentId = commentId;
}
@ -44,7 +44,7 @@ public class CommentsInfoItem extends InfoItem {
return commentText;
}
public void setCommentText(String commentText) {
public void setCommentText(final String commentText) {
this.commentText = commentText;
}
@ -52,7 +52,7 @@ public class CommentsInfoItem extends InfoItem {
return uploaderName;
}
public void setUploaderName(String uploaderName) {
public void setUploaderName(final String uploaderName) {
this.uploaderName = uploaderName;
}
@ -60,7 +60,7 @@ public class CommentsInfoItem extends InfoItem {
return uploaderAvatarUrl;
}
public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
public void setUploaderAvatarUrl(final String uploaderAvatarUrl) {
this.uploaderAvatarUrl = uploaderAvatarUrl;
}
@ -68,7 +68,7 @@ public class CommentsInfoItem extends InfoItem {
return uploaderUrl;
}
public void setUploaderUrl(String uploaderUrl) {
public void setUploaderUrl(final String uploaderUrl) {
this.uploaderUrl = uploaderUrl;
}
@ -76,7 +76,7 @@ public class CommentsInfoItem extends InfoItem {
return textualUploadDate;
}
public void setTextualUploadDate(String textualUploadDate) {
public void setTextualUploadDate(final String textualUploadDate) {
this.textualUploadDate = textualUploadDate;
}
@ -85,7 +85,7 @@ public class CommentsInfoItem extends InfoItem {
return uploadDate;
}
public void setUploadDate(@Nullable DateWrapper uploadDate) {
public void setUploadDate(@Nullable final DateWrapper uploadDate) {
this.uploadDate = uploadDate;
}
@ -97,7 +97,7 @@ public class CommentsInfoItem extends InfoItem {
return likeCount;
}
public void setLikeCount(int likeCount) {
public void setLikeCount(final int likeCount) {
this.likeCount = likeCount;
}
@ -105,11 +105,11 @@ public class CommentsInfoItem extends InfoItem {
return textualLikeCount;
}
public void setTextualLikeCount(String textualLikeCount) {
public void setTextualLikeCount(final String textualLikeCount) {
this.textualLikeCount = textualLikeCount;
}
public void setHeartedByUploader(boolean isHeartedByUploader) {
public void setHeartedByUploader(final boolean isHeartedByUploader) {
this.heartedByUploader = isHeartedByUploader;
}
@ -121,11 +121,11 @@ public class CommentsInfoItem extends InfoItem {
return pinned;
}
public void setPinned(boolean pinned) {
public void setPinned(final boolean pinned) {
this.pinned = pinned;
}
public void setUploaderVerified(boolean uploaderVerified) {
public void setUploaderVerified(final boolean uploaderVerified) {
this.uploaderVerified = uploaderVerified;
}
@ -146,7 +146,12 @@ public class CommentsInfoItem extends InfoItem {
return streamPosition;
}
public void setReplies(@Nullable Page replies) { this.replies = replies; }
public void setReplies(@Nullable final Page replies) {
this.replies = replies;
}
public Page getReplies() { return this.replies; }
@Nullable
public Page getReplies() {
return this.replies;
}
}

View File

@ -18,7 +18,8 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
*
* <br>
*
* NOTE: Currently only implemented for YT {@link YoutubeCommentsInfoItemExtractor#getLikeCount()}
* NOTE: Currently only implemented for YT {@link
* YoutubeCommentsInfoItemExtractor#getLikeCount()}
* with limitations (only approximate like count is returned)
*
* @see StreamExtractor#getLikeCount()

View File

@ -1,101 +1,97 @@
package org.schabi.newpipe.extractor.comments;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.ArrayList;
import java.util.List;
public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoItem, CommentsInfoItemExtractor> {
public final class CommentsInfoItemsCollector
extends InfoItemsCollector<CommentsInfoItem, CommentsInfoItemExtractor> {
public CommentsInfoItemsCollector(int serviceId) {
public CommentsInfoItemsCollector(final int serviceId) {
super(serviceId);
}
@Override
public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws ParsingException {
// important information
int serviceId = getServiceId();
String url = extractor.getUrl();
String name = extractor.getName();
CommentsInfoItem resultItem = new CommentsInfoItem(serviceId, url, name);
public CommentsInfoItem extract(final CommentsInfoItemExtractor extractor)
throws ParsingException {
final CommentsInfoItem resultItem = new CommentsInfoItem(
getServiceId(), extractor.getUrl(), extractor.getName());
// optional information
try {
resultItem.setCommentId(extractor.getCommentId());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setCommentText(extractor.getCommentText());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setTextualUploadDate(extractor.getTextualUploadDate());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploadDate(extractor.getUploadDate());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setLikeCount(extractor.getLikeCount());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setTextualLikeCount(extractor.getTextualLikeCount());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setHeartedByUploader(extractor.isHeartedByUploader());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setPinned(extractor.isPinned());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setStreamPosition(extractor.getStreamPosition());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setReplies(extractor.getReplies());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
@ -103,10 +99,10 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
}
@Override
public void commit(CommentsInfoItemExtractor extractor) {
public void commit(final CommentsInfoItemExtractor extractor) {
try {
addItem(extract(extractor));
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
}

View File

@ -19,13 +19,14 @@ public abstract class Downloader {
/**
* Do a GET request to get the resource that the url is pointing to.<br>
* <br>
* This method calls {@link #get(String, Map, Localization)} with the default preferred localization. It should only be
* used when the resource that will be fetched won't be affected by the localization.
* This method calls {@link #get(String, Map, Localization)} with the default preferred
* localization. It should only be used when the resource that will be fetched won't be affected
* by the localization.
*
* @param url the URL that is pointing to the wanted resource
* @return the result of the GET request
*/
public Response get(String url) throws IOException, ReCaptchaException {
public Response get(final String url) throws IOException, ReCaptchaException {
return get(url, null, NewPipe.getPreferredLocalization());
}
@ -38,7 +39,8 @@ public abstract class Downloader {
* @param localization the source of the value of the {@code Accept-Language} header
* @return the result of the GET request
*/
public Response get(String url, @Nullable Localization localization) throws IOException, ReCaptchaException {
public Response get(final String url, @Nullable final Localization localization)
throws IOException, ReCaptchaException {
return get(url, null, localization);
}
@ -50,7 +52,8 @@ public abstract class Downloader {
* Any default headers <b>should</b> be overridden by these.
* @return the result of the GET request
*/
public Response get(String url, @Nullable Map<String, List<String>> headers) throws IOException, ReCaptchaException {
public Response get(final String url, @Nullable final Map<String, List<String>> headers)
throws IOException, ReCaptchaException {
return get(url, headers, NewPipe.getPreferredLocalization());
}
@ -65,7 +68,9 @@ public abstract class Downloader {
* @param localization the source of the value of the {@code Accept-Language} header
* @return the result of the GET request
*/
public Response get(String url, @Nullable Map<String, List<String>> headers, @Nullable Localization localization)
public Response get(final String url,
@Nullable final Map<String, List<String>> headers,
@Nullable final Localization localization)
throws IOException, ReCaptchaException {
return execute(Request.newBuilder()
.get(url)
@ -80,7 +85,7 @@ public abstract class Downloader {
* @param url the URL that is pointing to the wanted resource
* @return the result of the HEAD request
*/
public Response head(String url) throws IOException, ReCaptchaException {
public Response head(final String url) throws IOException, ReCaptchaException {
return head(url, null);
}
@ -92,7 +97,7 @@ public abstract class Downloader {
* Any default headers <b>should</b> be overridden by these.
* @return the result of the HEAD request
*/
public Response head(String url, @Nullable Map<String, List<String>> headers)
public Response head(final String url, @Nullable final Map<String, List<String>> headers)
throws IOException, ReCaptchaException {
return execute(Request.newBuilder()
.head(url)
@ -109,7 +114,9 @@ public abstract class Downloader {
* @param dataToSend byte array that will be sent when doing the request.
* @return the result of the GET request
*/
public Response post(String url, @Nullable Map<String, List<String>> headers, @Nullable byte[] dataToSend)
public Response post(final String url,
@Nullable final Map<String, List<String>> headers,
@Nullable final byte[] dataToSend)
throws IOException, ReCaptchaException {
return post(url, headers, dataToSend, NewPipe.getPreferredLocalization());
}
@ -126,7 +133,10 @@ public abstract class Downloader {
* @param localization the source of the value of the {@code Accept-Language} header
* @return the result of the GET request
*/
public Response post(String url, @Nullable Map<String, List<String>> headers, @Nullable byte[] dataToSend, @Nullable Localization localization)
public Response post(final String url,
@Nullable final Map<String, List<String>> headers,
@Nullable final byte[] dataToSend,
@Nullable final Localization localization)
throws IOException, ReCaptchaException {
return execute(Request.newBuilder()
.post(url, dataToSend)
@ -140,5 +150,6 @@ public abstract class Downloader {
*
* @return the result of the request
*/
public abstract Response execute(@Nonnull Request request) throws IOException, ReCaptchaException;
public abstract Response execute(@Nonnull Request request)
throws IOException, ReCaptchaException;
}

View File

@ -2,24 +2,42 @@ package org.schabi.newpipe.extractor.downloader;
import org.schabi.newpipe.extractor.localization.Localization;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
/**
* An object that holds request information used when {@link Downloader#execute(Request) executing} a request.
* An object that holds request information used when {@link Downloader#execute(Request) executing}
* a request.
*/
public class Request {
private final String httpMethod;
private final String url;
private final Map<String, List<String>> headers;
@Nullable private final byte[] dataToSend;
@Nullable private final Localization localization;
@Nullable
private final byte[] dataToSend;
@Nullable
private final Localization localization;
public Request(String httpMethod, String url, Map<String, List<String>> headers, @Nullable byte[] dataToSend,
@Nullable Localization localization, boolean automaticLocalizationHeader) {
if (httpMethod == null) throw new IllegalArgumentException("Request's httpMethod is null");
if (url == null) throw new IllegalArgumentException("Request's url is null");
public Request(final String httpMethod,
final String url,
@Nullable final Map<String, List<String>> headers,
@Nullable final byte[] dataToSend,
@Nullable final Localization localization,
final boolean automaticLocalizationHeader) {
if (httpMethod == null) {
throw new IllegalArgumentException("Request's httpMethod is null");
}
if (url == null) {
throw new IllegalArgumentException("Request's url is null");
}
this.httpMethod = httpMethod;
this.url = url;
@ -37,7 +55,7 @@ public class Request {
this.headers = Collections.unmodifiableMap(actualHeaders);
}
private Request(Builder builder) {
private Request(final Builder builder) {
this(builder.httpMethod, builder.url, builder.headers, builder.dataToSend,
builder.localization, builder.automaticLocalizationHeader);
}
@ -94,7 +112,7 @@ public class Request {
public static final class Builder {
private String httpMethod;
private String url;
private Map<String, List<String>> headers = new LinkedHashMap<>();
private final Map<String, List<String>> headers = new LinkedHashMap<>();
private byte[] dataToSend;
private Localization localization;
private boolean automaticLocalizationHeader = true;
@ -105,27 +123,28 @@ public class Request {
/**
* A http method (i.e. {@code GET, POST, HEAD}).
*/
public Builder httpMethod(String httpMethod) {
this.httpMethod = httpMethod;
public Builder httpMethod(final String httpMethodToSet) {
this.httpMethod = httpMethodToSet;
return this;
}
/**
* The URL that is pointing to the wanted resource.
*/
public Builder url(String url) {
this.url = url;
public Builder url(final String urlToSet) {
this.url = urlToSet;
return this;
}
/**
* A list of headers that will be used in the request.<br>
* Any default headers that the implementation may have, <b>should</b> be overridden by these.
* Any default headers that the implementation may have, <b>should</b> be overridden by
* these.
*/
public Builder headers(@Nullable Map<String, List<String>> headers) {
public Builder headers(@Nullable final Map<String, List<String>> headersToSet) {
this.headers.clear();
if (headers != null) {
this.headers.putAll(headers);
if (headersToSet != null) {
this.headers.putAll(headersToSet);
}
return this;
}
@ -137,8 +156,8 @@ public class Request {
* The implementation should make note of some recommended headers
* (for example, {@code Content-Length} in a post request).
*/
public Builder dataToSend(byte[] dataToSend) {
this.dataToSend = dataToSend;
public Builder dataToSend(final byte[] dataToSendToSet) {
this.dataToSend = dataToSendToSet;
return this;
}
@ -148,16 +167,16 @@ public class Request {
* Usually the {@code Accept-Language} will be set to this value (a helper
* method to do this easily: {@link Request#headersFromLocalization(Localization)}).
*/
public Builder localization(Localization localization) {
this.localization = localization;
public Builder localization(final Localization localizationToSet) {
this.localization = localizationToSet;
return this;
}
/**
* If localization headers should automatically be included in the request.
*/
public Builder automaticLocalizationHeader(boolean automaticLocalizationHeader) {
this.automaticLocalizationHeader = automaticLocalizationHeader;
public Builder automaticLocalizationHeader(final boolean automaticLocalizationHeaderToSet) {
this.automaticLocalizationHeader = automaticLocalizationHeaderToSet;
return this;
}
@ -170,22 +189,22 @@ public class Request {
// Http Methods Utils
//////////////////////////////////////////////////////////////////////////*/
public Builder get(String url) {
public Builder get(final String urlToSet) {
this.httpMethod = "GET";
this.url = url;
this.url = urlToSet;
return this;
}
public Builder head(String url) {
public Builder head(final String urlToSet) {
this.httpMethod = "HEAD";
this.url = url;
this.url = urlToSet;
return this;
}
public Builder post(String url, @Nullable byte[] dataToSend) {
public Builder post(final String urlToSet, @Nullable final byte[] dataToSendToSet) {
this.httpMethod = "POST";
this.url = url;
this.dataToSend = dataToSend;
this.url = urlToSet;
this.dataToSend = dataToSendToSet;
return this;
}
@ -193,13 +212,13 @@ public class Request {
// Additional Headers Utils
//////////////////////////////////////////////////////////////////////////*/
public Builder setHeaders(String headerName, List<String> headerValueList) {
public Builder setHeaders(final String headerName, final List<String> headerValueList) {
this.headers.remove(headerName);
this.headers.put(headerName, headerValueList);
return this;
}
public Builder addHeaders(String headerName, List<String> headerValueList) {
public Builder addHeaders(final String headerName, final List<String> headerValueList) {
@Nullable List<String> currentHeaderValueList = this.headers.get(headerName);
if (currentHeaderValueList == null) {
currentHeaderValueList = new ArrayList<>();
@ -210,11 +229,11 @@ public class Request {
return this;
}
public Builder setHeader(String headerName, String headerValue) {
public Builder setHeader(final String headerName, final String headerValue) {
return setHeaders(headerName, Collections.singletonList(headerValue));
}
public Builder addHeader(String headerName, String headerValue) {
public Builder addHeader(final String headerName, final String headerValue) {
return addHeaders(headerName, Collections.singletonList(headerValue));
}
@ -226,15 +245,20 @@ public class Request {
@SuppressWarnings("WeakerAccess")
@Nonnull
public static Map<String, List<String>> headersFromLocalization(@Nullable Localization localization) {
if (localization == null) return Collections.emptyMap();
public static Map<String, List<String>> headersFromLocalization(
@Nullable final Localization localization) {
if (localization == null) {
return Collections.emptyMap();
}
final Map<String, List<String>> headers = new LinkedHashMap<>();
if (!localization.getCountryCode().isEmpty()) {
headers.put("Accept-Language", Collections.singletonList(localization.getLocalizationCode() +
", " + localization.getLanguageCode() + ";q=0.9"));
headers.put("Accept-Language",
Collections.singletonList(localization.getLocalizationCode()
+ ", " + localization.getLanguageCode() + ";q=0.9"));
} else {
headers.put("Accept-Language", Collections.singletonList(localization.getLanguageCode()));
headers.put("Accept-Language",
Collections.singletonList(localization.getLanguageCode()));
}
return headers;
@ -245,15 +269,19 @@ public class Request {
//////////////////////////////////////////////////////////////////////////*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
return httpMethod.equals(request.httpMethod) &&
url.equals(request.url) &&
headers.equals(request.headers) &&
Arrays.equals(dataToSend, request.dataToSend) &&
Objects.equals(localization, request.localization);
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Request request = (Request) o;
return httpMethod.equals(request.httpMethod)
&& url.equals(request.url)
&& headers.equals(request.headers)
&& Arrays.equals(dataToSend, request.dataToSend)
&& Objects.equals(localization, request.localization);
}
@Override

View File

@ -17,11 +17,14 @@ public class Response {
private final String latestUrl;
public Response(int responseCode, String responseMessage, Map<String, List<String>> responseHeaders,
@Nullable String responseBody, @Nullable String latestUrl) {
public Response(final int responseCode,
final String responseMessage,
@Nullable final Map<String, List<String>> responseHeaders,
@Nullable final String responseBody,
@Nullable final String latestUrl) {
this.responseCode = responseCode;
this.responseMessage = responseMessage;
this.responseHeaders = responseHeaders != null ? responseHeaders : Collections.<String, List<String>>emptyMap();
this.responseHeaders = responseHeaders == null ? Collections.emptyMap() : responseHeaders;
this.responseBody = responseBody == null ? "" : responseBody;
this.latestUrl = latestUrl;
@ -60,14 +63,15 @@ public class Response {
/**
* For easy access to some header value that (usually) don't repeat itself.
* <p>For getting all the values associated to the header, use {@link #responseHeaders()} (e.g. {@code Set-Cookie}).
* <p>For getting all the values associated to the header, use {@link #responseHeaders()} (e.g.
* {@code Set-Cookie}).
*
* @param name the name of the header
* @return the first value assigned to this header
*/
@Nullable
public String getHeader(String name) {
for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
public String getHeader(final String name) {
for (final Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
final String key = headerEntry.getKey();
if (key != null && key.equalsIgnoreCase(name) && !headerEntry.getValue().isEmpty()) {
return headerEntry.getValue().get(0);

View File

@ -11,7 +11,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
* YouTube is an example of a service that has this alternative available.
*/
public abstract class FeedExtractor extends ListExtractor<StreamInfoItem> {
public FeedExtractor(StreamingService service, ListLinkHandler listLinkHandler) {
public FeedExtractor(final StreamingService service, final ListLinkHandler listLinkHandler) {
super(service, listLinkHandler);
}
}

View File

@ -13,26 +13,35 @@ import java.util.List;
public class FeedInfo extends ListInfo<StreamInfoItem> {
public FeedInfo(int serviceId, String id, String url, String originalUrl, String name, List<String> contentFilter, String sortFilter) {
public FeedInfo(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, contentFilter, sortFilter);
}
public static FeedInfo getInfo(String url) throws IOException, ExtractionException {
public static FeedInfo getInfo(final String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static FeedInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
public static FeedInfo getInfo(final StreamingService service, final String url)
throws IOException, ExtractionException {
final FeedExtractor extractor = service.getFeedExtractor(url);
if (extractor == null) {
throw new IllegalArgumentException("Service \"" + service.getServiceInfo().getName() + "\" doesn't support FeedExtractor.");
throw new IllegalArgumentException("Service \"" + service.getServiceInfo().getName()
+ "\" doesn't support FeedExtractor.");
}
extractor.fetchPage();
return getInfo(extractor);
}
public static FeedInfo getInfo(FeedExtractor extractor) throws IOException, ExtractionException {
public static FeedInfo getInfo(final FeedExtractor extractor)
throws IOException, ExtractionException {
extractor.fetchPage();
final int serviceId = extractor.getServiceId();
@ -43,7 +52,8 @@ public class FeedInfo extends ListInfo<StreamInfoItem> {
final FeedInfo info = new FeedInfo(serviceId, id, url, originalUrl, name, null, null);
final InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
final InfoItemsPage<StreamInfoItem> itemsPage
= ExtractorHelper.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(itemsPage.getItems());
info.setNextPage(itemsPage.getNextPage());

View File

@ -31,9 +31,9 @@ import javax.annotation.Nonnull;
public abstract class KioskExtractor<T extends InfoItem> extends ListExtractor<T> {
private final String id;
public KioskExtractor(StreamingService streamingService,
ListLinkHandler linkHandler,
String kioskId) {
public KioskExtractor(final StreamingService streamingService,
final ListLinkHandler linkHandler,
final String kioskId) {
super(streamingService, linkHandler);
this.id = kioskId;
}
@ -50,7 +50,6 @@ public abstract class KioskExtractor<T extends InfoItem> extends ListExtractor<T
* In order to get the name of the kiosk in the desired language we have to
* crawl if from the website.
* @return the translated version of id
* @throws ParsingException
*/
@Nonnull
@Override

View File

@ -26,34 +26,30 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException;
public class KioskInfo extends ListInfo<StreamInfoItem> {
private KioskInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException {
public final class KioskInfo extends ListInfo<StreamInfoItem> {
private KioskInfo(final int serviceId, final ListLinkHandler linkHandler, final String name) {
super(serviceId, linkHandler, name);
}
public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
Page page)
public static ListExtractor.InfoItemsPage<StreamInfoItem> getMoreItems(
final StreamingService service, final String url, final Page page)
throws IOException, ExtractionException {
KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, page);
return extractor.getPage(page);
return service.getKioskList().getExtractorByUrl(url, page).getPage(page);
}
public static KioskInfo getInfo(String url) throws IOException, ExtractionException {
public static KioskInfo getInfo(final String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static KioskInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
KioskList kl = service.getKioskList();
KioskExtractor extractor = kl.getExtractorByUrl(url, null);
public static KioskInfo getInfo(final StreamingService service, final String url)
throws IOException, ExtractionException {
final KioskExtractor extractor = service.getKioskList().getExtractorByUrl(url, null);
extractor.fetchPage();
return getInfo(extractor);
}
@ -63,13 +59,14 @@ public class KioskInfo extends ListInfo<StreamInfoItem> {
*
* @param extractor an extractor where fetchPage() was already got called on.
*/
public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionException {
public static KioskInfo getInfo(final KioskExtractor extractor) throws ExtractionException {
final KioskInfo info = new KioskInfo(extractor.getServiceId(),
extractor.getLinkHandler(),
extractor.getName());
final ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
final ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage
= ExtractorHelper.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(itemsPage.getItems());
info.setNextPage(itemsPage.getNextPage());

View File

@ -19,9 +19,9 @@ import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
public class KioskList {
public interface KioskExtractorFactory {
KioskExtractor createNewKiosk(final StreamingService streamingService,
final String url,
final String kioskId)
KioskExtractor createNewKiosk(StreamingService streamingService,
String url,
String kioskId)
throws ExtractionException, IOException;
}
@ -34,8 +34,8 @@ public class KioskList {
@Nullable
private ContentCountry forcedContentCountry;
private class KioskEntry {
public KioskEntry(KioskExtractorFactory ef, ListLinkHandlerFactory h) {
private static class KioskEntry {
KioskEntry(final KioskExtractorFactory ef, final ListLinkHandlerFactory h) {
extractorFactory = ef;
handlerFactory = h;
}
@ -44,11 +44,13 @@ public class KioskList {
final ListLinkHandlerFactory handlerFactory;
}
public KioskList(StreamingService service) {
public KioskList(final StreamingService service) {
this.service = service;
}
public void addKioskEntry(KioskExtractorFactory extractorFactory, ListLinkHandlerFactory handlerFactory, String id)
public void addKioskEntry(final KioskExtractorFactory extractorFactory,
final ListLinkHandlerFactory handlerFactory,
final String id)
throws Exception {
if (kioskList.get(id) != null) {
throw new Exception("Kiosk with type " + id + " already exists.");
@ -56,7 +58,7 @@ public class KioskList {
kioskList.put(id, new KioskEntry(extractorFactory, handlerFactory));
}
public void setDefaultKiosk(String kioskType) {
public void setDefaultKiosk(final String kioskType) {
defaultKiosk = kioskType;
}
@ -65,19 +67,20 @@ public class KioskList {
return getDefaultKioskExtractor(null);
}
public KioskExtractor getDefaultKioskExtractor(Page nextPage)
public KioskExtractor getDefaultKioskExtractor(final Page nextPage)
throws ExtractionException, IOException {
return getDefaultKioskExtractor(nextPage, NewPipe.getPreferredLocalization());
}
public KioskExtractor getDefaultKioskExtractor(Page nextPage, Localization localization)
public KioskExtractor getDefaultKioskExtractor(final Page nextPage,
final Localization localization)
throws ExtractionException, IOException {
if (!isNullOrEmpty(defaultKiosk)) {
return getExtractorById(defaultKiosk, nextPage, localization);
} else {
if (!kioskList.isEmpty()) {
// if not set get any entry
Object[] keySet = kioskList.keySet().toArray();
final Object[] keySet = kioskList.keySet().toArray();
return getExtractorById(keySet[0].toString(), nextPage, localization);
} else {
return null;
@ -89,22 +92,28 @@ public class KioskList {
return defaultKiosk;
}
public KioskExtractor getExtractorById(String kioskId, Page nextPage)
public KioskExtractor getExtractorById(final String kioskId, final Page nextPage)
throws ExtractionException, IOException {
return getExtractorById(kioskId, nextPage, NewPipe.getPreferredLocalization());
}
public KioskExtractor getExtractorById(String kioskId, Page nextPage, Localization localization)
public KioskExtractor getExtractorById(final String kioskId,
final Page nextPage,
final Localization localization)
throws ExtractionException, IOException {
KioskEntry ke = kioskList.get(kioskId);
final KioskEntry ke = kioskList.get(kioskId);
if (ke == null) {
throw new ExtractionException("No kiosk found with the type: " + kioskId);
} else {
final KioskExtractor kioskExtractor = ke.extractorFactory.createNewKiosk(service,
ke.handlerFactory.fromId(kioskId).getUrl(), kioskId);
if (forcedLocalization != null) kioskExtractor.forceLocalization(forcedLocalization);
if (forcedContentCountry != null) kioskExtractor.forceContentCountry(forcedContentCountry);
if (forcedLocalization != null) {
kioskExtractor.forceLocalization(forcedLocalization);
}
if (forcedContentCountry != null) {
kioskExtractor.forceContentCountry(forcedContentCountry);
}
return kioskExtractor;
}
@ -114,15 +123,17 @@ public class KioskList {
return kioskList.keySet();
}
public KioskExtractor getExtractorByUrl(String url, Page nextPage)
public KioskExtractor getExtractorByUrl(final String url, final Page nextPage)
throws ExtractionException, IOException {
return getExtractorByUrl(url, nextPage, NewPipe.getPreferredLocalization());
}
public KioskExtractor getExtractorByUrl(String url, Page nextPage, Localization localization)
public KioskExtractor getExtractorByUrl(final String url,
final Page nextPage,
final Localization localization)
throws ExtractionException, IOException {
for (Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
KioskEntry ke = e.getValue();
for (final Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
final KioskEntry ke = e.getValue();
if (ke.handlerFactory.acceptUrl(url)) {
return getExtractorById(ke.handlerFactory.getId(url), nextPage, localization);
}
@ -130,15 +141,15 @@ public class KioskList {
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
}
public ListLinkHandlerFactory getListLinkHandlerFactoryByType(String type) {
public ListLinkHandlerFactory getListLinkHandlerFactoryByType(final String type) {
return kioskList.get(type).handlerFactory;
}
public void forceLocalization(@Nullable Localization localization) {
public void forceLocalization(@Nullable final Localization localization) {
this.forcedLocalization = localization;
}
public void forceContentCountry(@Nullable ContentCountry contentCountry) {
public void forceContentCountry(@Nullable final ContentCountry contentCountry) {
this.forcedContentCountry = contentCountry;
}
}

View File

@ -10,13 +10,13 @@ public class LinkHandler implements Serializable {
protected final String url;
protected final String id;
public LinkHandler(String originalUrl, String url, String id) {
public LinkHandler(final String originalUrl, final String url, final String id) {
this.originalUrl = originalUrl;
this.url = url;
this.id = id;
}
public LinkHandler(LinkHandler handler) {
public LinkHandler(final LinkHandler handler) {
this(handler.originalUrl, handler.url, handler.id);
}

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.extractor.linkhandler;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Utils;
@ -31,10 +30,12 @@ public abstract class LinkHandlerFactory {
///////////////////////////////////
public abstract String getId(String url) throws ParsingException;
public abstract String getUrl(String id) throws ParsingException;
public abstract boolean onAcceptUrl(final String url) throws ParsingException;
public String getUrl(String id, String baseUrl) throws ParsingException {
public abstract String getUrl(String id) throws ParsingException;
public abstract boolean onAcceptUrl(String url) throws ParsingException;
public String getUrl(final String id, final String baseUrl) throws ParsingException {
return getUrl(id);
}
@ -46,6 +47,7 @@ public abstract class LinkHandlerFactory {
* Builds a {@link LinkHandler} from a url.<br>
* Be sure to call {@link Utils#followGoogleRedirectIfNeeded(String)} on the url if overriding
* this function.
*
* @param url the url to extract path and id from
* @return a {@link LinkHandler} complete with information
*/
@ -64,12 +66,15 @@ public abstract class LinkHandlerFactory {
* extracted?).<br>
* So do not call {@link Utils#followGoogleRedirectIfNeeded(String)} on the URL if overriding
* this function, since that should be done in {@link #fromUrl(String)}.
* @param url the URL without Google search redirects to extract id from
*
* @param url the URL without Google search redirects to extract id from
* @param baseUrl the base URL
* @return a {@link LinkHandler} complete with information
*/
public LinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
if (url == null) throw new IllegalArgumentException("URL cannot be null");
public LinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
if (url == null) {
throw new IllegalArgumentException("URL cannot be null");
}
if (!acceptUrl(url)) {
throw new ParsingException("URL not accepted: " + url);
}
@ -78,14 +83,18 @@ public abstract class LinkHandlerFactory {
return new LinkHandler(url, getUrl(id, baseUrl), id);
}
public LinkHandler fromId(String id) throws ParsingException {
if (id == null) throw new IllegalArgumentException("id can not be null");
public LinkHandler fromId(final String id) throws ParsingException {
if (id == null) {
throw new IllegalArgumentException("id can not be null");
}
final String url = getUrl(id);
return new LinkHandler(url, url, id);
}
public LinkHandler fromId(String id, String baseUrl) throws ParsingException {
if (id == null) throw new IllegalArgumentException("id can not be null");
public LinkHandler fromId(final String id, final String baseUrl) throws ParsingException {
if (id == null) {
throw new IllegalArgumentException("id can not be null");
}
final String url = getUrl(id, baseUrl);
return new LinkHandler(url, url, id);
}
@ -96,11 +105,6 @@ public abstract class LinkHandlerFactory {
* Return false if this service shall not allow to be called through ACTIONs.
*/
public boolean acceptUrl(final String url) throws ParsingException {
try {
return onAcceptUrl(url);
} catch (FoundAdException fe) {
throw fe;
}
return onAcceptUrl(url);
}
}

View File

@ -7,17 +7,17 @@ public class ListLinkHandler extends LinkHandler {
protected final List<String> contentFilters;
protected final String sortFilter;
public ListLinkHandler(String originalUrl,
String url,
String id,
List<String> contentFilters,
String sortFilter) {
public ListLinkHandler(final String originalUrl,
final String url,
final String id,
final List<String> contentFilters,
final String sortFilter) {
super(originalUrl, url, id);
this.contentFilters = Collections.unmodifiableList(contentFilters);
this.sortFilter = sortFilter;
}
public ListLinkHandler(ListLinkHandler handler) {
public ListLinkHandler(final ListLinkHandler handler) {
this(handler.originalUrl,
handler.url,
handler.id,
@ -25,9 +25,9 @@ public class ListLinkHandler extends LinkHandler {
handler.sortFilter);
}
public ListLinkHandler(LinkHandler handler,
List<String> contentFilters,
String sortFilter) {
public ListLinkHandler(final LinkHandler handler,
final List<String> contentFilters,
final String sortFilter) {
this(handler.originalUrl,
handler.url,
handler.id,

View File

@ -13,17 +13,23 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
// To Override
///////////////////////////////////
public List<String> getContentFilter(String url) throws ParsingException {
@SuppressWarnings({"RedundantThrows", "unused"})
public List<String> getContentFilter(final String url) throws ParsingException {
return Collections.emptyList();
}
public String getSortFilter(String url) throws ParsingException {
@SuppressWarnings({"RedundantThrows", "unused"})
public String getSortFilter(final String url) throws ParsingException {
return "";
}
public abstract String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException;
public abstract String getUrl(String id, List<String> contentFilter, String sortFilter)
throws ParsingException;
public String getUrl(String id, List<String> contentFilter, String sortFilter, String baseUrl) throws ParsingException {
public String getUrl(final String id,
final List<String> contentFilter,
final String sortFilter,
final String baseUrl) throws ParsingException {
return getUrl(id, contentFilter, sortFilter);
}
@ -39,55 +45,59 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
}
@Override
public ListLinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
if (url == null) throw new IllegalArgumentException("url may not be null");
public ListLinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
if (url == null) {
throw new IllegalArgumentException("url may not be null");
}
return new ListLinkHandler(super.fromUrl(url, baseUrl), getContentFilter(url), getSortFilter(url));
return new ListLinkHandler(super.fromUrl(url, baseUrl), getContentFilter(url),
getSortFilter(url));
}
@Override
public ListLinkHandler fromId(String id) throws ParsingException {
return new ListLinkHandler(super.fromId(id), new ArrayList<String>(0), "");
public ListLinkHandler fromId(final String id) throws ParsingException {
return new ListLinkHandler(super.fromId(id), new ArrayList<>(0), "");
}
@Override
public ListLinkHandler fromId(String id, String baseUrl) throws ParsingException {
return new ListLinkHandler(super.fromId(id, baseUrl), new ArrayList<String>(0), "");
public ListLinkHandler fromId(final String id, final String baseUrl) throws ParsingException {
return new ListLinkHandler(super.fromId(id, baseUrl), new ArrayList<>(0), "");
}
public ListLinkHandler fromQuery(String id,
List<String> contentFilters,
String sortFilter) throws ParsingException {
public ListLinkHandler fromQuery(final String id,
final List<String> contentFilters,
final String sortFilter) throws ParsingException {
final String url = getUrl(id, contentFilters, sortFilter);
return new ListLinkHandler(url, url, id, contentFilters, sortFilter);
}
public ListLinkHandler fromQuery(String id,
List<String> contentFilters,
String sortFilter, String baseUrl) throws ParsingException {
public ListLinkHandler fromQuery(final String id,
final List<String> contentFilters,
final String sortFilter,
final String baseUrl) throws ParsingException {
final String url = getUrl(id, contentFilters, sortFilter, baseUrl);
return new ListLinkHandler(url, url, id, contentFilters, sortFilter);
}
/**
* For making ListLinkHandlerFactory compatible with LinkHandlerFactory we need to override this,
* however it should not be overridden by the actual implementation.
* For making ListLinkHandlerFactory compatible with LinkHandlerFactory we need to override
* this, however it should not be overridden by the actual implementation.
*
* @param id
* @return the url corresponding to id without any filters applied
*/
public String getUrl(String id) throws ParsingException {
return getUrl(id, new ArrayList<String>(0), "");
public String getUrl(final String id) throws ParsingException {
return getUrl(id, new ArrayList<>(0), "");
}
@Override
public String getUrl(String id, String baseUrl) throws ParsingException {
return getUrl(id, new ArrayList<String>(0), "", baseUrl);
public String getUrl(final String id, final String baseUrl) throws ParsingException {
return getUrl(id, new ArrayList<>(0), "", baseUrl);
}
/**
* Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc.
* Will returns content filter the corresponding extractor can handle like "channels", "videos",
* "music", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
@ -96,7 +106,8 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
}
/**
* Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first", "size", etc.
* Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first",
* "size", etc.
*
* @return filter that can be applied when building a query for getting a list
*/

View File

@ -4,15 +4,15 @@ import java.util.List;
public class SearchQueryHandler extends ListLinkHandler {
public SearchQueryHandler(String originalUrl,
String url,
String searchString,
List<String> contentFilters,
String sortFilter) {
public SearchQueryHandler(final String originalUrl,
final String url,
final String searchString,
final List<String> contentFilters,
final String sortFilter) {
super(originalUrl, url, searchString, contentFilters, sortFilter);
}
public SearchQueryHandler(ListLinkHandler handler) {
public SearchQueryHandler(final ListLinkHandler handler) {
this(handler.originalUrl,
handler.url,
handler.id,

View File

@ -14,9 +14,11 @@ public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory {
///////////////////////////////////
@Override
public abstract String getUrl(String query, List<String> contentFilter, String sortFilter) throws ParsingException;
public abstract String getUrl(String query, List<String> contentFilter, String sortFilter)
throws ParsingException;
public String getSearchString(String url) {
@SuppressWarnings("unused")
public String getSearchString(final String url) {
return "";
}
@ -25,28 +27,26 @@ public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory {
///////////////////////////////////
@Override
public String getId(String url) {
public String getId(final String url) {
return getSearchString(url);
}
@Override
public SearchQueryHandler fromQuery(String query,
List<String> contentFilter,
String sortFilter) throws ParsingException {
public SearchQueryHandler fromQuery(final String query,
final List<String> contentFilter,
final String sortFilter) throws ParsingException {
return new SearchQueryHandler(super.fromQuery(query, contentFilter, sortFilter));
}
public SearchQueryHandler fromQuery(String query) throws ParsingException {
public SearchQueryHandler fromQuery(final String query) throws ParsingException {
return fromQuery(query, new ArrayList<>(0), EMPTY_STRING);
}
/**
* It's not mandatory for NewPipe to handle the Url
*
* @param url
*/
@Override
public boolean onAcceptUrl(String url) {
public boolean onAcceptUrl(final String url) {
return false;
}
}

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.extractor.localization;
import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@ -9,23 +10,26 @@ import java.util.List;
/**
* Represents a country that should be used when fetching content.
* <p>
* YouTube, for example, give different results in their feed depending on which country is selected.
* YouTube, for example, give different results in their feed depending on which country is
* selected.
* </p>
*/
public class ContentCountry implements Serializable {
public static final ContentCountry DEFAULT = new ContentCountry(Localization.DEFAULT.getCountryCode());
public static final ContentCountry DEFAULT =
new ContentCountry(Localization.DEFAULT.getCountryCode());
@Nonnull private final String countryCode;
@Nonnull
private final String countryCode;
public static List<ContentCountry> listFrom(String... countryCodeList) {
public static List<ContentCountry> listFrom(final String... countryCodeList) {
final List<ContentCountry> toReturn = new ArrayList<>();
for (String countryCode : countryCodeList) {
for (final String countryCode : countryCodeList) {
toReturn.add(new ContentCountry(countryCode));
}
return Collections.unmodifiableList(toReturn);
}
public ContentCountry(@Nonnull String countryCode) {
public ContentCountry(@Nonnull final String countryCode) {
this.countryCode = countryCode;
}
@ -40,11 +44,15 @@ public class ContentCountry implements Serializable {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ContentCountry)) return false;
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ContentCountry)) {
return false;
}
ContentCountry that = (ContentCountry) o;
final ContentCountry that = (ContentCountry) o;
return countryCode.equals(that.countryCode);
}

View File

@ -9,7 +9,8 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* A wrapper class that provides a field to describe if the date/time is precise or just an approximation.
* A wrapper class that provides a field to describe if the date/time is precise or just an
* approximation.
*/
public class DateWrapper implements Serializable {
@Nonnull
@ -20,7 +21,8 @@ public class DateWrapper implements Serializable {
* @deprecated Use {@link #DateWrapper(OffsetDateTime)} instead.
*/
@Deprecated
public DateWrapper(@Nonnull Calendar calendar) {
public DateWrapper(@Nonnull final Calendar calendar) {
//noinspection deprecation
this(calendar, false);
}
@ -28,15 +30,16 @@ public class DateWrapper implements Serializable {
* @deprecated Use {@link #DateWrapper(OffsetDateTime, boolean)} instead.
*/
@Deprecated
public DateWrapper(@Nonnull Calendar calendar, boolean isApproximation) {
public DateWrapper(@Nonnull final Calendar calendar, final boolean isApproximation) {
this(OffsetDateTime.ofInstant(calendar.toInstant(), ZoneOffset.UTC), isApproximation);
}
public DateWrapper(@Nonnull OffsetDateTime offsetDateTime) {
public DateWrapper(@Nonnull final OffsetDateTime offsetDateTime) {
this(offsetDateTime, false);
}
public DateWrapper(@Nonnull OffsetDateTime offsetDateTime, boolean isApproximation) {
public DateWrapper(@Nonnull final OffsetDateTime offsetDateTime,
final boolean isApproximation) {
this.offsetDateTime = offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC);
this.isApproximation = isApproximation;
}
@ -60,8 +63,8 @@ public class DateWrapper implements Serializable {
}
/**
* @return if the date is considered is precise or just an approximation (e.g. service only returns an approximation
* like 2 weeks ago instead of a precise date).
* @return if the date is considered is precise or just an approximation (e.g. service only
* returns an approximation like 2 weeks ago instead of a precise date).
*/
public boolean isApproximation() {
return isApproximation;

View File

@ -4,8 +4,15 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
public class Localization implements Serializable {
public static final Localization DEFAULT = new Localization("en", "GB");
@ -16,11 +23,12 @@ public class Localization implements Serializable {
private final String countryCode;
/**
* @param localizationCodeList a list of localization code, formatted like {@link #getLocalizationCode()}
* @param localizationCodeList a list of localization code, formatted like {@link
* #getLocalizationCode()}
*/
public static List<Localization> listFrom(String... localizationCodeList) {
public static List<Localization> listFrom(final String... localizationCodeList) {
final List<Localization> toReturn = new ArrayList<>();
for (String localizationCode : localizationCodeList) {
for (final String localizationCode : localizationCodeList) {
toReturn.add(fromLocalizationCode(localizationCode));
}
return Collections.unmodifiableList(toReturn);
@ -29,10 +37,11 @@ public class Localization implements Serializable {
/**
* @param localizationCode a localization code, formatted like {@link #getLocalizationCode()}
*/
public static Localization fromLocalizationCode(String localizationCode) {
public static Localization fromLocalizationCode(final String localizationCode) {
final int indexSeparator = localizationCode.indexOf("-");
final String languageCode, countryCode;
final String languageCode;
final String countryCode;
if (indexSeparator != -1) {
languageCode = localizationCode.substring(0, indexSeparator);
countryCode = localizationCode.substring(indexSeparator + 1);
@ -44,15 +53,16 @@ public class Localization implements Serializable {
return new Localization(languageCode, countryCode);
}
public Localization(@Nonnull String languageCode, @Nullable String countryCode) {
public Localization(@Nonnull final String languageCode, @Nullable final String countryCode) {
this.languageCode = languageCode;
this.countryCode = countryCode;
}
public Localization(@Nonnull String languageCode) {
public Localization(@Nonnull final String languageCode) {
this(languageCode, null);
}
@Nonnull
public String getLanguageCode() {
return languageCode;
}
@ -66,7 +76,7 @@ public class Localization implements Serializable {
return new Locale(getLanguageCode(), getCountryCode());
}
public static Localization fromLocale(@Nonnull Locale locale) {
public static Localization fromLocale(@Nonnull final Locale locale) {
return new Localization(locale.getLanguage(), locale.getCountry());
}
@ -84,14 +94,18 @@ public class Localization implements Serializable {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Localization)) return false;
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Localization)) {
return false;
}
Localization that = (Localization) o;
final Localization that = (Localization) o;
return languageCode.equals(that.languageCode) &&
Objects.equals(countryCode, that.countryCode);
return languageCode.equals(that.languageCode)
&& Objects.equals(countryCode, that.countryCode);
}
@Override
@ -108,17 +122,19 @@ public class Localization implements Serializable {
* @param code a three letter language code
* @return the Locale corresponding
*/
public static Locale getLocaleFromThreeLetterCode(@Nonnull String code) throws ParsingException {
public static Locale getLocaleFromThreeLetterCode(@Nonnull final String code)
throws ParsingException {
final String[] languages = Locale.getISOLanguages();
final Map<String, Locale> localeMap = new HashMap<>(languages.length);
for (String language : languages) {
for (final String language : languages) {
final Locale locale = new Locale(language);
localeMap.put(locale.getISO3Language(), locale);
}
if (localeMap.containsKey(code)) {
return localeMap.get(code);
} else {
throw new ParsingException("Could not get Locale from this three letter language code" + code);
throw new ParsingException(
"Could not get Locale from this three letter language code" + code);
}
}
}

View File

@ -25,16 +25,17 @@ public class TimeAgoParser {
* Instantiate a new {@link TimeAgoParser} every time you extract a new batch of items.
* </p>
*
* @param patternsHolder An object that holds the "time ago" patterns, special cases, and the language word separator.
* @param patternsHolder An object that holds the "time ago" patterns, special cases, and the
* language word separator.
*/
public TimeAgoParser(PatternsHolder patternsHolder) {
public TimeAgoParser(final PatternsHolder patternsHolder) {
this.patternsHolder = patternsHolder;
now = OffsetDateTime.now(ZoneOffset.UTC);
}
/**
* Parses a textual date in the format '2 days ago' into a Calendar representation which is then wrapped in a
* {@link DateWrapper} object.
* Parses a textual date in the format '2 days ago' into a Calendar representation which is then
* wrapped in a {@link DateWrapper} object.
* <p>
* Beginning with days ago, the date is considered as an approximation.
*
@ -42,10 +43,12 @@ public class TimeAgoParser {
* @return The parsed time (can be approximated)
* @throws ParsingException if the time unit could not be recognized
*/
public DateWrapper parse(String textualDate) throws ParsingException {
for (Map.Entry<ChronoUnit, Map<String, Integer>> caseUnitEntry : patternsHolder.specialCases().entrySet()) {
public DateWrapper parse(final String textualDate) throws ParsingException {
for (final Map.Entry<ChronoUnit, Map<String, Integer>> caseUnitEntry
: patternsHolder.specialCases().entrySet()) {
final ChronoUnit chronoUnit = caseUnitEntry.getKey();
for (Map.Entry<String, Integer> caseMapToAmountEntry : caseUnitEntry.getValue().entrySet()) {
for (final Map.Entry<String, Integer> caseMapToAmountEntry
: caseUnitEntry.getValue().entrySet()) {
final String caseText = caseMapToAmountEntry.getKey();
final Integer caseAmount = caseMapToAmountEntry.getValue();
@ -58,7 +61,7 @@ public class TimeAgoParser {
int timeAgoAmount;
try {
timeAgoAmount = parseTimeAgoAmount(textualDate);
} catch (NumberFormatException e) {
} catch (final NumberFormatException e) {
// If there is no valid number in the textual date,
// assume it is 1 (as in 'a second ago').
timeAgoAmount = 1;
@ -68,16 +71,16 @@ public class TimeAgoParser {
return getResultFor(timeAgoAmount, chronoUnit);
}
private int parseTimeAgoAmount(String textualDate) throws NumberFormatException {
String timeValueStr = textualDate.replaceAll("\\D+", "");
return Integer.parseInt(timeValueStr);
private int parseTimeAgoAmount(final String textualDate) throws NumberFormatException {
return Integer.parseInt(textualDate.replaceAll("\\D+", ""));
}
private ChronoUnit parseChronoUnit(String textualDate) throws ParsingException {
for (Map.Entry<ChronoUnit, Collection<String>> entry : patternsHolder.asMap().entrySet()) {
private ChronoUnit parseChronoUnit(final String textualDate) throws ParsingException {
for (final Map.Entry<ChronoUnit, Collection<String>> entry
: patternsHolder.asMap().entrySet()) {
final ChronoUnit chronoUnit = entry.getKey();
for (String agoPhrase : entry.getValue()) {
for (final String agoPhrase : entry.getValue()) {
if (textualDateMatches(textualDate, agoPhrase)) {
return chronoUnit;
}
@ -87,7 +90,7 @@ public class TimeAgoParser {
throw new ParsingException("Unable to parse the date: " + textualDate);
}
private boolean textualDateMatches(String textualDate, String agoPhrase) {
private boolean textualDateMatches(final String textualDate, final String agoPhrase) {
if (textualDate.equals(agoPhrase)) {
return true;
}
@ -98,7 +101,8 @@ public class TimeAgoParser {
final String escapedPhrase = Pattern.quote(agoPhrase.toLowerCase());
final String escapedSeparator;
if (patternsHolder.wordSeparator().equals(" ")) {
// From JDK8 \h - Treat horizontal spaces as a normal one (non-breaking space, thin space, etc.)
// From JDK8 \h - Treat horizontal spaces as a normal one
// (non-breaking space, thin space, etc.)
escapedSeparator = "[ \\t\\xA0\\u1680\\u180e\\u2000-\\u200a\\u202f\\u205f\\u3000]";
} else {
escapedSeparator = Pattern.quote(patternsHolder.wordSeparator());
@ -113,7 +117,7 @@ public class TimeAgoParser {
}
}
private DateWrapper getResultFor(int timeAgoAmount, ChronoUnit chronoUnit) {
private DateWrapper getResultFor(final int timeAgoAmount, final ChronoUnit chronoUnit) {
OffsetDateTime offsetDateTime = now;
boolean isApproximation = false;

View File

@ -6,14 +6,18 @@ import org.schabi.newpipe.extractor.timeago.PatternsManager;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class TimeAgoPatternsManager {
@Nullable
private static PatternsHolder getPatternsFor(@Nonnull Localization localization) {
return PatternsManager.getPatterns(localization.getLanguageCode(), localization.getCountryCode());
public final class TimeAgoPatternsManager {
private TimeAgoPatternsManager() {
}
@Nullable
public static TimeAgoParser getTimeAgoParserFor(@Nonnull Localization localization) {
private static PatternsHolder getPatternsFor(@Nonnull final Localization localization) {
return PatternsManager.getPatterns(localization.getLanguageCode(),
localization.getCountryCode());
}
@Nullable
public static TimeAgoParser getTimeAgoParserFor(@Nonnull final Localization localization) {
final PatternsHolder holder = getPatternsFor(localization);
if (holder == null) {

View File

@ -15,7 +15,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class PlaylistInfo extends ListInfo<StreamInfoItem> {
public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
/**
* Mixes are handled as particular playlists in NewPipeExtractor. {@link PlaylistType#NORMAL} is
@ -52,23 +52,27 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
MIX_GENRE,
}
private PlaylistInfo(int serviceId, ListLinkHandler linkHandler, String name) throws ParsingException {
@SuppressWarnings("RedundantThrows")
private PlaylistInfo(final int serviceId, final ListLinkHandler linkHandler, final String name)
throws ParsingException {
super(serviceId, linkHandler, name);
}
public static PlaylistInfo getInfo(String url) throws IOException, ExtractionException {
public static PlaylistInfo getInfo(final String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static PlaylistInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
PlaylistExtractor extractor = service.getPlaylistExtractor(url);
public static PlaylistInfo getInfo(final StreamingService service, final String url)
throws IOException, ExtractionException {
final PlaylistExtractor extractor = service.getPlaylistExtractor(url);
extractor.fetchPage();
return getInfo(extractor);
}
public static InfoItemsPage<StreamInfoItem> getMoreItems(StreamingService service,
String url,
Page page) throws IOException, ExtractionException {
public static InfoItemsPage<StreamInfoItem> getMoreItems(final StreamingService service,
final String url,
final Page page)
throws IOException, ExtractionException {
return service.getPlaylistExtractor(url).getPage(page);
}
@ -77,7 +81,8 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
*
* @param extractor an extractor where fetchPage() was already got called on.
*/
public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws ExtractionException {
public static PlaylistInfo getInfo(final PlaylistExtractor extractor)
throws ExtractionException {
final PlaylistInfo info = new PlaylistInfo(
extractor.getServiceId(),
@ -85,73 +90,75 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
extractor.getName());
// collect uploader extraction failures until we are sure this is not
// just a playlist without an uploader
List<Throwable> uploaderParsingErrors = new ArrayList<Throwable>(3);
final List<Throwable> uploaderParsingErrors = new ArrayList<>();
try {
info.setOriginalUrl(extractor.getOriginalUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setStreamCount(extractor.getStreamCount());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.setUploaderUrl("");
uploaderParsingErrors.add(e);
}
try {
info.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
} catch (final Exception e) {
info.setUploaderName("");
uploaderParsingErrors.add(e);
}
try {
info.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.setUploaderAvatarUrl("");
uploaderParsingErrors.add(e);
}
try {
info.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) {
} catch (final Exception e) {
uploaderParsingErrors.add(e);
}
try {
info.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) {
} catch (final Exception e) {
uploaderParsingErrors.add(e);
}
try {
info.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
uploaderParsingErrors.add(e);
}
try {
info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setPlaylistType(extractor.getPlaylistType());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
// do not fail if everything but the uploader infos could be collected
if (!uploaderParsingErrors.isEmpty() &&
(!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) {
// do not fail if everything but the uploader infos could be collected (TODO better comment)
if (!uploaderParsingErrors.isEmpty()
&& (!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) {
info.addAllErrors(uploaderParsingErrors);
}
final InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);
final InfoItemsPage<StreamInfoItem> itemsPage
= ExtractorHelper.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(itemsPage.getItems());
info.setNextPage(itemsPage.getNextPage());
@ -173,7 +180,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return thumbnailUrl;
}
public void setThumbnailUrl(String thumbnailUrl) {
public void setThumbnailUrl(final String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
@ -181,7 +188,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return bannerUrl;
}
public void setBannerUrl(String bannerUrl) {
public void setBannerUrl(final String bannerUrl) {
this.bannerUrl = bannerUrl;
}
@ -189,7 +196,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return uploaderUrl;
}
public void setUploaderUrl(String uploaderUrl) {
public void setUploaderUrl(final String uploaderUrl) {
this.uploaderUrl = uploaderUrl;
}
@ -197,7 +204,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return uploaderName;
}
public void setUploaderName(String uploaderName) {
public void setUploaderName(final String uploaderName) {
this.uploaderName = uploaderName;
}
@ -205,7 +212,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return uploaderAvatarUrl;
}
public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
public void setUploaderAvatarUrl(final String uploaderAvatarUrl) {
this.uploaderAvatarUrl = uploaderAvatarUrl;
}
@ -213,7 +220,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return subChannelUrl;
}
public void setSubChannelUrl(String subChannelUrl) {
public void setSubChannelUrl(final String subChannelUrl) {
this.subChannelUrl = subChannelUrl;
}
@ -221,7 +228,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return subChannelName;
}
public void setSubChannelName(String subChannelName) {
public void setSubChannelName(final String subChannelName) {
this.subChannelName = subChannelName;
}
@ -229,7 +236,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return subChannelAvatarUrl;
}
public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) {
this.subChannelAvatarUrl = subChannelAvatarUrl;
}
@ -237,7 +244,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
return streamCount;
}
public void setStreamCount(long streamCount) {
public void setStreamCount(final long streamCount) {
this.streamCount = streamCount;
}

View File

@ -11,7 +11,7 @@ public class PlaylistInfoItem extends InfoItem {
private long streamCount = 0;
private PlaylistInfo.PlaylistType playlistType;
public PlaylistInfoItem(int serviceId, String url, String name) {
public PlaylistInfoItem(final int serviceId, final String url, final String name) {
super(InfoType.PLAYLIST, serviceId, url, name);
}
@ -19,16 +19,16 @@ public class PlaylistInfoItem extends InfoItem {
return uploaderName;
}
public void setUploaderName(String uploader_name) {
this.uploaderName = uploader_name;
public void setUploaderName(final String uploaderName) {
this.uploaderName = uploaderName;
}
public long getStreamCount() {
return streamCount;
}
public void setStreamCount(long stream_count) {
this.streamCount = stream_count;
public void setStreamCount(final long streamCount) {
this.streamCount = streamCount;
}
public PlaylistInfo.PlaylistType getPlaylistType() {

View File

@ -10,14 +10,12 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
/**
* Get the uploader name
* @return the uploader name
* @throws ParsingException
*/
String getUploaderName() throws ParsingException;
/**
* Get the number of streams
* @return the number of streams
* @throws ParsingException
*/
long getStreamCount() throws ParsingException;

View File

@ -3,34 +3,32 @@ package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
public class PlaylistInfoItemsCollector extends InfoItemsCollector<PlaylistInfoItem, PlaylistInfoItemExtractor> {
public class PlaylistInfoItemsCollector
extends InfoItemsCollector<PlaylistInfoItem, PlaylistInfoItemExtractor> {
public PlaylistInfoItemsCollector(int serviceId) {
public PlaylistInfoItemsCollector(final int serviceId) {
super(serviceId);
}
@Override
public PlaylistInfoItem extract(PlaylistInfoItemExtractor extractor) throws ParsingException {
String name = extractor.getName();
int serviceId = getServiceId();
String url = extractor.getUrl();
PlaylistInfoItem resultItem = new PlaylistInfoItem(serviceId, url, name);
public PlaylistInfoItem extract(final PlaylistInfoItemExtractor extractor)
throws ParsingException {
final PlaylistInfoItem resultItem = new PlaylistInfoItem(
getServiceId(), extractor.getUrl(), extractor.getName());
try {
resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setStreamCount(extractor.getStreamCount());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {

View File

@ -14,12 +14,12 @@ import java.util.List;
public abstract class SearchExtractor extends ListExtractor<InfoItem> {
public static class NothingFoundException extends ExtractionException {
public NothingFoundException(String message) {
public NothingFoundException(final String message) {
super(message);
}
}
public SearchExtractor(StreamingService service, SearchQueryHandler linkHandler) {
public SearchExtractor(final StreamingService service, final SearchQueryHandler linkHandler) {
super(service, linkHandler);
}
@ -34,11 +34,11 @@ public abstract class SearchExtractor extends ListExtractor<InfoItem> {
* {@link SearchExtractor#isCorrectedSearch()} is true.
*
* @return a suggestion to another query, the corrected query, or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getSearchSuggestion() throws ParsingException;
@Nonnull
@Override
public SearchQueryHandler getLinkHandler() {
return (SearchQueryHandler) super.getLinkHandler();
@ -66,8 +66,7 @@ public abstract class SearchExtractor extends ListExtractor<InfoItem> {
* Example: on YouTube, if you search for "Covid-19",
* there is a box with information from the WHO about Covid-19 and a link to the WHO's website.
* @return additional meta information about the search query
* @throws ParsingException
*/
@Nonnull
@Nonnull
public abstract List<MetaInfo> getMetaInfo() throws ParsingException;
}

View File

@ -1,6 +1,11 @@
package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
@ -11,26 +16,29 @@ import java.util.List;
import javax.annotation.Nonnull;
public class SearchInfo extends ListInfo<InfoItem> {
private String searchString;
private final String searchString;
private String searchSuggestion;
private boolean isCorrectedSearch;
private List<MetaInfo> metaInfo;
public SearchInfo(int serviceId,
SearchQueryHandler qIHandler,
String searchString) {
public SearchInfo(final int serviceId,
final SearchQueryHandler qIHandler,
final String searchString) {
super(serviceId, qIHandler, "Search");
this.searchString = searchString;
}
public static SearchInfo getInfo(StreamingService service, SearchQueryHandler searchQuery) throws ExtractionException, IOException {
SearchExtractor extractor = service.getSearchExtractor(searchQuery);
public static SearchInfo getInfo(final StreamingService service,
final SearchQueryHandler searchQuery)
throws ExtractionException, IOException {
final SearchExtractor extractor = service.getSearchExtractor(searchQuery);
extractor.fetchPage();
return getInfo(extractor);
}
public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException, IOException {
public static SearchInfo getInfo(final SearchExtractor extractor)
throws ExtractionException, IOException {
final SearchInfo info = new SearchInfo(
extractor.getServiceId(),
extractor.getLinkHandler(),
@ -38,26 +46,27 @@ public class SearchInfo extends ListInfo<InfoItem> {
try {
info.setOriginalUrl(extractor.getOriginalUrl());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setSearchSuggestion(extractor.getSearchSuggestion());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setIsCorrectedSearch(extractor.isCorrectedSearch());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
try {
info.setMetaInfo(extractor.getMetaInfo());
} catch (Exception e) {
} catch (final Exception e) {
info.addError(e);
}
ListExtractor.InfoItemsPage<InfoItem> page = ExtractorHelper.getItemsPageOrLogError(info, extractor);
final ListExtractor.InfoItemsPage<InfoItem> page
= ExtractorHelper.getItemsPageOrLogError(info, extractor);
info.setRelatedItems(page.getItems());
info.setNextPage(page.getNextPage());
@ -65,9 +74,9 @@ public class SearchInfo extends ListInfo<InfoItem> {
}
public static ListExtractor.InfoItemsPage<InfoItem> getMoreItems(StreamingService service,
SearchQueryHandler query,
Page page)
public static ListExtractor.InfoItemsPage<InfoItem> getMoreItems(final StreamingService service,
final SearchQueryHandler query,
final Page page)
throws IOException, ExtractionException {
return service.getSearchExtractor(query).getPage(page);
}
@ -85,11 +94,11 @@ public class SearchInfo extends ListInfo<InfoItem> {
return this.isCorrectedSearch;
}
public void setIsCorrectedSearch(boolean isCorrectedSearch) {
public void setIsCorrectedSearch(final boolean isCorrectedSearch) {
this.isCorrectedSearch = isCorrectedSearch;
}
public void setSearchSuggestion(String searchSuggestion) {
public void setSearchSuggestion(final String searchSuggestion) {
this.searchSuggestion = searchSuggestion;
}
@ -98,7 +107,7 @@ public class SearchInfo extends ListInfo<InfoItem> {
return metaInfo;
}
public void setMetaInfo(@Nonnull List<MetaInfo> metaInfo) {
public void setMetaInfo(@Nonnull final List<MetaInfo> metaInfo) {
this.metaInfo = metaInfo;
}
}

View File

@ -74,7 +74,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
try {
text = JsonUtils.getString(json, "description");
} catch (ParsingException e) {
return Description.emptyDescription;
return Description.EMPTY_DESCRIPTION;
}
if (text.length() == 250 && text.substring(247).equals("...")) {
//if description is shortened, get full description

View File

@ -24,7 +24,7 @@ import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.services.youtube.ItagItem;
public class AudioStream extends Stream {
public int average_bitrate = -1;
private final int averageBitrate;
// Fields for Dash
private int itag;
@ -42,9 +42,11 @@ public class AudioStream extends Stream {
* @param format the format
* @param averageBitrate the average bitrate
*/
public AudioStream(String url, MediaFormat format, int averageBitrate) {
public AudioStream(final String url,
final MediaFormat format,
final int averageBitrate) {
super(url, format);
this.average_bitrate = averageBitrate;
this.averageBitrate = averageBitrate;
}
/**
@ -52,7 +54,7 @@ public class AudioStream extends Stream {
* @param url the url
* @param itag the ItagItem of the Stream
*/
public AudioStream(String url, ItagItem itag) {
public AudioStream(final String url, final ItagItem itag) {
this(url, itag.getMediaFormat(), itag.avgBitrate);
this.itag = itag.id;
this.quality = itag.getQuality();
@ -65,9 +67,9 @@ public class AudioStream extends Stream {
}
@Override
public boolean equalStats(Stream cmp) {
return super.equalStats(cmp) && cmp instanceof AudioStream &&
average_bitrate == ((AudioStream) cmp).average_bitrate;
public boolean equalStats(final Stream cmp) {
return super.equalStats(cmp) && cmp instanceof AudioStream
&& averageBitrate == ((AudioStream) cmp).averageBitrate;
}
/**
@ -75,7 +77,7 @@ public class AudioStream extends Stream {
* @return the average bitrate or -1
*/
public int getAverageBitrate() {
return average_bitrate;
return averageBitrate;
}
public int getItag() {

View File

@ -10,12 +10,12 @@ public class Description implements Serializable {
public static final int HTML = 1;
public static final int MARKDOWN = 2;
public static final int PLAIN_TEXT = 3;
public static final Description emptyDescription = new Description(EMPTY_STRING, PLAIN_TEXT);
public static final Description EMPTY_DESCRIPTION = new Description(EMPTY_STRING, PLAIN_TEXT);
private String content;
private int type;
private final String content;
private final int type;
public Description(String content, int type) {
public Description(final String content, final int type) {
this.type = type;
if (content == null) {
this.content = "";
@ -33,10 +33,14 @@ public class Description implements Serializable {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Description that = (Description) o;
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Description that = (Description) o;
return type == that.type && Objects.equals(content, that.content);
}

View File

@ -21,7 +21,7 @@ public final class Frameset implements Serializable {
final int durationPerFrame,
final int framesPerPageX,
final int framesPerPageY) {
this.urls = urls;
this.totalCount = totalCount;
this.durationPerFrame = durationPerFrame;
@ -84,8 +84,8 @@ public final class Frameset implements Serializable {
* Returns the information for the frame at stream position.
*
* @param position Position in milliseconds
* @return An <code>int</code>-array containing the bounds and URL where the indexes are specified as
* followed:
* @return An <code>int</code>-array containing the bounds and URL where the indexes are
* specified as follows:
*
* <ul>
* <li><code>0</code>: Index of the URL</li>
@ -96,9 +96,9 @@ public final class Frameset implements Serializable {
* </ul>
*/
public int[] getFrameBoundsAt(final long position) {
if (position < 0 || position > ((totalCount + 1) * durationPerFrame)) {
if (position < 0 || position > ((long) (totalCount + 1) * durationPerFrame)) {
// Return the first frame as fallback
return new int[] { 0, 0, 0, frameWidth, frameHeight };
return new int[] {0, 0, 0, frameWidth, frameHeight};
}
final int framesPerStoryboard = framesPerPageX * framesPerPageY;
@ -116,4 +116,4 @@ public final class Frameset implements Serializable {
/* right */ columnIndex * frameWidth + frameWidth,
/* bottom */ rowIndex * frameHeight + frameHeight };
}
}
}

View File

@ -27,7 +27,7 @@ public abstract class Stream implements Serializable {
* @param url the url
* @param format the format
*/
public Stream(String url, MediaFormat format) {
public Stream(final String url, final MediaFormat format) {
this(url, null, format);
}
@ -35,12 +35,14 @@ public abstract class Stream implements Serializable {
* Instantiates a new stream object.
*
* @param url the url
* @param torrentUrl the url to torrent file, example https://webtorrent.io/torrents/big-buck-bunny.torrent
* @param torrentUrl the url to torrent file, example
* https://webtorrent.io/torrents/big-buck-bunny.torrent
* @param format the format
*/
public Stream(String url, String torrentUrl, MediaFormat format) {
public Stream(final String url, final String torrentUrl, final MediaFormat format) {
this.url = url;
this.torrentUrl = torrentUrl;
//noinspection deprecation
this.format = format.id;
this.mediaFormat = format;
}
@ -48,24 +50,29 @@ public abstract class Stream implements Serializable {
/**
* Reveals whether two streams have the same stats (format and bitrate, for example)
*/
public boolean equalStats(Stream cmp) {
public boolean equalStats(final Stream cmp) {
return cmp != null && getFormatId() == cmp.getFormatId();
}
/**
* Reveals whether two Streams are equal
*/
public boolean equals(Stream cmp) {
public boolean equals(final Stream cmp) {
return equalStats(cmp) && url.equals(cmp.url);
}
/**
* Check if the list already contains one stream with equals stats
*/
public static boolean containSimilarStream(Stream stream, List<? extends Stream> streamList) {
if (isNullOrEmpty(streamList)) return false;
for (Stream cmpStream : streamList) {
if (stream.equalStats(cmpStream)) return true;
public static boolean containSimilarStream(final Stream stream,
final List<? extends Stream> streamList) {
if (isNullOrEmpty(streamList)) {
return false;
}
for (final Stream cmpStream : streamList) {
if (stream.equalStats(cmpStream)) {
return true;
}
}
return false;
}

View File

@ -36,6 +36,7 @@ import org.schabi.newpipe.extractor.utils.Parser;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
@ -49,7 +50,7 @@ public abstract class StreamExtractor extends Extractor {
public static final int NO_AGE_LIMIT = 0;
public static final long UNKNOWN_SUBSCRIBER_COUNT = -1;
public StreamExtractor(StreamingService service, LinkHandler linkHandler) {
public StreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
super(service, linkHandler);
}
@ -70,7 +71,8 @@ public abstract class StreamExtractor extends Extractor {
/**
* A more general {@code Calendar} instance set to the date provided by the service.<br>
* Implementations usually will just parse the date returned from the {@link #getTextualUploadDate()}.
* Implementations usually will just parse the date returned from the {@link
* #getTextualUploadDate()}.
*
* <p>If the stream is a live stream, {@code null} should be returned.</p>
*
@ -85,10 +87,10 @@ public abstract class StreamExtractor extends Extractor {
}
/**
* This will return the url to the thumbnail of the stream. Try to return the medium resolution here.
* This will return the url to the thumbnail of the stream. Try to return the medium resolution
* here.
*
* @return The url of the thumbnail.
* @throws ParsingException
*/
@Nonnull
public abstract String getThumbnailUrl() throws ParsingException;
@ -96,12 +98,12 @@ public abstract class StreamExtractor extends Extractor {
/**
* This is the stream description.
*
* @return The description of the stream/video or Description.emptyDescription if the description is empty.
* @throws ParsingException
* @return The description of the stream/video or {@link Description#EMPTY_DESCRIPTION} if the
* description is empty.
*/
@Nonnull
public Description getDescription() throws ParsingException {
return Description.emptyDescription;
return Description.EMPTY_DESCRIPTION;
}
/**
@ -118,7 +120,6 @@ public abstract class StreamExtractor extends Extractor {
* This should return the length of a video in seconds.
*
* @return The length of the stream in seconds or 0 when it has no length (e.g. a livestream).
* @throws ParsingException
*/
public long getLength() throws ParsingException {
return 0;
@ -130,7 +131,6 @@ public abstract class StreamExtractor extends Extractor {
* If the url has no time stamp simply return zero.
*
* @return the timestamp in seconds or 0 when there is no timestamp
* @throws ParsingException
*/
public long getTimeStamp() throws ParsingException {
return 0;
@ -141,7 +141,6 @@ public abstract class StreamExtractor extends Extractor {
* If the current stream has no view count or its not available simply return -1
*
* @return amount of views or -1 if not available.
* @throws ParsingException
*/
public long getViewCount() throws ParsingException {
return -1;
@ -152,7 +151,6 @@ public abstract class StreamExtractor extends Extractor {
* If the current stream has no likes or its not available simply return -1
*
* @return the amount of likes the stream got or -1 if not available.
* @throws ParsingException
*/
public long getLikeCount() throws ParsingException {
return -1;
@ -163,7 +161,6 @@ public abstract class StreamExtractor extends Extractor {
* If the current stream has no dislikes or its not available simply return -1
*
* @return the amount of likes the stream got or -1 if not available.
* @throws ParsingException
*/
public long getDislikeCount() throws ParsingException {
return -1;
@ -172,12 +169,10 @@ public abstract class StreamExtractor extends Extractor {
/**
* The Url to the page of the creator/uploader of the stream. This must not be a homepage,
* but the page offered by the service the extractor handles. This url will be handled by the
* {@link ChannelExtractor},
* so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects
* this url.
* {@link ChannelExtractor}, so be sure to implement that one before you return a value here,
* otherwise NewPipe will crash if one selects this url.
*
* @return the url to the page of the creator/uploader of the stream or an empty string
* @throws ParsingException
*/
@Nonnull
public abstract String getUploaderUrl() throws ParsingException;
@ -187,7 +182,6 @@ public abstract class StreamExtractor extends Extractor {
* If the name is not available you can simply return an empty string.
*
* @return the name of the creator/uploader of the stream or an empty tring
* @throws ParsingException
*/
@Nonnull
public abstract String getUploaderName() throws ParsingException;
@ -197,7 +191,6 @@ public abstract class StreamExtractor extends Extractor {
* If there is no verification implemented, return <code>false</code>.
*
* @return whether the uploader has been verified by the service's provider
* @throws ParsingException
*/
public boolean isUploaderVerified() throws ParsingException {
return false;
@ -207,8 +200,8 @@ public abstract class StreamExtractor extends Extractor {
* The subscriber count of the uploader.
* If the subscriber count is not implemented, or is unavailable, return <code>-1</code>.
*
* @return the subscriber count of the uploader or {@value UNKNOWN_SUBSCRIBER_COUNT} if not available
* @throws ParsingException
* @return the subscriber count of the uploader or {@value UNKNOWN_SUBSCRIBER_COUNT} if not
* available
*/
public long getUploaderSubscriberCount() throws ParsingException {
return UNKNOWN_SUBSCRIBER_COUNT;
@ -219,7 +212,6 @@ public abstract class StreamExtractor extends Extractor {
* If the url is not available you can return an empty String.
*
* @return The url of the image file of the uploader or an empty String
* @throws ParsingException
*/
@Nonnull
public String getUploaderAvatarUrl() throws ParsingException {
@ -229,12 +221,10 @@ public abstract class StreamExtractor extends Extractor {
/**
* The Url to the page of the sub-channel of the stream. This must not be a homepage,
* but the page offered by the service the extractor handles. This url will be handled by the
* {@link ChannelExtractor},
* so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects
* this url.
* {@link ChannelExtractor}, so be sure to implement that one before you return a value here,
* otherwise NewPipe will crash if one selects this url.
*
* @return the url to the page of the sub-channel of the stream or an empty String
* @throws ParsingException
*/
@Nonnull
public String getSubChannelUrl() throws ParsingException {
@ -246,7 +236,6 @@ public abstract class StreamExtractor extends Extractor {
* If the name is not available you can simply return an empty string.
*
* @return the name of the sub-channel of the stream or an empty String
* @throws ParsingException
*/
@Nonnull
public String getSubChannelName() throws ParsingException {
@ -258,7 +247,6 @@ public abstract class StreamExtractor extends Extractor {
* If the url is not available you can return an empty String.
*
* @return The url of the image file of the sub-channel or an empty String
* @throws ParsingException
*/
@Nonnull
public String getSubChannelAvatarUrl() throws ParsingException {
@ -278,13 +266,12 @@ public abstract class StreamExtractor extends Extractor {
}
/**
* I am not sure if this is in use, and how this is used. However the frontend is missing support
* for HLS streams. Prove me if I am wrong. Please open an
* I am not sure if this is in use, and how this is used. However the frontend is missing
* support for HLS streams. Prove me if I am wrong. Please open an
* <a href="https://github.com/teamnewpipe/newpipe/issues">issue</a>,
* or fix this description if you know whats up with this.
*
* @return The Url to the hls stream or an empty string if not available.
* @throws ParsingException
*/
@Nonnull
public String getHlsUrl() throws ParsingException {
@ -292,54 +279,42 @@ public abstract class StreamExtractor extends Extractor {
}
/**
* This should return a list of available
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/stream/AudioStream.html">AudioStream</a>s
* This should return a list of available {@link AudioStream}s.
* You can also return null or an empty list, however be aware that if you don't return anything
* in getVideoStreams(), getVideoOnlyStreams() and getDashMpdUrl() either the Collector will handle this as
* a failed extraction procedure.
* in getVideoStreams(), getVideoOnlyStreams() and getDashMpdUrl() either the Collector will
* handle this as a failed extraction procedure.
*
* @return a list of audio only streams in the format of AudioStream
* @throws IOException
* @throws ExtractionException
*/
public abstract List<AudioStream> getAudioStreams() throws IOException, ExtractionException;
/**
* This should return a list of available
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/stream/VideoStream.html">VideoStream</a>s
* This should return a list of available {@link VideoStream}s.
* Be aware this is the list of video streams which do contain an audio stream.
* You can also return null or an empty list, however be aware that if you don't return anything
* in getAudioStreams(), getVideoOnlyStreams() and getDashMpdUrl() either the Collector will handle this as
* a failed extraction procedure.
* in getAudioStreams(), getVideoOnlyStreams() and getDashMpdUrl() either the Collector will
* handle this as a failed extraction procedure.
*
* @return a list of combined video and streams in the format of AudioStream
* @throws IOException
* @throws ExtractionException
*/
public abstract List<VideoStream> getVideoStreams() throws IOException, ExtractionException;
/**
* This should return a list of available
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/stream/VideoStream.html">VideoStream</a>s.
* This should return a list of available {@link VideoStream}s.
* Be aware this is the list of video streams which do NOT contain an audio stream.
* You can also return null or an empty list, however be aware that if you don't return anything
* in getAudioStreams(), getVideoStreams() and getDashMpdUrl() either the Collector will handle this as
* a failed extraction procedure.
* in getAudioStreams(), getVideoStreams() and getDashMpdUrl() either the Collector will handle
* this as a failed extraction procedure.
*
* @return a list of video and streams in the format of AudioStream
* @throws IOException
* @throws ExtractionException
*/
public abstract List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException;
/**
* This will return a list of available
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/stream/Subtitles.html">Subtitles</a>s.
* This will return a list of available {@link SubtitlesStream}s.
* If no subtitles are available an empty list can be returned.
*
* @return a list of available subtitles or an empty list
* @throws IOException
* @throws ExtractionException
*/
@Nonnull
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
@ -347,26 +322,22 @@ public abstract class StreamExtractor extends Extractor {
}
/**
* This will return a list of available
* <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/org/schabi/newpipe/extractor/stream/Subtitles.html">Subtitles</a>s.
* given by a specific type.
* This will return a list of available {@link SubtitlesStream}s given by a specific type.
* If no subtitles in that specific format are available an empty list can be returned.
*
* @param format the media format by which the subtitles should be filtered
* @return a list of available subtitles or an empty list
* @throws IOException
* @throws ExtractionException
*/
@Nonnull
public List<SubtitlesStream> getSubtitles(MediaFormat format) throws IOException, ExtractionException {
public List<SubtitlesStream> getSubtitles(final MediaFormat format)
throws IOException, ExtractionException {
return Collections.emptyList();
}
/**
* Get the <a href="https://teamnewpipe.github.io/NewPipeExtractor/javadoc/">StreamType</a>.
* Get the {@link StreamType}.
*
* @return the type of the stream
* @throws ParsingException
*/
public abstract StreamType getStreamType() throws ParsingException;
@ -378,8 +349,6 @@ public abstract class StreamExtractor extends Extractor {
* If related streams aren't available simply return {@code null}.
*
* @return a list of InfoItems showing the related videos/streams
* @throws IOException
* @throws ExtractionException
*/
@Nullable
public InfoItemsCollector<? extends InfoItem, ? extends InfoItemExtractor>
@ -388,26 +357,26 @@ public abstract class StreamExtractor extends Extractor {
}
/**
* @deprecated Use {@link #getRelatedItems()}. May be removed in a future version.
* @return The result of {@link #getRelatedItems()} if it is a
* StreamInfoItemsCollector, <code>null</code> otherwise
* @throws IOException
* @throws ExtractionException
* {@link StreamInfoItemsCollector}, <code>null</code> otherwise
* @deprecated Use {@link #getRelatedItems()}. May be removed in a future version.
*/
@Deprecated
@Nullable
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
InfoItemsCollector<?, ?> collector = getRelatedItems();
final InfoItemsCollector<?, ?> collector = getRelatedItems();
if (collector instanceof StreamInfoItemsCollector) {
return (StreamInfoItemsCollector) collector;
} else return null;
} else {
return null;
}
}
/**
* Should return a list of Frameset object that contains preview of stream frames
*
* @return list of preview frames or empty list if frames preview is not supported or not found for specified stream
* @throws ExtractionException
* @return list of preview frames or empty list if frames preview is not supported or not found
* for specified stream
*/
@Nonnull
public List<Frameset> getFrames() throws ExtractionException {
@ -428,18 +397,16 @@ public abstract class StreamExtractor extends Extractor {
//////////////////////////////////////////////////////////////////
/**
* Override this function if the format of time stamp in the url is not the same format as that form youtube.
* Honestly I don't even know the time stamp format of YouTube.
* Override this function if the format of timestamp in the url is not the same format as that
* from youtube.
*
* @param regexPattern
* @return the time stamp/seek for the video in seconds
* @throws ParsingException
*/
protected long getTimestampSeconds(String regexPattern) throws ParsingException {
String timeStamp;
protected long getTimestampSeconds(final String regexPattern) throws ParsingException {
final String timestamp;
try {
timeStamp = Parser.matchGroup1(regexPattern, getOriginalUrl());
} catch (Parser.RegexException e) {
timestamp = Parser.matchGroup1(regexPattern, getOriginalUrl());
} catch (final Parser.RegexException e) {
// catch this instantly since a url does not necessarily have a timestamp
// -2 because the testing system will consequently know that the regex failed
@ -447,33 +414,29 @@ public abstract class StreamExtractor extends Extractor {
return -2;
}
if (!timeStamp.isEmpty()) {
if (!timestamp.isEmpty()) {
try {
String secondsString = "";
String minutesString = "";
String hoursString = "";
try {
secondsString = Parser.matchGroup1("(\\d+)s", timeStamp);
minutesString = Parser.matchGroup1("(\\d+)m", timeStamp);
hoursString = Parser.matchGroup1("(\\d+)h", timeStamp);
} catch (Exception e) {
//it could be that time is given in another method
if (secondsString.isEmpty() //if nothing was got,
&& minutesString.isEmpty()//treat as unlabelled seconds
&& hoursString.isEmpty()) {
secondsString = Parser.matchGroup1("t=(\\d+)", timeStamp);
secondsString = Parser.matchGroup1("(\\d+)s", timestamp);
minutesString = Parser.matchGroup1("(\\d+)m", timestamp);
hoursString = Parser.matchGroup1("(\\d+)h", timestamp);
} catch (final Exception e) {
// it could be that time is given in another method
if (secondsString.isEmpty() && minutesString.isEmpty()) {
// if nothing was obtained, treat as unlabelled seconds
secondsString = Parser.matchGroup1("t=(\\d+)", timestamp);
}
}
int seconds = secondsString.isEmpty() ? 0 : Integer.parseInt(secondsString);
int minutes = minutesString.isEmpty() ? 0 : Integer.parseInt(minutesString);
int hours = hoursString.isEmpty() ? 0 : Integer.parseInt(hoursString);
final int seconds = secondsString.isEmpty() ? 0 : Integer.parseInt(secondsString);
final int minutes = minutesString.isEmpty() ? 0 : Integer.parseInt(minutesString);
final int hours = hoursString.isEmpty() ? 0 : Integer.parseInt(hoursString);
//don't trust BODMAS!
return seconds + (60 * minutes) + (3600 * hours);
//Log.d(TAG, "derived timestamp value:"+ret);
//the ordering varies internationally
} catch (ParsingException e) {
return seconds + (60L * minutes) + (3600L * hours);
} catch (final ParsingException e) {
throw new ParsingException("Could not get timestamp.", e);
}
} else {
@ -488,7 +451,6 @@ public abstract class StreamExtractor extends Extractor {
* you can simply return an empty string.
*
* @return the host of the stream or an empty string.
* @throws ParsingException
*/
@Nonnull
public String getHost() throws ParsingException {
@ -499,7 +461,6 @@ public abstract class StreamExtractor extends Extractor {
* The privacy of the stream (Eg. Public, Private, Unlisted).
*
* @return the privacy of the stream.
* @throws ParsingException
*/
public Privacy getPrivacy() throws ParsingException {
return Privacy.PUBLIC;
@ -510,7 +471,6 @@ public abstract class StreamExtractor extends Extractor {
* If the category is not available you can simply return an empty string.
*
* @return the category of the stream or an empty string.
* @throws ParsingException
*/
@Nonnull
public String getCategory() throws ParsingException {
@ -522,7 +482,6 @@ public abstract class StreamExtractor extends Extractor {
* If the licence is not available you can simply return an empty string.
*
* @return the licence of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public String getLicence() throws ParsingException {
@ -536,7 +495,6 @@ public abstract class StreamExtractor extends Extractor {
* new Locale(language_code);
*
* @return the locale language of the stream or <code>null</code>.
* @throws ParsingException
*/
@Nullable
public Locale getLanguageInfo() throws ParsingException {
@ -548,7 +506,6 @@ public abstract class StreamExtractor extends Extractor {
* If the tag list is not available you can simply return an empty list.
*
* @return the list of tags of the stream or Collections.emptyList().
* @throws ParsingException
*/
@Nonnull
public List<String> getTags() throws ParsingException {
@ -563,7 +520,6 @@ public abstract class StreamExtractor extends Extractor {
* you can simply return an empty String.
*
* @return the support information of the stream or an empty string.
* @throws ParsingException
*/
@Nonnull
public String getSupportInfo() throws ParsingException {
@ -575,7 +531,6 @@ public abstract class StreamExtractor extends Extractor {
* If the segment list is not available you can simply return an empty list.
*
* @return The list of segments of the stream or an empty list.
* @throws ParsingException
*/
@Nonnull
public List<StreamSegment> getStreamSegments() throws ParsingException {
@ -585,14 +540,14 @@ public abstract class StreamExtractor extends Extractor {
/**
* Meta information about the stream.
* <p>
* This can be information about the stream creator (e.g. if the creator is a public broadcaster)
* or further information on the topic (e.g. hints that the video might contain conspiracy theories
* or contains information about a current health situation like the Covid-19 pandemic).
* This can be information about the stream creator (e.g. if the creator is a public
* broadcaster) or further information on the topic (e.g. hints that the video might contain
* conspiracy theories or contains information about a current health situation like the
* Covid-19 pandemic).
* </p>
* The meta information often contains links to external sources like Wikipedia or the WHO.
*
* @return The meta info of the stream or an empty list if not provided.
* @throws ParsingException
*/
@Nonnull
public List<MetaInfo> getMetaInfo() throws ParsingException {

View File

@ -1,6 +1,10 @@
package org.schabi.newpipe.extractor.stream;
import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -44,34 +48,42 @@ import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
public class StreamInfo extends Info {
public static class StreamExtractException extends ExtractionException {
StreamExtractException(String message) {
StreamExtractException(final String message) {
super(message);
}
}
public StreamInfo(int serviceId, String url, String originalUrl, StreamType streamType, String id, String name,
int ageLimit) {
public StreamInfo(final int serviceId,
final String url,
final String originalUrl,
final StreamType streamType,
final String id,
final String name,
final int ageLimit) {
super(serviceId, id, url, originalUrl, name);
this.streamType = streamType;
this.ageLimit = ageLimit;
}
public static StreamInfo getInfo(String url) throws IOException, ExtractionException {
public static StreamInfo getInfo(final String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static StreamInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
public static StreamInfo getInfo(final StreamingService service,
final String url) throws IOException, ExtractionException {
return getInfo(service.getStreamExtractor(url));
}
public static StreamInfo getInfo(StreamExtractor extractor) throws ExtractionException, IOException {
public static StreamInfo getInfo(final StreamExtractor extractor)
throws ExtractionException, IOException {
extractor.fetchPage();
StreamInfo streamInfo;
try {
streamInfo = extractImportantData(extractor);
streamInfo = extractStreams(streamInfo, extractor);
streamInfo = extractOptionalData(streamInfo, extractor);
} catch (ExtractionException e) {
final StreamInfo streamInfo = extractImportantData(extractor);
extractStreams(streamInfo, extractor);
extractOptionalData(streamInfo, extractor);
return streamInfo;
} catch (final ExtractionException e) {
// Currently YouTube does not distinguish between age restricted videos and
// videos blocked
// by country. This means that during the initialisation of the extractor, the
@ -88,32 +100,32 @@ public class StreamInfo extends Info {
throw new ContentNotAvailableException(errorMessage, e);
}
}
return streamInfo;
}
private static StreamInfo extractImportantData(StreamExtractor extractor) throws ExtractionException {
private static StreamInfo extractImportantData(final StreamExtractor extractor)
throws ExtractionException {
/* ---- important data, without the video can't be displayed goes here: ---- */
// if one of these is not available an exception is meant to be thrown directly
// into the frontend.
int serviceId = extractor.getServiceId();
String url = extractor.getUrl();
String originalUrl = extractor.getOriginalUrl();
StreamType streamType = extractor.getStreamType();
String id = extractor.getId();
String name = extractor.getName();
int ageLimit = extractor.getAgeLimit();
final String url = extractor.getUrl();
final StreamType streamType = extractor.getStreamType();
final String id = extractor.getId();
final String name = extractor.getName();
final int ageLimit = extractor.getAgeLimit();
if ((streamType == StreamType.NONE) || isNullOrEmpty(url) || (isNullOrEmpty(id))
|| (name == null /* streamInfo.title can be empty of course */) || (ageLimit == -1)) {
// suppress always-non-null warning as here we double-check it really is not null
//noinspection ConstantConditions
if (streamType == StreamType.NONE || isNullOrEmpty(url) || isNullOrEmpty(id)
|| name == null /* but it can be empty of course */ || ageLimit == -1) {
throw new ExtractionException("Some important stream information was not given.");
}
return new StreamInfo(serviceId, url, originalUrl, streamType, id, name, ageLimit);
return new StreamInfo(extractor.getServiceId(), url, extractor.getOriginalUrl(),
streamType, id, name, ageLimit);
}
private static StreamInfo extractStreams(StreamInfo streamInfo, StreamExtractor extractor)
private static void extractStreams(final StreamInfo streamInfo, final StreamExtractor extractor)
throws ExtractionException {
/* ---- stream extraction goes here ---- */
// At least one type of stream has to be available,
@ -121,56 +133,59 @@ public class StreamInfo extends Info {
try {
streamInfo.setDashMpdUrl(extractor.getDashMpdUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get Dash manifest", e));
}
try {
streamInfo.setHlsUrl(extractor.getHlsUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get HLS manifest", e));
}
/* Load and extract audio */
try {
streamInfo.setAudioStreams(extractor.getAudioStreams());
} catch (ContentNotSupportedException e) {
} catch (final ContentNotSupportedException e) {
throw e;
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get audio streams", e));
}
/* Extract video stream url */
try {
streamInfo.setVideoStreams(extractor.getVideoStreams());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get video streams", e));
}
/* Extract video only stream url */
try {
streamInfo.setVideoOnlyStreams(extractor.getVideoOnlyStreams());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get video only streams", e));
}
// Lists can be null if a exception was thrown during extraction
if (streamInfo.getVideoStreams() == null)
if (streamInfo.getVideoStreams() == null) {
streamInfo.setVideoStreams(Collections.emptyList());
if (streamInfo.getVideoOnlyStreams() == null)
}
if (streamInfo.getVideoOnlyStreams() == null) {
streamInfo.setVideoOnlyStreams(Collections.emptyList());
if (streamInfo.getAudioStreams() == null)
}
if (streamInfo.getAudioStreams() == null) {
streamInfo.setAudioStreams(Collections.emptyList());
}
Exception dashMpdError = null;
if (!isNullOrEmpty(streamInfo.getDashMpdUrl())) {
try {
DashMpdParser.ParserResult result = DashMpdParser.getStreams(streamInfo);
final DashMpdParser.ParserResult result = DashMpdParser.getStreams(streamInfo);
streamInfo.getVideoOnlyStreams().addAll(result.getVideoOnlyStreams());
streamInfo.getAudioStreams().addAll(result.getAudioStreams());
streamInfo.getVideoStreams().addAll(result.getVideoStreams());
streamInfo.segmentedVideoOnlyStreams = result.getSegmentedVideoOnlyStreams();
streamInfo.segmentedAudioStreams = result.getSegmentedAudioStreams();
streamInfo.segmentedVideoStreams = result.getSegmentedVideoStreams();
} catch (Exception e) {
} catch (final Exception e) {
// Sometimes we receive 403 (forbidden) error when trying to download the
// manifest (similar to what happens with youtube-dl),
// just skip the exception (but store it somewhere), as we later check if we
@ -191,13 +206,13 @@ public class StreamInfo extends Info {
streamInfo.addError(dashMpdError);
}
throw new StreamExtractException("Could not get any stream. See error variable to get further details.");
throw new StreamExtractException(
"Could not get any stream. See error variable to get further details.");
}
return streamInfo;
}
private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtractor extractor) {
private static void extractOptionalData(final StreamInfo streamInfo,
final StreamExtractor extractor) {
/* ---- optional data goes here: ---- */
// If one of these fails, the frontend needs to handle that they are not
// available.
@ -207,153 +222,152 @@ public class StreamInfo extends Info {
try {
streamInfo.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setDuration(extractor.getLength());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderVerified(extractor.isUploaderVerified());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploaderSubscriberCount(extractor.getUploaderSubscriberCount());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubChannelName(extractor.getSubChannelName());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubChannelUrl(extractor.getSubChannelUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setDescription(extractor.getDescription());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setViewCount(extractor.getViewCount());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setTextualUploadDate(extractor.getTextualUploadDate());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setUploadDate(extractor.getUploadDate());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setStartPosition(extractor.getTimeStamp());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setLikeCount(extractor.getLikeCount());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setDislikeCount(extractor.getDislikeCount());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSubtitles(extractor.getSubtitlesDefault());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
//additional info
try {
streamInfo.setHost(extractor.getHost());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setPrivacy(extractor.getPrivacy());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setCategory(extractor.getCategory());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setLicence(extractor.getLicence());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setLanguageInfo(extractor.getLanguageInfo());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setTags(extractor.getTags());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setSupportInfo(extractor.getSupportInfo());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setStreamSegments(extractor.getStreamSegments());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setMetaInfo(extractor.getMetaInfo());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
try {
streamInfo.setPreviewFrames(extractor.getFrames());
} catch (Exception e) {
} catch (final Exception e) {
streamInfo.addError(e);
}
streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
return streamInfo;
streamInfo
.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
}
private StreamType streamType;
@ -361,7 +375,7 @@ public class StreamInfo extends Info {
private String textualUploadDate;
private DateWrapper uploadDate;
private long duration = -1;
private int ageLimit = -1;
private int ageLimit;
private Description description;
private long viewCount = -1;
@ -398,7 +412,7 @@ public class StreamInfo extends Info {
private StreamExtractor.Privacy privacy;
private String category = "";
private String licence = "";
private String support = "";
private String supportInfo = "";
private Locale language = null;
private List<String> tags = new ArrayList<>();
private List<StreamSegment> streamSegments = new ArrayList<>();
@ -418,7 +432,7 @@ public class StreamInfo extends Info {
return streamType;
}
public void setStreamType(StreamType streamType) {
public void setStreamType(final StreamType streamType) {
this.streamType = streamType;
}
@ -431,7 +445,7 @@ public class StreamInfo extends Info {
return thumbnailUrl;
}
public void setThumbnailUrl(String thumbnailUrl) {
public void setThumbnailUrl(final String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
@ -439,7 +453,7 @@ public class StreamInfo extends Info {
return textualUploadDate;
}
public void setTextualUploadDate(String textualUploadDate) {
public void setTextualUploadDate(final String textualUploadDate) {
this.textualUploadDate = textualUploadDate;
}
@ -447,7 +461,7 @@ public class StreamInfo extends Info {
return uploadDate;
}
public void setUploadDate(DateWrapper uploadDate) {
public void setUploadDate(final DateWrapper uploadDate) {
this.uploadDate = uploadDate;
}
@ -460,7 +474,7 @@ public class StreamInfo extends Info {
return duration;
}
public void setDuration(long duration) {
public void setDuration(final long duration) {
this.duration = duration;
}
@ -468,7 +482,7 @@ public class StreamInfo extends Info {
return ageLimit;
}
public void setAgeLimit(int ageLimit) {
public void setAgeLimit(final int ageLimit) {
this.ageLimit = ageLimit;
}
@ -476,7 +490,7 @@ public class StreamInfo extends Info {
return description;
}
public void setDescription(Description description) {
public void setDescription(final Description description) {
this.description = description;
}
@ -484,7 +498,7 @@ public class StreamInfo extends Info {
return viewCount;
}
public void setViewCount(long viewCount) {
public void setViewCount(final long viewCount) {
this.viewCount = viewCount;
}
@ -497,7 +511,7 @@ public class StreamInfo extends Info {
return likeCount;
}
public void setLikeCount(long likeCount) {
public void setLikeCount(final long likeCount) {
this.likeCount = likeCount;
}
@ -510,7 +524,7 @@ public class StreamInfo extends Info {
return dislikeCount;
}
public void setDislikeCount(long dislikeCount) {
public void setDislikeCount(final long dislikeCount) {
this.dislikeCount = dislikeCount;
}
@ -518,7 +532,7 @@ public class StreamInfo extends Info {
return uploaderName;
}
public void setUploaderName(String uploaderName) {
public void setUploaderName(final String uploaderName) {
this.uploaderName = uploaderName;
}
@ -526,7 +540,7 @@ public class StreamInfo extends Info {
return uploaderUrl;
}
public void setUploaderUrl(String uploaderUrl) {
public void setUploaderUrl(final String uploaderUrl) {
this.uploaderUrl = uploaderUrl;
}
@ -534,7 +548,7 @@ public class StreamInfo extends Info {
return uploaderAvatarUrl;
}
public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
public void setUploaderAvatarUrl(final String uploaderAvatarUrl) {
this.uploaderAvatarUrl = uploaderAvatarUrl;
}
@ -550,7 +564,7 @@ public class StreamInfo extends Info {
return uploaderSubscriberCount;
}
public void setUploaderSubscriberCount(long uploaderSubscriberCount) {
public void setUploaderSubscriberCount(final long uploaderSubscriberCount) {
this.uploaderSubscriberCount = uploaderSubscriberCount;
}
@ -558,7 +572,7 @@ public class StreamInfo extends Info {
return subChannelName;
}
public void setSubChannelName(String subChannelName) {
public void setSubChannelName(final String subChannelName) {
this.subChannelName = subChannelName;
}
@ -566,7 +580,7 @@ public class StreamInfo extends Info {
return subChannelUrl;
}
public void setSubChannelUrl(String subChannelUrl) {
public void setSubChannelUrl(final String subChannelUrl) {
this.subChannelUrl = subChannelUrl;
}
@ -574,7 +588,7 @@ public class StreamInfo extends Info {
return subChannelAvatarUrl;
}
public void setSubChannelAvatarUrl(String subChannelAvatarUrl) {
public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) {
this.subChannelAvatarUrl = subChannelAvatarUrl;
}
@ -582,7 +596,7 @@ public class StreamInfo extends Info {
return videoStreams;
}
public void setVideoStreams(List<VideoStream> videoStreams) {
public void setVideoStreams(final List<VideoStream> videoStreams) {
this.videoStreams = videoStreams;
}
@ -590,7 +604,7 @@ public class StreamInfo extends Info {
return audioStreams;
}
public void setAudioStreams(List<AudioStream> audioStreams) {
public void setAudioStreams(final List<AudioStream> audioStreams) {
this.audioStreams = audioStreams;
}
@ -598,7 +612,7 @@ public class StreamInfo extends Info {
return videoOnlyStreams;
}
public void setVideoOnlyStreams(List<VideoStream> videoOnlyStreams) {
public void setVideoOnlyStreams(final List<VideoStream> videoOnlyStreams) {
this.videoOnlyStreams = videoOnlyStreams;
}
@ -606,7 +620,7 @@ public class StreamInfo extends Info {
return dashMpdUrl;
}
public void setDashMpdUrl(String dashMpdUrl) {
public void setDashMpdUrl(final String dashMpdUrl) {
this.dashMpdUrl = dashMpdUrl;
}
@ -614,7 +628,7 @@ public class StreamInfo extends Info {
return segmentedVideoStreams;
}
public void setSegmentedVideoStreams(List<VideoStream> segmentedVideoStreams) {
public void setSegmentedVideoStreams(final List<VideoStream> segmentedVideoStreams) {
this.segmentedVideoStreams = segmentedVideoStreams;
}
@ -622,7 +636,7 @@ public class StreamInfo extends Info {
return segmentedAudioStreams;
}
public void setSegmentedAudioStreams(List<AudioStream> segmentedAudioStreams) {
public void setSegmentedAudioStreams(final List<AudioStream> segmentedAudioStreams) {
this.segmentedAudioStreams = segmentedAudioStreams;
}
@ -630,7 +644,7 @@ public class StreamInfo extends Info {
return segmentedVideoOnlyStreams;
}
public void setSegmentedVideoOnlyStreams(List<VideoStream> segmentedVideoOnlyStreams) {
public void setSegmentedVideoOnlyStreams(final List<VideoStream> segmentedVideoOnlyStreams) {
this.segmentedVideoOnlyStreams = segmentedVideoOnlyStreams;
}
@ -638,7 +652,7 @@ public class StreamInfo extends Info {
return hlsUrl;
}
public void setHlsUrl(String hlsUrl) {
public void setHlsUrl(final String hlsUrl) {
this.hlsUrl = hlsUrl;
}
@ -654,7 +668,7 @@ public class StreamInfo extends Info {
return getRelatedItems();
}
public void setRelatedItems(List<InfoItem> relatedItems) {
public void setRelatedItems(final List<InfoItem> relatedItems) {
this.relatedItems = relatedItems;
}
@ -662,15 +676,15 @@ public class StreamInfo extends Info {
* @deprecated Use {@link #setRelatedItems(List)}
*/
@Deprecated
public void setRelatedStreams(List<InfoItem> relatedItems) {
setRelatedItems(relatedItems);
public void setRelatedStreams(final List<InfoItem> relatedItemsToSet) {
setRelatedItems(relatedItemsToSet);
}
public long getStartPosition() {
return startPosition;
}
public void setStartPosition(long startPosition) {
public void setStartPosition(final long startPosition) {
this.startPosition = startPosition;
}
@ -678,7 +692,7 @@ public class StreamInfo extends Info {
return subtitles;
}
public void setSubtitles(List<SubtitlesStream> subtitles) {
public void setSubtitles(final List<SubtitlesStream> subtitles) {
this.subtitles = subtitles;
}
@ -686,63 +700,63 @@ public class StreamInfo extends Info {
return this.host;
}
public void setHost(String str) {
this.host = str;
public void setHost(final String host) {
this.host = host;
}
public StreamExtractor.Privacy getPrivacy() {
return this.privacy;
}
public void setPrivacy(StreamExtractor.Privacy str) {
this.privacy = str;
public void setPrivacy(final StreamExtractor.Privacy privacy) {
this.privacy = privacy;
}
public String getCategory() {
return this.category;
}
public void setCategory(String cat) {
this.category = cat;
public void setCategory(final String category) {
this.category = category;
}
public String getLicence() {
return this.licence;
}
public void setLicence(String str) {
this.licence = str;
public void setLicence(final String licence) {
this.licence = licence;
}
public Locale getLanguageInfo() {
return this.language;
}
public void setLanguageInfo(Locale lang) {
this.language = lang;
public void setLanguageInfo(final Locale locale) {
this.language = locale;
}
public List<String> getTags() {
return this.tags;
}
public void setTags(List<String> tags) {
public void setTags(final List<String> tags) {
this.tags = tags;
}
public void setSupportInfo(String support) {
this.support = support;
public void setSupportInfo(final String support) {
this.supportInfo = support;
}
public String getSupportInfo() {
return this.support;
return this.supportInfo;
}
public List<StreamSegment> getStreamSegments() {
return streamSegments;
}
public void setStreamSegments(List<StreamSegment> streamSegments) {
public void setStreamSegments(final List<StreamSegment> streamSegments) {
this.streamSegments = streamSegments;
}

View File

@ -43,7 +43,10 @@ public class StreamInfoItem extends InfoItem {
private String uploaderAvatarUrl = null;
private boolean uploaderVerified = false;
public StreamInfoItem(int serviceId, String url, String name, StreamType streamType) {
public StreamInfoItem(final int serviceId,
final String url,
final String name,
final StreamType streamType) {
super(InfoType.STREAM, serviceId, url, name);
this.streamType = streamType;
}
@ -56,23 +59,23 @@ public class StreamInfoItem extends InfoItem {
return uploaderName;
}
public void setUploaderName(String uploader_name) {
this.uploaderName = uploader_name;
public void setUploaderName(final String uploaderName) {
this.uploaderName = uploaderName;
}
public long getViewCount() {
return viewCount;
}
public void setViewCount(long view_count) {
this.viewCount = view_count;
public void setViewCount(final long viewCount) {
this.viewCount = viewCount;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
public void setDuration(final long duration) {
this.duration = duration;
}
@ -80,7 +83,7 @@ public class StreamInfoItem extends InfoItem {
return uploaderUrl;
}
public void setUploaderUrl(String uploaderUrl) {
public void setUploaderUrl(final String uploaderUrl) {
this.uploaderUrl = uploaderUrl;
}
@ -106,8 +109,8 @@ public class StreamInfoItem extends InfoItem {
return textualUploadDate;
}
public void setTextualUploadDate(String uploadDate) {
this.textualUploadDate = uploadDate;
public void setTextualUploadDate(final String textualUploadDate) {
this.textualUploadDate = textualUploadDate;
}
@Nullable
@ -115,7 +118,7 @@ public class StreamInfoItem extends InfoItem {
return uploadDate;
}
public void setUploadDate(@Nullable DateWrapper uploadDate) {
public void setUploadDate(@Nullable final DateWrapper uploadDate) {
this.uploadDate = uploadDate;
}
@ -123,25 +126,25 @@ public class StreamInfoItem extends InfoItem {
return uploaderVerified;
}
public void setUploaderVerified(boolean uploaderVerified) {
public void setUploaderVerified(final boolean uploaderVerified) {
this.uploaderVerified = uploaderVerified;
}
@Override
public String toString() {
return "StreamInfoItem{" +
"streamType=" + streamType +
", uploaderName='" + uploaderName + '\'' +
", textualUploadDate='" + textualUploadDate + '\'' +
", viewCount=" + viewCount +
", duration=" + duration +
", uploaderUrl='" + uploaderUrl + '\'' +
", infoType=" + getInfoType() +
", serviceId=" + getServiceId() +
", url='" + getUrl() + '\'' +
", name='" + getName() + '\'' +
", thumbnailUrl='" + getThumbnailUrl() + '\'' +
", uploaderVerified='" + isUploaderVerified() + '\'' +
'}';
return "StreamInfoItem{"
+ "streamType=" + streamType
+ ", uploaderName='" + uploaderName + '\''
+ ", textualUploadDate='" + textualUploadDate + '\''
+ ", viewCount=" + viewCount
+ ", duration=" + duration
+ ", uploaderUrl='" + uploaderUrl + '\''
+ ", infoType=" + getInfoType()
+ ", serviceId=" + getServiceId()
+ ", url='" + getUrl() + '\''
+ ", name='" + getName() + '\''
+ ", thumbnailUrl='" + getThumbnailUrl() + '\''
+ ", uploaderVerified='" + isUploaderVerified() + '\''
+ '}';
}
}
}

View File

@ -124,6 +124,7 @@ public interface StreamInfoItemExtractor extends InfoItemExtractor {
* @throws ParsingException if there is an error in the extraction
*/
@Nullable
default String getShortDescription() throws ParsingException { return null; }
default String getShortDescription() throws ParsingException {
return null;
}
}

View File

@ -1,14 +1,10 @@
package org.schabi.newpipe.extractor.stream;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Vector;
/*
* Created by Christian Schabesberger on 28.02.16.
@ -30,80 +26,76 @@ import java.util.Vector;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class StreamInfoItemsCollector extends InfoItemsCollector<StreamInfoItem, StreamInfoItemExtractor> {
public class StreamInfoItemsCollector
extends InfoItemsCollector<StreamInfoItem, StreamInfoItemExtractor> {
public StreamInfoItemsCollector(int serviceId) {
public StreamInfoItemsCollector(final int serviceId) {
super(serviceId);
}
public StreamInfoItemsCollector(int serviceId, Comparator<StreamInfoItem> comparator) {
public StreamInfoItemsCollector(final int serviceId,
final Comparator<StreamInfoItem> comparator) {
super(serviceId, comparator);
}
@Override
public StreamInfoItem extract(StreamInfoItemExtractor extractor) throws ParsingException {
public StreamInfoItem extract(final StreamInfoItemExtractor extractor) throws ParsingException {
if (extractor.isAd()) {
throw new FoundAdException("Found ad");
}
// important information
int serviceId = getServiceId();
String url = extractor.getUrl();
String name = extractor.getName();
StreamType streamType = extractor.getStreamType();
StreamInfoItem resultItem = new StreamInfoItem(serviceId, url, name, streamType);
final StreamInfoItem resultItem = new StreamInfoItem(
getServiceId(), extractor.getUrl(), extractor.getName(), extractor.getStreamType());
// optional information
try {
resultItem.setDuration(extractor.getDuration());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setTextualUploadDate(extractor.getTextualUploadDate());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploadDate(extractor.getUploadDate());
} catch (ParsingException e) {
} catch (final ParsingException e) {
addError(e);
}
try {
resultItem.setViewCount(extractor.getViewCount());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setUploaderVerified(extractor.isUploaderVerified());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
try {
resultItem.setShortDescription(extractor.getShortDescription());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
@ -111,23 +103,13 @@ public class StreamInfoItemsCollector extends InfoItemsCollector<StreamInfoItem,
}
@Override
public void commit(StreamInfoItemExtractor extractor) {
public void commit(final StreamInfoItemExtractor extractor) {
try {
addItem(extract(extractor));
} catch (FoundAdException ae) {
} catch (final FoundAdException ae) {
//System.out.println("AD_WARNING: " + ae.getMessage());
} catch (Exception e) {
} catch (final Exception e) {
addError(e);
}
}
public List<StreamInfoItem> getStreamInfoItemList() {
List<StreamInfoItem> siiList = new ArrayList<>();
for (InfoItem ii : super.getItems()) {
if (ii instanceof StreamInfoItem) {
siiList.add((StreamInfoItem) ii);
}
}
return siiList;
}
}

View File

@ -33,7 +33,7 @@ public class StreamSegment implements Serializable {
@Nullable
private String previewUrl = null;
public StreamSegment(String title, int startTimeSeconds) {
public StreamSegment(final String title, final int startTimeSeconds) {
this.title = title;
this.startTimeSeconds = startTimeSeconds;
}

View File

@ -11,7 +11,10 @@ public class SubtitlesStream extends Stream implements Serializable {
private final boolean autoGenerated;
private final String code;
public SubtitlesStream(MediaFormat format, String languageCode, String url, boolean autoGenerated) {
public SubtitlesStream(final MediaFormat format,
final String languageCode,
final String url,
final boolean autoGenerated) {
super(url, format);
/*
@ -25,7 +28,8 @@ public class SubtitlesStream extends Stream implements Serializable {
this.locale = new Locale(splits[0]);
break;
case 3:
this.locale = new Locale(splits[0], splits[1], splits[2]);// complex variants doesn't work!
// complex variants doesn't work!
this.locale = new Locale(splits[0], splits[1], splits[2]);
break;
case 2:
this.locale = new Locale(splits[0], splits[1]);
@ -45,11 +49,11 @@ public class SubtitlesStream extends Stream implements Serializable {
}
@Override
public boolean equalStats(Stream cmp) {
return super.equalStats(cmp) &&
cmp instanceof SubtitlesStream &&
code.equals(((SubtitlesStream) cmp).code) &&
autoGenerated == ((SubtitlesStream) cmp).autoGenerated;
public boolean equalStats(final Stream cmp) {
return super.equalStats(cmp)
&& cmp instanceof SubtitlesStream
&& code.equals(((SubtitlesStream) cmp).code)
&& autoGenerated == ((SubtitlesStream) cmp).autoGenerated;
}
public String getDisplayLanguageName() {

View File

@ -40,15 +40,18 @@ public class VideoStream extends Stream {
private String quality;
private String codec;
public VideoStream(String url, MediaFormat format, String resolution) {
public VideoStream(final String url, final MediaFormat format, final String resolution) {
this(url, format, resolution, false);
}
public VideoStream(String url, MediaFormat format, String resolution, boolean isVideoOnly) {
public VideoStream(final String url,
final MediaFormat format,
final String resolution,
final boolean isVideoOnly) {
this(url, null, format, resolution, isVideoOnly);
}
public VideoStream(String url, boolean isVideoOnly, ItagItem itag) {
public VideoStream(final String url, final boolean isVideoOnly, final ItagItem itag) {
this(url, itag.getMediaFormat(), itag.resolutionString, isVideoOnly);
this.itag = itag.id;
this.bitrate = itag.getBitrate();
@ -63,21 +66,28 @@ public class VideoStream extends Stream {
this.fps = itag.fps;
}
public VideoStream(String url, String torrentUrl, MediaFormat format, String resolution) {
public VideoStream(final String url,
final String torrentUrl,
final MediaFormat format,
final String resolution) {
this(url, torrentUrl, format, resolution, false);
}
public VideoStream(String url, String torrentUrl, MediaFormat format, String resolution, boolean isVideoOnly) {
public VideoStream(final String url,
final String torrentUrl,
final MediaFormat format,
final String resolution,
final boolean isVideoOnly) {
super(url, torrentUrl, format);
this.resolution = resolution;
this.isVideoOnly = isVideoOnly;
}
@Override
public boolean equalStats(Stream cmp) {
return super.equalStats(cmp) && cmp instanceof VideoStream &&
resolution.equals(((VideoStream) cmp).resolution) &&
isVideoOnly == ((VideoStream) cmp).isVideoOnly;
public boolean equalStats(final Stream cmp) {
return super.equalStats(cmp) && cmp instanceof VideoStream
&& resolution.equals(((VideoStream) cmp).resolution)
&& isVideoOnly == ((VideoStream) cmp).isVideoOnly;
}
/**

View File

@ -22,16 +22,17 @@ public abstract class SubscriptionExtractor {
this(null, null);
}
public InvalidSourceException(String detailMessage) {
public InvalidSourceException(@Nullable final String detailMessage) {
this(detailMessage, null);
}
public InvalidSourceException(Throwable cause) {
public InvalidSourceException(final Throwable cause) {
this(null, cause);
}
public InvalidSourceException(String detailMessage, Throwable cause) {
super(detailMessage == null ? "Not a valid source" : "Not a valid source (" + detailMessage + ")", cause);
public InvalidSourceException(@Nullable final String detailMessage, final Throwable cause) {
super("Not a valid source" + (detailMessage == null ? "" : " (" + detailMessage + ")"),
cause);
}
}
@ -42,7 +43,8 @@ public abstract class SubscriptionExtractor {
private final List<ContentSource> supportedSources;
protected final StreamingService service;
public SubscriptionExtractor(StreamingService service, List<ContentSource> supportedSources) {
public SubscriptionExtractor(final StreamingService service,
final List<ContentSource> supportedSources) {
this.service = service;
this.supportedSources = Collections.unmodifiableList(supportedSources);
}
@ -52,7 +54,8 @@ public abstract class SubscriptionExtractor {
}
/**
* Returns an url that can help/guide the user to the file (or channel url) to extract the subscriptions.
* Returns an url that can help/guide the user to the file (or channel url) to extract the
* subscriptions.
* <p>For example, in YouTube, the export subscriptions url is a good choice to return here.</p>
*/
@Nullable
@ -72,7 +75,8 @@ public abstract class SubscriptionExtractor {
/**
* Reads and parse a list of {@link SubscriptionItem} from the given InputStream.
*
* @throws InvalidSourceException when the content read from the InputStream is invalid and can not be parsed
* @throws InvalidSourceException when the content read from the InputStream is invalid and can
* not be parsed
*/
public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream contentInputStream)
throws ExtractionException {
@ -83,7 +87,8 @@ public abstract class SubscriptionExtractor {
/**
* Reads and parse a list of {@link SubscriptionItem} from the given InputStream.
*
* @throws InvalidSourceException when the content read from the InputStream is invalid and can not be parsed
* @throws InvalidSourceException when the content read from the InputStream is invalid and can
* not be parsed
*/
public List<SubscriptionItem> fromInputStream(@Nonnull final InputStream contentInputStream,
@Nonnull final String contentType)

View File

@ -4,9 +4,10 @@ import java.io.Serializable;
public class SubscriptionItem implements Serializable {
private final int serviceId;
private final String url, name;
private final String url;
private final String name;
public SubscriptionItem(int serviceId, String url, String name) {
public SubscriptionItem(final int serviceId, final String url, final String name) {
this.serviceId = serviceId;
this.url = url;
this.name = name;
@ -26,7 +27,7 @@ public class SubscriptionItem implements Serializable {
@Override
public String toString() {
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) +
"[name=" + name + " > " + serviceId + ":" + url + "]";
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
+ "[name=" + name + " > " + serviceId + ":" + url + "]";
}
}

View File

@ -15,11 +15,12 @@ public abstract class SuggestionExtractor {
@Nullable private Localization forcedLocalization;
@Nullable private ContentCountry forcedContentCountry;
public SuggestionExtractor(StreamingService service) {
public SuggestionExtractor(final StreamingService service) {
this.service = service;
}
public abstract List<String> suggestionList(String query) throws IOException, ExtractionException;
public abstract List<String> suggestionList(String query)
throws IOException, ExtractionException;
public int getServiceId() {
return service.getServiceId();
@ -31,11 +32,11 @@ public abstract class SuggestionExtractor {
// TODO: Create a more general Extractor class
public void forceLocalization(@Nullable Localization localization) {
public void forceLocalization(@Nullable final Localization localization) {
this.forcedLocalization = localization;
}
public void forceContentCountry(@Nullable ContentCountry contentCountry) {
public void forceContentCountry(@Nullable final ContentCountry contentCountry) {
this.forcedContentCountry = contentCountry;
}
@ -46,6 +47,7 @@ public abstract class SuggestionExtractor {
@Nonnull
public ContentCountry getExtractorContentCountry() {
return forcedContentCountry == null ? getService().getContentCountry() : forcedContentCountry;
return forcedContentCountry == null
? getService().getContentCountry() : forcedContentCountry;
}
}