Browse Source

custom folder + username folder

legacy
Austin Huang 4 years ago
parent
commit
4fed608ffc
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 34
      app/src/main/java/awais/instagrabber/asyncs/DiscoverFetcher.java
  2. 3
      app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java
  3. 3
      app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java

34
app/src/main/java/awais/instagrabber/asyncs/DiscoverFetcher.java

@ -46,16 +46,10 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
@Nullable
@Override
protected final DiscoverItemModel[] doInBackground(final Void... voids) {
// to check if file exists
File customDir = null;
if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
final String customPath = settingsHelper.getString(FOLDER_PATH);
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
}
DiscoverItemModel[] result = null;
final ArrayList<DiscoverItemModel> discoverItemModels = fetchItems(customDir, null, maxId);
final ArrayList<DiscoverItemModel> discoverItemModels = fetchItems(null, maxId);
if (discoverItemModels != null) {
result = discoverItemModels.toArray(new DiscoverItemModel[0]);
if (result.length > 0) {
@ -67,8 +61,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
return result;
}
private ArrayList<DiscoverItemModel> fetchItems(final File customDir,
ArrayList<DiscoverItemModel> discoverItemModels, final String maxId) {
private ArrayList<DiscoverItemModel> fetchItems(ArrayList<DiscoverItemModel> discoverItemModels, final String maxId) {
try {
final String url = "https://www.instagram.com/explore/grid/?is_prefetch=false&omit_cover_media=true&module=explore_popular" +
"&use_sectional_payload=false&cluster_id=explore_all%3A0&include_fixed_destinations=true" + maxId;
@ -99,8 +92,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
if ("media_grid".equals(layoutType)) {
final JSONArray medias = layoutContent.getJSONArray("medias");
for (int j = 0; j < medias.length(); ++j)
discoverItemModels.add(makeDiscoverModel(customDir,
medias.getJSONObject(j).getJSONObject("media")));
discoverItemModels.add(makeDiscoverModel(medias.getJSONObject(j).getJSONObject("media")));
} else {
final boolean isOneSide = "one_by_two_left".equals(layoutType);
@ -108,14 +100,12 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
final JSONObject layoutItem = layoutContent.getJSONObject(isOneSide ? "one_by_two_item" : "two_by_two_item");
if (layoutItem.has("media"))
discoverItemModels.add(makeDiscoverModel(customDir,
layoutItem.getJSONObject("media")));
discoverItemModels.add(makeDiscoverModel(layoutItem.getJSONObject("media")));
if (layoutContent.has("fill_items")) {
final JSONArray fillItems = layoutContent.getJSONArray("fill_items");
for (int j = 0; j < fillItems.length(); ++j)
discoverItemModels.add(makeDiscoverModel(customDir,
fillItems.getJSONObject(j).getJSONObject("media")));
discoverItemModels.add(makeDiscoverModel(fillItems.getJSONObject(j).getJSONObject("media")));
}
}
}
@ -129,8 +119,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
if (this.isFirst) {
final int size = discoverItemModels.size();
if (size > 50) this.isFirst = false;
discoverItemModels = fetchItems(customDir, discoverItemModels,
"&max_id=" + (lastId++));
discoverItemModels = fetchItems(discoverItemModels, "&max_id=" + (lastId++));
}
} else {
urlConnection.disconnect();
@ -149,8 +138,7 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
}
@NonNull
private DiscoverItemModel makeDiscoverModel(final File customDir,
@NonNull final JSONObject media) throws Exception {
private DiscoverItemModel makeDiscoverModel(@NonNull final JSONObject media) throws Exception {
final JSONObject user = media.getJSONObject(Constants.EXTRAS_USER);
final String username = user.getString(Constants.EXTRAS_USERNAME);
// final ProfileModel userProfileModel = new ProfileModel(user.getBoolean("is_private"),
@ -179,6 +167,14 @@ public final class DiscoverFetcher extends AsyncTask<Void, Void, DiscoverItemMod
final File downloadDir = new File(Environment.getExternalStorageDirectory(), "Download" +
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
// to check if file exists
File customDir = null;
if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
final String customPath = settingsHelper.getString(FOLDER_PATH);
if (!Utils.isEmpty(customPath)) customDir = new File(customPath +
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
}
Utils.checkExistence(downloadDir, customDir, mediaType == MediaItemType.MEDIA_TYPE_SLIDER, model);
return model;

3
app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java

@ -53,7 +53,8 @@ public final class PostFetcher extends AsyncTask<Void, Void, ViewerPostModel[]>
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
File customDir = null;
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH);
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH +
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
}

3
app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java

@ -83,7 +83,8 @@ public final class PostsFetcher extends AsyncTask<Void, Void, PostModel[]> {
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
File customDir = null;
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH);
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH +
(Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : ""));
if (!Utils.isEmpty(customPath)) customDir = new File(customPath);
}

Loading…
Cancel
Save