From 1ae54f6f8c62a487bfd72c03c6edf431b4a221cc Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 23 Dec 2018 22:07:27 +0100 Subject: [PATCH] further compatiblity fix for meadic.ccc --- app/build.gradle | 2 +- .../fragments/detail/VideoDetailFragment.java | 21 +++++++++++++------ .../list/channel/ChannelFragment.java | 4 ++-- .../resolver/VideoPlaybackResolver.java | 18 +++++++++------- .../schabi/newpipe/util/ExtractorHelper.java | 13 ++++++++---- .../newpipe/util/StreamItemAdapter.java | 14 +++++++++---- app/src/main/res/values/colors_services.xml | 11 ++++++++++ 7 files changed, 58 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 782634a0b..59cf01e89 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.TeamNewPipe:NewPipeExtractor:f7c7b9df1a' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:73232a7ba' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index edca200d7..6738083c3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -55,6 +55,7 @@ import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; @@ -699,13 +700,13 @@ public class VideoDetailFragment switch (id) { case R.id.menu_item_share: { if (currentInfo != null) { - shareUrl(currentInfo.getName(), currentInfo.getUrl()); + shareUrl(currentInfo.getName(), currentInfo.getOriginalUrl()); } return true; } case R.id.menu_item_openInBrowser: { if (currentInfo != null) { - openUrlInBrowser(currentInfo.getUrl()); + openUrlInBrowser(currentInfo.getOriginalUrl()); } return true; } @@ -1269,10 +1270,18 @@ public class VideoDetailFragment downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog"); } catch (Exception e) { - Toast.makeText(activity, - R.string.could_not_setup_download_menu, - Toast.LENGTH_LONG).show(); - e.printStackTrace(); + ErrorActivity.ErrorInfo info = ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + ServiceList.all() + .get(currentInfo + .getServiceId()) + .getServiceInfo() + .getName(), "", + R.string.could_not_setup_download_menu); + + ErrorActivity.reportError(getActivity(), + e, + getActivity().getClass(), + getActivity().findViewById(android.R.id.content), info); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 6a3b3eb50..b9489ffa7 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -233,10 +233,10 @@ public class ChannelFragment extends BaseListInfoFragment { openRssFeed(); break; case R.id.menu_item_openInBrowser: - openUrlInBrowser(url); + openUrlInBrowser(currentInfo.getOriginalUrl()); break; case R.id.menu_item_share: - shareUrl(name, url); + shareUrl(name, currentInfo.getOriginalUrl()); break; default: return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java b/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java index ad2b79523..c62dc1088 100644 --- a/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java +++ b/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java @@ -93,15 +93,17 @@ public class VideoPlaybackResolver implements PlaybackResolver { // Below are auxiliary media sources // Create subtitle sources - for (final SubtitlesStream subtitle : info.getSubtitles()) { - final String mimeType = PlayerHelper.subtitleMimeTypesOf(subtitle.getFormat()); - if (mimeType == null) continue; + if(info.getSubtitles() != null) { + for (final SubtitlesStream subtitle : info.getSubtitles()) { + final String mimeType = PlayerHelper.subtitleMimeTypesOf(subtitle.getFormat()); + if (mimeType == null) continue; - final Format textFormat = Format.createTextSampleFormat(null, mimeType, - SELECTION_FLAG_AUTOSELECT, PlayerHelper.captionLanguageOf(context, subtitle)); - final MediaSource textSource = dataSource.getSampleMediaSourceFactory() - .createMediaSource(Uri.parse(subtitle.getURL()), textFormat, TIME_UNSET); - mediaSources.add(textSource); + final Format textFormat = Format.createTextSampleFormat(null, mimeType, + SELECTION_FLAG_AUTOSELECT, PlayerHelper.captionLanguageOf(context, subtitle)); + final MediaSource textSource = dataSource.getSampleMediaSourceFactory() + .createMediaSource(Uri.parse(subtitle.getURL()), textFormat, TIME_UNSET); + mediaSources.add(textSource); + } } if (mediaSources.size() == 1) { diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index e04c1e8d0..041f4933f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -31,6 +31,7 @@ import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.SuggestionExtractor; import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; @@ -46,6 +47,7 @@ import org.schabi.newpipe.report.UserAction; import java.io.IOException; import java.io.InterruptedIOException; +import java.util.Collections; import java.util.List; import io.reactivex.Maybe; @@ -95,10 +97,13 @@ public final class ExtractorHelper { public static Single> suggestionsFor(final int serviceId, final String query) { checkServiceId(serviceId); - return Single.fromCallable(() -> - NewPipe.getService(serviceId) - .getSuggestionExtractor() - .suggestionList(query)); + return Single.fromCallable(() -> { + SuggestionExtractor extractor = NewPipe.getService(serviceId) + .getSuggestionExtractor(); + return extractor != null + ? extractor.suggestionList(query) + : Collections.emptyList(); + }); } public static Single getStreamInfo(final int serviceId, diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java b/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java index eb106f91d..49a7125ed 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java @@ -28,7 +28,8 @@ import io.reactivex.schedulers.Schedulers; import us.shandian.giga.util.Utility; /** - * A list adapter for a list of {@link Stream streams}, currently supporting {@link VideoStream} and {@link AudioStream}. + * A list adapter for a list of {@link Stream streams}, + * currently supporting {@link VideoStream}, {@link AudioStream} and {@link SubtitlesStream} */ public class StreamItemAdapter extends BaseAdapter { private final Context context; @@ -110,7 +111,10 @@ public class StreamItemAdapter extends BaseA } } } else if (stream instanceof AudioStream) { - qualityString = ((AudioStream) stream).getAverageBitrate() + "kbps"; + AudioStream audioStream = ((AudioStream) stream); + qualityString = audioStream.getAverageBitrate() > 0 + ? audioStream.getAverageBitrate() + "kbps" + : audioStream.getFormat().getName(); } else if (stream instanceof SubtitlesStream) { qualityString = ((SubtitlesStream) stream).getDisplayLanguageName(); if (((SubtitlesStream) stream).isAutoGenerated()) { @@ -154,8 +158,10 @@ public class StreamItemAdapter extends BaseA private final long[] streamSizes; private final String unknownSize; - public StreamSizeWrapper(List streamsList, Context context) { - this.streamsList = streamsList; + public StreamSizeWrapper(List sL, Context context) { + this.streamsList = sL != null + ? sL + : Collections.emptyList(); this.streamSizes = new long[streamsList.size()]; this.unknownSize = context == null ? "--.-" : context.getString(R.string.unknown_content); diff --git a/app/src/main/res/values/colors_services.xml b/app/src/main/res/values/colors_services.xml index 761b721d0..1cc464280 100644 --- a/app/src/main/res/values/colors_services.xml +++ b/app/src/main/res/values/colors_services.xml @@ -22,4 +22,15 @@ #FFFFFF #ff9100 + + #888888 + #555555 + #000000 + #777777 + + #888888 + #555555 + #FFFFFF + #777777 + \ No newline at end of file