Search in sources :

Example 1 with ChannelInfo

use of org.schabi.newpipe.extractor.channel.ChannelInfo 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 ChannelInfo

use of org.schabi.newpipe.extractor.channel.ChannelInfo in project NewPipe by TeamNewPipe.

the class FeedFragment method getChannelInfoObserver.

/**
 * On each request, a subscription item from the updated table is transformed
 * into a ChannelInfo, containing the latest streams from the channel.
 * <p>
 * Currently, the feed uses the first into from the list of streams.
 * <p>
 * If chosen feed already displayed, then we request another feed from another
 * subscription, until the subscription table runs out of new items.
 * <p>
 * This Observer is self-contained and will dispose itself when complete. However, this
 * does not obey the fragment lifecycle and may continue running in the background
 * until it is complete. This is done due to RxJava2 no longer propagate errors once
 * an observer is unsubscribed while the thread process is still running.
 * <p>
 * To solve the above issue, we can either set a global RxJava Error Handler, or
 * manage exceptions case by case. This should be done if the current implementation is
 * too costly when dealing with larger subscription sets.
 *
 * @param url + serviceId to put in {@link #allItemsLoaded} to signal that this specific entity has been loaded.
 */
private MaybeObserver<ChannelInfo> getChannelInfoObserver(final int serviceId, final String url) {
    return new MaybeObserver<ChannelInfo>() {

        private Disposable observer;

        @Override
        public void onSubscribe(Disposable d) {
            observer = d;
            compositeDisposable.add(d);
            isLoading.set(true);
        }

        // Called only when response is non-empty
        @Override
        public void onSuccess(final ChannelInfo channelInfo) {
            if (infoListAdapter == null || channelInfo.getRelatedItems().isEmpty()) {
                onDone();
                return;
            }
            final InfoItem item = channelInfo.getRelatedItems().get(0);
            // Keep requesting new items if the current one already exists
            boolean itemExists = doesItemExist(infoListAdapter.getItemsList(), item);
            if (!itemExists) {
                infoListAdapter.addInfoItem(item);
            // updateSubscription(channelInfo);
            } else {
                requestFeed(1);
            }
            onDone();
        }

        @Override
        public void onError(Throwable exception) {
            showSnackBarError(exception, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(serviceId), url, 0);
            requestFeed(1);
            onDone();
        }

        // Called only when response is empty
        @Override
        public void onComplete() {
            onDone();
        }

        private void onDone() {
            if (observer.isDisposed()) {
                return;
            }
            itemsLoaded.add(serviceId + url);
            compositeDisposable.remove(observer);
            int loaded = requestLoadedAtomic.incrementAndGet();
            if (loaded >= Math.min(FEED_LOAD_COUNT, subscriptionPoolSize)) {
                requestLoadedAtomic.set(0);
                isLoading.set(false);
            }
            if (itemsLoaded.size() == subscriptionPoolSize) {
                if (DEBUG)
                    Log.d(TAG, "getChannelInfoObserver > All Items Loaded");
                allItemsLoaded.set(true);
                showListFooter(false);
                isLoading.set(false);
                hideLoading();
                if (infoListAdapter.getItemsList().size() == 0) {
                    showEmptyState();
                }
            }
        }
    };
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) MaybeObserver(io.reactivex.MaybeObserver) InfoItem(org.schabi.newpipe.extractor.InfoItem) ChannelInfo(org.schabi.newpipe.extractor.channel.ChannelInfo)

Example 3 with ChannelInfo

use of org.schabi.newpipe.extractor.channel.ChannelInfo in project NewPipe by TeamNewPipe.

the class ChannelFragment method openRssFeed.

private void openRssFeed() {
    final ChannelInfo info = currentInfo;
    if (info != null) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(info.getFeedUrl()));
        startActivity(intent);
    }
}
Also used : ChannelInfo(org.schabi.newpipe.extractor.channel.ChannelInfo) Intent(android.content.Intent)

Aggregations

ChannelInfo (org.schabi.newpipe.extractor.channel.ChannelInfo)3 Intent (android.content.Intent)1 Handler (android.os.Handler)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 MaybeObserver (io.reactivex.MaybeObserver)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 IOException (java.io.IOException)1 InfoItem (org.schabi.newpipe.extractor.InfoItem)1 StreamingService (org.schabi.newpipe.extractor.StreamingService)1 ChannelExtractor (org.schabi.newpipe.extractor.channel.ChannelExtractor)1 ExtractionException (org.schabi.newpipe.extractor.exceptions.ExtractionException)1 ParsingException (org.schabi.newpipe.extractor.exceptions.ParsingException)1