download file name improvement

This commit is contained in:
Austin Huang 2020-10-24 13:13:16 -04:00
parent a0f608442a
commit 99e1cbef93
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 24 additions and 15 deletions

View File

@ -147,7 +147,7 @@ public final class PostFetcher extends AsyncTask<Void, Void, FeedModel> {
: 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)

View File

@ -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 + '\'' +

View File

@ -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()
);