Skip to content

Commit

Permalink
fix Download failure, closed #80
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleydu committed Aug 22, 2020
1 parent c8befed commit f75b0a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/hiroshi/cimoc/core/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public static DocumentFile updateChapterIndex(ContentResolver resolver, Document
String jsonString = getJsonFromChapter(task.getTitle(), task.getPath());
DocumentFile dir1 = DocumentUtils.getOrCreateSubDirectory(root, DOWNLOAD);
DocumentFile dir2 = DocumentUtils.getOrCreateSubDirectory(dir1, String.valueOf(task.getSource()));
DocumentFile dir3 = DocumentUtils.getOrCreateSubDirectory(dir2, task.getCid().replaceAll("/|\\?", ""));
DocumentFile dir4 = DocumentUtils.getOrCreateSubDirectory(dir3, DecryptionUtils.urlDecrypt(task.getPath().replaceAll("/|\\?", "-")));
DocumentFile dir3 = DocumentUtils.getOrCreateSubDirectory(dir2, task.getCid().replaceAll("[:/(\\\\)(\\?)<>\"(\\|)(\\.)]", ""));
DocumentFile dir4 = DocumentUtils.getOrCreateSubDirectory(dir3, DecryptionUtils.urlDecrypt(task.getPath().replaceAll("[:/(\\\\)(\\?)<>\"(\\|)(\\.)]", "-")));
if (dir4 != null) {
DocumentFile file = DocumentUtils.getOrCreateFile(dir4, FILE_INDEX);
DocumentUtils.writeStringToFile(resolver, file, "cimoc".concat(jsonString));
Expand Down Expand Up @@ -224,8 +224,8 @@ private static List<String> readPathFromJson(String jsonString) throws JSONExcep
public static DocumentFile getChapterDir(DocumentFile root, Comic comic, Chapter chapter, String title) {
DocumentFile result = DocumentUtils.findFile(root, DOWNLOAD,
String.valueOf(comic.getSource()),
comic.getCid().replaceAll("/|\\?", ""),
DecryptionUtils.urlDecrypt(chapter.getPath().replaceAll("/|\\?", "-"))
comic.getCid().replaceAll("[:/(\\\\)(\\?)<>\"(\\|)(\\.)]", ""),
DecryptionUtils.urlDecrypt(chapter.getPath().replaceAll("[:/(\\\\)(\\?)<>\"(\\|)(\\.)]", "-"))
);
if (result == null) {
result = DocumentUtils.findFile(root, DOWNLOAD, title, comic.getTitle(), chapter.getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.IBinder;
import androidx.annotation.Nullable;
import androidx.collection.LongSparseArray;

import android.util.Pair;

import com.hiroshi.cimoc.App;
Expand Down Expand Up @@ -226,6 +227,7 @@ private boolean RequestAndWrite(DocumentFile parent, Request request, int num, S
response = mHttpClient.newCall(request).execute();
if (response.isSuccessful()) {
String displayName = buildFileName(num, url);
displayName = displayName.replaceAll("[:/(\\\\)(\\?)<>\"(\\|)(\\.)]", "_");
DocumentFile file = DocumentUtils.getOrCreateFile(parent, displayName);
DocumentUtils.writeBinaryToFile(mContentResolver, file, response.body().byteStream());
return true;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/hiroshi/cimoc/source/CopyMH.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedList;
import java.util.List;

import okhttp3.Headers;
import okhttp3.Request;
import taobe.tec.jcc.JChineseConvertor;

Expand Down Expand Up @@ -167,4 +168,9 @@ public Request getCheckRequest(String cid) {
public String parseCheck(String html) {
return new Node(html).text("div.col-9.comicParticulars-title-right > ul > li:nth-child(5) > span.comicParticulars-right-txt");
}

@Override
public Headers getHeader() {
return Headers.of("Referer", website);
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/com/hiroshi/cimoc/source/MH160.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.LinkedList;
import java.util.List;

import okhttp3.Headers;
import okhttp3.Request;

/**
Expand Down Expand Up @@ -151,4 +152,9 @@ public String parseCheck(String html) {
return new Node(html).text("div.cy_zhangjie_top > :eq(2) > font");
}

@Override
public Headers getHeader() {
return Headers.of("Referer", baseUrl);
}

}

0 comments on commit f75b0a6

Please sign in to comment.