Skip to content

Commit

Permalink
Merge branch 'lx200916-YKMH' into release-tci
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleydu committed Feb 5, 2021
2 parents 4ce67b9 + b282f71 commit 89fba2d
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private static void initSource(DaoSession session) {
list.add(WebtoonDongManManHua.getDefaultSource());
list.add(MH160.getDefaultSource());
list.add(QiMiaoMH.getDefaultSource());
list.add(YKMH.getDefaultSource());
session.getSourceDao().insertOrReplaceInTx(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public Parser getParser(int type) {
case QiMiaoMH.TYPE:
parser = new QiMiaoMH(source);
break;
case YKMH.TYPE:
parser = new YKMH(source);
break;
default:
parser = new Null();
break;
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/hiroshi/cimoc/soup/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public Node id(String id) {
return new Node(element.getElementById(id));
}

public Node getParent(String cssQuery) {
return new Node(get().select(cssQuery).first().parent());
}

public Node getChild(String cssQuery) {
return new Node(get().select(cssQuery).first());
}
Expand Down Expand Up @@ -73,6 +77,12 @@ public String textWithSubstring(String cssQuery, int start) {
return textWithSubstring(cssQuery, start, -1);
}

public String hrefWithLastSplit() {
String string = href();
String[] arr = string.split("/");
return arr[arr.length - 1];
}

public String textWithSplit(String cssQuery, String regex, int index) {
return StringUtils.split(text(cssQuery), regex, index);
}
Expand Down
183 changes: 183 additions & 0 deletions app/src/main/java/com/hiroshi/cimoc/source/YKMH.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.hiroshi.cimoc.source;

import android.util.Log;

import com.hiroshi.cimoc.core.Manga;
import com.hiroshi.cimoc.model.Chapter;
import com.hiroshi.cimoc.model.Comic;
import com.hiroshi.cimoc.model.ImageUrl;
import com.hiroshi.cimoc.model.Source;
import com.hiroshi.cimoc.parser.MangaParser;
import com.hiroshi.cimoc.parser.NodeIterator;
import com.hiroshi.cimoc.parser.SearchIterator;
import com.hiroshi.cimoc.soup.Node;
import com.hiroshi.cimoc.utils.StringUtils;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.Headers;
import okhttp3.Request;

public class YKMH extends MangaParser {
public static final int TYPE = 91;
public static final String DEFAULT_TITLE = "优酷漫画";
public final String Host = "https://www.ykmh.com/";
public final String mHost = "https://m.ykmh.com/";

public YKMH(Source source) {
init(source, null);
}

public static Source getDefaultSource() {
return new Source(null, DEFAULT_TITLE, TYPE, true);
}

@Override
public Request getSearchRequest(String keyword, int page) throws UnsupportedEncodingException {
Log.d("SourceSearch:", String.valueOf(keyword));

return new Request.Builder().url(mHost + "search/?keywords=" + keyword + "&page=" + page).addHeader("referer", "https://m.ykmh.com/search").addHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36")
.build();
}

@Override
public SearchIterator getSearchIterator(String html, int page) throws JSONException {
Node body = new Node(html);
return new NodeIterator(body.list("#update_list > div.UpdateList > div")) {
@Override
protected Comic parse(Node node) {
Node titleN = node.getChild("div.itemTxt > a");
String cid = titleN.hrefWithLastSplit();
String title = titleN.text();
String cover = node.attr("div.itemImg > a > img", "src");
String Update = node.text("p.txtItme > span.date");
String Author = node.text("p > a");
return new Comic(TYPE, cid, title, cover, Update, Author);
}
};
}

@Override
public String getUrl(String cid) {
return StringUtils.format("%smanhua/%s", mHost, cid);
}

@Override
public Headers getHeader() {
return Headers.of("Referer", "https://m.ykmh.com/search/", "user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36");
}

@Override
public Request getInfoRequest(String cid) {
Log.d("SourceInfo:", String.valueOf(cid));

return new Request.Builder().url(mHost.concat("manhua/").concat(cid).concat("/")).addHeader("referer", "https://m.ykmh.com/search").addHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36")
.build();

}

@Override
public Comic parseInfo(String html, Comic comic) throws UnsupportedEncodingException {
Node body = new Node(html);
Node info = body.getChild("div.Introduct_Sub");
String title = body.text("div#comicName");
String cover = info.getChild("div#Cover > *").src();
String update = info.text("p.txtItme > span.date");
String author = info.getParent("p.txtItme > span.icon01").text();
String intro = body.getParent("p#full-des #showmore-des").text();
String isFinish = info.getParent("p.txtItme > span.icon01").text();
boolean finish = false;
if (isFinish.contains("完结")) finish = true;
comic.setInfo(title, cover, update, intro, author, finish);


return comic;
}

@Override
public List<Chapter> parseChapter(String html) {
List<Chapter> list = new LinkedList<>();
Node body = new Node(html);
for (Node node : body.list("div.chapter-warp ul.Drama > li > a")) {
String title = node.text();
// String path = StringUtils.split(node.href(), "/", 3);
String path = node.hrefWithSubString(1);
list.add(new Chapter(title, path));
}
return list;
}

@Override
public List<Chapter> parseChapter(String html, Comic comic, Long sourceComic) throws JSONException {
List<Chapter> list = new LinkedList<>();
Node body = new Node(html);
int i = 0;
for (Node node : body.list("div.chapter-warp ul.Drama > li > a")) {
String title = node.text();
// String path = StringUtils.split(node.href(), "/", 3);
String path = node.hrefWithSubString(1);
list.add(new Chapter(Long.parseLong(sourceComic + "000" + i++), sourceComic, title, path));
}
return list;
}

@Override
public Request getImagesRequest(String cid, String path) {
Log.d("SourceImage:", String.valueOf(path));

return new Request.Builder().url(mHost.concat(path)).addHeader("referer", "https://m.ykmh.com/search").addHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36")
.build();
}


@Override
public List<ImageUrl> parseImages(String html, Chapter chapter) throws Manga.NetworkErrorException, JSONException {
List<ImageUrl> list = new LinkedList<>();
Matcher matcher = Pattern.compile("var chapterImages\\s*=\\s*\\[(.+?)]").matcher(html);
if (!matcher.find()) {
return null;
}
String CDATA = String.format("[%s]", matcher.group(1));
JSONArray array = null;
try {
array = new JSONArray(CDATA);
for (int i = 0; i < array.length(); i++) {
String url = StringUtils.format("https://pic.w1fl.com%s", array.getString(i));
Long comicChapter = chapter.getId();
Long id = Long.parseLong(comicChapter + "000" + i + 1);
list.add(new ImageUrl(id, comicChapter, i + 1, url, false));

}

} catch (JSONException e) {
e.printStackTrace();
Log.e("parseImages", "parseImages Error", e);
return null;

}

return list;
}

@Override
public Request getCheckRequest(String cid) {
return getInfoRequest(cid);
}

@Override
public String parseCheck(String html) {
return new Node(html).text("p.txtItme > span.date");
}

@Override
public String getTitle() {
return DEFAULT_TITLE;
}
}

0 comments on commit 89fba2d

Please sign in to comment.