Browse Source

Fix a variable name, add logging to upload video request and handle non json errors correctly.

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
4b6ab15e26
  1. 2
      app/src/main/java/awais/instagrabber/models/UploadVideoOptions.kt
  2. 39
      app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt
  3. 1
      app/src/main/java/awais/instagrabber/utils/MediaUploader.java
  4. 15
      app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java

2
app/src/main/java/awais/instagrabber/models/UploadVideoOptions.kt

@ -11,7 +11,7 @@ data class UploadVideoOptions(
val height: Int = 0,
val isSideCar: Boolean = false,
// Stories
val isForAlbum: Boolean = false,
val forAlbum: Boolean = false,
val isDirect: Boolean = false,
val isDirectVoice: Boolean = false,
val isForDirectStory: Boolean = false,

39
app/src/main/java/awais/instagrabber/utils/MediaUploadHelper.kt

@ -30,27 +30,24 @@ private fun createPhotoRuploadParams(options: UploadPhotoOptions): Map<String, S
).toMap()
}
private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, String> {
val retryContextString = retryContextString
return listOfNotNull(
"retry_context" to retryContextString,
"media_type" to "2",
"xsharing_user_ids" to "[]",
"upload_id" to options.uploadId,
"upload_media_width" to options.width.toString(),
"upload_media_height" to options.height.toString(),
"upload_media_duration_ms" to options.duration.toString(),
if (options.isSideCar) "is_sidecar" to "1" else null,
if (options.isForAlbum) "for_album" to "1" else null,
if (options.isDirect) "direct_v2" to "1" else null,
*(if (options.isForDirectStory) arrayOf(
"for_direct_story" to "1",
"content_tags" to ""
) else emptyArray()),
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
).toMap()
}
private fun createVideoRuploadParams(options: UploadVideoOptions): Map<String, String> = listOfNotNull(
"retry_context" to retryContextString,
"media_type" to "2",
"xsharing_user_ids" to "[]",
"upload_id" to options.uploadId,
"upload_media_width" to options.width.toString(),
"upload_media_height" to options.height.toString(),
"upload_media_duration_ms" to options.duration.toString(),
if (options.isSideCar) "is_sidecar" to "1" else null,
if (options.forAlbum) "for_album" to "1" else null,
if (options.isDirect) "direct_v2" to "1" else null,
*(if (options.isForDirectStory) arrayOf(
"for_direct_story" to "1",
"content_tags" to ""
) else emptyArray()),
if (options.isIgtvVideo) "is_igtv_video" to "1" else null,
if (options.isDirectVoice) "is_direct_voice" to "1" else null,
).toMap()
val retryContextString: String
get() {

1
app/src/main/java/awais/instagrabber/utils/MediaUploader.java

@ -110,6 +110,7 @@ public final class MediaUploader {
@NonNull final OnMediaUploadCompleteListener listener) {
try {
final OkHttpClient client = new OkHttpClient.Builder()
// .addInterceptor(new LoggingInterceptor())
.addInterceptor(new AddCookiesInterceptor())
.followRedirects(false)
.followSslRedirects(false)

15
app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.FragmentManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
@ -70,8 +71,18 @@ public class IgErrorsInterceptor implements Interceptor {
try {
final String bodyString = body.string();
Log.d(TAG, "checkError: " + bodyString);
final JSONObject jsonObject = new JSONObject(bodyString);
String message = jsonObject.optString("message");
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(bodyString);
} catch (JSONException e) {
Log.e(TAG, "checkError: ", e);
}
String message;
if (jsonObject != null) {
message = jsonObject.optString("message");
} else {
message = bodyString;
}
if (!TextUtils.isEmpty(message)) {
message = message.toLowerCase();
switch (message) {

Loading…
Cancel
Save