mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	refactored StreamingService interface so it acts as a Factory (returning new instances of called classes, eg Extractor), rather than passing Class objects (which loses type safety) which are then instantiated. Also noticed there is a conflict between existing gradle setup and mine: misc.xml and app.iml have had their jvm version values switched from 1.8 to 1.7
This commit is contained in:
		
							
								
								
									
										2
									
								
								.idea/gradle.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/gradle.xml
									
									
									
										generated
									
									
									
								
							| @@ -6,7 +6,7 @@ | |||||||
|         <option name="distributionType" value="LOCAL" /> |         <option name="distributionType" value="LOCAL" /> | ||||||
|         <option name="externalProjectPath" value="$PROJECT_DIR$" /> |         <option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||||||
|         <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" /> |         <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" /> | ||||||
|         <option name="gradleJvm" value="1.8" /> |         <option name="gradleJvm" value="1.7" /> | ||||||
|         <option name="modules"> |         <option name="modules"> | ||||||
|           <set> |           <set> | ||||||
|             <option value="$PROJECT_DIR$" /> |             <option value="$PROJECT_DIR$" /> | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							| @@ -37,7 +37,7 @@ | |||||||
|     <ConfirmationsSetting value="0" id="Add" /> |     <ConfirmationsSetting value="0" id="Add" /> | ||||||
|     <ConfirmationsSetting value="0" id="Remove" /> |     <ConfirmationsSetting value="0" id="Remove" /> | ||||||
|   </component> |   </component> | ||||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> |   <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK"> | ||||||
|     <output url="file://$PROJECT_DIR$/build/classes" /> |     <output url="file://$PROJECT_DIR$/build/classes" /> | ||||||
|   </component> |   </component> | ||||||
|   <component name="ProjectType"> |   <component name="ProjectType"> | ||||||
|   | |||||||
| @@ -92,12 +92,12 @@ | |||||||
|     </content> |     </content> | ||||||
|     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" /> |     <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" /> | ||||||
|     <orderEntry type="sourceFolder" forTests="false" /> |     <orderEntry type="sourceFolder" forTests="false" /> | ||||||
|  |     <orderEntry type="library" exported="" name="rhino-1.7.7" level="project" /> | ||||||
|     <orderEntry type="library" exported="" name="recyclerview-v7-23.1.0" level="project" /> |     <orderEntry type="library" exported="" name="recyclerview-v7-23.1.0" level="project" /> | ||||||
|  |     <orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" /> | ||||||
|  |     <orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" /> | ||||||
|  |     <orderEntry type="library" exported="" name="design-23.1.0" level="project" /> | ||||||
|     <orderEntry type="library" exported="" name="jsoup-1.8.3" level="project" /> |     <orderEntry type="library" exported="" name="jsoup-1.8.3" level="project" /> | ||||||
|     <orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" /> |     <orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" /> | ||||||
|     <orderEntry type="library" exported="" name="rhino-1.7.7" level="project" /> |  | ||||||
|     <orderEntry type="library" exported="" name="design-23.1.0" level="project" /> |  | ||||||
|     <orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" /> |  | ||||||
|     <orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" /> |  | ||||||
|   </component> |   </component> | ||||||
| </module> | </module> | ||||||
| @@ -1,9 +1,12 @@ | |||||||
| package org.schabi.newpipe; | package org.schabi.newpipe; | ||||||
|  |  | ||||||
|  | import android.widget.Toast; | ||||||
|  |  | ||||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||||
| import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||||
| import java.net.HttpURLConnection; | import java.net.HttpURLConnection; | ||||||
| import java.net.URL; | import java.net.URL; | ||||||
|  | import java.net.UnknownHostException; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by Christian Schabesberger on 14.08.15. |  * Created by Christian Schabesberger on 14.08.15. | ||||||
| @@ -45,7 +48,13 @@ public class Downloader { | |||||||
|                 response.append(inputLine); |                 response.append(inputLine); | ||||||
|             } |             } | ||||||
|             in.close(); |             in.close(); | ||||||
|         } catch (Exception e) { |  | ||||||
|  |         } | ||||||
|  |         catch(UnknownHostException uhe) {//thrown when there's no internet connection | ||||||
|  |             uhe.printStackTrace(); | ||||||
|  |             //Toast.makeText(getActivity(), uhe.getMessage(), Toast.LENGTH_LONG).show(); | ||||||
|  |         } | ||||||
|  |         catch (Exception e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
|         return response.toString(); |         return response.toString(); | ||||||
|   | |||||||
| @@ -24,12 +24,12 @@ public interface StreamingService { | |||||||
|     class ServiceInfo { |     class ServiceInfo { | ||||||
|         public String name = ""; |         public String name = ""; | ||||||
|     } |     } | ||||||
|     ServiceInfo getServiceInfo(); |     public ServiceInfo getServiceInfo(); | ||||||
|     Class getExtractorClass(); |     public Extractor getExtractorInstance(); | ||||||
|     Class getSearchEngineClass(); |     public SearchEngine getSearchEngineInstance(); | ||||||
|  |  | ||||||
|     // When a VIEW_ACTION is caught this function will test if the url delivered within the calling |     /**When a VIEW_ACTION is caught this function will test if the url delivered within the calling | ||||||
|     // Intent was meant to be watched with this Service. |     Intent was meant to be watched with this Service. | ||||||
|     // Return false if this service shall not allow to be callean through ACTIONs. |     Return false if this service shall not allow to be callean through ACTIONs.*/ | ||||||
|     boolean acceptUrl(String videoUrl); |     boolean acceptUrl(String videoUrl); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -59,7 +59,7 @@ public class VideoInfo { | |||||||
|  |  | ||||||
|     public static final int VIDEO_AVAILABLE = 0x00; |     public static final int VIDEO_AVAILABLE = 0x00; | ||||||
|     public static final int VIDEO_UNAVAILABLE = 0x01; |     public static final int VIDEO_UNAVAILABLE = 0x01; | ||||||
|     public static final int VIDEO_UNAVAILABLE_GEMA = 0x02; |     public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation; sound pretty draconian | ||||||
|  |  | ||||||
|     public static String getNameById(int id) { |     public static String getNameById(int id) { | ||||||
|         switch(id) { |         switch(id) { | ||||||
| @@ -68,8 +68,7 @@ public class VideoInfo { | |||||||
|             case I_WEBM: return F_WEBM; |             case I_WEBM: return F_WEBM; | ||||||
|             case I_M4A: return F_M4A; |             case I_M4A: return F_M4A; | ||||||
|             case I_WEBMA: return F_WEBMA; |             case I_WEBMA: return F_WEBMA; | ||||||
|             default: Log.e(TAG, "format not known: " + |             default: formatNotKnown(id); | ||||||
|                     Integer.toString(id) + "call the programmer he messed it up."); |  | ||||||
|         } |         } | ||||||
|         return ""; |         return ""; | ||||||
|     } |     } | ||||||
| @@ -81,8 +80,7 @@ public class VideoInfo { | |||||||
|             case I_WEBM: return C_WEBM; |             case I_WEBM: return C_WEBM; | ||||||
|             case I_M4A: return C_M4A; |             case I_M4A: return C_M4A; | ||||||
|             case I_WEBMA: return C_WEBMA; |             case I_WEBMA: return C_WEBMA; | ||||||
|             default: Log.e(TAG, "format not known: " + |             default: formatNotKnown(id); | ||||||
|                     Integer.toString(id) + "call the programmer he messed it up."); |  | ||||||
|         } |         } | ||||||
|         return ""; |         return ""; | ||||||
|     } |     } | ||||||
| @@ -94,8 +92,7 @@ public class VideoInfo { | |||||||
|             case I_WEBM: return M_WEBM; |             case I_WEBM: return M_WEBM; | ||||||
|             case I_M4A: return M_M4A; |             case I_M4A: return M_M4A; | ||||||
|             case I_WEBMA: return M_WEBMA; |             case I_WEBMA: return M_WEBMA; | ||||||
|             default: Log.e(TAG, "format not known: " + |             default: formatNotKnown(id); | ||||||
|                     Integer.toString(id) + "call the programmer he messed it up."); |  | ||||||
|         } |         } | ||||||
|         return ""; |         return ""; | ||||||
|     } |     } | ||||||
| @@ -109,6 +106,12 @@ public class VideoInfo { | |||||||
|         public String resolution = ""; |         public String resolution = ""; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     protected static void formatNotKnown(int id) | ||||||
|  |     { | ||||||
|  |         Log.e(TAG, "format not known: \"" + | ||||||
|  |             Integer.toString(id) + "\". Call the programmer, he messed it up!"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public static class AudioStream { |     public static class AudioStream { | ||||||
|         public AudioStream(String url, int format, int bandwidth, int samplingRate) { |         public AudioStream(String url, int format, int bandwidth, int samplingRate) { | ||||||
|             this.url = url; this.format = format; |             this.url = url; this.format = format; | ||||||
|   | |||||||
| @@ -61,7 +61,7 @@ public class VideoInfoItemViewCreator { | |||||||
|         if(!info.upload_date.isEmpty()) { |         if(!info.upload_date.isEmpty()) { | ||||||
|             holder.itemUploadDateView.setText(info.upload_date); |             holder.itemUploadDateView.setText(info.upload_date); | ||||||
|         } else { |         } else { | ||||||
|             //tewak if nececeary: This is a hack preventing to have a white space in the layout :P |             //tweak if necessary: This is a hack to prevent having white space in the layout :P | ||||||
|             holder.itemUploadDateView.setText(info.view_count); |             holder.itemUploadDateView.setText(info.view_count); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ import android.widget.Toast; | |||||||
|  * along with NewPipe.  If not, see <http://www.gnu.org/licenses/>. |  * along with NewPipe.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | /***/ | ||||||
| public class VideoItemDetailActivity extends AppCompatActivity { | public class VideoItemDetailActivity extends AppCompatActivity { | ||||||
|  |  | ||||||
|     private static final String TAG = VideoItemDetailActivity.class.toString(); |     private static final String TAG = VideoItemDetailActivity.class.toString(); | ||||||
| @@ -69,7 +70,7 @@ public class VideoItemDetailActivity extends AppCompatActivity { | |||||||
|                         try { |                         try { | ||||||
|                             currentStreamingService = i; |                             currentStreamingService = i; | ||||||
|                             extractor = (Extractor) ServiceList.getService(i) |                             extractor = (Extractor) ServiceList.getService(i) | ||||||
|                                     .getExtractorClass().newInstance(); |                                     .getExtractorInstance(); | ||||||
|                         } catch (Exception e) { |                         } catch (Exception e) { | ||||||
|                             e.printStackTrace(); |                             e.printStackTrace(); | ||||||
|                         } |                         } | ||||||
| @@ -123,9 +124,9 @@ public class VideoItemDetailActivity extends AppCompatActivity { | |||||||
|             // activity, the Up button is shown. Use NavUtils to allow users |             // activity, the Up button is shown. Use NavUtils to allow users | ||||||
|             // to navigate up one level in the application structure. For |             // to navigate up one level in the application structure. For | ||||||
|             // more details, see the Navigation pattern on Android Design: |             // more details, see the Navigation pattern on Android Design: | ||||||
|             // |  | ||||||
|             // http://developer.android.com/design/patterns/navigation.html#up-vs-back |             // http://developer.android.com/design/patterns/navigation.html#up-vs-back | ||||||
|             // |  | ||||||
|             Intent intent = new Intent(this, VideoItemListActivity.class); |             Intent intent = new Intent(this, VideoItemListActivity.class); | ||||||
|             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | ||||||
|             NavUtils.navigateUpTo(this, intent); |             NavUtils.navigateUpTo(this, intent); | ||||||
|   | |||||||
| @@ -79,16 +79,15 @@ public class VideoItemDetailFragment extends Fragment { | |||||||
|  |  | ||||||
|     private class ExtractorRunnable implements Runnable { |     private class ExtractorRunnable implements Runnable { | ||||||
|         private Handler h = new Handler(); |         private Handler h = new Handler(); | ||||||
|         private Class extractorClass; |         private Extractor extractor; | ||||||
|         private String videoUrl; |         private String videoUrl; | ||||||
|         public ExtractorRunnable(String videoUrl, Class extractorClass, VideoItemDetailFragment f) { |         public ExtractorRunnable(String videoUrl, Extractor extractor, VideoItemDetailFragment f) { | ||||||
|             this.extractorClass = extractorClass; |             this.extractor = extractor; | ||||||
|             this.videoUrl = videoUrl; |             this.videoUrl = videoUrl; | ||||||
|         } |         } | ||||||
|         @Override |         @Override | ||||||
|         public void run() { |         public void run() { | ||||||
|             try { |             try { | ||||||
|                 Extractor extractor = (Extractor) extractorClass.newInstance(); |  | ||||||
|                 VideoInfo videoInfo = extractor.getVideoInfo(videoUrl); |                 VideoInfo videoInfo = extractor.getVideoInfo(videoUrl); | ||||||
|                 h.post(new VideoResultReturnedRunnable(videoInfo)); |                 h.post(new VideoResultReturnedRunnable(videoInfo)); | ||||||
|                 if (videoInfo.videoAvailableStatus == VideoInfo.VIDEO_AVAILABLE) { |                 if (videoInfo.videoAvailableStatus == VideoInfo.VIDEO_AVAILABLE) { | ||||||
| @@ -170,7 +169,7 @@ public class VideoItemDetailFragment extends Fragment { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|         } catch (java.lang.NullPointerException e) { |         } catch (java.lang.NullPointerException e) { | ||||||
|             // No god programm design i know. :/ |             // Not good program design, I know. :/ | ||||||
|             Log.w(TAG, "updateThumbnail(): Fragment closed before thread ended work"); |             Log.w(TAG, "updateThumbnail(): Fragment closed before thread ended work"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -312,7 +311,7 @@ public class VideoItemDetailFragment extends Fragment { | |||||||
|                 StreamingService streamingService = ServiceList.getService( |                 StreamingService streamingService = ServiceList.getService( | ||||||
|                         getArguments().getInt(STREAMING_SERVICE)); |                         getArguments().getInt(STREAMING_SERVICE)); | ||||||
|                 extractorThread = new Thread(new ExtractorRunnable( |                 extractorThread = new Thread(new ExtractorRunnable( | ||||||
|                         getArguments().getString(VIDEO_URL), streamingService.getExtractorClass(), this)); |                         getArguments().getString(VIDEO_URL), streamingService.getExtractorInstance(), this)); | ||||||
|                 autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY); |                 autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY); | ||||||
|                 extractorThread.start(); |                 extractorThread.start(); | ||||||
|             } catch (Exception e) { |             } catch (Exception e) { | ||||||
|   | |||||||
| @@ -87,13 +87,11 @@ public class VideoItemListActivity extends AppCompatActivity | |||||||
|         super.onCreate(savedInstanceState); |         super.onCreate(savedInstanceState); | ||||||
|         setContentView(R.layout.activity_videoitem_list); |         setContentView(R.layout.activity_videoitem_list); | ||||||
|  |  | ||||||
|         listFragment = (VideoItemListFragment) |  | ||||||
|                 getSupportFragmentManager().findFragmentById(R.id.videoitem_list); |  | ||||||
|  |  | ||||||
|         //-------- remove this line when multiservice support is implemented ---------- |         //-------- remove this line when multiservice support is implemented ---------- | ||||||
|         currentStreamingServiceId = ServiceList.getIdOfService("Youtube"); |         currentStreamingServiceId = ServiceList.getIdOfService("Youtube"); | ||||||
|         //----------------------------------------------------------------------------- |         //----------------------------------------------------------------------------- | ||||||
|         VideoItemListFragment listFragment = (VideoItemListFragment) getSupportFragmentManager() |  | ||||||
|  |         listFragment = (VideoItemListFragment) getSupportFragmentManager() | ||||||
|                 .findFragmentById(R.id.videoitem_list); |                 .findFragmentById(R.id.videoitem_list); | ||||||
|         listFragment.setStreamingService(ServiceList.getService(currentStreamingServiceId)); |         listFragment.setStreamingService(ServiceList.getService(currentStreamingServiceId)); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -65,14 +65,14 @@ public class VideoItemListFragment extends ListFragment { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private class SearchRunnable implements Runnable { |     private class SearchRunnable implements Runnable { | ||||||
|         private Class engineClass = null; |         private SearchEngine engine; | ||||||
|         private String query; |         private String query; | ||||||
|         private int page; |         private int page; | ||||||
|         Handler h = new Handler(); |         Handler h = new Handler(); | ||||||
|         private volatile boolean run = true; |         private volatile boolean run = true; | ||||||
|         private int requestId; |         private int requestId; | ||||||
|         public SearchRunnable(Class engineClass, String query, int page, int requestId) { |         public SearchRunnable(SearchEngine engine, String query, int page, int requestId) { | ||||||
|             this.engineClass = engineClass; |             this.engine = engine; | ||||||
|             this.query = query; |             this.query = query; | ||||||
|             this.page = page; |             this.page = page; | ||||||
|             this.requestId = requestId; |             this.requestId = requestId; | ||||||
| @@ -82,13 +82,6 @@ public class VideoItemListFragment extends ListFragment { | |||||||
|         } |         } | ||||||
|         @Override |         @Override | ||||||
|         public void run() { |         public void run() { | ||||||
|             SearchEngine engine = null; |  | ||||||
|             try { |  | ||||||
|                 engine = (SearchEngine) engineClass.newInstance(); |  | ||||||
|             } catch(Exception e) { |  | ||||||
|                 e.printStackTrace(); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             try { |             try { | ||||||
|                 SearchEngine.Result result = engine.search(query, page); |                 SearchEngine.Result result = engine.search(query, page); | ||||||
|                 if(run) { |                 if(run) { | ||||||
| @@ -179,7 +172,7 @@ public class VideoItemListFragment extends ListFragment { | |||||||
|     private void startSearch(String query, int page) { |     private void startSearch(String query, int page) { | ||||||
|         currentRequestId++; |         currentRequestId++; | ||||||
|         terminateThreads(); |         terminateThreads(); | ||||||
|         searchRunnable = new SearchRunnable(streamingService.getSearchEngineClass(), query, page, currentRequestId); |         searchRunnable = new SearchRunnable(streamingService.getSearchEngineInstance(), query, page, currentRequestId); | ||||||
|         searchThread = new Thread(searchRunnable); |         searchThread = new Thread(searchRunnable); | ||||||
|         searchThread.start(); |         searchThread.start(); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ public class YoutubeExtractor implements Extractor { | |||||||
|     private static final String TAG = YoutubeExtractor.class.toString(); |     private static final String TAG = YoutubeExtractor.class.toString(); | ||||||
|  |  | ||||||
|     // These lists only contain itag formats that are supported by the common Android Video player. |     // These lists only contain itag formats that are supported by the common Android Video player. | ||||||
|     // How ever if you are heading for a list showing all itag formats lock at |     // How ever if you are heading for a list showing all itag formats look at | ||||||
|     // https://github.com/rg3/youtube-dl/issues/1687 |     // https://github.com/rg3/youtube-dl/issues/1687 | ||||||
|  |  | ||||||
|     public static int resolveFormat(int itag) { |     public static int resolveFormat(int itag) { | ||||||
|   | |||||||
| @@ -1,6 +1,9 @@ | |||||||
| package org.schabi.newpipe.youtube; | package org.schabi.newpipe.youtube; | ||||||
|  |  | ||||||
| import org.schabi.newpipe.StreamingService; | import org.schabi.newpipe.StreamingService; | ||||||
|  | import org.schabi.newpipe.Extractor; | ||||||
|  | import org.schabi.newpipe.SearchEngine; | ||||||
|  |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by Christian Schabesberger on 23.08.15. |  * Created by Christian Schabesberger on 23.08.15. | ||||||
| @@ -30,12 +33,12 @@ public class YoutubeService implements StreamingService { | |||||||
|         return serviceInfo; |         return serviceInfo; | ||||||
|     } |     } | ||||||
|     @Override |     @Override | ||||||
|     public Class getExtractorClass() { |     public Extractor getExtractorInstance() { | ||||||
|         return YoutubeExtractor.class; |         return (Extractor) new YoutubeExtractor(); | ||||||
|     } |     } | ||||||
|     @Override |     @Override | ||||||
|     public Class getSearchEngineClass() { |     public SearchEngine getSearchEngineInstance() { | ||||||
|         return YoutubeSearchEngine.class; |         return (SearchEngine) new YoutubeSearchEngine(); | ||||||
|     } |     } | ||||||
|     @Override |     @Override | ||||||
|     public boolean acceptUrl(String videoUrl) { |     public boolean acceptUrl(String videoUrl) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Adam Howard
					Adam Howard