2017-08-05 16:15:36 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2017-12-07 02:09:46 +01:00
|
|
|
import org.junit.BeforeClass;
|
2017-08-05 10:03:56 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.schabi.newpipe.Downloader;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2018-05-08 21:19:03 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
|
2017-11-23 16:33:03 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.*;
|
2018-09-15 21:47:53 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Localization;
|
2017-11-25 19:21:33 +01:00
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2017-08-16 04:40:03 +02:00
|
|
|
import static org.junit.Assert.*;
|
2018-01-04 17:21:03 +01:00
|
|
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
2017-08-07 18:12:51 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
|
|
|
/*
|
2017-08-05 10:03:56 +02:00
|
|
|
* Created by Christian Schabesberger on 30.12.15.
|
|
|
|
*
|
|
|
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
|
|
|
* YoutubeVideoExtractorDefault.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for {@link StreamExtractor}
|
|
|
|
*/
|
|
|
|
public class YoutubeStreamExtractorDefaultTest {
|
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
public static class AdeleHello {
|
|
|
|
private static YoutubeStreamExtractor extractor;
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
2018-09-15 21:47:53 +02:00
|
|
|
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
|
2018-09-07 22:18:22 +02:00
|
|
|
extractor = (YoutubeStreamExtractor) YouTube
|
|
|
|
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
|
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetInvalidTimeStamp() throws ParsingException {
|
|
|
|
assertTrue(extractor.getTimeStamp() + "",
|
|
|
|
extractor.getTimeStamp() <= 0);
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetValidTimeStamp() throws ExtractionException {
|
|
|
|
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
|
|
|
|
assertEquals(extractor.getTimeStamp() + "", "174");
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetTitle() throws ParsingException {
|
|
|
|
assertFalse(extractor.getName().isEmpty());
|
|
|
|
}
|
2018-08-16 17:11:18 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetDescription() throws ParsingException {
|
|
|
|
assertNotNull(extractor.getDescription());
|
|
|
|
assertFalse(extractor.getDescription().isEmpty());
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetFullLinksInDescriptlion() throws ParsingException {
|
|
|
|
assertTrue(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQid=yt"));
|
|
|
|
assertFalse(extractor.getDescription().contains("http://smarturl.it/SubscribeAdele?IQi..."));
|
|
|
|
}
|
2017-11-25 01:10:04 +01:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetUploaderName() throws ParsingException {
|
|
|
|
assertNotNull(extractor.getUploaderName());
|
|
|
|
assertFalse(extractor.getUploaderName().isEmpty());
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetLength() throws ParsingException {
|
|
|
|
assertTrue(extractor.getLength() > 0);
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetViewCount() throws ParsingException {
|
|
|
|
Long count = extractor.getViewCount();
|
|
|
|
assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784);
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetUploadDate() throws ParsingException {
|
|
|
|
assertTrue(extractor.getUploadDate().length() > 0);
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetUploaderUrl() throws ParsingException {
|
|
|
|
assertTrue(extractor.getUploaderUrl().length() > 0);
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetThumbnailUrl() throws ParsingException {
|
|
|
|
assertIsSecureUrl(extractor.getThumbnailUrl());
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetUploaderAvatarUrl() throws ParsingException {
|
|
|
|
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
2017-08-05 10:03:56 +02:00
|
|
|
}
|
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetAudioStreams() throws IOException, ExtractionException {
|
|
|
|
assertFalse(extractor.getAudioStreams().isEmpty());
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetVideoStreams() throws IOException, ExtractionException {
|
|
|
|
for (VideoStream s : extractor.getVideoStreams()) {
|
|
|
|
assertIsSecureUrl(s.url);
|
|
|
|
assertTrue(s.resolution.length() > 0);
|
|
|
|
assertTrue(Integer.toString(s.getFormatId()),
|
|
|
|
0 <= s.getFormatId() && s.getFormatId() <= 4);
|
|
|
|
}
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testStreamType() throws ParsingException {
|
|
|
|
assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetDashMpd() throws ParsingException {
|
|
|
|
// we dont expect this particular video to have a DASH file. For this purpouse we use a different test class.
|
|
|
|
assertTrue(extractor.getDashMpdUrl(),
|
|
|
|
extractor.getDashMpdUrl() != null && extractor.getDashMpdUrl().isEmpty());
|
|
|
|
}
|
2017-11-22 18:39:38 +01:00
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
@Test
|
|
|
|
public void testGetRelatedVideos() throws ExtractionException, IOException {
|
2018-11-07 18:28:44 +01:00
|
|
|
StreamInfoItemsCollector relatedVideos = extractor.getRelatedStreams();
|
2018-09-07 22:18:22 +02:00
|
|
|
Utils.printErrors(relatedVideos.getErrors());
|
|
|
|
assertFalse(relatedVideos.getItems().isEmpty());
|
|
|
|
assertTrue(relatedVideos.getErrors().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
|
|
|
|
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
|
|
|
assertTrue(extractor.getSubtitlesDefault().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetSubtitlesList() throws IOException, ExtractionException {
|
|
|
|
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
|
|
|
assertTrue(extractor.getSubtitles(SubtitlesFormat.TTML).isEmpty());
|
|
|
|
}
|
2017-11-23 16:33:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 22:18:22 +02:00
|
|
|
public static class DescriptionTestPewdiepie {
|
|
|
|
private static YoutubeStreamExtractor extractor;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
2018-09-15 21:47:53 +02:00
|
|
|
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
|
2018-09-07 22:18:22 +02:00
|
|
|
extractor = (YoutubeStreamExtractor) YouTube
|
2018-10-05 16:01:10 +02:00
|
|
|
.getStreamExtractor("https://www.youtube.com/watch?v=fBc4Q_htqPg");
|
2018-09-07 22:18:22 +02:00
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetDescription() throws ParsingException {
|
|
|
|
assertNotNull(extractor.getDescription());
|
|
|
|
assertFalse(extractor.getDescription().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-09-24 15:06:00 +02:00
|
|
|
public void testGetFullLinksInDescription() throws ParsingException {
|
2018-09-07 22:18:22 +02:00
|
|
|
assertTrue(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSubmissions/"));
|
2018-09-24 15:17:57 +02:00
|
|
|
assertTrue(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8EMTOn4g6ZSKggHTnNng"));
|
2018-09-20 13:51:06 +02:00
|
|
|
assertTrue(extractor.getDescription().contains("https://usa.clutchchairz.com/product/pewdiepie-edition-throttle-series/"));
|
2018-09-07 22:18:22 +02:00
|
|
|
|
|
|
|
assertFalse(extractor.getDescription().contains("https://www.reddit.com/r/PewdiepieSub..."));
|
2018-09-24 15:17:57 +02:00
|
|
|
assertFalse(extractor.getDescription().contains("https://www.youtube.com/channel/UC3e8..."));
|
2018-09-07 22:18:22 +02:00
|
|
|
assertFalse(extractor.getDescription().contains("https://usa.clutchchairz.com/product/..."));
|
|
|
|
}
|
2017-11-22 18:39:38 +01:00
|
|
|
}
|
2018-09-24 15:06:00 +02:00
|
|
|
|
|
|
|
public static class DescriptionTestUnboxing {
|
|
|
|
private static YoutubeStreamExtractor extractor;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
|
|
|
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
|
|
|
|
extractor = (YoutubeStreamExtractor) YouTube
|
|
|
|
.getStreamExtractor("https://www.youtube.com/watch?v=cV5TjZCJkuA");
|
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetDescription() throws ParsingException {
|
|
|
|
assertNotNull(extractor.getDescription());
|
|
|
|
assertFalse(extractor.getDescription().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetFullLinksInDescription() throws ParsingException {
|
|
|
|
assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=X7FLCHVXpsA&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
|
|
|
|
assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=Lqv6G0pDNnw&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
|
|
|
|
assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=XxaRBPyrnBU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
|
|
|
|
assertTrue(extractor.getDescription().contains("https://www.youtube.com/watch?v=U-9tUEOFKNU&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
|
|
|
|
|
|
|
|
assertFalse(extractor.getDescription().contains("https://youtu.be/X7FLCHVXpsA?list=PL7..."));
|
|
|
|
assertFalse(extractor.getDescription().contains("https://youtu.be/Lqv6G0pDNnw?list=PL7..."));
|
|
|
|
assertFalse(extractor.getDescription().contains("https://youtu.be/XxaRBPyrnBU?list=PL7..."));
|
|
|
|
assertFalse(extractor.getDescription().contains("https://youtu.be/U-9tUEOFKNU?list=PL7..."));
|
|
|
|
}
|
|
|
|
}
|
2017-08-05 10:03:56 +02:00
|
|
|
}
|