NewPipeExtractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefau...

164 lines
5.6 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor.services.youtube;
2017-08-05 10:03:56 +02:00
import com.grack.nanojson.JsonParserException;
2017-08-05 10:03:56 +02:00
import org.junit.Before;
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;
import org.schabi.newpipe.extractor.stream.*;
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;
import java.util.HashMap;
2017-08-06 22:20:15 +02:00
import static org.junit.Assert.*;
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 {
public static final String HTTPS = "https://";
2017-11-28 13:37:01 +01:00
private YoutubeStreamExtractor extractor;
2017-08-05 10:03:56 +02:00
@Before
public void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
2017-11-28 13:37:01 +01:00
extractor = (YoutubeStreamExtractor) YouTube.getService()
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
extractor.fetchPage();
2017-08-05 10:03:56 +02:00
}
@Test
public void testGetInvalidTimeStamp() throws ParsingException {
2017-08-11 03:23:09 +02:00
assertTrue(extractor.getTimeStamp() + "",
2017-08-05 10:03:56 +02:00
extractor.getTimeStamp() <= 0);
}
@Test
2017-08-06 22:20:15 +02:00
public void testGetValidTimeStamp() throws IOException, ExtractionException {
2017-08-07 18:12:51 +02:00
StreamExtractor extractor = YouTube.getService().getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
2017-08-11 03:23:09 +02:00
assertEquals(extractor.getTimeStamp() + "", "174");
2017-08-05 10:03:56 +02:00
}
@Test
public void testGetTitle() throws ParsingException {
2017-11-25 02:07:12 +01:00
assertFalse(extractor.getName().isEmpty());
2017-08-05 10:03:56 +02:00
}
@Test
public void testGetDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
assertFalse(extractor.getDescription().isEmpty());
2017-08-05 10:03:56 +02:00
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetUploaderName() throws ParsingException {
assertNotNull(extractor.getUploaderName());
assertFalse(extractor.getUploaderName().isEmpty());
2017-08-05 10:03:56 +02:00
}
2017-08-05 10:03:56 +02:00
@Test
public void testGetLength() throws ParsingException {
assertTrue(extractor.getLength() > 0);
}
@Test
public void testGetViewCount() throws ParsingException {
2017-11-25 19:21:33 +01:00
Long count = extractor.getViewCount();
assertTrue(Long.toString(count), count >= /* specific to that video */ 1220025784);
2017-08-05 10:03:56 +02:00
}
@Test
public void testGetUploadDate() throws ParsingException {
assertTrue(extractor.getUploadDate().length() > 0);
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetUploaderUrl() throws ParsingException {
assertTrue(extractor.getUploaderUrl().length() > 0);
2017-08-05 10:03:56 +02:00
}
@Test
public void testGetThumbnailUrl() throws ParsingException {
assertTrue(extractor.getThumbnailUrl(),
extractor.getThumbnailUrl().contains(HTTPS));
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetUploaderAvatarUrl() throws ParsingException {
assertTrue(extractor.getUploaderAvatarUrl(),
extractor.getUploaderAvatarUrl().contains(HTTPS));
2017-08-05 10:03:56 +02:00
}
@Test
2017-08-06 22:20:15 +02:00
public void testGetAudioStreams() throws IOException, ExtractionException {
2017-11-25 02:07:12 +01:00
assertFalse(extractor.getAudioStreams().isEmpty());
2017-08-05 10:03:56 +02:00
}
@Test
2017-08-06 22:20:15 +02:00
public void testGetVideoStreams() throws IOException, ExtractionException {
for (VideoStream s : extractor.getVideoStreams()) {
2017-08-05 10:03:56 +02:00
assertTrue(s.url,
s.url.contains(HTTPS));
assertTrue(s.resolution.length() > 0);
assertTrue(Integer.toString(s.getFormatId()),
0 <= s.getFormatId() && s.getFormatId() <= 4);
2017-08-05 10:03:56 +02:00
}
}
@Test
public void testStreamType() throws ParsingException {
assertTrue(extractor.getStreamType() == StreamType.VIDEO_STREAM);
}
@Test
public void testGetDashMpd() throws ParsingException {
assertTrue(extractor.getDashMpdUrl(),
extractor.getDashMpdUrl() != null || !extractor.getDashMpdUrl().isEmpty());
}
2017-08-06 22:20:15 +02:00
@Test
public void testGetRelatedVideos() throws ExtractionException, IOException {
StreamInfoItemCollector relatedVideos = extractor.getRelatedVideos();
2017-11-25 19:21:33 +01:00
Utils.printErrors(relatedVideos);
2017-08-06 22:20:15 +02:00
assertFalse(relatedVideos.getItemList().isEmpty());
assertTrue(relatedVideos.getErrors().isEmpty());
}
@Test
2017-11-24 13:57:54 +01:00
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitlesDefault() == null);
}
@Test
2017-11-24 13:57:54 +01:00
public void testGetSubtitlesList() throws IOException, ExtractionException {
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
}
2017-08-05 10:03:56 +02:00
}