Search in sources :

Example 1 with StreamingService

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

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

the class NavigationHelper method getIntentByLink.

public static Intent getIntentByLink(Context context, StreamingService service, String url) throws ExtractionException {
    StreamingService.LinkType linkType = service.getLinkTypeByUrl(url);
    if (linkType == StreamingService.LinkType.NONE) {
        throw new ExtractionException("Url not known to service. service=" + service + " url=" + url);
    }
    url = getCleanUrl(service, url, linkType);
    Intent rIntent = getOpenIntent(context, url, service.getServiceId(), linkType);
    switch(linkType) {
        case STREAM:
            rIntent.putExtra(VideoDetailFragment.AUTO_PLAY, PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.autoplay_through_intent_key), false));
            break;
    }
    return rIntent;
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) Intent(android.content.Intent) StreamingService(org.schabi.newpipe.extractor.StreamingService)

Example 3 with StreamingService

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

the class ThemeHelper method getThemeForService.

/**
 * Return the selected theme styled according to the serviceId.
 *
 * @param context   context to get the selected theme
 * @param serviceId return a theme styled to this service,
 *                  -1 to get the default
 * @return the selected style (styled)
 */
@StyleRes
public static int getThemeForService(Context context, int serviceId) {
    String lightTheme = context.getResources().getString(R.string.light_theme_key);
    String darkTheme = context.getResources().getString(R.string.dark_theme_key);
    String blackTheme = context.getResources().getString(R.string.black_theme_key);
    String selectedTheme = getSelectedThemeString(context);
    int defaultTheme = R.style.DarkTheme;
    if (selectedTheme.equals(lightTheme))
        defaultTheme = R.style.LightTheme;
    else if (selectedTheme.equals(blackTheme))
        defaultTheme = R.style.BlackTheme;
    else if (selectedTheme.equals(darkTheme))
        defaultTheme = R.style.DarkTheme;
    if (serviceId <= -1) {
        return defaultTheme;
    }
    final StreamingService service;
    try {
        service = NewPipe.getService(serviceId);
    } catch (ExtractionException ignored) {
        return defaultTheme;
    }
    String themeName = "DarkTheme";
    if (selectedTheme.equals(lightTheme))
        themeName = "LightTheme";
    else if (selectedTheme.equals(blackTheme))
        themeName = "BlackTheme";
    else if (selectedTheme.equals(darkTheme))
        themeName = "DarkTheme";
    themeName += "." + service.getServiceInfo().getName();
    int resourceId = context.getResources().getIdentifier(themeName, "style", context.getPackageName());
    if (resourceId > 0) {
        return resourceId;
    }
    return defaultTheme;
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) StreamingService(org.schabi.newpipe.extractor.StreamingService) StyleRes(android.support.annotation.StyleRes)

Example 4 with StreamingService

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

the class PopupActivity method handleIntent.

private void handleIntent(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(this)) {
        Toast.makeText(this, R.string.msg_popup_permission, Toast.LENGTH_LONG).show();
        return;
    }
    String videoUrl = "";
    StreamingService service = null;
    // first gather data and find service
    if (intent.getData() != null) {
        // this means the video was called though another app
        videoUrl = intent.getData().toString();
    } else if (intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
        //this means that vidoe was called through share menu
        String extraText = intent.getStringExtra(Intent.EXTRA_TEXT);
        videoUrl = getUris(extraText)[0];
    }
    service = NewPipe.getServiceByUrl(videoUrl);
    if (service == null) {
        Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
        return;
    } else {
        Intent callIntent = new Intent();
        switch(service.getLinkTypeByUrl(videoUrl)) {
            case STREAM:
                callIntent.setClass(this, PopupVideoPlayer.class);
                break;
            case PLAYLIST:
                Log.e(TAG, "NOT YET DEFINED");
                break;
            default:
                Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
                return;
        }
        callIntent.putExtra(NavStack.URL, videoUrl);
        callIntent.putExtra(NavStack.SERVICE_ID, service.getServiceId());
        startService(callIntent);
    }
}
Also used : Intent(android.content.Intent) StreamingService(org.schabi.newpipe.extractor.StreamingService)

Example 5 with StreamingService

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

the class RouterActivity method handleIntent.

private void handleIntent(Intent intent) {
    String videoUrl = "";
    StreamingService service = null;
    // first gather data and find service
    if (intent.getData() != null) {
        // this means the video was called though another app
        videoUrl = intent.getData().toString();
    } else if (intent.getStringExtra(Intent.EXTRA_TEXT) != null) {
        //this means that vidoe was called through share menu
        String extraText = intent.getStringExtra(Intent.EXTRA_TEXT);
        videoUrl = getUris(extraText)[0];
    }
    service = NewPipe.getServiceByUrl(videoUrl);
    if (service == null) {
        Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
        return;
    } else {
        Intent callIntent = new Intent();
        switch(service.getLinkTypeByUrl(videoUrl)) {
            case CHANNEL:
                callIntent.setClass(this, ChannelActivity.class);
                break;
            case STREAM:
                callIntent.setClass(this, VideoItemDetailActivity.class);
                callIntent.putExtra(VideoItemDetailFragment.AUTO_PLAY, PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.autoplay_through_intent_key), false));
                break;
            case PLAYLIST:
                Log.e(TAG, "NOT YET DEFINED");
                break;
            default:
                Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG).show();
                return;
        }
        callIntent.putExtra(NavStack.URL, videoUrl);
        callIntent.putExtra(NavStack.SERVICE_ID, service.getServiceId());
        startActivity(callIntent);
    }
}
Also used : Intent(android.content.Intent) StreamingService(org.schabi.newpipe.extractor.StreamingService)

Aggregations

StreamingService (org.schabi.newpipe.extractor.StreamingService)12 ExtractionException (org.schabi.newpipe.extractor.exceptions.ExtractionException)5 Intent (android.content.Intent)4 View (android.view.View)3 TextView (android.widget.TextView)3 IOException (java.io.IOException)3 Handler (android.os.Handler)2 RecyclerView (android.support.v7.widget.RecyclerView)2 MenuItem (android.view.MenuItem)2 ImageView (android.widget.ImageView)2 ParsingException (org.schabi.newpipe.extractor.exceptions.ParsingException)2 StyleRes (android.support.annotation.StyleRes)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 Toolbar (android.support.v7.widget.Toolbar)1 Consumer (io.reactivex.functions.Consumer)1 InterruptedIOException (java.io.InterruptedIOException)1