Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private String parseHtmlAndGetFullLinks(String descriptionHtml)
throws MalformedURLException, UnsupportedEncodingException, ParsingException {
final Document description = Jsoup.parse(descriptionHtml, getUrl());
for(Element a : description.select("a")) {
final URL redirectLink = new URL(
a.attr("abs:href"));
final String rawUrl = a.attr("abs:href");
final URL redirectLink = new URL(rawUrl);
final String queryString = redirectLink.getQuery();
if(queryString != null) {
// if the query string is null we are not dealing with a redirect link,
Expand All @@ -179,11 +179,15 @@ private String parseHtmlAndGetFullLinks(String descriptionHtml)
// if link is null the a tag is a hashtag.
// They refer to the youtube search. We do not handle them.
a.text(link);
a.attr("href", link);
} else if(redirectLink.toString().contains("https://www.youtube.com/")) {
a.text(redirectLink.toString());
a.attr("href", redirectLink.toString());
}
} else if(redirectLink.toString().contains("https://www.youtube.com/")) {
descriptionHtml = descriptionHtml.replace(rawUrl, redirectLink.toString());
a.text(redirectLink.toString());
a.attr("href", redirectLink.toString());
}
}
return description.select("body").first().html();
Expand All @@ -206,29 +210,40 @@ public int getAgeLimit() throws ParsingException {
@Override
public long getLength() throws ParsingException {
assertPageFetched();
if(playerArgs != null) {
try {
long returnValue = Long.parseLong(playerArgs.get("length_seconds") + "");
if (returnValue >= 0) return returnValue;
} catch (Exception ignored) {
// Try other method...

final JsonObject playerResponse;
try {
final String pr;
if(playerArgs != null) {
pr = playerArgs.getString("player_response");
} else {
pr = videoInfoPage.get("player_response");
}
playerResponse = JsonParser.object()
.from(pr);
} catch (Exception e) {
throw new ParsingException("Could not get playerResponse", e);
}

String lengthString = videoInfoPage.get("length_seconds");
// try getting duration from playerargs
try {
return Long.parseLong(lengthString);
} catch (Exception ignored) {
// Try other method...
String durationMs = playerResponse
.getObject("streamingData")
.getArray("formats")
.getObject(0)
.getString("approxDurationMs");
return Long.parseLong(durationMs)/1000;
} catch (Exception e) {
}

// TODO: 25.11.17 Implement a way to get the length for age restricted videos #44
//try getting value from age gated video
try {
// Fallback to HTML method
return Long.parseLong(doc.select("div[class~=\"ytp-progress-bar\"][role=\"slider\"]").first()
.attr("aria-valuemax"));
String duration = playerResponse
.getObject("videoDetails")
.getString("lengthSeconds");
return Long.parseLong(duration);
} catch (Exception e) {
throw new ParsingException("Could not get video length", e);
throw new ParsingException("Every methode to get the duration has failed: ", e);
}
}

Expand Down Expand Up @@ -597,6 +612,7 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
final String playerUrl;
// Check if the video is age restricted
if (pageContent.contains("<meta property=\"og:restrictions:age")) {
// do this if it is age gated
final EmbeddedInfo info = getEmbeddedInfo();
final String videoInfoUrl = getVideoInfoUrl(getId(), info.sts);
final String infoPageResponse = downloader.download(videoInfoUrl);
Expand Down Expand Up @@ -685,11 +701,16 @@ private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaExcepti
playerUrl = HTTPS + playerUrl;
}

// Get embed sts
final String stsPattern = "\"sts\"\\s*:\\s*(\\d+)";
final String sts = Parser.matchGroup1(stsPattern, embedPageContent);
try {
// Get embed sts
final String stsPattern = "\"sts\"\\s*:\\s*(\\d+)";
final String sts = Parser.matchGroup1(stsPattern, embedPageContent);
return new EmbeddedInfo(playerUrl, sts);
} catch (Exception i) {
// if it failes we simply reply with no sts as then it does not seem to be necessary
return new EmbeddedInfo(playerUrl, "");
}

return new EmbeddedInfo(playerUrl, sts);
} catch (IOException e) {
throw new ParsingException(
"Could load decryption code form restricted video for the Youtube service.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void getAudioStreamsCount() throws Exception {
@Test
public void getAudioStreamsContainOgg() throws Exception {
for(AudioStream stream : extractor.getAudioStreams()) {
System.out.println(stream.getFormat());
assertEquals("OGG", stream.getFormat().toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void testGetDownloader() throws Exception {
assertNotNull(NewPipe.getDownloader());
}

@Ignore
@Test
public void testGetName() throws Exception {
assertEquals(extractor.getName(), "Top 50");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public static void setUp() throws Exception {
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/

@Ignore
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
Expand Down Expand Up @@ -270,6 +271,8 @@ public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}

//TODO: FUCK THIS: This triggers a 500 at sever
@Ignore
@Test
public void testMoreRelatedItems() throws Exception {
ListExtractor.InfoItemsPage<StreamInfoItem> currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ public void testGetInvalidTimeStamp() throws ParsingException {
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
StreamExtractor extractor = SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69");
assertEquals(extractor.getTimeStamp() + "", "69");
assertEquals("69", extractor.getTimeStamp() + "");
}

@Test
public void testGetTitle() throws ParsingException {
assertEquals(extractor.getName(), "Do What I Want [Produced By Maaly Raw + Don Cannon]");
assertEquals("Do What I Want [Produced By Maaly Raw + Don Cannon]", extractor.getName());
}

@Test
public void testGetDescription() throws ParsingException {
assertEquals(extractor.getDescription(), "The Perfect LUV Tape®️");
assertEquals("The Perfect LUV Tape®️", extractor.getDescription());
}

@Test
public void testGetUploaderName() throws ParsingException {
assertEquals(extractor.getUploaderName(), "LIL UZI VERT");
assertEquals("LIL UZI VERT", extractor.getUploaderName());
}

@Test
public void testGetLength() throws ParsingException {
assertEquals(extractor.getLength(), 175);
assertEquals(175, extractor.getLength());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ public void testGetUploaderName() throws ParsingException {
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);
assertEquals(1789, extractor.getLength());
}

@Test
Expand All @@ -97,8 +96,6 @@ public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}

// FIXME: 25.11.17 Are there no streams or are they not listed?
@Ignore
@Test
public void testGetAudioStreams() throws IOException, ExtractionException {
// audio streams are not always necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ public void testGetUploaderName() throws ParsingException {
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);
assertEquals(219, extractor.getLength());
}

@Test
Expand All @@ -97,8 +96,6 @@ public void testGetUploaderAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}

// FIXME: 25.11.17 Are there no streams or are they not listed?
@Ignore
@Test
public void testGetAudioStreams() throws IOException, ExtractionException {
// audio streams are not always necessary
Expand All @@ -113,17 +110,15 @@ public void testGetVideoStreams() throws IOException, ExtractionException {
assertTrue(streams.size() > 0);
}

@Ignore
@Test
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(!extractor.getSubtitlesDefault().isEmpty());
assertFalse(extractor.getSubtitlesDefault().isEmpty());
}

@Ignore
@Test
public void testGetSubtitlesList() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(!extractor.getSubtitles(MediaFormat.TTML).isEmpty());
assertFalse(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static class AdeleHello {
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
.getStreamExtractor("https://www.youtube.com/watch?v=YQHsXMglC9A");
extractor.fetchPage();
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public void testGetDescription() throws ParsingException {

@Test
public void testGetFullLinksInDescriptlion() throws ParsingException {
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
assertTrue(extractor.getDescription().contains("http://adele.com"));
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
}

Expand All @@ -95,7 +95,7 @@ public void testGetUploaderName() throws ParsingException {

@Test
public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0);
assertEquals(366, extractor.getLength());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.schabi.newpipe.extractor.services.youtube.search;

import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void testGetSecondPageUrl() throws Exception {
assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=2", extractor.getNextPageUrl());
}

@Ignore
@Test
public void testOnlyContainChannels() {
for(InfoItem item : itemsPage.getItems()) {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Jan 18 11:51:40 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
18 changes: 17 additions & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.