made service list do propper error handling

This commit is contained in:
Christian Schabesberger 2016-03-04 14:10:41 +01:00
parent 0c716c12d7
commit 9548dfabd6
6 changed files with 29 additions and 18 deletions

View file

@ -77,9 +77,11 @@ public class ErrorActivity extends AppCompatActivity {
public static final int SEARCHED = 0; public static final int SEARCHED = 0;
public static final int REQUESTED_STREAM = 1; public static final int REQUESTED_STREAM = 1;
public static final int GET_SUGGESTIONS = 2; public static final int GET_SUGGESTIONS = 2;
public static final int SOMETHING_ELSE = 3;
public static final String SEARCHED_STRING = "searched"; public static final String SEARCHED_STRING = "searched";
public static final String REQUESTED_STREAM_STRING = "requested stream"; public static final String REQUESTED_STREAM_STRING = "requested stream";
public static final String GET_SUGGESTIONS_STRING = "get suggestions"; public static final String GET_SUGGESTIONS_STRING = "get suggestions";
public static final String SOMETHING_ELSE_STRING = "something";
public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org"; public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org";
public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME; public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME;
@ -308,6 +310,8 @@ public class ErrorActivity extends AppCompatActivity {
return SEARCHED_STRING; return SEARCHED_STRING;
case GET_SUGGESTIONS: case GET_SUGGESTIONS:
return GET_SUGGESTIONS_STRING; return GET_SUGGESTIONS_STRING;
case SOMETHING_ELSE:
return SOMETHING_ELSE_STRING;
default: default:
return "Your description is in another castle."; return "Your description is in another castle.";
} }

View file

@ -117,7 +117,6 @@ class VideoInfoItemViewCreator {
} }
public static String getDurationString(int duration) { public static String getDurationString(int duration) {
Log.d("asfd", Integer.toString(duration) + " ----------------------");
String output = ""; String output = "";
int days = duration / (24 * 60 * 60); /* greater than a day */ int days = duration / (24 * 60 * 60); /* greater than a day */
duration %= (24 * 60 * 60); duration %= (24 * 60 * 60);

View file

@ -197,9 +197,16 @@ public class VideoItemListActivity extends AppCompatActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_videoitem_list); setContentView(R.layout.activity_videoitem_list);
try {
//------ todo: remove this line when multiservice support is implemented ------ //------ todo: remove this line when multiservice support is implemented ------
currentStreamingServiceId = ServiceList.getIdOfService("Youtube"); currentStreamingServiceId = ServiceList.getIdOfService("Youtube");
streamingService=ServiceList.getService(currentStreamingServiceId); streamingService = ServiceList.getService(currentStreamingServiceId);
} catch (Exception e) {
e.printStackTrace();
ErrorActivity.reportError(VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list),
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
/* todo: this shoudl not be assigned static */ "Youtube", "", R.string.general_error));
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//to solve issue 38 //to solve issue 38
listFragment = (VideoItemListFragment) getSupportFragmentManager() listFragment = (VideoItemListFragment) getSupportFragmentManager()

View file

@ -36,19 +36,23 @@ public class ServiceList {
public static StreamingService[] getServices() { public static StreamingService[] getServices() {
return services; return services;
} }
public static StreamingService getService(int serviceId) { public static StreamingService getService(int serviceId) throws ExtractionException {
return services[serviceId]; for(StreamingService s : services) {
if(s.getServiceId() == serviceId) {
return s;
} }
public static StreamingService getService(String serviceName) { }
throw new ExtractionException("Service not known: " + Integer.toString(serviceId));
}
public static StreamingService getService(String serviceName) throws ExtractionException {
return services[getIdOfService(serviceName)]; return services[getIdOfService(serviceName)];
} }
public static int getIdOfService(String serviceName) { public static int getIdOfService(String serviceName) throws ExtractionException {
for(int i = 0; i < services.length; i++) { for(int i = 0; i < services.length; i++) {
if(services[i].getServiceInfo().name.equals(serviceName)) { if(services[i].getServiceInfo().name.equals(serviceName)) {
return i; return i;
} }
} }
Log.e(TAG, "Error: Service " + serviceName + " not known."); throw new ExtractionException("Error: Service " + serviceName + " not known.");
return -1;
} }
} }

View file

@ -11,7 +11,6 @@ import org.schabi.newpipe.extractor.ExtractionException;
import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.Parser;
import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ParsingException;
import org.schabi.newpipe.extractor.SearchEngine; import org.schabi.newpipe.extractor.SearchEngine;
import org.schabi.newpipe.extractor.StreamExtractor;
import org.schabi.newpipe.extractor.StreamPreviewInfoCollector; import org.schabi.newpipe.extractor.StreamPreviewInfoCollector;
import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor; import org.schabi.newpipe.extractor.StreamPreviewInfoExtractor;
import org.schabi.newpipe.extractor.StreamUrlIdHandler; import org.schabi.newpipe.extractor.StreamUrlIdHandler;

View file

@ -1,7 +1,5 @@
package org.schabi.newpipe.extractor.services.youtube; package org.schabi.newpipe.extractor.services.youtube;
import android.util.Log;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
@ -15,7 +13,6 @@ import org.schabi.newpipe.extractor.ExtractionException;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.Parser;
import org.schabi.newpipe.extractor.ParsingException; import org.schabi.newpipe.extractor.ParsingException;
import org.schabi.newpipe.extractor.StreamInfo;
import org.schabi.newpipe.extractor.StreamPreviewInfo; import org.schabi.newpipe.extractor.StreamPreviewInfo;
import org.schabi.newpipe.extractor.StreamUrlIdHandler; import org.schabi.newpipe.extractor.StreamUrlIdHandler;
import org.schabi.newpipe.extractor.StreamExtractor; import org.schabi.newpipe.extractor.StreamExtractor;
@ -311,7 +308,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
return playerArgs.getString("title"); return playerArgs.getString("title");
} catch(JSONException je) {//html <meta> method } catch(JSONException je) {//html <meta> method
je.printStackTrace(); je.printStackTrace();
Log.w(TAG, "failed to load title from JSON args; trying to extract it from HTML"); System.err.println("failed to load title from JSON args; trying to extract it from HTML");
try { // fall through to fall-back try { // fall through to fall-back
return doc.select("meta[name=title]").attr("content"); return doc.select("meta[name=title]").attr("content");
} catch (Exception e) { } catch (Exception e) {
@ -339,7 +336,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
return playerArgs.getString("author"); return playerArgs.getString("author");
} catch(JSONException je) { } catch(JSONException je) {
je.printStackTrace(); je.printStackTrace();
Log.w(TAG, System.err.println(
"failed to load uploader name from JSON args; trying to extract it from HTML"); "failed to load uploader name from JSON args; trying to extract it from HTML");
} try {//fall through to fallback HTML method } try {//fall through to fallback HTML method
return doc.select("div.yt-user-info").first().text(); return doc.select("div.yt-user-info").first().text();
@ -387,7 +384,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
try { try {
return doc.select("link[itemprop=\"thumbnailUrl\"]").first().attr("abs:href"); return doc.select("link[itemprop=\"thumbnailUrl\"]").first().attr("abs:href");
} catch(Exception e) { } catch(Exception e) {
Log.w(TAG, "Could not find high res Thumbnail. Using low res instead"); System.err.println("Could not find high res Thumbnail. Using low res instead");
} }
try { //fall through to fallback try { //fall through to fallback
return playerArgs.getString("thumbnail_url"); return playerArgs.getString("thumbnail_url");
@ -512,7 +509,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
} }
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Could not get Video stream."); //todo: dont log throw an error
System.err.println( "Could not get Video stream.");
e.printStackTrace(); e.printStackTrace();
} }
} }