mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-17 07:14:54 +00:00
add error handling to suggestions
This commit is contained in:
parent
1210ab0de0
commit
77b9457707
@ -76,8 +76,11 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
public static final String TAG = ErrorActivity.class.toString();
|
public static final String TAG = ErrorActivity.class.toString();
|
||||||
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 String SEARCHED_STRING = "Searched";
|
public static final int GET_SUGGESTIONS = 2;
|
||||||
public static final String REQUESTED_STREAM_STRING = "Requested Stream";
|
public static final String SEARCHED_STRING = "searched";
|
||||||
|
public static final String REQUESTED_STREAM_STRING = "requested stream";
|
||||||
|
public static final String GET_SUGGESTIONS_STRING = "get suggestions";
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -303,6 +306,8 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
return REQUESTED_STREAM_STRING;
|
return REQUESTED_STREAM_STRING;
|
||||||
case SEARCHED:
|
case SEARCHED:
|
||||||
return SEARCHED_STRING;
|
return SEARCHED_STRING;
|
||||||
|
case GET_SUGGESTIONS:
|
||||||
|
return GET_SUGGESTIONS_STRING;
|
||||||
default:
|
default:
|
||||||
return "Your description is in another castle.";
|
return "Your description is in another castle.";
|
||||||
}
|
}
|
||||||
|
@ -172,11 +172,17 @@ public class VideoItemListActivity extends AppCompatActivity
|
|||||||
ArrayList<String>suggestions = engine.suggestionList(query,searchLanguage,new Downloader());
|
ArrayList<String>suggestions = engine.suggestionList(query,searchLanguage,new Downloader());
|
||||||
h.post(new SuggestionResultRunnable(suggestions));
|
h.post(new SuggestionResultRunnable(suggestions));
|
||||||
} catch (ExtractionException e) {
|
} catch (ExtractionException e) {
|
||||||
postNewErrorToast(h, R.string.parsing_error);
|
ErrorActivity.reportError(h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list),
|
||||||
|
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
|
||||||
|
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
postNewErrorToast(h, R.string.network_error);
|
postNewErrorToast(h, R.string.network_error);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ErrorActivity.reportError(h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list),
|
||||||
|
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
|
||||||
|
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,8 +151,6 @@ public class VideoItemListFragment extends ListFragment {
|
|||||||
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
|
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@ public class ParsingException extends ExtractionException {
|
|||||||
public ParsingException(String message) {
|
public ParsingException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
public ParsingException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
public ParsingException(String message, Throwable cause) {
|
public ParsingException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,6 @@ public interface StreamExtractor {
|
|||||||
public ContentNotAvailableException(String message) {
|
public ContentNotAvailableException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
public ContentNotAvailableException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
public ContentNotAvailableException(String message, Throwable cause) {
|
public ContentNotAvailableException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
@ -137,39 +137,34 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||||||
|
|
||||||
String response = dl.download(url);
|
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 {
|
try {
|
||||||
|
dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
doc = dBuilder.parse(new InputSource(
|
||||||
|
new ByteArrayInputStream(response.getBytes("utf-8"))));
|
||||||
|
doc.getDocumentElement().normalize();
|
||||||
|
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||||
|
throw new ParsingException("Could not parse document.");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Parse xml data using Jsoup not done
|
try {
|
||||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
NodeList nList = doc.getElementsByTagName("CompleteSuggestion");
|
||||||
DocumentBuilder dBuilder;
|
for (int temp = 0; temp < nList.getLength(); temp++) {
|
||||||
org.w3c.dom.Document doc = null;
|
|
||||||
|
|
||||||
try {
|
NodeList nList1 = doc.getElementsByTagName("suggestion");
|
||||||
dBuilder = dbFactory.newDocumentBuilder();
|
Node nNode1 = nList1.item(temp);
|
||||||
doc = dBuilder.parse(new InputSource(
|
if (nNode1.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
new ByteArrayInputStream(response.getBytes("utf-8"))));
|
org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode1;
|
||||||
doc.getDocumentElement().normalize();
|
suggestions.add(eElement.getAttribute("data"));
|
||||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doc != null) {
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log.e(TAG, "GREAT FUCKING ERROR");
|
|
||||||
}
|
}
|
||||||
return suggestions;
|
return suggestions;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new ParsingException(e);
|
throw new ParsingException("Could not get suggestions form document.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +52,6 @@ public class YoutubeStreamExtractor implements StreamExtractor {
|
|||||||
// exceptions
|
// exceptions
|
||||||
|
|
||||||
public class DecryptException extends ParsingException {
|
public class DecryptException extends ParsingException {
|
||||||
DecryptException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
DecryptException(String message, Throwable cause) {
|
DecryptException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
@ -718,7 +715,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
|
|||||||
info.thumbnail_url = "https:" + info.thumbnail_url;
|
info.thumbnail_url = "https:" + info.thumbnail_url;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException(e);
|
throw new ParsingException("Could not get video preview info", e);
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -772,7 +769,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
|
|||||||
Function decryptionFunc = (Function) scope.get("decrypt", scope);
|
Function decryptionFunc = (Function) scope.get("decrypt", scope);
|
||||||
result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
|
result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DecryptException(e);
|
throw new DecryptException("could not get decrypt signature", e);
|
||||||
} finally {
|
} finally {
|
||||||
Context.exit();
|
Context.exit();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user