Search in sources :

Example 1 with ParsingException

use of org.schabi.newpipe.extractor.exceptions.ParsingException in project NewPipe by TeamNewPipe.

the class ChannelActivity method requestData.

private void requestData(final boolean onlyVideos) {
    // start processing
    isLoading = true;
    if (!onlyVideos) {
        //delete already displayed content
        progressBar.setVisibility(View.VISIBLE);
        infoListAdapter.clearSteamItemList();
        pageNumber = 0;
        subscriberLayout.setVisibility(View.GONE);
        titleView.setText("");
        getSupportActionBar().setTitle("");
        if (SDK_INT >= 21) {
            channelBanner.setImageDrawable(getDrawable(R.drawable.channel_banner));
            avatarView.setImageDrawable(getDrawable(R.drawable.buddy));
        }
        infoListAdapter.showFooter(false);
    }
    Thread channelExtractorThread = new Thread(new Runnable() {

        Handler h = new Handler();

        @Override
        public void run() {
            StreamingService service = null;
            try {
                service = NewPipe.getService(serviceId);
                ChannelExtractor extractor = service.getChannelExtractorInstance(channelUrl, pageNumber);
                final ChannelInfo info = ChannelInfo.getInfo(extractor);
                h.post(new Runnable() {

                    @Override
                    public void run() {
                        isLoading = false;
                        if (!onlyVideos) {
                            updateUi(info);
                            infoListAdapter.showFooter(true);
                        }
                        hasNextPage = info.hasNextPage;
                        if (!hasNextPage) {
                            infoListAdapter.showFooter(false);
                        }
                        addVideos(info);
                    }
                });
                // look for non critical errors during extraction
                if (info != null && !info.errors.isEmpty()) {
                    Log.e(TAG, "OCCURRED ERRORS DURING EXTRACTION:");
                    for (Throwable e : info.errors) {
                        e.printStackTrace();
                        Log.e(TAG, "------");
                    }
                    View rootView = findViewById(android.R.id.content);
                    ErrorActivity.reportError(h, ChannelActivity.this, info.errors, null, rootView, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, service.getServiceInfo().name, channelUrl, 0));
                }
            } catch (IOException ioe) {
                postNewErrorToast(h, R.string.network_error);
                ioe.printStackTrace();
            } catch (ParsingException pe) {
                ErrorActivity.reportError(h, ChannelActivity.this, pe, VideoItemDetailFragment.class, null, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, service.getServiceInfo().name, channelUrl, R.string.parsing_error));
                h.post(new Runnable() {

                    @Override
                    public void run() {
                        ChannelActivity.this.finish();
                    }
                });
                pe.printStackTrace();
            } catch (ExtractionException ex) {
                String name = "none";
                if (service != null) {
                    name = service.getServiceInfo().name;
                }
                ErrorActivity.reportError(h, ChannelActivity.this, ex, VideoItemDetailFragment.class, null, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, name, channelUrl, R.string.parsing_error));
                h.post(new Runnable() {

                    @Override
                    public void run() {
                        ChannelActivity.this.finish();
                    }
                });
                ex.printStackTrace();
            } catch (Exception e) {
                ErrorActivity.reportError(h, ChannelActivity.this, e, VideoItemDetailFragment.class, null, ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_CHANNEL, service.getServiceInfo().name, channelUrl, R.string.general_error));
                h.post(new Runnable() {

                    @Override
                    public void run() {
                        ChannelActivity.this.finish();
                    }
                });
                e.printStackTrace();
            }
        }
    });
    channelExtractorThread.start();
}
Also used : Handler(android.os.Handler) ChannelInfo(org.schabi.newpipe.extractor.channel.ChannelInfo) StreamingService(org.schabi.newpipe.extractor.StreamingService) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) IOException(java.io.IOException) ChannelExtractor(org.schabi.newpipe.extractor.channel.ChannelExtractor) ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException)

Example 2 with ParsingException

use of org.schabi.newpipe.extractor.exceptions.ParsingException in project NewPipe by TeamNewPipe.

the class ExtractorHelper method handleGeneralException.

/**
 * A simple and general error handler that show a Toast for known exceptions, and for others, opens the report error activity with the (optional) error message.
 */
public static void handleGeneralException(Context context, int serviceId, String url, Throwable exception, UserAction userAction, String optionalErrorMessage) {
    final Handler handler = new Handler(context.getMainLooper());
    handler.post(() -> {
        if (exception instanceof ReCaptchaException) {
            Toast.makeText(context, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
            // Starting ReCaptcha Challenge Activity
            Intent intent = new Intent(context, ReCaptchaActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        } else if (exception instanceof IOException) {
            Toast.makeText(context, R.string.network_error, Toast.LENGTH_LONG).show();
        } else if (exception instanceof YoutubeStreamExtractor.GemaException) {
            Toast.makeText(context, R.string.blocked_by_gema, Toast.LENGTH_LONG).show();
        } else if (exception instanceof ContentNotAvailableException) {
            Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
        } else {
            int errorId = exception instanceof YoutubeStreamExtractor.DecryptException ? R.string.youtube_signature_decryption_error : exception instanceof ParsingException ? R.string.parsing_error : R.string.general_error;
            ErrorActivity.reportError(handler, context, exception, MainActivity.class, null, ErrorActivity.ErrorInfo.make(userAction, serviceId == -1 ? "none" : NewPipe.getNameOfService(serviceId), url + (optionalErrorMessage == null ? "" : optionalErrorMessage), errorId));
        }
    });
}
Also used : ParsingException(org.schabi.newpipe.extractor.exceptions.ParsingException) Handler(android.os.Handler) ContentNotAvailableException(org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException) Intent(android.content.Intent) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) MainActivity(org.schabi.newpipe.MainActivity) ReCaptchaException(org.schabi.newpipe.extractor.exceptions.ReCaptchaException)

Aggregations

Handler (android.os.Handler)2 IOException (java.io.IOException)2 ParsingException (org.schabi.newpipe.extractor.exceptions.ParsingException)2 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 InterruptedIOException (java.io.InterruptedIOException)1 MainActivity (org.schabi.newpipe.MainActivity)1 StreamingService (org.schabi.newpipe.extractor.StreamingService)1 ChannelExtractor (org.schabi.newpipe.extractor.channel.ChannelExtractor)1 ChannelInfo (org.schabi.newpipe.extractor.channel.ChannelInfo)1 ContentNotAvailableException (org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException)1 ExtractionException (org.schabi.newpipe.extractor.exceptions.ExtractionException)1 ReCaptchaException (org.schabi.newpipe.extractor.exceptions.ReCaptchaException)1