Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash, webp support #762

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/src/main/java/com/dar/nclientv2/api/SimpleGallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ public SimpleGallery(Context context, Element e) {
id = Integer.parseInt(temp.substring(3, temp.length() - 1));
a = e.getElementsByTag("img").first();
temp = a.hasAttr("data-src") ? a.attr("data-src") : a.attr("src");
//temp = a.attr("src");
mediaId = Integer.parseInt(temp.substring(temp.indexOf("galleries") + 10, temp.lastIndexOf('/')));
thumbnail = Page.charToExt(temp.charAt(temp.length() - 3));
String extension = temp.substring(temp.lastIndexOf('.') + 1);
thumbnail = Page.charToExt(extension.charAt(0));//thumbnail = Page.charToExt(temp.charAt(temp.length() - 3));
title = e.getElementsByTag("div").first().text();
if (context != null && id > Global.getMaxId()) Global.updateMaxId(context, id);
}
Expand All @@ -93,13 +95,19 @@ public SimpleGallery(Gallery gallery) {
}

private static String extToString(ImageExt ext) {
//just in case
if (ext == null) {
return null;
}
switch (ext) {
case GIF:
return "gif";
case PNG:
return "png";
case JPG:
return "jpg";
case WEBP:
return "webp";
}
return null;
}
Expand Down Expand Up @@ -171,9 +179,9 @@ public void writeToParcel(Parcel dest, int flags) {

public Uri getThumbnail() {
if (thumbnail == ImageExt.GIF) {
return Uri.parse(String.format(Locale.US, "https://i." + Utility.getHost() + "/galleries/%d/1.gif", mediaId));
return Uri.parse(String.format(Locale.US, "https://i1." + Utility.getHost() + "/galleries/%d/1.gif", mediaId));
}
return Uri.parse(String.format(Locale.US, "https://t." + Utility.getHost() + "/galleries/%d/thumb.%s", mediaId, extToString(thumbnail)));
return Uri.parse(String.format(Locale.US, "https://t1." + Utility.getHost() + "/galleries/%d/thumb.%s", mediaId, extToString(thumbnail)));
}

public int getMediaId() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/api/comments/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public int getId() {
}

public Uri getAvatarUrl() {
return Uri.parse(String.format(Locale.US, "https://i.%s/%s", Utility.getHost(), avatarUrl));
return Uri.parse(String.format(Locale.US, "https://i1.%s/%s", Utility.getHost(), avatarUrl));
}

public String getUsername() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public String getPathTitle() {
public Uri getCover() {
if (Global.getDownloadPolicy() == Global.DataUsageType.THUMBNAIL) return getThumbnail();
if (galleryData.getCover().getImageExt() == ImageExt.GIF) return getHighPage(0);
return Uri.parse(String.format(Locale.US, "https://t." + Utility.getHost() + "/galleries/%d/cover.%s", getMediaId(), galleryData.getCover().extToString()));
return Uri.parse(String.format(Locale.US, "https://t1." + Utility.getHost() + "/galleries/%d/cover.%s", getMediaId(), galleryData.getCover().extToString()));
}

public ImageExt getThumb() {
Expand All @@ -164,7 +164,7 @@ public ImageExt getThumb() {

public Uri getThumbnail() {
if (galleryData.getCover().getImageExt() == ImageExt.GIF) return getHighPage(0);
return Uri.parse(String.format(Locale.US, "https://t." + Utility.getHost() + "/galleries/%d/thumb.%s", getMediaId(), galleryData.getThumbnail().extToString()));
return Uri.parse(String.format(Locale.US, "https://t1." + Utility.getHost() + "/galleries/%d/thumb.%s", getMediaId(), galleryData.getThumbnail().extToString()));
}

private @Nullable
Expand All @@ -183,13 +183,13 @@ public Uri getPageUrl(int page) {
}

public Uri getHighPage(int page) {
return Uri.parse(String.format(Locale.US, "https://i." + Utility.getHost() + "/galleries/%d/%d.%s", getMediaId(), page + 1, getPageExtension(page)));
return Uri.parse(String.format(Locale.US, "https://i1." + Utility.getHost() + "/galleries/%d/%d.%s", getMediaId(), page + 1, getPageExtension(page)));
}

public Uri getLowPage(int page) {
Uri uri = getFileUri(page);
if (uri != null) return uri;
return Uri.parse(String.format(Locale.US, "https://t." + Utility.getHost() + "/galleries/%d/%dt.%s", getMediaId(), page + 1, getPageExtension(page)));
return Uri.parse(String.format(Locale.US, "https://t1." + Utility.getHost() + "/galleries/%d/%dt.%s", getMediaId(), page + 1, getPageExtension(page)));
}

public String getPageExtension(int page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ private void readPagePath(String path) throws IOException {
case 'p':
case 'j':
case 'g':
case 'w':
if (specialImages) {
cover = new Page(ImageType.COVER, Page.charToExt(actualChar));
thumbnail = new Page(ImageType.THUMBNAIL, Page.charToExt(actualChar));
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/dar/nclientv2/api/components/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public static String extToString(ImageExt ext) {
return "png";
case JPG:
return "jpg";
case WEBP:
return "webp";
}
return null;
}
Expand All @@ -102,6 +104,8 @@ public static char extToChar(ImageExt imageExt) {
return 'p';
case JPG:
return 'j';
case WEBP:
return 'w';
}
return '\0';
}
Expand All @@ -114,6 +118,8 @@ public static ImageExt charToExt(int ext) {
return ImageExt.PNG;
case 'j':
return ImageExt.JPG;
case 'w':
return ImageExt.WEBP;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dar.nclientv2.api.enums;

public enum ImageExt {
JPG("jpg"), PNG("png"), GIF("gif");
JPG("jpg"), PNG("png"), GIF("gif"), WEBP("webp");

private final char firstLetter;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LocalGallery[] newArray(int size) {
return new LocalGallery[size];
}
};
private static final Pattern FILE_PATTERN = Pattern.compile("^(\\d{1,9})\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
private static final Pattern FILE_PATTERN = Pattern.compile("^(\\d{1,9})\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
private static final Pattern DUP_PATTERN = Pattern.compile("^(.*)\\.DUP\\d+$");
private static final Pattern IDFILE_PATTERN = Pattern.compile("^\\.\\d{1,6}$");
private final GalleryFolder folder;
Expand Down Expand Up @@ -106,6 +106,8 @@ public static File getPage(File dir, int page) {
if (dir == null || !dir.exists()) return null;
String pag = String.format(Locale.US, "%03d.", page);
File x;
x = new File(dir, pag + "webp");
if (x.exists()) return x;
x = new File(dir, pag + "jpg");
if (x.exists()) return x;
x = new File(dir, pag + "png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public GalleryFolder[] newArray(int size) {
return new GalleryFolder[size];
}
};
private static final Pattern FILE_PATTERN = Pattern.compile("^0*(\\d{1,9})\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
private static final Pattern FILE_PATTERN = Pattern.compile("^0*(\\d{1,9})\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
private static final Pattern IDFILE_PATTERN = Pattern.compile("^\\.(\\d{1,6})$");
private static final String NOMEDIA_FILE = ".nomedia";
private final SparseArrayCompat<PageFile> pageArray = new SparseArrayCompat<>();
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/dar/nclientv2/files/PageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public PageFile[] newArray(int size) {
return new PageFile[size];
}
};
private static final Pattern DEFAULT_THUMBNAIL = Pattern.compile("^0*1\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
private static final Pattern VALID_PAGE = Pattern.compile("^0*(\\d+)\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
private static final Pattern DEFAULT_THUMBNAIL = Pattern.compile("^0*1\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
private static final Pattern VALID_PAGE = Pattern.compile("^0*(\\d+)\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
private final ImageExt ext;
private final int page;

Expand Down