From 1829dc79c8a72c02ab7966aa28dcad994a869c37 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 29 Feb 2016 19:02:40 +0100 Subject: [PATCH] make erroractivity handle search engine exceptions --- .../newpipe/VideoItemDetailFragment.java | 37 ++++++++++------- .../schabi/newpipe/VideoItemListFragment.java | 40 ++++++++++++++++--- .../services/youtube/YoutubeSearchEngine.java | 3 ++ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index d86b195de..d5d6ff052 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -133,6 +133,28 @@ public class VideoItemDetailFragment extends Fragment { streamInfo = StreamInfo.getVideoInfo(streamExtractor, new Downloader()); 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) { postNewErrorToast(h, R.string.network_error); e.printStackTrace(); @@ -205,21 +227,6 @@ public class VideoItemDetailFragment extends Fragment { } }); 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 */)); - } } } } diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java index ac1d1a2cd..7dc01bd38 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe; +import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -101,26 +102,53 @@ public class VideoItemListFragment extends ListFragment { } @Override public void run() { + SearchResult result = null; try { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); String searchLanguageKey = getContext().getString(R.string.search_language_key); String searchLanguage = sp.getString(searchLanguageKey, getString(R.string.default_language_value)); - SearchResult result = SearchResult + result = SearchResult .getSearchResult(engine, query, page, searchLanguage, new Downloader()); - //Log.i(TAG, "language code passed:\""+searchLanguage+"\""); if(runs) { 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) { postNewErrorToast(h, R.string.network_error); e.printStackTrace(); - } catch(ExtractionException ce) { - postNewErrorToast(h, R.string.parsing_error); - ce.printStackTrace(); + } catch(ExtractionException e) { + ErrorActivity.reportError(h, getActivity(), e, null, null, + 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) { - 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(); } } 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 83b8dab36..6afed94eb 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 @@ -211,6 +211,8 @@ public class YoutubeSearchEngine implements SearchEngine { @Override public long getViewCount() throws ParsingException { + throw new ParsingException("blabla"); + /* String output; String input = item.select("div[class=\"yt-lockup-meta\"]").first() .select("li").get(1) @@ -224,6 +226,7 @@ public class YoutubeSearchEngine implements SearchEngine { Log.d(TAG, "bla"); } return Long.parseLong(output); + */ } @Override