Search in sources :

Example 1 with ExtractionException

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

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

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

the class ContentSettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    homeDir = getActivity().getApplicationInfo().dataDir;
    databasesDir = new File(homeDir + "/databases");
    newpipe_db = new File(homeDir + "/databases/newpipe.db");
    newpipe_db_journal = new File(homeDir + "/databases/newpipe.db-journal");
    addPreferencesFromResource(R.xml.content_settings);
    final ListPreference mainPageContentPref = (ListPreference) findPreference(getString(R.string.main_page_content_key));
    mainPageContentPref.setOnPreferenceChangeListener((Preference preference, Object newValueO) -> {
        final String newValue = newValueO.toString();
        final String mainPrefOldValue = defaultPreferences.getString(getString(R.string.main_page_content_key), "blank_page");
        final String mainPrefOldSummary = getMainPagePrefSummery(mainPrefOldValue, mainPageContentPref);
        if (newValue.equals(getString(R.string.kiosk_page_key))) {
            SelectKioskFragment selectKioskFragment = new SelectKioskFragment();
            selectKioskFragment.setOnSelectedLisener((String kioskId, int service_id) -> {
                defaultPreferences.edit().putInt(getString(R.string.main_page_selected_service), service_id).apply();
                defaultPreferences.edit().putString(getString(R.string.main_page_selectd_kiosk_id), kioskId).apply();
                String serviceName = "";
                try {
                    serviceName = NewPipe.getService(service_id).getServiceInfo().getName();
                } catch (ExtractionException e) {
                    onError(e);
                }
                String kioskName = KioskTranslator.getTranslatedKioskName(kioskId, getContext());
                String summary = String.format(getString(R.string.service_kiosk_string), serviceName, kioskName);
                mainPageContentPref.setSummary(summary);
            });
            selectKioskFragment.setOnCancelListener(() -> {
                mainPageContentPref.setSummary(mainPrefOldSummary);
                mainPageContentPref.setValue(mainPrefOldValue);
            });
            selectKioskFragment.show(getFragmentManager(), "select_kiosk");
        } else if (newValue.equals(getString(R.string.channel_page_key))) {
            SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
            selectChannelFragment.setOnSelectedLisener((String url, String name, int service) -> {
                defaultPreferences.edit().putInt(getString(R.string.main_page_selected_service), service).apply();
                defaultPreferences.edit().putString(getString(R.string.main_page_selected_channel_url), url).apply();
                defaultPreferences.edit().putString(getString(R.string.main_page_selected_channel_name), name).apply();
                mainPageContentPref.setSummary(name);
            });
            selectChannelFragment.setOnCancelListener(() -> {
                mainPageContentPref.setSummary(mainPrefOldSummary);
                mainPageContentPref.setValue(mainPrefOldValue);
            });
            selectChannelFragment.show(getFragmentManager(), "select_channel");
        } else {
            mainPageContentPref.setSummary(getMainPageSummeryByKey(newValue));
        }
        defaultPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, true).apply();
        return true;
    });
    Preference importDataPreference = findPreference(getString(R.string.import_data));
    importDataPreference.setOnPreferenceClickListener((Preference p) -> {
        Intent i = new Intent(getActivity(), FilePickerActivityHelper.class).putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false).putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, false).putExtra(FilePickerActivityHelper.EXTRA_MODE, FilePickerActivityHelper.MODE_FILE);
        startActivityForResult(i, REQUEST_IMPORT_PATH);
        return true;
    });
    Preference exportDataPreference = findPreference(getString(R.string.export_data));
    exportDataPreference.setOnPreferenceClickListener((Preference p) -> {
        Intent i = new Intent(getActivity(), FilePickerActivityHelper.class).putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false).putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, true).putExtra(FilePickerActivityHelper.EXTRA_MODE, FilePickerActivityHelper.MODE_DIR);
        startActivityForResult(i, REQUEST_EXPORT_PATH);
        return true;
    });
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) FilePickerActivityHelper(org.schabi.newpipe.util.FilePickerActivityHelper) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 4 with ExtractionException

use of org.schabi.newpipe.extractor.exceptions.ExtractionException 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 5 with ExtractionException

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

the class SuggestionSearchRunnable method run.

@Override
public void run() {
    try {
        SuggestionExtractor se = NewPipe.getService(serviceId).getSuggestionExtractorInstance();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(a);
        String searchLanguageKey = a.getString(R.string.search_language_key);
        String searchLanguage = sp.getString(searchLanguageKey, a.getString(R.string.default_language_value));
        List<String> suggestions = se.suggestionList(query, searchLanguage);
        h.post(new SuggestionResultRunnable(suggestions));
    } catch (ExtractionException e) {
        ErrorActivity.reportError(h, a, e, null, a.findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, NewPipe.getNameOfService(serviceId), query, R.string.parsing_error));
        e.printStackTrace();
    } catch (IOException e) {
        postNewErrorToast(h, R.string.network_error);
        e.printStackTrace();
    } catch (Exception e) {
        ErrorActivity.reportError(h, a, e, null, a.findViewById(android.R.id.content), ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED, NewPipe.getNameOfService(serviceId), query, R.string.general_error));
    }
}
Also used : ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException) SharedPreferences(android.content.SharedPreferences) SuggestionExtractor(org.schabi.newpipe.extractor.SuggestionExtractor) IOException(java.io.IOException) IOException(java.io.IOException) ExtractionException(org.schabi.newpipe.extractor.exceptions.ExtractionException)

Aggregations

ExtractionException (org.schabi.newpipe.extractor.exceptions.ExtractionException)7 StreamingService (org.schabi.newpipe.extractor.StreamingService)4 Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 IOException (java.io.IOException)2 SubscriptionExtractor (org.schabi.newpipe.extractor.subscription.SubscriptionExtractor)2 SharedPreferences (android.content.SharedPreferences)1 Handler (android.os.Handler)1 StyleRes (android.support.annotation.StyleRes)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 File (java.io.File)1 ZipFile (java.util.zip.ZipFile)1 SuggestionExtractor (org.schabi.newpipe.extractor.SuggestionExtractor)1 ChannelExtractor (org.schabi.newpipe.extractor.channel.ChannelExtractor)1 ChannelInfo (org.schabi.newpipe.extractor.channel.ChannelInfo)1 ParsingException (org.schabi.newpipe.extractor.exceptions.ParsingException)1