mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
let avatar viewer show one-off stories, redo avatar fetcher
This commit is contained in:
parent
c40a0033db
commit
fbd3212d83
@ -40,51 +40,34 @@ public final class ProfilePictureFetcher extends AsyncTask<Void, Void, String> {
|
|||||||
protected String doInBackground(final Void... voids) {
|
protected String doInBackground(final Void... voids) {
|
||||||
String out = null;
|
String out = null;
|
||||||
if (isHashtag) out = picUrl;
|
if (isHashtag) out = picUrl;
|
||||||
else try {
|
else if (Utils.settingsHelper.getBoolean(Constants.INSTADP)) try {
|
||||||
final HttpURLConnection conn =
|
final HttpURLConnection backup =
|
||||||
(HttpURLConnection) new URL("https://i.instagram.com/api/v1/users/"+userId+"/info/").openConnection();
|
(HttpURLConnection) new URL("https://instadp.com/fullsize/" + userName).openConnection();
|
||||||
conn.setUseCaches(false);
|
backup.setUseCaches(false);
|
||||||
conn.setRequestMethod("GET");
|
backup.setRequestMethod("GET");
|
||||||
conn.setRequestProperty("User-Agent", Constants.USER_AGENT);
|
backup.setRequestProperty("User-Agent", Constants.A_USER_AGENT);
|
||||||
|
|
||||||
final String result = conn.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(conn) : null;
|
final String instadp = backup.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(backup) : null;
|
||||||
conn.disconnect();
|
backup.disconnect();
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(result)) {
|
if (!TextUtils.isEmpty(instadp)) {
|
||||||
JSONObject data = new JSONObject(result).getJSONObject("user");
|
final Document doc = Jsoup.parse(instadp);
|
||||||
if (data.has("hd_profile_pic_url_info"))
|
boolean fallback = false;
|
||||||
out = data.getJSONObject("hd_profile_pic_url_info").optString("url");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(out) && Utils.settingsHelper.getBoolean(Constants.INSTADP)) {
|
final int imgIndex = instadp.indexOf("preloadImg('"), lastIndex;
|
||||||
final HttpURLConnection backup =
|
|
||||||
(HttpURLConnection) new URL("https://instadp.com/fullsize/" + userName).openConnection();
|
|
||||||
backup.setUseCaches(false);
|
|
||||||
backup.setRequestMethod("GET");
|
|
||||||
backup.setRequestProperty("User-Agent", Constants.A_USER_AGENT);
|
|
||||||
|
|
||||||
final String instadp = backup.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(backup) : null;
|
Element element = doc.selectFirst(".instadp");
|
||||||
backup.disconnect();
|
if (element != null && (element = element.selectFirst(".picture")) != null)
|
||||||
|
out = element.attr("src");
|
||||||
if (!TextUtils.isEmpty(instadp)) {
|
else if ((element = doc.selectFirst(".download-btn")) != null)
|
||||||
final Document doc = Jsoup.parse(instadp);
|
out = element.attr("href");
|
||||||
boolean fallback = false;
|
else if (imgIndex != -1 && (lastIndex = instadp.indexOf("')", imgIndex)) != -1)
|
||||||
|
out = instadp.substring(imgIndex + 12, lastIndex);
|
||||||
final int imgIndex = instadp.indexOf("preloadImg('"), lastIndex;
|
else {
|
||||||
|
final Elements imgs = doc.getElementsByTag("img");
|
||||||
Element element = doc.selectFirst(".instadp");
|
for (final Element img : imgs) {
|
||||||
if (element != null && (element = element.selectFirst(".picture")) != null)
|
final String imgStr = img.toString();
|
||||||
out = element.attr("src");
|
if (imgStr.contains("cdninstagram.com")) out = img.attr("src");
|
||||||
else if ((element = doc.selectFirst(".download-btn")) != null)
|
|
||||||
out = element.attr("href");
|
|
||||||
else if (imgIndex != -1 && (lastIndex = instadp.indexOf("')", imgIndex)) != -1)
|
|
||||||
out = instadp.substring(imgIndex + 12, lastIndex);
|
|
||||||
else {
|
|
||||||
final Elements imgs = doc.getElementsByTag("img");
|
|
||||||
for (final Element img : imgs) {
|
|
||||||
final String imgStr = img.toString();
|
|
||||||
if (imgStr.contains("cdninstagram.com")) out = img.attr("src");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -19,6 +20,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||||
import com.facebook.drawee.controller.BaseControllerListener;
|
import com.facebook.drawee.controller.BaseControllerListener;
|
||||||
@ -30,9 +32,20 @@ import java.io.File;
|
|||||||
import awais.instagrabber.R;
|
import awais.instagrabber.R;
|
||||||
import awais.instagrabber.asyncs.ProfilePictureFetcher;
|
import awais.instagrabber.asyncs.ProfilePictureFetcher;
|
||||||
import awais.instagrabber.databinding.DialogProfilepicBinding;
|
import awais.instagrabber.databinding.DialogProfilepicBinding;
|
||||||
|
import awais.instagrabber.db.entities.Account;
|
||||||
|
import awais.instagrabber.db.repositories.RepositoryCallback;
|
||||||
import awais.instagrabber.interfaces.FetchListener;
|
import awais.instagrabber.interfaces.FetchListener;
|
||||||
|
import awais.instagrabber.models.StoryModel;
|
||||||
|
import awais.instagrabber.repositories.responses.UserInfo;
|
||||||
|
import awais.instagrabber.utils.Constants;
|
||||||
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.DownloadUtils;
|
import awais.instagrabber.utils.DownloadUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
import awais.instagrabber.webservices.ProfileService;
|
||||||
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
|
import awais.instagrabber.webservices.StoriesService;
|
||||||
|
|
||||||
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
|
|
||||||
public class ProfilePicDialogFragment extends DialogFragment {
|
public class ProfilePicDialogFragment extends DialogFragment {
|
||||||
private static final String TAG = "ProfilePicDlgFragment";
|
private static final String TAG = "ProfilePicDlgFragment";
|
||||||
@ -41,9 +54,15 @@ public class ProfilePicDialogFragment extends DialogFragment {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String fallbackUrl;
|
private final String fallbackUrl;
|
||||||
|
|
||||||
|
private boolean isLoggedIn;
|
||||||
private DialogProfilepicBinding binding;
|
private DialogProfilepicBinding binding;
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
private final FetchListener<String> fetchListener = profileUrl -> {
|
||||||
|
url = profileUrl;
|
||||||
|
setupPhoto();
|
||||||
|
};
|
||||||
|
|
||||||
public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) {
|
public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -55,6 +74,8 @@ public class ProfilePicDialogFragment extends DialogFragment {
|
|||||||
final ViewGroup container,
|
final ViewGroup container,
|
||||||
final Bundle savedInstanceState) {
|
final Bundle savedInstanceState) {
|
||||||
binding = DialogProfilepicBinding.inflate(inflater, container, false);
|
binding = DialogProfilepicBinding.inflate(inflater, container, false);
|
||||||
|
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||||
|
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +104,8 @@ public class ProfilePicDialogFragment extends DialogFragment {
|
|||||||
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
init();
|
init();
|
||||||
fetchPhoto();
|
if (id.contains("_")) fetchStory();
|
||||||
|
else fetchAvatar();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
@ -106,37 +128,75 @@ public class ProfilePicDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchPhoto() {
|
private void fetchAvatar() {
|
||||||
final FetchListener<String> fetchListener = profileUrl -> {
|
if (isLoggedIn) {
|
||||||
url = profileUrl;
|
final ProfileService profileService = ProfileService.getInstance();
|
||||||
if (TextUtils.isEmpty(url)) {
|
profileService.getUserInfo(id, new ServiceCallback<UserInfo>() {
|
||||||
url = fallbackUrl;
|
@Override
|
||||||
}
|
public void onSuccess(final UserInfo result) {
|
||||||
final DraweeController controller = Fresco
|
if (result != null) {
|
||||||
.newDraweeControllerBuilder()
|
fetchListener.onResult(result.getHDProfilePicUrl());
|
||||||
.setUri(url)
|
}
|
||||||
.setOldController(binding.imageViewer.getController())
|
}
|
||||||
.setControllerListener(new BaseControllerListener<ImageInfo>() {
|
|
||||||
@Override
|
|
||||||
public void onFailure(final String id, final Throwable throwable) {
|
|
||||||
super.onFailure(id, throwable);
|
|
||||||
binding.download.setVisibility(View.GONE);
|
|
||||||
binding.progressView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinalImageSet(final String id,
|
public void onFailure(final Throwable t) {
|
||||||
final ImageInfo imageInfo,
|
final Context context = getContext();
|
||||||
final Animatable animatable) {
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||||
super.onFinalImageSet(id, imageInfo, animatable);
|
getDialog().dismiss();
|
||||||
binding.download.setVisibility(View.VISIBLE);
|
}
|
||||||
binding.progressView.setVisibility(View.GONE);
|
});
|
||||||
}
|
}
|
||||||
})
|
else new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
.build();
|
}
|
||||||
binding.imageViewer.setController(controller);
|
|
||||||
};
|
private void fetchStory() {
|
||||||
new ProfilePictureFetcher(name, id, fetchListener, url, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
final StoriesService storiesService = StoriesService.getInstance();
|
||||||
|
storiesService.fetch(id, new ServiceCallback<StoryModel>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(final StoryModel result) {
|
||||||
|
if (result != null) {
|
||||||
|
fetchListener.onResult(result.getStoryUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(final Throwable t) {
|
||||||
|
final Context context = getContext();
|
||||||
|
Log.d("austin_debug", "error", t);
|
||||||
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||||
|
getDialog().dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupPhoto() {
|
||||||
|
if (TextUtils.isEmpty(url)) {
|
||||||
|
url = fallbackUrl;
|
||||||
|
}
|
||||||
|
final DraweeController controller = Fresco
|
||||||
|
.newDraweeControllerBuilder()
|
||||||
|
.setUri(url)
|
||||||
|
.setOldController(binding.imageViewer.getController())
|
||||||
|
.setControllerListener(new BaseControllerListener<ImageInfo>() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(final String id, final Throwable throwable) {
|
||||||
|
super.onFailure(id, throwable);
|
||||||
|
binding.download.setVisibility(View.GONE);
|
||||||
|
binding.progressView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinalImageSet(final String id,
|
||||||
|
final ImageInfo imageInfo,
|
||||||
|
final Animatable animatable) {
|
||||||
|
super.onFinalImageSet(id, imageInfo, animatable);
|
||||||
|
binding.download.setVisibility(View.VISIBLE);
|
||||||
|
binding.progressView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
binding.imageViewer.setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadProfilePicture() {
|
private void downloadProfilePicture() {
|
||||||
|
@ -14,6 +14,9 @@ import retrofit2.http.QueryMap;
|
|||||||
import retrofit2.http.Url;
|
import retrofit2.http.Url;
|
||||||
|
|
||||||
public interface StoriesRepository {
|
public interface StoriesRepository {
|
||||||
|
@GET("/api/v1/media/{mediaId}/info/")
|
||||||
|
Call<String> fetch(@Path("mediaId") final String mediaId);
|
||||||
|
// this one is the same as MediaRepository.fetch BUT you need to make sure it's a story
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("/api/v1/feed/reels_tray/")
|
@POST("/api/v1/feed/reels_tray/")
|
||||||
|
@ -2,15 +2,18 @@ package awais.instagrabber.repositories.responses;
|
|||||||
|
|
||||||
public class UserInfo {
|
public class UserInfo {
|
||||||
private final String pk;
|
private final String pk;
|
||||||
private final String username;
|
private final String username, fullName, profilePicUrl, hdProfilePicUrl;
|
||||||
private final String fullName;
|
|
||||||
private final String profilePicUrl;
|
|
||||||
|
|
||||||
public UserInfo(final String pk, final String username, final String fullName, final String profilePicUrl) {
|
public UserInfo(final String pk,
|
||||||
|
final String username,
|
||||||
|
final String fullName,
|
||||||
|
final String profilePicUrl,
|
||||||
|
final String hdProfilePicUrl) {
|
||||||
this.pk = pk;
|
this.pk = pk;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.fullName = fullName;
|
this.fullName = fullName;
|
||||||
this.profilePicUrl = profilePicUrl;
|
this.profilePicUrl = profilePicUrl;
|
||||||
|
this.hdProfilePicUrl = hdProfilePicUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPk() {
|
public String getPk() {
|
||||||
@ -29,6 +32,10 @@ public class UserInfo {
|
|||||||
return profilePicUrl;
|
return profilePicUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHDProfilePicUrl() {
|
||||||
|
return hdProfilePicUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "UserInfo{" +
|
return "UserInfo{" +
|
||||||
@ -36,6 +43,7 @@ public class UserInfo {
|
|||||||
", username='" + username + '\'' +
|
", username='" + username + '\'' +
|
||||||
", fullName='" + fullName + '\'' +
|
", fullName='" + fullName + '\'' +
|
||||||
", profilePicUrl='" + profilePicUrl + '\'' +
|
", profilePicUrl='" + profilePicUrl + '\'' +
|
||||||
|
", hdProfilePicUrl='" + hdProfilePicUrl + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import awais.instagrabber.BuildConfig;
|
|||||||
import awais.instagrabber.models.FeedModel;
|
import awais.instagrabber.models.FeedModel;
|
||||||
import awais.instagrabber.models.PostChild;
|
import awais.instagrabber.models.PostChild;
|
||||||
import awais.instagrabber.models.ProfileModel;
|
import awais.instagrabber.models.ProfileModel;
|
||||||
|
import awais.instagrabber.models.StoryModel;
|
||||||
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
import awais.instagrabber.models.direct_messages.DirectItemModel;
|
||||||
import awais.instagrabber.models.direct_messages.InboxThreadModel;
|
import awais.instagrabber.models.direct_messages.InboxThreadModel;
|
||||||
import awais.instagrabber.models.enums.DirectItemType;
|
import awais.instagrabber.models.enums.DirectItemType;
|
||||||
@ -25,6 +26,11 @@ import awais.instagrabber.models.enums.InboxReadState;
|
|||||||
import awais.instagrabber.models.enums.MediaItemType;
|
import awais.instagrabber.models.enums.MediaItemType;
|
||||||
import awais.instagrabber.models.enums.RavenExpiringMediaType;
|
import awais.instagrabber.models.enums.RavenExpiringMediaType;
|
||||||
import awais.instagrabber.models.enums.RavenMediaViewType;
|
import awais.instagrabber.models.enums.RavenMediaViewType;
|
||||||
|
import awais.instagrabber.models.stickers.PollModel;
|
||||||
|
import awais.instagrabber.models.stickers.QuestionModel;
|
||||||
|
import awais.instagrabber.models.stickers.QuizModel;
|
||||||
|
import awais.instagrabber.models.stickers.SliderModel;
|
||||||
|
import awais.instagrabber.models.stickers.SwipeUpModel;
|
||||||
import awaisomereport.LogCollector;
|
import awaisomereport.LogCollector;
|
||||||
|
|
||||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
@ -875,4 +881,127 @@ public final class ResponseBodyUtils {
|
|||||||
}
|
}
|
||||||
return sliderItems;
|
return sliderItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static StoryModel parseStoryItem(final JSONObject data,
|
||||||
|
final boolean isLoc,
|
||||||
|
final boolean isHashtag,
|
||||||
|
final String localUsername) throws JSONException {
|
||||||
|
final boolean isVideo = data.has("video_duration");
|
||||||
|
final StoryModel model = new StoryModel(data.getString("id"),
|
||||||
|
data.getJSONObject("image_versions2").getJSONArray("candidates").getJSONObject(0)
|
||||||
|
.getString("url"),
|
||||||
|
isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE,
|
||||||
|
data.optLong("taken_at", 0),
|
||||||
|
(isLoc || isHashtag)
|
||||||
|
? data.getJSONObject("user").getString("username")
|
||||||
|
: localUsername,
|
||||||
|
data.getJSONObject("user").getString("pk"),
|
||||||
|
data.optBoolean("can_reply"));
|
||||||
|
|
||||||
|
final JSONArray videoResources = data.optJSONArray("video_versions");
|
||||||
|
if (isVideo && videoResources != null)
|
||||||
|
model.setVideoUrl(ResponseBodyUtils.getHighQualityPost(videoResources, true, true, false));
|
||||||
|
|
||||||
|
if (data.has("story_feed_media")) {
|
||||||
|
model.setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_code"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this may not be limited to spotify
|
||||||
|
if (!data.isNull("story_app_attribution"))
|
||||||
|
model.setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]);
|
||||||
|
|
||||||
|
if (data.has("story_polls")) {
|
||||||
|
final JSONArray storyPolls = data.optJSONArray("story_polls");
|
||||||
|
JSONObject tappableObject = null;
|
||||||
|
if (storyPolls != null) {
|
||||||
|
tappableObject = storyPolls.getJSONObject(0).optJSONObject("poll_sticker");
|
||||||
|
}
|
||||||
|
if (tappableObject != null) model.setPoll(new PollModel(
|
||||||
|
String.valueOf(tappableObject.getLong("poll_id")),
|
||||||
|
tappableObject.getString("question"),
|
||||||
|
tappableObject.getJSONArray("tallies").getJSONObject(0).getString("text"),
|
||||||
|
tappableObject.getJSONArray("tallies").getJSONObject(0).getInt("count"),
|
||||||
|
tappableObject.getJSONArray("tallies").getJSONObject(1).getString("text"),
|
||||||
|
tappableObject.getJSONArray("tallies").getJSONObject(1).getInt("count"),
|
||||||
|
tappableObject.optInt("viewer_vote", -1)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (data.has("story_questions")) {
|
||||||
|
final JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0)
|
||||||
|
.optJSONObject("question_sticker");
|
||||||
|
if (tappableObject != null && !tappableObject.getString("question_type").equals("music"))
|
||||||
|
model.setQuestion(new QuestionModel(
|
||||||
|
String.valueOf(tappableObject.getLong("question_id")),
|
||||||
|
tappableObject.getString("question")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (data.has("story_quizs")) {
|
||||||
|
JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker");
|
||||||
|
if (tappableObject != null) {
|
||||||
|
String[] choices = new String[tappableObject.getJSONArray("tallies").length()];
|
||||||
|
Long[] counts = new Long[choices.length];
|
||||||
|
for (int q = 0; q < choices.length; ++q) {
|
||||||
|
JSONObject tempchoice = tappableObject.getJSONArray("tallies").getJSONObject(q);
|
||||||
|
choices[q] = (q == tappableObject.getInt("correct_answer") ? "*** " : "")
|
||||||
|
+ tempchoice.getString("text");
|
||||||
|
counts[q] = tempchoice.getLong("count");
|
||||||
|
}
|
||||||
|
model.setQuiz(new QuizModel(
|
||||||
|
String.valueOf(tappableObject.getLong("quiz_id")),
|
||||||
|
tappableObject.getString("question"),
|
||||||
|
choices,
|
||||||
|
counts,
|
||||||
|
tappableObject.optInt("viewer_answer", -1)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data.has("story_cta") && data.has("link_text")) {
|
||||||
|
JSONObject tappableObject = data.getJSONArray("story_cta").getJSONObject(0).getJSONArray("links").getJSONObject(0);
|
||||||
|
String swipeUpUrl = tappableObject.getString("webUri");
|
||||||
|
if (swipeUpUrl.startsWith("http")) {
|
||||||
|
model.setSwipeUp(new SwipeUpModel(swipeUpUrl, data.getString("link_text")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data.has("story_sliders")) {
|
||||||
|
final JSONObject tappableObject = data.getJSONArray("story_sliders").getJSONObject(0)
|
||||||
|
.optJSONObject("slider_sticker");
|
||||||
|
if (tappableObject != null)
|
||||||
|
model.setSlider(new SliderModel(
|
||||||
|
String.valueOf(tappableObject.getLong("slider_id")),
|
||||||
|
tappableObject.getString("question"),
|
||||||
|
tappableObject.getString("emoji"),
|
||||||
|
tappableObject.getBoolean("viewer_can_vote"),
|
||||||
|
tappableObject.getDouble("slider_vote_average"),
|
||||||
|
tappableObject.getInt("slider_vote_count"),
|
||||||
|
tappableObject.optDouble("viewer_vote")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
JSONArray hashtags = data.optJSONArray("story_hashtags");
|
||||||
|
JSONArray locations = data.optJSONArray("story_locations");
|
||||||
|
JSONArray atmarks = data.optJSONArray("reel_mentions");
|
||||||
|
String[] mentions = new String[(hashtags == null ? 0 : hashtags.length())
|
||||||
|
+ (atmarks == null ? 0 : atmarks.length())
|
||||||
|
+ (locations == null ? 0 : locations.length())];
|
||||||
|
if (hashtags != null) {
|
||||||
|
for (int h = 0; h < hashtags.length(); ++h) {
|
||||||
|
mentions[h] = "#" + hashtags.getJSONObject(h).getJSONObject("hashtag").getString("name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (atmarks != null) {
|
||||||
|
for (int h = 0; h < atmarks.length(); ++h) {
|
||||||
|
mentions[h + (hashtags == null ? 0 : hashtags.length())] =
|
||||||
|
"@" + atmarks.getJSONObject(h).getJSONObject("user").getString("username");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (locations != null) {
|
||||||
|
for (int h = 0; h < locations.length(); ++h) {
|
||||||
|
mentions[h + (hashtags == null ? 0 : hashtags.length()) + (atmarks == null ? 0 : atmarks.length())] =
|
||||||
|
locations.getJSONObject(h).getJSONObject("location").getString("short_name")
|
||||||
|
+ " (" + locations.getJSONObject(h).getJSONObject("location").getLong("pk") + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mentions.length != 0) model.setMentions(mentions);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,9 @@ public class ProfileService extends BaseService {
|
|||||||
uid,
|
uid,
|
||||||
user.getString(Constants.EXTRAS_USERNAME),
|
user.getString(Constants.EXTRAS_USERNAME),
|
||||||
user.optString("full_name"),
|
user.optString("full_name"),
|
||||||
user.optString("profile_pic_url")
|
user.optString("profile_pic_url"),
|
||||||
|
user.has("hd_profile_pic_url_info")
|
||||||
|
? user.getJSONObject("hd_profile_pic_url_info").optString("url") : null
|
||||||
);
|
);
|
||||||
callback.onSuccess(userInfo);
|
callback.onSuccess(userInfo);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package awais.instagrabber.webservices;
|
package awais.instagrabber.webservices;
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -9,11 +8,6 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -63,6 +57,37 @@ public class StoriesService extends BaseService {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fetch(final String mediaId,
|
||||||
|
final ServiceCallback<StoryModel> callback) {
|
||||||
|
final Call<String> request = repository.fetch(mediaId);
|
||||||
|
request.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull final Call<String> call,
|
||||||
|
@NonNull final Response<String> response) {
|
||||||
|
if (callback == null) return;
|
||||||
|
final String body = response.body();
|
||||||
|
if (body == null) {
|
||||||
|
callback.onSuccess(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final JSONObject itemJson = new JSONObject(body).getJSONArray("items").getJSONObject(0);
|
||||||
|
callback.onSuccess(ResponseBodyUtils.parseStoryItem(itemJson, false, false, null));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
callback.onFailure(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull final Call<String> call,
|
||||||
|
@NonNull final Throwable t) {
|
||||||
|
if (callback != null) {
|
||||||
|
callback.onFailure(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void getFeedStories(final String csrfToken, final ServiceCallback<List<FeedStoryModel>> callback) {
|
public void getFeedStories(final String csrfToken, final ServiceCallback<List<FeedStoryModel>> callback) {
|
||||||
final Map<String, Object> form = new HashMap<>(4);
|
final Map<String, Object> form = new HashMap<>(4);
|
||||||
form.put("reason", "cold_start");
|
form.put("reason", "cold_start");
|
||||||
@ -198,122 +223,7 @@ public class StoriesService extends BaseService {
|
|||||||
final List<StoryModel> models = new ArrayList<>();
|
final List<StoryModel> models = new ArrayList<>();
|
||||||
for (int i = 0; i < mediaLen; ++i) {
|
for (int i = 0; i < mediaLen; ++i) {
|
||||||
data = media.getJSONObject(i);
|
data = media.getJSONObject(i);
|
||||||
final boolean isVideo = data.has("video_duration");
|
models.add(ResponseBodyUtils.parseStoryItem(data, isLoc, isHashtag, localUsername));
|
||||||
final StoryModel model = new StoryModel(data.getString("id"),
|
|
||||||
data.getJSONObject("image_versions2").getJSONArray("candidates").getJSONObject(0)
|
|
||||||
.getString("url"),
|
|
||||||
isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE,
|
|
||||||
data.optLong("taken_at", 0),
|
|
||||||
(isLoc || isHashtag)
|
|
||||||
? data.getJSONObject("user").getString("username")
|
|
||||||
: localUsername,
|
|
||||||
data.getJSONObject("user").getString("pk"),
|
|
||||||
data.getBoolean("can_reply"));
|
|
||||||
|
|
||||||
final JSONArray videoResources = data.optJSONArray("video_versions");
|
|
||||||
if (isVideo && videoResources != null)
|
|
||||||
model.setVideoUrl(ResponseBodyUtils.getHighQualityPost(videoResources, true, true, false));
|
|
||||||
|
|
||||||
if (data.has("story_feed_media")) {
|
|
||||||
model.setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_code"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this may not be limited to spotify
|
|
||||||
if (!data.isNull("story_app_attribution"))
|
|
||||||
model.setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]);
|
|
||||||
|
|
||||||
if (data.has("story_polls")) {
|
|
||||||
final JSONArray storyPolls = data.optJSONArray("story_polls");
|
|
||||||
JSONObject tappableObject = null;
|
|
||||||
if (storyPolls != null) {
|
|
||||||
tappableObject = storyPolls.getJSONObject(0).optJSONObject("poll_sticker");
|
|
||||||
}
|
|
||||||
if (tappableObject != null) model.setPoll(new PollModel(
|
|
||||||
String.valueOf(tappableObject.getLong("poll_id")),
|
|
||||||
tappableObject.getString("question"),
|
|
||||||
tappableObject.getJSONArray("tallies").getJSONObject(0).getString("text"),
|
|
||||||
tappableObject.getJSONArray("tallies").getJSONObject(0).getInt("count"),
|
|
||||||
tappableObject.getJSONArray("tallies").getJSONObject(1).getString("text"),
|
|
||||||
tappableObject.getJSONArray("tallies").getJSONObject(1).getInt("count"),
|
|
||||||
tappableObject.optInt("viewer_vote", -1)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (data.has("story_questions")) {
|
|
||||||
final JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0)
|
|
||||||
.optJSONObject("question_sticker");
|
|
||||||
if (tappableObject != null && !tappableObject.getString("question_type").equals("music"))
|
|
||||||
model.setQuestion(new QuestionModel(
|
|
||||||
String.valueOf(tappableObject.getLong("question_id")),
|
|
||||||
tappableObject.getString("question")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (data.has("story_quizs")) {
|
|
||||||
JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker");
|
|
||||||
if (tappableObject != null) {
|
|
||||||
String[] choices = new String[tappableObject.getJSONArray("tallies").length()];
|
|
||||||
Long[] counts = new Long[choices.length];
|
|
||||||
for (int q = 0; q < choices.length; ++q) {
|
|
||||||
JSONObject tempchoice = tappableObject.getJSONArray("tallies").getJSONObject(q);
|
|
||||||
choices[q] = (q == tappableObject.getInt("correct_answer") ? "*** " : "")
|
|
||||||
+ tempchoice.getString("text");
|
|
||||||
counts[q] = tempchoice.getLong("count");
|
|
||||||
}
|
|
||||||
model.setQuiz(new QuizModel(
|
|
||||||
String.valueOf(tappableObject.getLong("quiz_id")),
|
|
||||||
tappableObject.getString("question"),
|
|
||||||
choices,
|
|
||||||
counts,
|
|
||||||
tappableObject.optInt("viewer_answer", -1)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (data.has("story_cta") && data.has("link_text")) {
|
|
||||||
JSONObject tappableObject = data.getJSONArray("story_cta").getJSONObject(0).getJSONArray("links").getJSONObject(0);
|
|
||||||
String swipeUpUrl = tappableObject.getString("webUri");
|
|
||||||
if (swipeUpUrl.startsWith("http")) {
|
|
||||||
model.setSwipeUp(new SwipeUpModel(swipeUpUrl, data.getString("link_text")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (data.has("story_sliders")) {
|
|
||||||
final JSONObject tappableObject = data.getJSONArray("story_sliders").getJSONObject(0)
|
|
||||||
.optJSONObject("slider_sticker");
|
|
||||||
if (tappableObject != null)
|
|
||||||
model.setSlider(new SliderModel(
|
|
||||||
String.valueOf(tappableObject.getLong("slider_id")),
|
|
||||||
tappableObject.getString("question"),
|
|
||||||
tappableObject.getString("emoji"),
|
|
||||||
tappableObject.getBoolean("viewer_can_vote"),
|
|
||||||
tappableObject.getDouble("slider_vote_average"),
|
|
||||||
tappableObject.getInt("slider_vote_count"),
|
|
||||||
tappableObject.optDouble("viewer_vote")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
JSONArray hashtags = data.optJSONArray("story_hashtags");
|
|
||||||
JSONArray locations = data.optJSONArray("story_locations");
|
|
||||||
JSONArray atmarks = data.optJSONArray("reel_mentions");
|
|
||||||
String[] mentions = new String[(hashtags == null ? 0 : hashtags.length())
|
|
||||||
+ (atmarks == null ? 0 : atmarks.length())
|
|
||||||
+ (locations == null ? 0 : locations.length())];
|
|
||||||
if (hashtags != null) {
|
|
||||||
for (int h = 0; h < hashtags.length(); ++h) {
|
|
||||||
mentions[h] = "#" + hashtags.getJSONObject(h).getJSONObject("hashtag").getString("name");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (atmarks != null) {
|
|
||||||
for (int h = 0; h < atmarks.length(); ++h) {
|
|
||||||
mentions[h + (hashtags == null ? 0 : hashtags.length())] =
|
|
||||||
"@" + atmarks.getJSONObject(h).getJSONObject("user").getString("username");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (locations != null) {
|
|
||||||
for (int h = 0; h < locations.length(); ++h) {
|
|
||||||
mentions[h + (hashtags == null ? 0 : hashtags.length()) + (atmarks == null ? 0 : atmarks.length())] =
|
|
||||||
locations.getJSONObject(h).getJSONObject("location").getString("short_name")
|
|
||||||
+ " (" + locations.getJSONObject(h).getJSONObject("location").getLong("pk") + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mentions.length != 0) model.setMentions(mentions);
|
|
||||||
models.add(model);
|
|
||||||
}
|
}
|
||||||
callback.onSuccess(models);
|
callback.onSuccess(models);
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
|
android:backgroundTint="@color/black_a50"
|
||||||
android:text="@string/action_download"
|
android:text="@string/action_download"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:icon="@drawable/ic_download"
|
app:icon="@drawable/ic_download"
|
||||||
|
Loading…
Reference in New Issue
Block a user