diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java index 39f04f4a0..82e117011 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeSearchEngineTest.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.youtube; import android.test.AndroidTestCase; import org.apache.commons.lang.exception.ExceptionUtils; +import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.SearchResult; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamPreviewInfo; @@ -14,7 +15,7 @@ import org.schabi.newpipe.extractor.services.youtube.YoutubeService; import java.util.ArrayList; /** - * Created by the-scrabi on 29.12.15. + * Created by Christian Schabesberger on 29.12.15. * * Copyright (C) Christian Schabesberger 2015 * YoutubeSearchEngineTest.java is part of NewPipe. @@ -100,6 +101,14 @@ public class YoutubeSearchEngineTest extends AndroidTestCase { } } + public void testStreamType() { + for(StreamPreviewInfo i : result.resultList) { + assertTrue("not a livestream and not a video", + i.stream_type == AbstractVideoInfo.StreamType.VIDEO_STREAM || + i.stream_type == AbstractVideoInfo.StreamType.LIVE_STREAM); + } + } + public void testIfSuggestionsAreReplied() { assertEquals(suggestionReply.size() > 0, true); } diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java index 5217a5753..41fc99c6b 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorDefaultTest.java @@ -3,18 +3,17 @@ package org.schabi.newpipe.extractor.youtube; import android.test.AndroidTestCase; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.VideoStream; -import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.StreamInfo; import java.io.IOException; /** - * Created by the-scrabi on 30.12.15. + * Created by Christian Schabesberger on 30.12.15. * * Copyright (C) Christian Schabesberger 2015 * YoutubeVideoExtractorDefault.java is part of NewPipe. @@ -37,10 +36,6 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase { private StreamExtractor extractor; public void setUp() throws IOException, ExtractionException { - /* some anonymus video test - extractor = new YoutubeStreamExtractor("https://www.youtube.com/watch?v=FmG385_uUys", - new Downloader()); */ - /* some vevo video (suggested to test against) */ extractor = ServiceList.getService("Youtube") .getExtractorInstance("https://www.youtube.com/watch?v=YQHsXMglC9A", new Downloader()); } @@ -107,6 +102,10 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase { } } + public void testStreamType() throws ParsingException { + assertTrue(extractor.getStreamType() == AbstractVideoInfo.StreamType.VIDEO_STREAM); + } + public void testGetDashMpd() throws ParsingException { assertTrue(extractor.getDashMpdUrl(), extractor.getDashMpdUrl() != null || !extractor.getDashMpdUrl().isEmpty()); diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java index 695544a01..13ce65a31 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorGemaTest.java @@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import java.io.IOException; /** - * Created by the-scrabi on 30.12.15. + * Created by Christian Schabesberger on 30.12.15. * * Copyright (C) Christian Schabesberger 2015 * YoutubeVideoExtractorGema.java is part of NewPipe. diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java index d848bb2ce..37be22b73 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorRestrictedTest.java @@ -7,9 +7,7 @@ import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamExtractor; -import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.VideoStream; -import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import java.io.IOException; diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubestreamExtractorLiveStreamTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubestreamExtractorLiveStreamTest.java new file mode 100644 index 000000000..0394bbb27 --- /dev/null +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubestreamExtractorLiveStreamTest.java @@ -0,0 +1,52 @@ +package org.schabi.newpipe.extractor.youtube; + +import android.test.AndroidTestCase; + +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.AbstractVideoInfo; +import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.ParsingException; +import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.StreamExtractor; + +import java.io.IOException; + +/** + * Created by Christian Schabesberger on 11.03.16. + * + * Copyright (C) Christian Schabesberger 2016 + * YoutubestreamExtractorLiveStreamTest.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 . + */ + + +public class YoutubestreamExtractorLiveStreamTest extends AndroidTestCase { + + private StreamExtractor extractor; + + public void setUp() throws IOException, ExtractionException { + //todo: make the extractor not throw over a livestream + /* + extractor = ServiceList.getService("Youtube") + .getExtractorInstance("https://www.youtube.com/watch?v=J0s6NjqdjLE", new Downloader()); + */ + } + + public void testStreamType() throws ParsingException { + assertTrue(true); + // assertTrue(extractor.getStreamType() == AbstractVideoInfo.StreamType.LIVE_STREAM); + } +} + diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java index 9c71a1bde..baeaef813 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java @@ -6,6 +6,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.StreamPreviewInfo; import com.nostra13.universalimageloader.core.DisplayImageOptions; @@ -76,7 +77,11 @@ public class VideoInfoItemViewCreator { if(info.duration > 0) { holder.itemDurationView.setText(getDurationString(info.duration)); } else { - holder.itemDurationView.setVisibility(View.GONE); + if(info.stream_type == AbstractVideoInfo.StreamType.LIVE_STREAM) { + holder.itemDurationView.setText(R.string.duration_live); + } else { + holder.itemDurationView.setVisibility(View.GONE); + } } if(info.view_count >= 0) { holder.itemViewCountView.setText(shortViewCount(info.view_count)); @@ -84,7 +89,7 @@ public class VideoInfoItemViewCreator { holder.itemViewCountView.setVisibility(View.GONE); } if(!info.upload_date.isEmpty()) { - holder.itemUploadDateView.setText(info.upload_date+" • "); + holder.itemUploadDateView.setText(info.upload_date + " • "); } holder.itemThumbnailView.setImageResource(R.drawable.dummy_thumbnail); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java index 5da44c3d4..9ea107f22 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java @@ -22,6 +22,16 @@ import android.graphics.Bitmap; /**Common properties between StreamInfo and StreamPreviewInfo.*/ public abstract class AbstractVideoInfo { + public static enum StreamType { + NONE, // placeholder to check if stream type was checked or not + VIDEO_STREAM, + AUDIO_STREAM, + LIVE_STREAM, + AUDIO_LIVE_STREAM, + FILE + } + + public StreamType stream_type; public int service_id = -1; public String id = ""; public String title = ""; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java index baf513187..eb444f136 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java @@ -242,16 +242,6 @@ public class StreamInfo extends AbstractVideoInfo { return streamInfo; } - public static enum StreamType { - NONE, // placeholder to check if stream type was checked or not - VIDEO_STREAM, - AUDIO_STREAM, - LIVE_STREAM, - AUDIO_LIVE_STREAM, - FILE - } - - public StreamType stream_type; public String uploader_thumbnail_url = ""; public String description = ""; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java index d30a7d5dd..70c2feb77 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java @@ -56,6 +56,7 @@ public class StreamPreviewInfoCollector { resultItem.id = (new YoutubeStreamUrlIdHandler()).getVideoId(resultItem.webpage_url); } resultItem.title = extractor.getTitle(); + resultItem.stream_type = extractor.getStreamType(); // optional iformation try { diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java index 8c64d6f79..bea8eb4e6 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java @@ -21,6 +21,7 @@ package org.schabi.newpipe.extractor; */ public interface StreamPreviewInfoExtractor { + AbstractVideoInfo.StreamType getStreamType() throws ParsingException; String getWebPageUrl() throws ParsingException; String getTitle() throws ParsingException; int getDuration() throws ParsingException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java index 0b0c147fc..700f06766 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngine.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.Parser; @@ -303,6 +304,15 @@ public class YoutubeSearchEngine extends SearchEngine { } } + @Override + public AbstractVideoInfo.StreamType getStreamType() { + if(isLiveStream(item)) { + return AbstractVideoInfo.StreamType.LIVE_STREAM; + } else { + return AbstractVideoInfo.StreamType.VIDEO_STREAM; + } + } + private boolean isLiveStream(Element item) { Element bla = item.select("span[class*=\"yt-badge-live\"]").first(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38e22404f..b4a5b1346 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,6 +77,7 @@ Content Show age restricted content Video is Age restricted. Enable age restricted videos in the settings first. + live Error