From 99e1cbef93750cbbe7a0d7ba238b766c9906b27b Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 24 Oct 2020 13:13:16 -0400 Subject: [PATCH] download file name improvement --- .../instagrabber/asyncs/PostFetcher.java | 2 +- .../awais/instagrabber/models/PostChild.java | 29 +++++++++++++------ .../instagrabber/utils/DownloadUtils.java | 8 ++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java index 8c372d53..556bd073 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java @@ -147,7 +147,7 @@ public final class PostFetcher extends AsyncTask { : MediaItemType.MEDIA_TYPE_IMAGE) .setDisplayUrl(isChildVideo ? childNode.getString("video_url") : childNode.getString("display_url")) - // .setShortCode(childNode.getString(Constants.EXTRAS_SHORTCODE)) + .setShortCode(media.getString(Constants.EXTRAS_SHORTCODE)) .setVideoViews(isChildVideo && childNode.has("video_view_count") ? childNode.getLong("video_view_count") : -1) diff --git a/app/src/main/java/awais/instagrabber/models/PostChild.java b/app/src/main/java/awais/instagrabber/models/PostChild.java index 954a11b3..9a0b17ad 100644 --- a/app/src/main/java/awais/instagrabber/models/PostChild.java +++ b/app/src/main/java/awais/instagrabber/models/PostChild.java @@ -5,20 +5,19 @@ import java.io.Serializable; import awais.instagrabber.models.enums.MediaItemType; public final class PostChild implements Serializable { - private String postId; - private MediaItemType itemType; - private String displayUrl; + private final String postId; + private final String displayUrl; + private final String shortCode; + private final MediaItemType itemType; private final String thumbnailUrl; private final long videoViews; - private int width; - private int height; + private final int width; + private final int height; public static class Builder { - private String postId; + private String postId, displayUrl, shortCode, thumbnailUrl; private MediaItemType itemType; - private String displayUrl; private long videoViews; - private String thumbnailUrl; private int width; private int height; @@ -27,6 +26,11 @@ public final class PostChild implements Serializable { return this; } + public Builder setShortCode(final String shortCode) { + this.shortCode = shortCode; + return this; + } + public Builder setItemType(final MediaItemType itemType) { this.itemType = itemType; return this; @@ -58,11 +62,12 @@ public final class PostChild implements Serializable { } public PostChild build() { - return new PostChild(postId, itemType, displayUrl, thumbnailUrl, videoViews, height, width); + return new PostChild(postId, shortCode, itemType, displayUrl, thumbnailUrl, videoViews, height, width); } } public PostChild(final String postId, + final String shortCode, final MediaItemType itemType, final String displayUrl, final String thumbnailUrl, @@ -70,6 +75,7 @@ public final class PostChild implements Serializable { final int height, final int width) { this.postId = postId; + this.shortCode = shortCode; this.itemType = itemType; this.displayUrl = displayUrl; this.thumbnailUrl = thumbnailUrl; @@ -82,6 +88,10 @@ public final class PostChild implements Serializable { return postId; } + public String getShortCode() { + return shortCode; + } + public MediaItemType getItemType() { return itemType; } @@ -110,6 +120,7 @@ public final class PostChild implements Serializable { public String toString() { return "PostChild{" + "postId='" + postId + '\'' + + ", shortCode=" + shortCode + ", itemType=" + itemType + ", displayUrl='" + displayUrl + '\'' + ", thumbnailUrl='" + thumbnailUrl + '\'' + diff --git a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java index 84dde0fe..b9bea336 100644 --- a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java @@ -88,11 +88,9 @@ public final class DownloadUtils { switch (method) { case DOWNLOAD_SAVED: case DOWNLOAD_MAIN: + case DOWNLOAD_DISCOVER: checkEachPost = true; break; - case DOWNLOAD_FEED: - checkEachPost = false; - break; } final int itemsToDownloadSize = itemsToDownload.size(); for (int i = 0; i < itemsToDownloadSize; i++) { @@ -100,7 +98,7 @@ public final class DownloadUtils { if (!checkEachPost) { final boolean isSlider = itemsToDownloadSize > 1; final File saveFile = getDownloadSaveFile(dir, - selectedItem.getPostId(), + selectedItem.getShortCode(), isSlider ? "_slide_" + (i + 1) : "", selectedItem.getDisplayUrl() ); @@ -119,7 +117,7 @@ public final class DownloadUtils { final PostChild model = result.getSliderItems().get(j); final File saveFile = getDownloadSaveFile( finalDir, - model.getPostId(), + model.getShortCode(), "_slide_" + (j + 1), model.getDisplayUrl() );