1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-09-28 07:08:23 +00:00

Start reCaptcha activity when starting video directly

This commit is contained in:
Benoît Mauduit 2017-01-03 14:22:07 +01:00
parent c87da9903f
commit 143df9a529
3 changed files with 45 additions and 2 deletions

View File

@ -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

View File

@ -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 <chris.schabesberger@mailbox.org>
@ -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);
}
}
@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;
}
}
}

View File

@ -271,6 +271,7 @@
<string name="action_settings">Settings</string>
<string name="reCaptchaActivity">reCaptcha</string>
<string name="reCaptcha_title">reCaptcha Challenge</string>
<string name="recaptcha_request_toast">ReCaptcha Challenge requested</string>
<!-- End of GigaGet's Strings -->