make erroractivity handle search engine exceptions
This commit is contained in:
parent
4ac36af40c
commit
1829dc79c8
3 changed files with 59 additions and 21 deletions
|
@ -133,6 +133,28 @@ public class VideoItemDetailFragment extends Fragment {
|
||||||
streamInfo = StreamInfo.getVideoInfo(streamExtractor, new Downloader());
|
streamInfo = StreamInfo.getVideoInfo(streamExtractor, new Downloader());
|
||||||
|
|
||||||
h.post(new VideoResultReturnedRunnable(streamInfo));
|
h.post(new VideoResultReturnedRunnable(streamInfo));
|
||||||
|
|
||||||
|
// look for errors during extraction
|
||||||
|
// this if statement only covers extra information.
|
||||||
|
// if these are not available or caused an error, they are just not available
|
||||||
|
// but don't render the stream information unusalbe.
|
||||||
|
if(streamInfo != null &&
|
||||||
|
!streamInfo.errors.isEmpty()) {
|
||||||
|
Log.e(TAG, "OCCURRED ERRORS DURING EXTRACTION:");
|
||||||
|
for (Exception e : streamInfo.errors) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e(TAG, "------");
|
||||||
|
}
|
||||||
|
|
||||||
|
Activity a = getActivity();
|
||||||
|
View rootView = a != null ? a.findViewById(R.id.videoitem_detail) : null;
|
||||||
|
ErrorActivity.reportError(h, getActivity(),
|
||||||
|
streamInfo.errors, null, rootView,
|
||||||
|
ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_STREAM,
|
||||||
|
service.getServiceInfo().name, videoUrl, 0 /* no message for the user */));
|
||||||
|
}
|
||||||
|
|
||||||
|
// These errors render the stream information unusable.
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
postNewErrorToast(h, R.string.network_error);
|
postNewErrorToast(h, R.string.network_error);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -205,21 +227,6 @@ public class VideoItemDetailFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
if(streamInfo != null &&
|
|
||||||
!streamInfo.errors.isEmpty()) {
|
|
||||||
Log.e(TAG, "OCCURRED ERRORS DURING EXTRACTION:");
|
|
||||||
for(Exception e : streamInfo.errors) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Activity a = getActivity();
|
|
||||||
View rootView = a != null ? a.findViewById(R.id.videoitem_detail) : null;
|
|
||||||
ErrorActivity.reportError(h, getActivity(),
|
|
||||||
streamInfo.errors, null, rootView,
|
|
||||||
ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_STREAM,
|
|
||||||
service.getServiceInfo().name, videoUrl, 0 /* no message for the user */));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe;
|
package org.schabi.newpipe;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -101,26 +102,53 @@ public class VideoItemListFragment extends ListFragment {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
SearchResult result = null;
|
||||||
try {
|
try {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
String searchLanguageKey = getContext().getString(R.string.search_language_key);
|
String searchLanguageKey = getContext().getString(R.string.search_language_key);
|
||||||
String searchLanguage = sp.getString(searchLanguageKey,
|
String searchLanguage = sp.getString(searchLanguageKey,
|
||||||
getString(R.string.default_language_value));
|
getString(R.string.default_language_value));
|
||||||
SearchResult result = SearchResult
|
result = SearchResult
|
||||||
.getSearchResult(engine, query, page, searchLanguage, new Downloader());
|
.getSearchResult(engine, query, page, searchLanguage, new Downloader());
|
||||||
|
|
||||||
//Log.i(TAG, "language code passed:\""+searchLanguage+"\"");
|
|
||||||
if(runs) {
|
if(runs) {
|
||||||
h.post(new ResultRunnable(result, requestId));
|
h.post(new ResultRunnable(result, requestId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// look for errors during extraction
|
||||||
|
// soft errors:
|
||||||
|
if(result != null &&
|
||||||
|
!result.errors.isEmpty()) {
|
||||||
|
Log.e(TAG, "OCCURRED ERRORS DURING SEARCH EXTRACTION:");
|
||||||
|
for(Exception e : result.errors) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e(TAG, "------");
|
||||||
|
}
|
||||||
|
|
||||||
|
Activity a = getActivity();
|
||||||
|
View rootView = a.findViewById(R.id.videoitem_list);
|
||||||
|
ErrorActivity.reportError(h, getActivity(), result.errors, null, rootView,
|
||||||
|
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
|
||||||
|
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
|
||||||
|
|
||||||
|
}
|
||||||
|
// hard errors:
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
postNewErrorToast(h, R.string.network_error);
|
postNewErrorToast(h, R.string.network_error);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch(ExtractionException ce) {
|
} catch(ExtractionException e) {
|
||||||
postNewErrorToast(h, R.string.parsing_error);
|
ErrorActivity.reportError(h, getActivity(), e, null, null,
|
||||||
ce.printStackTrace();
|
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
|
||||||
|
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error));
|
||||||
|
|
||||||
|
//postNewErrorToast(h, R.string.parsing_error);
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
postNewErrorToast(h, R.string.general_error);
|
ErrorActivity.reportError(h, getActivity(), e, null, null,
|
||||||
|
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
|
||||||
|
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,8 @@ public class YoutubeSearchEngine implements SearchEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getViewCount() throws ParsingException {
|
public long getViewCount() throws ParsingException {
|
||||||
|
throw new ParsingException("blabla");
|
||||||
|
/*
|
||||||
String output;
|
String output;
|
||||||
String input = item.select("div[class=\"yt-lockup-meta\"]").first()
|
String input = item.select("div[class=\"yt-lockup-meta\"]").first()
|
||||||
.select("li").get(1)
|
.select("li").get(1)
|
||||||
|
@ -224,6 +226,7 @@ public class YoutubeSearchEngine implements SearchEngine {
|
||||||
Log.d(TAG, "bla");
|
Log.d(TAG, "bla");
|
||||||
}
|
}
|
||||||
return Long.parseLong(output);
|
return Long.parseLong(output);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue