From 43afd5a2b860b9106ba4f9d31bcb0cf48f746111 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 27 Sep 2016 22:59:04 +0200 Subject: [PATCH 1/4] clean up downloader thing --- .../youtube/YoutubeChannelExtractorTest.java | 9 +++--- .../youtube/YoutubeSearchEngineTest.java | 8 ++--- .../YoutubeStreamExtractorDefaultTest.java | 6 ++-- .../YoutubeStreamExtractorGemaTest.java | 4 +-- .../YoutubeStreamExtractorLiveStreamTest.java | 5 +-- .../YoutubeStreamExtractorRestrictedTest.java | 6 ++-- app/src/main/java/org/schabi/newpipe/App.java | 4 +++ .../org/schabi/newpipe/ChannelActivity.java | 6 ++-- .../newpipe/ImageErrorLoadingListener.java | 4 +-- .../newpipe/detail/StreamInfoWorker.java | 6 ++-- .../detail/VideoItemDetailActivity.java | 6 ++-- .../detail/VideoItemDetailFragment.java | 4 +-- .../newpipe/extractor/ChannelExtractor.java | 5 +-- .../extractor/ExtractionException.java | 2 -- .../{ServiceList.java => NewPipe.java} | 32 +++++++++++++------ .../newpipe/extractor/SearchEngine.java | 4 +-- .../newpipe/extractor/SearchResult.java | 4 +-- .../newpipe/extractor/StreamExtractor.java | 7 +--- .../newpipe/extractor/StreamingService.java | 6 ++-- .../youtube/YoutubeChannelExtractor.java | 9 +++--- .../services/youtube/YoutubeSearchEngine.java | 31 ++++-------------- .../services/youtube/YoutubeService.java | 10 +++--- .../youtube/YoutubeStreamExtractor.java | 12 +++---- .../SearchInfoItemFragment.java | 8 ++--- .../newpipe/search_fragment/SearchWorker.java | 9 +++--- .../SuggestionSearchRunnable.java | 10 +++--- 26 files changed, 98 insertions(+), 119 deletions(-) rename app/src/main/java/org/schabi/newpipe/extractor/{ServiceList.java => NewPipe.java} (75%) diff --git a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeChannelExtractorTest.java b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeChannelExtractorTest.java index 70dbe3c15..89a0f0c8e 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeChannelExtractorTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeChannelExtractorTest.java @@ -4,8 +4,7 @@ import android.test.AndroidTestCase; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.ChannelExtractor; -import org.schabi.newpipe.extractor.SearchEngine; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; /** * Created by Christian Schabesberger on 12.09.16. @@ -33,7 +32,7 @@ public class YoutubeChannelExtractorTest extends AndroidTestCase { @Override public void setUp() throws Exception { super.setUp(); - extractor = ServiceList.getService("Youtube") + extractor = NewPipe.getService("Youtube") .getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 0, new Downloader()); } @@ -67,13 +66,13 @@ public class YoutubeChannelExtractorTest extends AndroidTestCase { } public void testGetNextPage() throws Exception { - extractor = ServiceList.getService("Youtube") + extractor = NewPipe.getService("Youtube") .getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 1, new Downloader()); assertTrue("next page didn't have content", !extractor.getStreams().getItemList().isEmpty()); } public void testGetNextNextPageUrl() throws Exception { - extractor = ServiceList.getService("Youtube") + extractor = NewPipe.getService("Youtube") .getChannelExtractorInstance("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", 2, new Downloader()); assertTrue("next page didn't have content", extractor.hasNextPage()); } 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 25d9dd810..24fde8342 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 @@ -2,15 +2,11 @@ package org.schabi.newpipe.extractor.youtube; import android.test.AndroidTestCase; -import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.SearchResult; -import org.schabi.newpipe.extractor.ServiceList; -import org.schabi.newpipe.extractor.StreamPreviewInfo; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.SearchEngine; import org.schabi.newpipe.Downloader; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.List; /** @@ -40,7 +36,7 @@ public class YoutubeSearchEngineTest extends AndroidTestCase { @Override public void setUp() throws Exception { super.setUp(); - SearchEngine engine = ServiceList.getService("Youtube") + SearchEngine engine = NewPipe.getService("Youtube") .getSearchEngineInstance(new Downloader()); result = engine.search("this is something boring", 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 cc163dbb9..e0ebb570f 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 @@ -6,7 +6,7 @@ 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.NewPipe; import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.VideoStream; @@ -37,7 +37,7 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase { private StreamExtractor extractor; public void setUp() throws IOException, ExtractionException { - extractor = ServiceList.getService("Youtube") + extractor = NewPipe.getService("Youtube") .getExtractorInstance("https://www.youtube.com/watch?v=YQHsXMglC9A", new Downloader()); } @@ -48,7 +48,7 @@ public class YoutubeStreamExtractorDefaultTest extends AndroidTestCase { public void testGetValidTimeStamp() throws ExtractionException, IOException { StreamExtractor extractor = - ServiceList.getService("Youtube") + NewPipe.getService("Youtube") .getExtractorInstance("https://youtu.be/FmG385_uUys?t=174", new Downloader()); assertTrue(Integer.toString(extractor.getTimeStamp()), extractor.getTimeStamp() == 174); 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 13ce65a31..800128ec8 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 @@ -4,7 +4,7 @@ import android.test.AndroidTestCase; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.ExtractionException; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import java.io.IOException; @@ -39,7 +39,7 @@ public class YoutubeStreamExtractorGemaTest extends AndroidTestCase { public void testGemaError() throws IOException, ExtractionException { if(testActive) { try { - ServiceList.getService("Youtube") + NewPipe.getService("Youtube") .getExtractorInstance("https://www.youtube.com/watch?v=3O1_3zBUKM8", new Downloader()); } catch(YoutubeStreamExtractor.GemaException ge) { 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 index c8d0d20ba..3c0fbce11 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorLiveStreamTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/extractor/youtube/YoutubeStreamExtractorLiveStreamTest.java @@ -2,11 +2,8 @@ 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; @@ -39,7 +36,7 @@ public class YoutubeStreamExtractorLiveStreamTest extends AndroidTestCase { public void setUp() throws IOException, ExtractionException { //todo: make the extractor not throw over a livestream /* - extractor = ServiceList.getService("Youtube") + extractor = NewPipe.getService("Youtube") .getExtractorInstance("https://www.youtube.com/watch?v=J0s6NjqdjLE", new Downloader()); */ } 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 8435f3675..a66a1f3f0 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 @@ -4,8 +4,8 @@ import android.test.AndroidTestCase; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.VideoStream; @@ -16,7 +16,7 @@ public class YoutubeStreamExtractorRestrictedTest extends AndroidTestCase { private StreamExtractor extractor; public void setUp() throws IOException, ExtractionException { - extractor = ServiceList.getService("Youtube") + extractor = NewPipe.getService("Youtube") .getExtractorInstance("https://www.youtube.com/watch?v=i6JTvzrpBy0", new Downloader()); } @@ -27,7 +27,7 @@ public class YoutubeStreamExtractorRestrictedTest extends AndroidTestCase { } public void testGetValidTimeStamp() throws ExtractionException, IOException { - StreamExtractor extractor=ServiceList.getService("Youtube") + StreamExtractor extractor= NewPipe.getService("Youtube") .getExtractorInstance("https://youtu.be/FmG385_uUys?t=174", new Downloader()); assertTrue(Integer.toString(extractor.getTimeStamp()), diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 6b51c6cd5..7e93969bc 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -11,6 +11,7 @@ import org.acra.config.ACRAConfiguration; import org.acra.config.ACRAConfigurationException; import org.acra.config.ConfigurationBuilder; import org.acra.sender.ReportSenderFactory; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.report.AcraReportSenderFactory; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.settings.SettingsActivity; @@ -60,6 +61,9 @@ public class App extends Application { "Could not initialize ACRA crash report", R.string.app_ui_crash)); } + //init NewPipe + NewPipe.init(new Downloader()); + // Initialize image loader ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build(); ImageLoader.getInstance().init(config); diff --git a/app/src/main/java/org/schabi/newpipe/ChannelActivity.java b/app/src/main/java/org/schabi/newpipe/ChannelActivity.java index e5902897d..878da5b7f 100644 --- a/app/src/main/java/org/schabi/newpipe/ChannelActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ChannelActivity.java @@ -23,8 +23,8 @@ import org.schabi.newpipe.detail.VideoItemDetailFragment; import org.schabi.newpipe.extractor.ChannelExtractor; import org.schabi.newpipe.extractor.ChannelInfo; import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.info_list.InfoListAdapter; @@ -188,9 +188,9 @@ public class ChannelActivity extends AppCompatActivity { public void run() { StreamingService service = null; try { - service = ServiceList.getService(serviceId); + service = NewPipe.getService(serviceId); ChannelExtractor extractor = service.getChannelExtractorInstance( - channelUrl, pageNumber, new Downloader()); + channelUrl, pageNumber); final ChannelInfo info = ChannelInfo.getInfo(extractor, new Downloader()); diff --git a/app/src/main/java/org/schabi/newpipe/ImageErrorLoadingListener.java b/app/src/main/java/org/schabi/newpipe/ImageErrorLoadingListener.java index 7616cd8d0..837d96846 100644 --- a/app/src/main/java/org/schabi/newpipe/ImageErrorLoadingListener.java +++ b/app/src/main/java/org/schabi/newpipe/ImageErrorLoadingListener.java @@ -8,7 +8,7 @@ import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import org.schabi.newpipe.report.ErrorActivity; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; /** * Created by Christian Schabesberger on 01.08.16. @@ -50,7 +50,7 @@ public class ImageErrorLoadingListener implements ImageLoadingListener { ErrorActivity.reportError(activity, failReason.getCause(), null, rootView, ErrorActivity.ErrorInfo.make(ErrorActivity.LOAD_IMAGE, - ServiceList.getNameOfService(serviceId), imageUri, + NewPipe.getNameOfService(serviceId), imageUri, R.string.could_not_load_image)); } diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index 31b65536e..e3e8c4a1d 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -9,7 +9,7 @@ import org.schabi.newpipe.Downloader; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.StreamingService; @@ -51,7 +51,7 @@ public class StreamInfoWorker { StreamInfo streamInfo = null; StreamingService service = null; try { - service = ServiceList.getService(serviceId); + service = NewPipe.getService(serviceId); } catch (Exception e) { e.printStackTrace(); ErrorActivity.reportError(h, a, e, VideoItemDetailFragment.class, null, @@ -60,7 +60,7 @@ public class StreamInfoWorker { return; } try { - streamExtractor = service.getExtractorInstance(videoUrl, new Downloader()); + streamExtractor = service.getExtractorInstance(videoUrl); streamInfo = StreamInfo.getVideoInfo(streamExtractor, new Downloader()); final StreamInfo info = streamInfo; diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java index 04649bf4d..ef0421e9f 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java @@ -14,7 +14,7 @@ import android.widget.Toast; import org.schabi.newpipe.App; import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; @@ -73,13 +73,13 @@ public class VideoItemDetailActivity extends AppCompatActivity { // this means the video was called though another app if (getIntent().getData() != null) { videoUrl = getIntent().getData().toString(); - StreamingService[] serviceList = ServiceList.getServices(); + StreamingService[] serviceList = NewPipe.getServices(); //StreamExtractor videoExtractor = null; for (int i = 0; i < serviceList.length; i++) { if (serviceList[i].getUrlIdHandlerInstance().acceptUrl(videoUrl)) { arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i); currentStreamingService = i; - //videoExtractor = ServiceList.getService(i).getExtractorInstance(); + //videoExtractor = NewPipe.getService(i).getExtractorInstance(); break; } } diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index bbca4dcae..aef14a8e4 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -52,7 +52,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.extractor.AudioStream; import org.schabi.newpipe.extractor.MediaFormat; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.VideoStream; import org.schabi.newpipe.player.BackgroundPlayer; @@ -306,7 +306,7 @@ public class VideoItemDetailFragment extends Fragment { ErrorActivity.reportError(getActivity(), failReason.getCause(), null, rootView, ErrorActivity.ErrorInfo.make(ErrorActivity.LOAD_IMAGE, - ServiceList.getNameOfService(info.service_id), imageUri, + NewPipe.getNameOfService(info.service_id), imageUri, R.string.could_not_load_thumbnails)); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java index 0f41d442e..90b97f5bf 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java @@ -26,15 +26,13 @@ public abstract class ChannelExtractor { private int serviceId; private String url; private UrlIdHandler urlIdHandler; - private Downloader downloader; private StreamPreviewInfoCollector previewInfoCollector; private int page = -1; - public ChannelExtractor(UrlIdHandler urlIdHandler, String url, int page, Downloader dl, int serviceId) + public ChannelExtractor(UrlIdHandler urlIdHandler, String url, int page, int serviceId) throws ExtractionException, IOException { this.url = url; this.page = page; - this.downloader = dl; this.serviceId = serviceId; this.urlIdHandler = urlIdHandler; previewInfoCollector = new StreamPreviewInfoCollector(urlIdHandler, serviceId); @@ -42,7 +40,6 @@ public abstract class ChannelExtractor { public String getUrl() { return url; } public UrlIdHandler getUrlIdHandler() { return urlIdHandler; } - public Downloader getDownloader() { return downloader; } public StreamPreviewInfoCollector getStreamPreviewInfoCollector() { return previewInfoCollector; } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java b/app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java index fbbca89c1..38e28d6b0 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java @@ -24,11 +24,9 @@ public class ExtractionException extends Exception { public ExtractionException(String message) { super(message); } - public ExtractionException(Throwable cause) { super(cause); } - public ExtractionException(String message, Throwable cause) { super(message, cause); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java b/app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java similarity index 75% rename from app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java rename to app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java index fd3dc506d..db67e1e14 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ServiceList.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java @@ -6,7 +6,7 @@ import org.schabi.newpipe.extractor.services.youtube.YoutubeService; * Created by Christian Schabesberger on 23.08.15. * * Copyright (C) Christian Schabesberger 2015 - * ServiceList.java is part of NewPipe. + * NewPipe.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 @@ -26,20 +26,24 @@ import org.schabi.newpipe.extractor.services.youtube.YoutubeService; * Currently only Youtube until the API becomes more stable.*/ @SuppressWarnings("ALL") -public class ServiceList { +public class NewPipe { - private ServiceList() { + private NewPipe() { } - private static final String TAG = ServiceList.class.toString(); - private static final StreamingService[] services = { + private static final String TAG = NewPipe.class.toString(); + + private static final StreamingService[] serviceList = { new YoutubeService(0) }; + + private static Downloader downloader = null; + public static StreamingService[] getServices() { - return services; + return serviceList; } public static StreamingService getService(int serviceId)throws ExtractionException { - for(StreamingService s : services) { + for(StreamingService s : serviceList) { if(s.getServiceId() == serviceId) { return s; } @@ -47,7 +51,7 @@ public class ServiceList { throw new ExtractionException("Service not known: " + Integer.toString(serviceId)); } public static StreamingService getService(String serviceName) throws ExtractionException { - return services[getIdOfService(serviceName)]; + return serviceList[getIdOfService(serviceName)]; } public static String getNameOfService(int id) { try { @@ -59,11 +63,19 @@ public class ServiceList { } } public static int getIdOfService(String serviceName) throws ExtractionException { - for(int i = 0; i < services.length; i++) { - if(services[i].getServiceInfo().name.equals(serviceName)) { + for(int i = 0; i < serviceList.length; i++) { + if(serviceList[i].getServiceInfo().name.equals(serviceName)) { return i; } } throw new ExtractionException("Error: Service " + serviceName + " not known."); } + + public static void init(Downloader d) { + downloader = d; + } + + public static Downloader getDownloader() { + return downloader; + } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java index 3b700f129..f7586a304 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java @@ -42,11 +42,11 @@ public abstract class SearchEngine { } public abstract List suggestionList( - String query,String contentCountry, Downloader dl) + String query,String contentCountry) throws ExtractionException, IOException; //Result search(String query, int page); public abstract StreamPreviewInfoSearchCollector search( - String query, int page, String contentCountry, Downloader dl) + String query, int page, String contentCountry) throws ExtractionException, IOException; } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java b/app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java index 8feccad0c..eac14f288 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java @@ -26,10 +26,10 @@ import java.util.Vector; public class SearchResult { public static SearchResult getSearchResult(SearchEngine engine, String query, - int page, String languageCode, Downloader dl) + int page, String languageCode) throws ExtractionException, IOException { - SearchResult result = engine.search(query, page, languageCode, dl).getSearchResult(); + SearchResult result = engine.search(query, page, languageCode).getSearchResult(); if(result.resultList.isEmpty()) { if(result.suggestion.isEmpty()) { throw new ExtractionException("Empty result despite no error"); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java index c3e8c6fcb..6b0da4f89 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java @@ -31,7 +31,6 @@ public abstract class StreamExtractor { private int serviceId; private String url; private UrlIdHandler urlIdHandler; - private Downloader downloader; private StreamPreviewInfoCollector previewInfoCollector; public class ExctractorInitException extends ExtractionException { @@ -55,7 +54,7 @@ public abstract class StreamExtractor { } } - public StreamExtractor(UrlIdHandler urlIdHandler, String url, Downloader dl, int serviceId) { + public StreamExtractor(UrlIdHandler urlIdHandler, String url, int serviceId) { this.serviceId = serviceId; this.urlIdHandler = urlIdHandler; previewInfoCollector = new StreamPreviewInfoCollector(urlIdHandler, serviceId); @@ -73,10 +72,6 @@ public abstract class StreamExtractor { return urlIdHandler; } - public Downloader getDownloader() { - return downloader; - } - public abstract int getTimeStamp() throws ParsingException; public abstract String getTitle() throws ParsingException; public abstract String getDescription() throws ParsingException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index 1805b48db..eea1f1783 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -35,12 +35,12 @@ public abstract class StreamingService { public abstract ServiceInfo getServiceInfo(); - public abstract StreamExtractor getExtractorInstance(String url, Downloader downloader) + public abstract StreamExtractor getExtractorInstance(String url) throws IOException, ExtractionException; - public abstract SearchEngine getSearchEngineInstance(Downloader downloader); + public abstract SearchEngine getSearchEngineInstance(); public abstract UrlIdHandler getUrlIdHandlerInstance(); public abstract UrlIdHandler getChannelUrlIdHandlerInstance(); - public abstract ChannelExtractor getChannelExtractorInstance(String url, int page, Downloader downloader) + public abstract ChannelExtractor getChannelExtractorInstance(String url, int page) throws ExtractionException, IOException; public final int getServiceId() { diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index f7f5e4923..fb46de97c 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.ChannelExtractor; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.StreamPreviewInfoCollector; @@ -46,7 +47,6 @@ public class YoutubeChannelExtractor extends ChannelExtractor { // private CSSOMParser cssParser = new CSSOMParser(new SACParserCSS3()); - private Downloader downloader; private Document doc = null; private boolean isAjaxPage = false; @@ -59,12 +59,13 @@ public class YoutubeChannelExtractor extends ChannelExtractor { // this request url. private static String nextPageUrl = ""; - public YoutubeChannelExtractor(UrlIdHandler urlIdHandler, String url, int page, Downloader dl, int serviceId) + public YoutubeChannelExtractor(UrlIdHandler urlIdHandler, String url, int page, int serviceId) throws ExtractionException, IOException { - super(urlIdHandler, url, page, dl, serviceId); + super(urlIdHandler, url, page, serviceId); + + Downloader downloader = NewPipe.getDownloader(); url = urlIdHandler.cleanUrl(url) ; //+ "/video?veiw=0&flow=list&sort=dd"; - downloader = dl; if(page == 0) { if (isUserUrl(url)) { 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 2a361ed7b..cf79b247a 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 @@ -5,6 +5,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.SearchEngine; import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor; @@ -55,20 +56,11 @@ public class YoutubeSearchEngine extends SearchEngine { } @Override - public StreamPreviewInfoSearchCollector search(String query, int page, String languageCode, Downloader downloader) + public StreamPreviewInfoSearchCollector search(String query, int page, String languageCode) throws IOException, ExtractionException { StreamPreviewInfoSearchCollector collector = getStreamPreviewInfoSearchCollector(); - /* Cant use Uri.Bilder since it's android code. - // Android code is baned from the extractor side. - Uri.Builder builder = new Uri.Builder(); - builder.scheme("https") - .authority("www.youtube.com") - .appendPath("results") - .appendQueryParameter("search_query", query) - .appendQueryParameter("page", Integer.toString(page)) - .appendQueryParameter("filters", "video"); - */ + Downloader downloader = NewPipe.getDownloader(); String url = "https://www.youtube.com/results" + "?search_query=" + URLEncoder.encode(query, CHARSET_UTF_8) @@ -127,24 +119,13 @@ public class YoutubeSearchEngine extends SearchEngine { } @Override - public List suggestionList(String query, String contentCountry, Downloader dl) + public List suggestionList(String query, String contentCountry) throws IOException, ParsingException { List suggestions = new ArrayList<>(); - /* Cant use Uri.Bilder since it's android code. - // Android code is baned from the extractor side. - Uri.Builder builder = new Uri.Builder(); - builder.scheme("https") - .authority("suggestqueries.google.com") - .appendPath("complete") - .appendPath("search") - .appendQueryParameter("client", "") - .appendQueryParameter("output", "toolbar") - .appendQueryParameter("ds", "yt") - .appendQueryParameter("hl",contentCountry) - .appendQueryParameter("q", query); - */ + Downloader dl = NewPipe.getDownloader(); + String url = "https://suggestqueries.google.com/complete/search" + "?client=" + "" + "&output=" + "toolbar" diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index 9c2198926..cd4197474 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -44,18 +44,18 @@ public class YoutubeService extends StreamingService { return serviceInfo; } @Override - public StreamExtractor getExtractorInstance(String url, Downloader downloader) + public StreamExtractor getExtractorInstance(String url) throws ExtractionException, IOException { UrlIdHandler urlIdHandler = new YoutubeStreamUrlIdHandler(); if(urlIdHandler.acceptUrl(url)) { - return new YoutubeStreamExtractor(urlIdHandler, url, downloader, getServiceId()); + return new YoutubeStreamExtractor(urlIdHandler, url, getServiceId()); } else { throw new IllegalArgumentException("supplied String is not a valid Youtube URL"); } } @Override - public SearchEngine getSearchEngineInstance(Downloader downloader) { + public SearchEngine getSearchEngineInstance() { return new YoutubeSearchEngine(getUrlIdHandlerInstance(), getServiceId()); } @@ -70,8 +70,8 @@ public class YoutubeService extends StreamingService { } @Override - public ChannelExtractor getChannelExtractorInstance(String url, int page, Downloader downloader) + public ChannelExtractor getChannelExtractorInstance(String url, int page) throws ExtractionException, IOException { - return new YoutubeChannelExtractor(getChannelUrlIdHandlerInstance(), url, page, downloader, getServiceId()); + return new YoutubeChannelExtractor(getChannelUrlIdHandlerInstance(), url, page, getServiceId()); } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 824fe3b6c..4a37c5ce6 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -12,6 +12,7 @@ import org.schabi.newpipe.extractor.AbstractVideoInfo; import org.schabi.newpipe.extractor.AudioStream; import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.Downloader; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.StreamInfo; @@ -185,15 +186,12 @@ public class YoutubeStreamExtractor extends StreamExtractor { UrlIdHandler urlidhandler = new YoutubeStreamUrlIdHandler(); String pageUrl = ""; - private Downloader downloader; - - public YoutubeStreamExtractor(UrlIdHandler urlIdHandler, String pageUrl, - Downloader dl, int serviceId) + public YoutubeStreamExtractor(UrlIdHandler urlIdHandler, String pageUrl, int serviceId) throws ExtractionException, IOException { - super(urlIdHandler ,pageUrl, dl, serviceId); + super(urlIdHandler, pageUrl, serviceId); //most common videoInfo fields are now set in our superclass, for all services - downloader = dl; this.pageUrl = pageUrl; + Downloader downloader = NewPipe.getDownloader(); String pageContent = downloader.download(urlidhandler.cleanUrl(pageUrl)); doc = Jsoup.parse(pageContent, pageUrl); JSONObject ytPlayerConfig; @@ -284,6 +282,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { private String getPlayerUrlFromRestrictedVideo(String pageUrl) throws ParsingException { try { + Downloader downloader = NewPipe.getDownloader(); String playerUrl = ""; String videoId = urlidhandler.getId(pageUrl); String embedUrl = "https://www.youtube.com/embed/" + videoId; @@ -788,6 +787,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { String decryptionCode; try { + Downloader downloader = NewPipe.getDownloader(); String playerCode = downloader.download(playerUrl); decryptionFuncName = diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java index 9f893c0c6..af56cc3f2 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java @@ -18,13 +18,13 @@ import android.view.inputmethod.InputMethodManager; import android.widget.ProgressBar; import android.widget.Toast; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.detail.VideoItemDetailActivity; import org.schabi.newpipe.detail.VideoItemDetailFragment; import org.schabi.newpipe.extractor.SearchResult; -import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.info_list.InfoListAdapter; /** @@ -72,7 +72,7 @@ public class SearchInfoItemFragment extends Fragment { ErrorActivity.reportError(a, e, null, a.findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - ServiceList.getNameOfService(streamingServiceId), + NewPipe.getNameOfService(streamingServiceId), "Could not get widget with focus", R.string.general_error)); } // clear focus @@ -137,13 +137,13 @@ public class SearchInfoItemFragment extends Fragment { streamingServiceId = savedInstanceState.getInt(STREAMING_SERVICE); } else { try { - streamingServiceId = ServiceList.getIdOfService("Youtube"); + streamingServiceId = NewPipe.getIdOfService("Youtube"); } catch(Exception e) { e.printStackTrace(); ErrorActivity.reportError(getActivity(), e, null, getActivity().findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - ServiceList.getNameOfService(streamingServiceId), + NewPipe.getNameOfService(streamingServiceId), "", R.string.general_error)); } } diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java index 9e592ba47..ccb4a4173 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java @@ -13,7 +13,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.SearchEngine; import org.schabi.newpipe.extractor.SearchResult; -import org.schabi.newpipe.extractor.ServiceList; +import org.schabi.newpipe.extractor.NewPipe; import java.io.IOException; @@ -85,8 +85,8 @@ public class SearchWorker { SearchEngine engine = null; try { - engine = ServiceList.getService(serviceId) - .getSearchEngineInstance(new Downloader()); + engine = NewPipe.getService(serviceId) + .getSearchEngineInstance(); } catch(ExtractionException e) { ErrorActivity.reportError(h, a, e, null, null, ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, @@ -100,8 +100,7 @@ public class SearchWorker { String searchLanguage = sp.getString(searchLanguageKey, a.getString(R.string.default_language_value)); result = SearchResult - .getSearchResult(engine, query, page, searchLanguage, new Downloader()); - + .getSearchResult(engine, query, page, searchLanguage); if(runs) { h.post(new ResultRunnable(result, requestId)); } diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java index 4a8840d95..bd483f1bf 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java @@ -7,11 +7,11 @@ import android.preference.PreferenceManager; import android.widget.Toast; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.SearchEngine; -import org.schabi.newpipe.extractor.ServiceList; import java.io.IOException; import java.util.List; @@ -71,17 +71,17 @@ public class SuggestionSearchRunnable implements Runnable{ public void run() { try { SearchEngine engine = - ServiceList.getService(serviceId).getSearchEngineInstance(new Downloader()); + NewPipe.getService(serviceId).getSearchEngineInstance(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(a); String searchLanguageKey = a.getString(R.string.search_language_key); String searchLanguage = sp.getString(searchLanguageKey, a.getString(R.string.default_language_value)); - List suggestions = engine.suggestionList(query,searchLanguage,new Downloader()); + List suggestions = engine.suggestionList(query, searchLanguage); h.post(new SuggestionResultRunnable(suggestions, adapter)); } catch (ExtractionException e) { ErrorActivity.reportError(h, a, e, null, a.findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - ServiceList.getNameOfService(serviceId), query, R.string.parsing_error)); + NewPipe.getNameOfService(serviceId), query, R.string.parsing_error)); e.printStackTrace(); } catch (IOException e) { postNewErrorToast(h, R.string.network_error); @@ -89,7 +89,7 @@ public class SuggestionSearchRunnable implements Runnable{ } catch (Exception e) { ErrorActivity.reportError(h, a, e, null, a.findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, - ServiceList.getNameOfService(serviceId), query, R.string.general_error)); + NewPipe.getNameOfService(serviceId), query, R.string.general_error)); } } From 5f7ee15d1e76489b8fc5f4f3df76e407f7709376 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 28 Sep 2016 13:09:42 +0900 Subject: [PATCH 2/4] Launch video player in single task mode (fixes #154) --- app/src/main/AndroidManifest.xml | 1 + .../newpipe/detail/ActionBarHandler.java | 3 + .../detail/VideoItemDetailActivity.java | 84 +++++++++++-------- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5bae70262..447d01ddc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,6 +29,7 @@ videoStreams) { + if (defaultPreferences == null) + return 0; + String defaultResolution = defaultPreferences .getString(activity.getString(R.string.default_resolution_key), activity.getString(R.string.default_resolution_value)); diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java index 04649bf4d..2bbc6cb07 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailActivity.java @@ -68,52 +68,66 @@ public class VideoItemDetailActivity extends AppCompatActivity { // http://developer.android.com/guide/components/fragments.html // - Bundle arguments = new Bundle(); if (savedInstanceState == null) { - // this means the video was called though another app - if (getIntent().getData() != null) { - videoUrl = getIntent().getData().toString(); - StreamingService[] serviceList = ServiceList.getServices(); - //StreamExtractor videoExtractor = null; - for (int i = 0; i < serviceList.length; i++) { - if (serviceList[i].getUrlIdHandlerInstance().acceptUrl(videoUrl)) { - arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i); - currentStreamingService = i; - //videoExtractor = ServiceList.getService(i).getExtractorInstance(); - break; - } - } - if(currentStreamingService == -1) { - Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG) - .show(); - } - //arguments.putString(VideoItemDetailFragment.VIDEO_URL, - // videoExtractor.getUrl(videoExtractor.getId(videoUrl)));//cleans URL - arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); - - arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, - PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(getString(R.string.autoplay_through_intent_key), false)); - } else { - videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL); - currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1); - arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); - arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService); - arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false); - } - + handleIntent(getIntent()); } else { videoUrl = savedInstanceState.getString(VideoItemDetailFragment.VIDEO_URL); currentStreamingService = savedInstanceState.getInt(VideoItemDetailFragment.STREAMING_SERVICE); - arguments = savedInstanceState; + addFragment(savedInstanceState); } + } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); + handleIntent(intent); + } + + private void handleIntent(Intent intent) { + Bundle arguments = new Bundle(); + // this means the video was called though another app + if (intent.getData() != null) { + videoUrl = intent.getData().toString(); + StreamingService[] serviceList = ServiceList.getServices(); + //StreamExtractor videoExtractor = null; + for (int i = 0; i < serviceList.length; i++) { + if (serviceList[i].getUrlIdHandlerInstance().acceptUrl(videoUrl)) { + arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i); + currentStreamingService = i; + //videoExtractor = ServiceList.getService(i).getExtractorInstance(); + break; + } + } + if(currentStreamingService == -1) { + Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG) + .show(); + } + //arguments.putString(VideoItemDetailFragment.VIDEO_URL, + // videoExtractor.getUrl(videoExtractor.getId(videoUrl)));//cleans URL + arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); + + arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, + PreferenceManager.getDefaultSharedPreferences(this) + .getBoolean(getString(R.string.autoplay_through_intent_key), false)); + } else { + videoUrl = intent.getStringExtra(VideoItemDetailFragment.VIDEO_URL); + currentStreamingService = intent.getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1); + arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); + arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService); + arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false); + } + addFragment(arguments); + + } + + private void addFragment(final Bundle arguments) { // Create the detail fragment and add it to the activity // using a fragment transaction. fragment = new VideoItemDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() - .add(R.id.videoitem_detail_container, fragment) + .replace(R.id.videoitem_detail_container, fragment) .commit(); } From 5eef116aaae1e4a56839374e0b1c55c46efc8c1a Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 28 Sep 2016 12:53:23 +0200 Subject: [PATCH 3/4] put Suggestion extraction into its own class --- .../newpipe/extractor/SearchEngine.java | 4 - .../newpipe/extractor/StreamingService.java | 1 + .../extractor/SuggestionExtractor.java | 41 +++++++ .../services/youtube/YoutubeSearchEngine.java | 49 --------- .../services/youtube/YoutubeService.java | 6 ++ .../youtube/YoutubeSuggestionExtractor.java | 100 ++++++++++++++++++ .../SuggestionSearchRunnable.java | 7 +- 7 files changed, 152 insertions(+), 56 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java create mode 100644 app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java index f7586a304..d27198c1a 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java @@ -41,10 +41,6 @@ public abstract class SearchEngine { return collector; } - public abstract List suggestionList( - String query,String contentCountry) - throws ExtractionException, IOException; - //Result search(String query, int page); public abstract StreamPreviewInfoSearchCollector search( String query, int page, String contentCountry) diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index eea1f1783..ac90e60d0 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -42,6 +42,7 @@ public abstract class StreamingService { public abstract UrlIdHandler getChannelUrlIdHandlerInstance(); public abstract ChannelExtractor getChannelExtractorInstance(String url, int page) throws ExtractionException, IOException; + public abstract SuggestionExtractor getSuggestionExtractorInstance(); public final int getServiceId() { return serviceId; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java new file mode 100644 index 000000000..d0e55d5d9 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java @@ -0,0 +1,41 @@ +package org.schabi.newpipe.extractor; + +import java.io.IOException; +import java.util.List; + +/** + * Created by Christian Schabesberger on 28.09.16. + * + * Copyright (C) Christian Schabesberger 2016 + * SuggestionExtractor.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 abstract class SuggestionExtractor { + + private int serviceId; + + public SuggestionExtractor(int serviceId) { + this.serviceId = serviceId; + } + + public abstract List suggestionList( + String query,String contentCountry) + throws ExtractionException, IOException; + + public int getServiceId() { + return serviceId; + } +} 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 cf79b247a..31d233438 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 @@ -118,55 +118,6 @@ public class YoutubeSearchEngine extends SearchEngine { return collector; } - @Override - public List suggestionList(String query, String contentCountry) - throws IOException, ParsingException { - - List suggestions = new ArrayList<>(); - - Downloader dl = NewPipe.getDownloader(); - - String url = "https://suggestqueries.google.com/complete/search" - + "?client=" + "" - + "&output=" + "toolbar" - + "&ds=" + "yt" - + "&hl=" + URLEncoder.encode(contentCountry, CHARSET_UTF_8) - + "&q=" + URLEncoder.encode(query, CHARSET_UTF_8); - - - String response = dl.download(url); - - //TODO: Parse xml data using Jsoup not done - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder; - org.w3c.dom.Document doc = null; - - try { - dBuilder = dbFactory.newDocumentBuilder(); - doc = dBuilder.parse(new InputSource( - new ByteArrayInputStream(response.getBytes(CHARSET_UTF_8)))); - doc.getDocumentElement().normalize(); - } catch (ParserConfigurationException | SAXException | IOException e) { - throw new ParsingException("Could not parse document."); - } - - try { - NodeList nList = doc.getElementsByTagName("CompleteSuggestion"); - for (int temp = 0; temp < nList.getLength(); temp++) { - - NodeList nList1 = doc.getElementsByTagName("suggestion"); - Node nNode1 = nList1.item(temp); - if (nNode1.getNodeType() == Node.ELEMENT_NODE) { - org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode1; - suggestions.add(eElement.getAttribute("data")); - } - } - return suggestions; - } catch(Exception e) { - throw new ParsingException("Could not get suggestions form document.", e); - } - } - private StreamPreviewInfoExtractor extractPreviewInfo(final Element item) { return new YoutubeStreamPreviewInfoExtractor(item); } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index cd4197474..41ffe4a6d 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -5,6 +5,7 @@ import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.extractor.UrlIdHandler; import org.schabi.newpipe.extractor.SearchEngine; @@ -74,4 +75,9 @@ public class YoutubeService extends StreamingService { throws ExtractionException, IOException { return new YoutubeChannelExtractor(getChannelUrlIdHandlerInstance(), url, page, getServiceId()); } + + @Override + public SuggestionExtractor getSuggestionExtractorInstance() { + return new YoutubeSuggestionExtractor(getServiceId()); + } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java new file mode 100644 index 000000000..ea5f9ecbb --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java @@ -0,0 +1,100 @@ +package org.schabi.newpipe.extractor.services.youtube; + +import org.schabi.newpipe.extractor.Downloader; +import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.ParsingException; +import org.schabi.newpipe.extractor.SuggestionExtractor; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +/** + * Created by Christian Schabesberger on 28.09.16. + * + * Copyright (C) Christian Schabesberger 2015 + * YoutubeSuggestionExtractor.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 YoutubeSuggestionExtractor extends SuggestionExtractor { + + public static final String CHARSET_UTF_8 = "UTF-8"; + + public YoutubeSuggestionExtractor(int serviceId) { + super(serviceId); + } + + @Override + public List suggestionList( + String query, String contentCountry) + throws ExtractionException, IOException { + List suggestions = new ArrayList<>(); + + Downloader dl = NewPipe.getDownloader(); + + String url = "https://suggestqueries.google.com/complete/search" + + "?client=" + "" + + "&output=" + "toolbar" + + "&ds=" + "yt" + + "&hl=" + URLEncoder.encode(contentCountry, CHARSET_UTF_8) + + "&q=" + URLEncoder.encode(query, CHARSET_UTF_8); + + + String response = dl.download(url); + + //TODO: Parse xml data using Jsoup not done + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder; + org.w3c.dom.Document doc = null; + + try { + dBuilder = dbFactory.newDocumentBuilder(); + doc = dBuilder.parse(new InputSource( + new ByteArrayInputStream(response.getBytes(CHARSET_UTF_8)))); + doc.getDocumentElement().normalize(); + } catch (ParserConfigurationException | SAXException | IOException e) { + throw new ParsingException("Could not parse document."); + } + + try { + NodeList nList = doc.getElementsByTagName("CompleteSuggestion"); + for (int temp = 0; temp < nList.getLength(); temp++) { + + NodeList nList1 = doc.getElementsByTagName("suggestion"); + Node nNode1 = nList1.item(temp); + if (nNode1.getNodeType() == Node.ELEMENT_NODE) { + org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode1; + suggestions.add(eElement.getAttribute("data")); + } + } + return suggestions; + } catch(Exception e) { + throw new ParsingException("Could not get suggestions form document.", e); + } + } +} diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java index bd483f1bf..33fe5de44 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java @@ -8,6 +8,7 @@ import android.widget.Toast; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.ExtractionException; @@ -70,13 +71,13 @@ public class SuggestionSearchRunnable implements Runnable{ @Override public void run() { try { - SearchEngine engine = - NewPipe.getService(serviceId).getSearchEngineInstance(); + SuggestionExtractor se = + NewPipe.getService(serviceId).getSuggestionExtractorInstance(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(a); String searchLanguageKey = a.getString(R.string.search_language_key); String searchLanguage = sp.getString(searchLanguageKey, a.getString(R.string.default_language_value)); - List suggestions = engine.suggestionList(query, searchLanguage); + List suggestions = se.suggestionList(query, searchLanguage); h.post(new SuggestionResultRunnable(suggestions, adapter)); } catch (ExtractionException e) { ErrorActivity.reportError(h, a, e, null, a.findViewById(android.R.id.content), From 01875b389db5e71db5883f58a3d75c9b7d8bbcda Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 28 Sep 2016 17:13:15 +0200 Subject: [PATCH 4/4] clean up extractor --- .../YoutubeStreamExtractorDefaultTest.java | 2 +- .../YoutubeStreamExtractorRestrictedTest.java | 2 +- .../org/schabi/newpipe/ChannelActivity.java | 10 +++---- .../newpipe/detail/ActionBarHandler.java | 2 +- .../newpipe/detail/StreamInfoWorker.java | 26 ++++++++++++++---- .../detail/VideoItemDetailFragment.java | 8 +++--- ...VideoInfo.java => AbstractStreamInfo.java} | 6 ++--- .../newpipe/extractor/DashMpdParser.java | 6 +++-- .../org/schabi/newpipe/extractor/NewPipe.java | 1 + .../org/schabi/newpipe/extractor/Parser.java | 2 ++ .../newpipe/extractor/StreamingService.java | 6 +++++ .../newpipe/extractor/UrlIdHandler.java | 2 ++ .../{ => channel}/ChannelExtractor.java | 7 ++++- .../extractor/{ => channel}/ChannelInfo.java | 8 ++++-- .../{ => exceptions}/ExtractionException.java | 2 +- .../{ => exceptions}/FoundAdException.java | 2 +- .../{ => exceptions}/ParsingException.java | 2 +- .../extractor/{ => search}/SearchEngine.java | 5 +++- .../extractor/{ => search}/SearchResult.java | 5 +++- .../StreamPreviewInfoSearchCollector.java | 5 +++- .../{ => search}/SuggestionExtractor.java | 4 ++- .../youtube/YoutubeChannelExtractor.java | 16 +++++------ .../youtube/YoutubeChannelUrlIdHandler.java | 2 +- .../youtube/YoutubeParsingHelper.java | 3 ++- .../services/youtube/YoutubeSearchEngine.java | 19 +++---------- .../services/youtube/YoutubeService.java | 11 ++++---- .../youtube/YoutubeStreamExtractor.java | 20 +++++++------- .../YoutubeStreamPreviewInfoExtractor.java | 12 ++++----- .../youtube/YoutubeStreamUrlIdHandler.java | 4 +-- .../youtube/YoutubeSuggestionExtractor.java | 6 ++--- .../{ => stream_info}/AudioStream.java | 2 +- .../{ => stream_info}/StreamExtractor.java | 6 ++++- .../{ => stream_info}/StreamInfo.java | 27 +++++++++++-------- .../{ => stream_info}/StreamPreviewInfo.java | 6 +++-- .../StreamPreviewInfoCollector.java | 5 +++- .../StreamPreviewInfoExtractor.java | 7 +++-- .../{ => stream_info}/VideoStream.java | 2 +- .../newpipe/info_list/InfoItemBuilder.java | 6 ++--- .../newpipe/info_list/InfoListAdapter.java | 7 +---- .../SearchInfoItemFragment.java | 2 +- .../newpipe/search_fragment/SearchWorker.java | 7 +++-- .../SuggestionSearchRunnable.java | 6 ++--- 42 files changed, 168 insertions(+), 121 deletions(-) rename app/src/main/java/org/schabi/newpipe/extractor/{AbstractVideoInfo.java => AbstractStreamInfo.java} (89%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => channel}/ChannelExtractor.java (87%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => channel}/ChannelInfo.java (90%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => exceptions}/ExtractionException.java (95%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => exceptions}/FoundAdException.java (95%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => exceptions}/ParsingException.java (95%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => search}/SearchEngine.java (91%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => search}/SearchResult.java (90%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => search}/StreamPreviewInfoSearchCollector.java (89%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => search}/SuggestionExtractor.java (91%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/AudioStream.java (96%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/StreamExtractor.java (94%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/StreamInfo.java (93%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/StreamPreviewInfo.java (84%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/StreamPreviewInfoCollector.java (93%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/StreamPreviewInfoExtractor.java (83%) rename app/src/main/java/org/schabi/newpipe/extractor/{ => stream_info}/VideoStream.java (96%) 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 e0ebb570f..8aab43b9b 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 @@ -8,7 +8,7 @@ import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamExtractor; -import org.schabi.newpipe.extractor.VideoStream; +import org.schabi.newpipe.extractor.stream_info.VideoStream; import java.io.IOException; 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 a66a1f3f0..07121fa12 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,7 +7,7 @@ import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.StreamExtractor; -import org.schabi.newpipe.extractor.VideoStream; +import org.schabi.newpipe.extractor.stream_info.VideoStream; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/ChannelActivity.java b/app/src/main/java/org/schabi/newpipe/ChannelActivity.java index 878da5b7f..83936475c 100644 --- a/app/src/main/java/org/schabi/newpipe/ChannelActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ChannelActivity.java @@ -20,12 +20,12 @@ import com.nostra13.universalimageloader.core.ImageLoader; import org.schabi.newpipe.detail.VideoItemDetailActivity; import org.schabi.newpipe.detail.VideoItemDetailFragment; -import org.schabi.newpipe.extractor.ChannelExtractor; -import org.schabi.newpipe.extractor.ChannelInfo; -import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.channel.ChannelInfo; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.info_list.InfoListAdapter; import org.schabi.newpipe.report.ErrorActivity; @@ -192,7 +192,7 @@ public class ChannelActivity extends AppCompatActivity { ChannelExtractor extractor = service.getChannelExtractorInstance( channelUrl, pageNumber); - final ChannelInfo info = ChannelInfo.getInfo(extractor, new Downloader()); + final ChannelInfo info = ChannelInfo.getInfo(extractor); h.post(new Runnable() { diff --git a/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java index 242d1d39e..30ddf3da9 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java @@ -14,7 +14,7 @@ import android.widget.ArrayAdapter; import org.schabi.newpipe.R; import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.extractor.MediaFormat; -import org.schabi.newpipe.extractor.VideoStream; +import org.schabi.newpipe.extractor.stream_info.VideoStream; import java.util.List; diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index e3e8c4a1d..bb1130fdf 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -6,19 +6,35 @@ import android.util.Log; import android.view.View; import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.StreamExtractor; +import org.schabi.newpipe.extractor.stream_info.StreamInfo; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.StreamExtractor; -import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import java.io.IOException; /** - * Created by the-scrabi on 02.08.16. + * Created by Christian Schabesberger on 02.08.16. + * + * Copyright (C) Christian Schabesberger 2016 + * StreamInfoWorker.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 StreamInfoWorker { @@ -61,7 +77,7 @@ public class StreamInfoWorker { } try { streamExtractor = service.getExtractorInstance(videoUrl); - streamInfo = StreamInfo.getVideoInfo(streamExtractor, new Downloader()); + streamInfo = StreamInfo.getVideoInfo(streamExtractor); final StreamInfo info = streamInfo; h.post(new Runnable() { diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index aef14a8e4..1fa80175f 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -43,18 +43,18 @@ import java.util.Vector; import org.schabi.newpipe.ActivityCommunicator; import org.schabi.newpipe.ChannelActivity; -import org.schabi.newpipe.extractor.StreamPreviewInfo; +import org.schabi.newpipe.extractor.stream_info.StreamInfo; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.ImageErrorLoadingListener; import org.schabi.newpipe.Localization; import org.schabi.newpipe.R; import org.schabi.newpipe.download.DownloadDialog; -import org.schabi.newpipe.extractor.AudioStream; +import org.schabi.newpipe.extractor.stream_info.AudioStream; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.StreamInfo; -import org.schabi.newpipe.extractor.VideoStream; +import org.schabi.newpipe.extractor.stream_info.VideoStream; import org.schabi.newpipe.player.BackgroundPlayer; import org.schabi.newpipe.player.PlayVideoActivity; import org.schabi.newpipe.player.ExoPlayerActivity; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/AbstractStreamInfo.java similarity index 89% rename from app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java rename to app/src/main/java/org/schabi/newpipe/extractor/AbstractStreamInfo.java index 8c9b28c5e..308f5127d 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/AbstractVideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/AbstractStreamInfo.java @@ -1,8 +1,8 @@ package org.schabi.newpipe.extractor; /** - * Copyright (C) Christian Schabesberger 2015 - * AbstractVideoInfo.java is part of NewPipe. + * Copyright (C) Christian Schabesberger 2016 + * AbstractStreamInfo.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 @@ -19,7 +19,7 @@ package org.schabi.newpipe.extractor; */ /**Common properties between StreamInfo and StreamPreviewInfo.*/ -public abstract class AbstractVideoInfo { +public abstract class AbstractStreamInfo { public static enum StreamType { NONE, // placeholder to check if stream type was checked or not VIDEO_STREAM, diff --git a/app/src/main/java/org/schabi/newpipe/extractor/DashMpdParser.java b/app/src/main/java/org/schabi/newpipe/extractor/DashMpdParser.java index a834d0b9b..db26e3871 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/DashMpdParser.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/DashMpdParser.java @@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor; import android.util.Xml; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.AudioStream; import org.xmlpull.v1.XmlPullParser; import java.io.IOException; @@ -40,10 +42,10 @@ public class DashMpdParser { } } - public static List getAudioStreams(String dashManifestUrl, - Downloader downloader) + public static List getAudioStreams(String dashManifestUrl) throws DashMpdParsingException { String dashDoc; + Downloader downloader = NewPipe.getDownloader(); try { dashDoc = downloader.download(dashManifestUrl); } catch(IOException ioe) { diff --git a/app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java b/app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java index db67e1e14..17d22feea 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/NewPipe.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.services.youtube.YoutubeService; /** diff --git a/app/src/main/java/org/schabi/newpipe/extractor/Parser.java b/app/src/main/java/org/schabi/newpipe/extractor/Parser.java index 5ed9b8708..b68d01fa7 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/Parser.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/Parser.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index ac90e60d0..8ed6f9234 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -1,5 +1,11 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SuggestionExtractor; +import org.schabi.newpipe.extractor.stream_info.StreamExtractor; + import java.io.IOException; /** diff --git a/app/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java b/app/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java index f38f60658..932fd5ce9 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + /** * Created by Christian Schabesberger on 26.07.16. * diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java similarity index 87% rename from app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java rename to app/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java index 90b97f5bf..35d3604d9 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ChannelExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java @@ -1,4 +1,9 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.channel; + +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoCollector; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ChannelInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java similarity index 90% rename from app/src/main/java/org/schabi/newpipe/extractor/ChannelInfo.java rename to app/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java index 941d08564..7dc4b00e0 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ChannelInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java @@ -1,4 +1,8 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.channel; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoCollector; import java.util.List; import java.util.Vector; @@ -30,7 +34,7 @@ public class ChannelInfo { errors.add(e); } - public static ChannelInfo getInfo(ChannelExtractor extractor, Downloader dl) + public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException { ChannelInfo info = new ChannelInfo(); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java b/app/src/main/java/org/schabi/newpipe/extractor/exceptions/ExtractionException.java similarity index 95% rename from app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java rename to app/src/main/java/org/schabi/newpipe/extractor/exceptions/ExtractionException.java index 38e28d6b0..311850187 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ExtractionException.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/exceptions/ExtractionException.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.exceptions; /** * Created by Christian Schabesberger on 30.01.16. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java b/app/src/main/java/org/schabi/newpipe/extractor/exceptions/FoundAdException.java similarity index 95% rename from app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java rename to app/src/main/java/org/schabi/newpipe/extractor/exceptions/FoundAdException.java index 036ec902a..4d6d29826 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/FoundAdException.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/exceptions/FoundAdException.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.exceptions; /** * Created by Christian Schabesberger on 12.09.16. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/ParsingException.java b/app/src/main/java/org/schabi/newpipe/extractor/exceptions/ParsingException.java similarity index 95% rename from app/src/main/java/org/schabi/newpipe/extractor/ParsingException.java rename to app/src/main/java/org/schabi/newpipe/extractor/exceptions/ParsingException.java index 5803537bb..41a7acce1 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/ParsingException.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/exceptions/ParsingException.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.exceptions; /** * Created by Christian Schabesberger on 31.01.16. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java similarity index 91% rename from app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java rename to app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java index d27198c1a..f6e0434a6 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/SearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/search/SearchEngine.java @@ -1,4 +1,7 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; import java.io.IOException; import java.util.List; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java b/app/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java similarity index 90% rename from app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java rename to app/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java index eac14f288..97ceb46fb 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/SearchResult.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/search/SearchResult.java @@ -1,4 +1,7 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; import java.io.IOException; import java.util.List; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoSearchCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/search/StreamPreviewInfoSearchCollector.java similarity index 89% rename from app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoSearchCollector.java rename to app/src/main/java/org/schabi/newpipe/extractor/search/StreamPreviewInfoSearchCollector.java index 905543be0..40874f717 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoSearchCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/search/StreamPreviewInfoSearchCollector.java @@ -1,4 +1,7 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoCollector; /** * Created by Christian Schabesberger on 11.05.16. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/search/SuggestionExtractor.java similarity index 91% rename from app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java rename to app/src/main/java/org/schabi/newpipe/extractor/search/SuggestionExtractor.java index d0e55d5d9..f77b1912d 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/SuggestionExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/search/SuggestionExtractor.java @@ -1,4 +1,6 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.search; + +import org.schabi.newpipe.extractor.exceptions.ExtractionException; import java.io.IOException; import java.util.List; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index fb46de97c..7f2a9ecdd 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -7,16 +7,16 @@ import org.json.JSONObject; 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.ChannelExtractor; +import org.schabi.newpipe.extractor.AbstractStreamInfo; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Parser; -import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.StreamPreviewInfoCollector; -import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor; import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoCollector; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoExtractor; import java.io.IOException; @@ -163,8 +163,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor { if (li.select("div[class=\"feed-item-dismissable\"]").first() != null) { collector.commit(new StreamPreviewInfoExtractor() { @Override - public AbstractVideoInfo.StreamType getStreamType() throws ParsingException { - return AbstractVideoInfo.StreamType.VIDEO_STREAM; + public AbstractStreamInfo.StreamType getStreamType() throws ParsingException { + return AbstractStreamInfo.StreamType.VIDEO_STREAM; } @Override diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java index 5f6f85ae6..23960f608 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelUrlIdHandler.java @@ -1,8 +1,8 @@ package org.schabi.newpipe.extractor.services.youtube; import org.schabi.newpipe.extractor.Parser; -import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ParsingException; /** * Created by Christian Schabesberger on 25.07.16. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 11e2d564d..3b4ad42e1 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.extractor.services.youtube; -import org.schabi.newpipe.extractor.ParsingException; + +import org.schabi.newpipe.extractor.exceptions.ParsingException; /** * Created by Christian Schabesberger on 02.03.16. 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 31d233438..3eb8ffb14 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 @@ -4,27 +4,16 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.SearchEngine; -import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor; -import org.schabi.newpipe.extractor.StreamPreviewInfoSearchCollector; import org.schabi.newpipe.extractor.UrlIdHandler; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.StreamPreviewInfoSearchCollector; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoExtractor; import java.net.URLEncoder; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; /** * Created by Christian Schabesberger on 09.08.15. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index 41ffe4a6d..b7cd33bc7 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -1,13 +1,12 @@ package org.schabi.newpipe.extractor.services.youtube; -import org.schabi.newpipe.extractor.ChannelExtractor; -import org.schabi.newpipe.extractor.ExtractionException; -import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.SearchEngine; +import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SuggestionExtractor; +import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 4a37c5ce6..e1cbdd1a6 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -8,20 +8,20 @@ import org.jsoup.nodes.Element; import org.mozilla.javascript.Context; import org.mozilla.javascript.Function; import org.mozilla.javascript.ScriptableObject; -import org.schabi.newpipe.extractor.AbstractVideoInfo; -import org.schabi.newpipe.extractor.AudioStream; -import org.schabi.newpipe.extractor.ExtractionException; +import org.schabi.newpipe.extractor.AbstractStreamInfo; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.AudioStream; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Parser; -import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.StreamInfo; -import org.schabi.newpipe.extractor.StreamPreviewInfoCollector; -import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor; import org.schabi.newpipe.extractor.UrlIdHandler; -import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.MediaFormat; -import org.schabi.newpipe.extractor.VideoStream; +import org.schabi.newpipe.extractor.stream_info.StreamExtractor; +import org.schabi.newpipe.extractor.stream_info.StreamInfo; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoCollector; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoExtractor; +import org.schabi.newpipe.extractor.stream_info.VideoStream; import java.io.IOException; import java.util.List; @@ -709,7 +709,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { private StreamPreviewInfoExtractor extractVideoPreviewInfo(final Element li) { return new StreamPreviewInfoExtractor() { @Override - public AbstractVideoInfo.StreamType getStreamType() throws ParsingException { + public AbstractStreamInfo.StreamType getStreamType() throws ParsingException { return null; } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamPreviewInfoExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamPreviewInfoExtractor.java index 371cc96ff..e7420deda 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamPreviewInfoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamPreviewInfoExtractor.java @@ -1,10 +1,10 @@ package org.schabi.newpipe.extractor.services.youtube; import org.jsoup.nodes.Element; -import org.schabi.newpipe.extractor.AbstractVideoInfo; +import org.schabi.newpipe.extractor.AbstractStreamInfo; import org.schabi.newpipe.extractor.Parser; -import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfoExtractor; /** * Copyright (C) Christian Schabesberger 2016 @@ -146,11 +146,11 @@ public class YoutubeStreamPreviewInfoExtractor implements StreamPreviewInfoExtra } @Override - public AbstractVideoInfo.StreamType getStreamType() { + public AbstractStreamInfo.StreamType getStreamType() { if(isLiveStream(item)) { - return AbstractVideoInfo.StreamType.LIVE_STREAM; + return AbstractStreamInfo.StreamType.LIVE_STREAM; } else { - return AbstractVideoInfo.StreamType.VIDEO_STREAM; + return AbstractStreamInfo.StreamType.VIDEO_STREAM; } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java index 9096ffbb3..2c3f76293 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java @@ -1,9 +1,9 @@ package org.schabi.newpipe.extractor.services.youtube; -import org.schabi.newpipe.extractor.FoundAdException; import org.schabi.newpipe.extractor.Parser; -import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.FoundAdException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java index ea5f9ecbb..8cd1651b8 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractor.java @@ -1,10 +1,10 @@ package org.schabi.newpipe.extractor.services.youtube; import org.schabi.newpipe.extractor.Downloader; -import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ParsingException; -import org.schabi.newpipe.extractor.SuggestionExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.search.SuggestionExtractor; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/AudioStream.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/AudioStream.java similarity index 96% rename from app/src/main/java/org/schabi/newpipe/extractor/AudioStream.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/AudioStream.java index 807ae666e..c345b3fa8 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/AudioStream.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/AudioStream.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; /** * Created by Christian Schabesberger on 04.03.16. diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamExtractor.java similarity index 94% rename from app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamExtractor.java index 6b0da4f89..66c500358 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamExtractor.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; /** * Created by Christian Schabesberger on 10.08.15. @@ -20,6 +20,10 @@ package org.schabi.newpipe.extractor; * along with NewPipe. If not, see . */ +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + import java.util.List; /**Scrapes information from a video streaming service (eg, YouTube).*/ diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamInfo.java similarity index 93% rename from app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamInfo.java index f3fde27ae..23b90b083 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamInfo.java @@ -1,4 +1,9 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; + +import org.schabi.newpipe.extractor.AbstractStreamInfo; +import org.schabi.newpipe.extractor.DashMpdParser; +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; import java.io.IOException; import java.util.List; @@ -26,7 +31,7 @@ import java.util.Vector; /**Info object for opened videos, ie the video ready to play.*/ @SuppressWarnings("ALL") -public class StreamInfo extends AbstractVideoInfo { +public class StreamInfo extends AbstractStreamInfo { public static class StreamExctractException extends ExtractionException { StreamExctractException(String message) { @@ -39,7 +44,7 @@ public class StreamInfo extends AbstractVideoInfo { /**Creates a new StreamInfo object from an existing AbstractVideoInfo. * All the shared properties are copied to the new StreamInfo.*/ @SuppressWarnings("WeakerAccess") - public StreamInfo(AbstractVideoInfo avi) { + public StreamInfo(AbstractStreamInfo avi) { this.id = avi.id; this.title = avi.title; this.uploader = avi.uploader; @@ -67,19 +72,19 @@ public class StreamInfo extends AbstractVideoInfo { /**Fills out the video info fields which are common to all services. * Probably needs to be overridden by subclasses*/ - public static StreamInfo getVideoInfo(StreamExtractor extractor, Downloader downloader) + public static StreamInfo getVideoInfo(StreamExtractor extractor) throws ExtractionException, IOException { StreamInfo streamInfo = new StreamInfo(); - streamInfo = extractImportantData(streamInfo, extractor, downloader); - streamInfo = extractStreams(streamInfo, extractor, downloader); - streamInfo = extractOptionalData(streamInfo, extractor, downloader); + streamInfo = extractImportantData(streamInfo, extractor); + streamInfo = extractStreams(streamInfo, extractor); + streamInfo = extractOptionalData(streamInfo, extractor); return streamInfo; } private static StreamInfo extractImportantData( - StreamInfo streamInfo, StreamExtractor extractor, Downloader downloader) + StreamInfo streamInfo, StreamExtractor extractor) throws ExtractionException, IOException { /* ---- importand data, withoug the video can't be displayed goes here: ---- */ // if one of these is not available an exception is ment to be thrown directly into the frontend. @@ -105,7 +110,7 @@ public class StreamInfo extends AbstractVideoInfo { } private static StreamInfo extractStreams( - StreamInfo streamInfo, StreamExtractor extractor, Downloader downloader) + StreamInfo streamInfo, StreamExtractor extractor) throws ExtractionException, IOException { /* ---- stream extraction goes here ---- */ // At least one type of stream has to be available, @@ -132,7 +137,7 @@ public class StreamInfo extends AbstractVideoInfo { // same as the quick and dirty aboth try { streamInfo.audio_streams.addAll( - DashMpdParser.getAudioStreams(streamInfo.dashMpdUrl, downloader)); + DashMpdParser.getAudioStreams(streamInfo.dashMpdUrl)); } catch(Exception e) { streamInfo.addException( new ExtractionException("Couldn't get audio streams from dash mpd", e)); @@ -166,7 +171,7 @@ public class StreamInfo extends AbstractVideoInfo { } private static StreamInfo extractOptionalData( - StreamInfo streamInfo, StreamExtractor extractor, Downloader downloader) { + StreamInfo streamInfo, StreamExtractor extractor) { /* ---- optional data goes here: ---- */ // If one of these failes, the frontend neets to handle that they are not available. // Exceptions are therfore not thrown into the frontend, but stored into the error List, diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfo.java similarity index 84% rename from app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfo.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfo.java index b85fe96af..77de2db95 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfo.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; /** * Created by Christian Schabesberger on 26.08.15. @@ -20,7 +20,9 @@ package org.schabi.newpipe.extractor; * along with NewPipe. If not, see . */ +import org.schabi.newpipe.extractor.AbstractStreamInfo; + /**Info object for previews of unopened videos, eg search results, related videos*/ -public class StreamPreviewInfo extends AbstractVideoInfo { +public class StreamPreviewInfo extends AbstractStreamInfo { public int duration; } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfoCollector.java similarity index 93% rename from app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfoCollector.java index 7c890c0f3..ea978f730 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfoCollector.java @@ -1,5 +1,8 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; +import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.exceptions.FoundAdException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamUrlIdHandler; import java.util.List; diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfoExtractor.java similarity index 83% rename from app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfoExtractor.java index bea8eb4e6..3e35fc8da 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/StreamPreviewInfoExtractor.java @@ -1,4 +1,7 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; + +import org.schabi.newpipe.extractor.AbstractStreamInfo; +import org.schabi.newpipe.extractor.exceptions.ParsingException; /** * Created by Christian Schabesberger on 28.02.16. @@ -21,7 +24,7 @@ package org.schabi.newpipe.extractor; */ public interface StreamPreviewInfoExtractor { - AbstractVideoInfo.StreamType getStreamType() throws ParsingException; + AbstractStreamInfo.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/VideoStream.java b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/VideoStream.java similarity index 96% rename from app/src/main/java/org/schabi/newpipe/extractor/VideoStream.java rename to app/src/main/java/org/schabi/newpipe/extractor/stream_info/VideoStream.java index b1642f2c6..c3e12fdbd 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/VideoStream.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/stream_info/VideoStream.java @@ -1,4 +1,4 @@ -package org.schabi.newpipe.extractor; +package org.schabi.newpipe.extractor.stream_info; /** * Created by Christian Schabesberger on 04.03.16. diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java index 11ceca08d..30836053e 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java @@ -10,8 +10,8 @@ import com.nostra13.universalimageloader.core.ImageLoader; import org.schabi.newpipe.ImageErrorLoadingListener; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.AbstractVideoInfo; -import org.schabi.newpipe.extractor.StreamPreviewInfo; +import org.schabi.newpipe.extractor.AbstractStreamInfo; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; /** * Created by Christian Schabesberger on 26.09.16. @@ -66,7 +66,7 @@ public class InfoItemBuilder { if(info.duration > 0) { holder.itemDurationView.setText(getDurationString(info.duration)); } else { - if(info.stream_type == AbstractVideoInfo.StreamType.LIVE_STREAM) { + if(info.stream_type == AbstractStreamInfo.StreamType.LIVE_STREAM) { holder.itemDurationView.setText(R.string.duration_live); } else { holder.itemDurationView.setVisibility(View.GONE); diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 13a8d821a..30d3803ac 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -6,13 +6,8 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.nostra13.universalimageloader.core.DisplayImageOptions; -import com.nostra13.universalimageloader.core.ImageLoader; - -import org.schabi.newpipe.ImageErrorLoadingListener; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.AbstractVideoInfo; -import org.schabi.newpipe.extractor.StreamPreviewInfo; +import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; import java.util.List; import java.util.Vector; diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java index af56cc3f2..782f7a78b 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchInfoItemFragment.java @@ -19,12 +19,12 @@ import android.widget.ProgressBar; import android.widget.Toast; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.detail.VideoItemDetailActivity; import org.schabi.newpipe.detail.VideoItemDetailFragment; -import org.schabi.newpipe.extractor.SearchResult; import org.schabi.newpipe.info_list.InfoListAdapter; /** diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java index ccb4a4173..b6be1e259 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SearchWorker.java @@ -7,12 +7,11 @@ import android.preference.PreferenceManager; import android.util.Log; import android.view.View; -import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SearchEngine; +import org.schabi.newpipe.extractor.search.SearchResult; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.ExtractionException; -import org.schabi.newpipe.extractor.SearchEngine; -import org.schabi.newpipe.extractor.SearchResult; import org.schabi.newpipe.extractor.NewPipe; import java.io.IOException; diff --git a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java index 33fe5de44..ed090d230 100644 --- a/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java +++ b/app/src/main/java/org/schabi/newpipe/search_fragment/SuggestionSearchRunnable.java @@ -6,13 +6,11 @@ import android.os.Handler; import android.preference.PreferenceManager; import android.widget.Toast; -import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.SuggestionExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SuggestionExtractor; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.ExtractionException; -import org.schabi.newpipe.extractor.SearchEngine; import java.io.IOException; import java.util.List;