diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index bb1130fdf..df2f8454d 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -5,8 +5,8 @@ import android.os.Handler; import android.util.Log; import android.view.View; -import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.stream_info.StreamExtractor; import org.schabi.newpipe.extractor.stream_info.StreamInfo; import org.schabi.newpipe.report.ErrorActivity; @@ -44,6 +44,7 @@ public class StreamInfoWorker { public interface OnStreamInfoReceivedListener { void onReceive(StreamInfo info); void onError(int messageId); + void onReCaptchaException(); void onBlockedByGemaError(); void onContentErrorWithMessage(int messageId); void onContentError(); @@ -107,6 +108,13 @@ public class StreamInfoWorker { } // These errors render the stream information unusable. + } catch (ReCaptchaException e) { + h.post(new Runnable() { + @Override + public void run() { + onStreamInfoReceivedListener.onReCaptchaException(); + } + }); } catch (IOException e) { h.post(new Runnable() { @Override diff --git a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java index 1fa80175f..d44b7887e 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/detail/VideoItemDetailFragment.java @@ -43,6 +43,7 @@ import java.util.Vector; import org.schabi.newpipe.ActivityCommunicator; import org.schabi.newpipe.ChannelActivity; +import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.stream_info.StreamInfo; import org.schabi.newpipe.extractor.stream_info.StreamPreviewInfo; import org.schabi.newpipe.info_list.InfoItemBuilder; @@ -59,6 +60,9 @@ import org.schabi.newpipe.player.BackgroundPlayer; import org.schabi.newpipe.player.PlayVideoActivity; import org.schabi.newpipe.player.ExoPlayerActivity; +import static android.app.Activity.RESULT_OK; +import static org.schabi.newpipe.ReCaptchaActivity.RECAPTCHA_REQUEST; + /** * Copyright (C) Christian Schabesberger 2015 @@ -604,6 +608,17 @@ public class VideoItemDetailFragment extends Fragment { postNewErrorToast(messageId); } + @Override + public void onReCaptchaException() { + Toast.makeText(getActivity(), R.string.recaptcha_request_toast, + Toast.LENGTH_LONG).show(); + + // Starting ReCaptcha Challenge Activity + startActivityForResult( + new Intent(getActivity(), ReCaptchaActivity.class), + RECAPTCHA_REQUEST); + } + @Override public void onBlockedByGemaError() { onErrorBlockedByGema(); @@ -793,4 +808,23 @@ public class VideoItemDetailFragment extends Fragment { VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId); activity.startActivity(detailIntent); } -} \ No newline at end of file + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case RECAPTCHA_REQUEST: + if (resultCode == RESULT_OK) { + String videoUrl = getArguments().getString(VIDEO_URL); + StreamInfoWorker siw = StreamInfoWorker.getInstance(); + siw.search(streamingServiceId, videoUrl, getActivity()); + } else { + Log.d(TAG, "ReCaptcha failed"); + } + break; + + default: + Log.e(TAG, "Request code from activity not supported [" + requestCode + "]"); + break; + } + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 208cac70d..bdada975d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -271,6 +271,7 @@ Settings reCaptcha reCaptcha Challenge + ReCaptcha Challenge requested