diff --git a/build.gradle b/build.gradle index 8c9923265..f8b8b0a6d 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ dependencies { implementation 'com.grack:nanojson:1.1' implementation 'org.jsoup:jsoup:1.9.2' implementation 'org.mozilla:rhino:1.7.7.1' - + implementation 'com.github.spotbugs:spotbugs:3.1.0' testImplementation 'junit:junit:4.12' } diff --git a/src/main/java/org/schabi/newpipe/extractor/Extractor.java b/src/main/java/org/schabi/newpipe/extractor/Extractor.java index 6cfd5f723..3e0456a94 100644 --- a/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -3,6 +3,8 @@ package org.schabi.newpipe.extractor; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; public abstract class Extractor { @@ -29,6 +31,7 @@ public abstract class Extractor { *

* Is lazily-cleaned by calling {@link #getCleanUrl()} */ + @Nullable private String cleanUrl; public Extractor(StreamingService service, String url) throws ExtractionException { @@ -41,6 +44,7 @@ public abstract class Extractor { /** * @return a {@link UrlIdHandler} of the current extractor type (e.g. a ChannelExtractor should return a channel url handler). */ + @Nonnull protected abstract UrlIdHandler getUrlIdHandler() throws ParsingException; /** @@ -48,9 +52,18 @@ public abstract class Extractor { */ public abstract void fetchPage() throws IOException, ExtractionException; + @Nonnull public abstract String getId() throws ParsingException; + + /** + * Get the name + * @return the name + * @throws ParsingException if the name cannot be extracted + */ + @Nonnull public abstract String getName() throws ParsingException; + @Nonnull public String getOriginalUrl() { return originalUrl; } @@ -59,6 +72,7 @@ public abstract class Extractor { * Get a clean url and as a fallback the original url. * @return the clean url or the original url */ + @Nonnull public String getCleanUrl() { if (cleanUrl != null && !cleanUrl.isEmpty()) return cleanUrl; @@ -72,6 +86,7 @@ public abstract class Extractor { return cleanUrl; } + @Nonnull public StreamingService getService() { return service; } diff --git a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java index cb44ffd64..db909fb9b 100644 --- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java @@ -6,6 +6,7 @@ import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import javax.annotation.Nonnull; import java.io.IOException; /* @@ -34,6 +35,7 @@ public abstract class ChannelExtractor extends ListExtractor { super(service, url, nextStreamsUrl); } + @Nonnull @Override protected UrlIdHandler getUrlIdHandler() throws ParsingException { return getService().getChannelUrlIdHandler(); diff --git a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java index 9d30c9829..f402a6a7f 100644 --- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java @@ -7,11 +7,9 @@ import org.schabi.newpipe.extractor.ServiceList; 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.stream.StreamInfoItemCollector; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; -import java.util.ArrayList; /* * Created by Christian Schabesberger on 31.07.16. diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java index e11e89b0c..5df579e7a 100644 --- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java @@ -25,6 +25,7 @@ import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import javax.annotation.Nonnull; import java.io.IOException; public abstract class KioskExtractor extends ListExtractor { @@ -51,6 +52,7 @@ public abstract class KioskExtractor extends ListExtractor { } + @Nonnull @Override public String getId() throws ParsingException { return id; @@ -64,6 +66,7 @@ public abstract class KioskExtractor extends ListExtractor { * @return the tranlsated version of id * @throws ParsingException */ + @Nonnull @Override public abstract String getName() throws ParsingException; diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index da81af04d..bbaab0092 100644 --- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java @@ -1,16 +1,13 @@ package org.schabi.newpipe.extractor.kiosk; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import java.io.IOError; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Random; import java.util.Set; public class KioskList { diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java index 41844bb88..2223c6a09 100644 --- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java @@ -6,6 +6,7 @@ import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import javax.annotation.Nonnull; import java.io.IOException; public abstract class PlaylistExtractor extends ListExtractor { @@ -14,6 +15,7 @@ public abstract class PlaylistExtractor extends ListExtractor { super(service, url, nextStreamsUrl); } + @Nonnull @Override protected UrlIdHandler getUrlIdHandler() throws ParsingException { return getService().getPlaylistUrlIdHandler(); diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index f8f2a2114..9a766fdea 100644 --- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -4,7 +4,6 @@ import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; diff --git a/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java b/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java index 14bb8fcff..2b2618e35 100644 --- a/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java +++ b/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java @@ -3,9 +3,9 @@ package org.schabi.newpipe.extractor.search; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -32,7 +32,9 @@ import java.util.List; public class SearchResult { private final int serviceId; public final String suggestion; + @Nonnull public final List resultList; + @Nonnull public final List errors; public SearchResult(int serviceId, String suggestion, List results, List errors) { @@ -66,10 +68,12 @@ public class SearchResult { } + @Nonnull public List getResults() { return Collections.unmodifiableList(resultList); } + @Nonnull public List getErrors() { return errors; } diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java index 3cab5dd8b..b54febae8 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector; +import javax.annotation.Nonnull; import java.io.IOException; @SuppressWarnings("WeakerAccess") @@ -38,16 +39,19 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { } } + @Nonnull @Override public String getCleanUrl() { return user.isString("permalink_url") ? user.getString("permalink_url") : getOriginalUrl(); } + @Nonnull @Override public String getId() { return userId; } + @Nonnull @Override public String getName() { return user.getString("username"); diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java index b1466e8f5..c7a1e6ff2 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractor.java @@ -11,6 +11,8 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector; +import javax.annotation.Nonnull; + public class SoundcloudChartsExtractor extends KioskExtractor { private String url; @@ -24,11 +26,13 @@ public class SoundcloudChartsExtractor extends KioskExtractor { public void fetchPage() { } + @Nonnull @Override public String getName() throws ParsingException { return "< Implement me (♥_♥) >"; } + @Nonnull @Override public UrlIdHandler getUrlIdHandler() { return new SoundcloudChartsUrlIdHandler(); diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java index b21e585be..df2b5bd51 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector; +import javax.annotation.Nonnull; import java.io.IOException; @SuppressWarnings("WeakerAccess") @@ -39,16 +40,19 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { } } + @Nonnull @Override public String getCleanUrl() { return playlist.isString("permalink_url") ? playlist.getString("permalink_url") : getOriginalUrl(); } + @Nonnull @Override public String getId() { return playlistId; } + @Nonnull @Override public String getName() { return playlist.getString("title"); diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java index 5e790bcbf..a01ec1792 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.stream.*; import org.schabi.newpipe.extractor.utils.Parser; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.*; @@ -19,6 +20,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { public SoundcloudStreamExtractor(StreamingService service, String url) throws IOException, ExtractionException { super(service, url); + fetchPage(); } @Override @@ -31,31 +33,37 @@ public class SoundcloudStreamExtractor extends StreamExtractor { } } + @Nonnull @Override public String getCleanUrl() { return track.isString("permalink_url") ? track.getString("permalink_url") : getOriginalUrl(); } + @Nonnull @Override public String getId() { return track.getInt("id") + ""; } + @Nonnull @Override public String getName() { return track.getString("title"); } + @Nonnull @Override public String getUploadDate() throws ParsingException { return SoundcloudParsingHelper.toDateString(track.getString("created_at")); } + @Nonnull @Override public String getThumbnailUrl() { return track.getString("artwork_url", ""); } + @Nonnull @Override public String getDescription() { return track.getString("description"); @@ -91,16 +99,19 @@ public class SoundcloudStreamExtractor extends StreamExtractor { return -1; } + @Nonnull @Override public String getUploaderUrl() { return track.getObject("user").getString("permalink_url", ""); } + @Nonnull @Override public String getUploaderName() { return track.getObject("user").getString("username", ""); } + @Nonnull @Override public String getUploaderAvatarUrl() { return track.getObject("user", new JsonObject()).getString("avatar_url", ""); diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index f8a460643..b2178baac 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -18,6 +18,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; +import javax.annotation.Nonnull; import java.io.IOException; /* @@ -79,6 +80,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { return true; } + @Nonnull @Override public String getCleanUrl() { try { @@ -88,6 +90,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { } } + @Nonnull @Override public String getId() throws ParsingException { try { @@ -100,6 +103,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { } } + @Nonnull @Override public String getName() throws ParsingException { try { diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java index feae173f3..de3b485b9 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java @@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; +import javax.annotation.Nonnull; import java.io.IOException; @SuppressWarnings("WeakerAccess") @@ -45,6 +46,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { nextStreamsAjax = null; } + @Nonnull @Override public String getId() throws ParsingException { try { @@ -54,6 +56,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { } } + @Nonnull @Override public String getName() throws ParsingException { try { diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 84eb1c1e3..cefd7e783 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -22,6 +22,8 @@ import org.schabi.newpipe.extractor.stream.*; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import java.util.*; import java.util.regex.Matcher; @@ -75,19 +77,23 @@ public class YoutubeStreamExtractor extends StreamExtractor { /*//////////////////////////////////////////////////////////////////////////*/ private Document doc; + @Nullable private JsonObject playerArgs; - private Map videoInfoPage; + @Nonnull + private final Map videoInfoPage = new HashMap<>(); private boolean isAgeRestricted; public YoutubeStreamExtractor(StreamingService service, String url) throws IOException, ExtractionException { super(service, url); + fetchPage(); } /*////////////////////////////////////////////////////////////////////////// // Impl //////////////////////////////////////////////////////////////////////////*/ + @Nonnull @Override public String getId() throws ParsingException { try { @@ -97,28 +103,25 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nonnull @Override public String getName() throws ParsingException { - try { - return playerArgs.getString("title"); - } catch (Exception ignored) { - // Try other method... - } - - try { - return videoInfoPage.get("title"); - } catch (Exception ignored) { - // Try other method... - } - - try { + String name = getStringFromMetaData("title"); + if(name == null) { // Fallback to HTML method - return doc.select("meta[name=title]").attr(CONTENT); - } catch (Exception e) { - throw new ParsingException("Could not get the title", e); + try { + name = doc.select("meta[name=title]").attr(CONTENT); + } catch (Exception e) { + throw new ParsingException("Could not get the title", e); + } } + if(name == null || name.isEmpty()) { + throw new ParsingException("Could not get the title"); + } + return name; } + @Nonnull @Override public String getUploadDate() throws ParsingException { try { @@ -128,6 +131,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nonnull @Override public String getThumbnailUrl() throws ParsingException { // Try to get high resolution thumbnail first, if it fails, use low res from the player instead @@ -138,7 +142,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } try { - if (playerArgs.isString("thumbnail_url")) return playerArgs.getString("thumbnail_url"); + if (playerArgs != null && playerArgs.isString("thumbnail_url")) return playerArgs.getString("thumbnail_url"); } catch (Exception ignored) { // Try other method... } @@ -150,6 +154,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nonnull @Override public String getDescription() throws ParsingException { try { @@ -174,23 +179,27 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Override public long getLength() throws ParsingException { + if(playerArgs != null) { + try { + long returnValue = Long.parseLong(playerArgs.get("length_seconds") + ""); + if (returnValue >= 0) return returnValue; + } catch (Exception ignored) { + // Try other method... + } + } + + String lengthString = videoInfoPage.get("length_seconds"); try { - long returnValue = Long.parseLong(playerArgs.get("length_seconds") + ""); - if (returnValue >= 0) return returnValue; - } catch (Exception ignored) { - // Try other method... - } - - try { - return Long.parseLong(videoInfoPage.get("length_seconds")); + return Long.parseLong(lengthString); } catch (Exception ignored) { // Try other method... } + // TODO: 25.11.17 Implement a way to get the length for age restricted videos #44 try { // Fallback to HTML method - return Long.parseLong(doc.select("div[class~=\"ytp-progress-bar\"][role=\"slider\"]") - .first().attr("aria-valuemax")); + return Long.parseLong(doc.select("div[class~=\"ytp-progress-bar\"][role=\"slider\"]").first() + .attr("aria-valuemax")); } catch (Exception e) { throw new ParsingException("Could not get video length", e); } @@ -253,6 +262,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nonnull @Override public String getUploaderUrl() throws ParsingException { try { @@ -263,28 +273,41 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } - @Override - public String getUploaderName() throws ParsingException { - try { - return playerArgs.getString("author"); - } catch (Exception ignored) { - // Try other method... - } - try { - return videoInfoPage.get("author"); - } catch (Exception ignored) { - // Try other method... + @Nullable + private String getStringFromMetaData(String field) { + String value = null; + if(playerArgs != null) { + // This can not fail + value = playerArgs.getString(field); } - - try { - // Fallback to HTML method - return doc.select("div.yt-user-info").first().text(); - } catch (Exception e) { - throw new ParsingException("Could not get uploader name", e); + if(value == null) { + // This can not fail too + value = videoInfoPage.get(field); } + return value; } + @Nonnull + @Override + public String getUploaderName() throws ParsingException { + String name = getStringFromMetaData("author"); + + if(name == null) { + try { + // Fallback to HTML method + name = doc.select("div.yt-user-info").first().text(); + } catch (Exception e) { + throw new ParsingException("Could not get uploader name", e); + } + } + if(name == null || name.isEmpty()) { + throw new ParsingException("Could not get uploader name"); + } + return name; + } + + @Nonnull @Override public String getUploaderAvatarUrl() throws ParsingException { try { @@ -300,9 +323,9 @@ public class YoutubeStreamExtractor extends StreamExtractor { public String getDashMpdUrl() throws ParsingException { try { String dashManifestUrl; - if (videoInfoPage != null && videoInfoPage.containsKey("dashmpd")) { + if (videoInfoPage.containsKey("dashmpd")) { dashManifestUrl = videoInfoPage.get("dashmpd"); - } else if (playerArgs.isString("dashmpd")) { + } else if (playerArgs != null && playerArgs.isString("dashmpd")) { dashManifestUrl = playerArgs.getString("dashmpd", ""); } else { return ""; @@ -521,7 +544,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { // Check if the video is age restricted if (pageContent.contains(" getAudioStreams() throws IOException, ExtractionException; public abstract List getVideoStreams() throws IOException, ExtractionException; diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 1ede39cfe..871720cc5 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -7,7 +7,6 @@ import org.schabi.newpipe.extractor.utils.DashMpdParser; import org.schabi.newpipe.extractor.utils.ExtractorHelper; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/src/test/java/org/schabi/newpipe/Downloader.java b/src/test/java/org/schabi/newpipe/Downloader.java index 6a3554e50..542c853bf 100644 --- a/src/test/java/org/schabi/newpipe/Downloader.java +++ b/src/test/java/org/schabi/newpipe/Downloader.java @@ -89,10 +89,8 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { public String download(String siteUrl, Map customProperties) throws IOException, ReCaptchaException { URL url = new URL(siteUrl); HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); - Iterator it = customProperties.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = (Map.Entry) it.next(); - con.setRequestProperty((String) pair.getKey(), (String) pair.getValue()); + for (Map.Entry pair: customProperties.entrySet()) { + con.setRequestProperty(pair.getKey(), pair.getValue()); } return dl(con); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java index 79636c8c8..ffb3c31f8 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java @@ -10,13 +10,10 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItemCollector; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector; -import java.util.List; - /** * Test for {@link SoundcloudChartsUrlIdHandler} */ diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java index 890c2fd38..1954b8c67 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineAllTest.java @@ -9,6 +9,7 @@ import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchResult; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; @@ -36,8 +37,9 @@ public class SoundcloudSearchEngineAllTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java index e4ccee6e2..15c0a4e6a 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java @@ -43,8 +43,9 @@ public class SoundcloudSearchEngineChannelTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java index 89c5dac35..6a24d4f21 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java @@ -63,8 +63,9 @@ public class SoundcloudSearchEnginePlaylistTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java index b0b554ebc..14f0c6c60 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java @@ -43,8 +43,9 @@ public class SoundcloudSearchEngineStreamTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java index 5cf1bda5a..273fedd1a 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java @@ -1,6 +1,5 @@ package org.schabi.newpipe.extractor.services.youtube; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -11,7 +10,6 @@ import org.schabi.newpipe.extractor.search.SearchResult; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; /* * Created by Christian Schabesberger on 29.12.15. diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java index 9f10c3bbd..48c476263 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java @@ -64,8 +64,9 @@ public class YoutubeSearchEngineChannelTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java index 29c6ed441..bc9096146 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java @@ -64,8 +64,9 @@ public class YoutubeSearchEnginePlaylistTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java index f2b06a0be..c0a8de516 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java @@ -64,8 +64,9 @@ public class YoutubeSearchEngineStreamTest { @Test public void testResultErrors() { + assertNotNull(result.errors); if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace(); - assertTrue(result.errors == null || result.errors.isEmpty()); + assertTrue(result.errors.isEmpty()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java index 64b7538b7..4bb396396 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java @@ -26,7 +26,6 @@ import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.kiosk.KioskList; -import org.schabi.newpipe.extractor.search.SearchEngine; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java index 74342d162..c5d66f4bc 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java @@ -67,14 +67,17 @@ public class YoutubeStreamExtractorDefaultTest { @Test public void testGetDescription() throws ParsingException { - assertTrue(extractor.getDescription() != null); + assertNotNull(extractor.getDescription()); + assertFalse(extractor.getDescription().isEmpty()); } @Test public void testGetUploaderName() throws ParsingException { - assertTrue(!extractor.getUploaderName().isEmpty()); + assertNotNull(extractor.getUploaderName()); + assertFalse(extractor.getUploaderName().isEmpty()); } + @Test public void testGetLength() throws ParsingException { assertTrue(extractor.getLength() > 0); diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java index da3d9aa86..e051e2baf 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.youtube; import com.grack.nanojson.JsonParserException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; @@ -13,8 +14,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** @@ -22,12 +22,12 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube; */ public class YoutubeStreamExtractorRestrictedTest { public static final String HTTPS = "https://"; - private StreamExtractor extractor; + private YoutubeStreamExtractor extractor; @Before public void setUp() throws Exception { NewPipe.init(Downloader.getInstance()); - extractor = YouTube.getService() + extractor = (YoutubeStreamExtractor) YouTube.getService() .getStreamExtractor("https://www.youtube.com/watch?v=i6JTvzrpBy0"); } @@ -48,20 +48,24 @@ public class YoutubeStreamExtractorRestrictedTest { } @Test - public void testGetTitle() throws ParsingException { - assertTrue(!extractor.getName().isEmpty()); + public void testGetName() throws ParsingException { + assertNotNull("name is null", extractor.getName()); + assertFalse("name is empty", extractor.getName().isEmpty()); } @Test public void testGetDescription() throws ParsingException { - assertTrue(extractor.getDescription() != null); + assertNotNull(extractor.getDescription()); + assertFalse(extractor.getDescription().isEmpty()); } @Test public void testGetUploaderName() throws ParsingException { - assertTrue(!extractor.getUploaderName().isEmpty()); + assertNotNull(extractor.getUploaderName()); + assertFalse(extractor.getUploaderName().isEmpty()); } + @Ignore // Currently there is no way get the length from restricted videos @Test public void testGetLength() throws ParsingException { assertTrue(extractor.getLength() > 0); @@ -89,9 +93,10 @@ public class YoutubeStreamExtractorRestrictedTest { extractor.getUploaderAvatarUrl().contains(HTTPS)); } + // FIXME: 25.11.17 Are there no streams or are they not listed? @Test public void testGetAudioStreams() throws IOException, ExtractionException { - // audiostream not always necessary + // audio streams are not always necessary assertTrue(!extractor.getAudioStreams().isEmpty()); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java index 9841ef5d6..cabeb0c6b 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java @@ -23,7 +23,6 @@ package org.schabi.newpipe.extractor.services.youtube; import org.junit.Before; import org.junit.Test; import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.InfoItemCollector; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;