1 package be
.nikiroo
.fanfix
.searchable
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.net
.URLEncoder
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Arrays
;
11 import org
.jsoup
.helper
.DataUtil
;
12 import org
.jsoup
.nodes
.Document
;
13 import org
.jsoup
.nodes
.Element
;
14 import org
.jsoup
.select
.Elements
;
16 import be
.nikiroo
.fanfix
.Instance
;
17 import be
.nikiroo
.fanfix
.bundles
.StringId
;
18 import be
.nikiroo
.fanfix
.data
.MetaData
;
19 import be
.nikiroo
.fanfix
.supported
.SupportType
;
20 import be
.nikiroo
.utils
.Image
;
21 import be
.nikiroo
.utils
.StringUtils
;
23 class MangaLel
extends BasicSearchable
{
24 private String BASE_URL
= "http://mangas-lecture-en-ligne.fr/index_lel.php";
27 super(SupportType
.MANGA_LEL
);
31 public List
<SearchableTag
> getTags() throws IOException
{
32 List
<SearchableTag
> tags
= new ArrayList
<SearchableTag
>();
34 String url
= BASE_URL
+ "?page=recherche";
35 Document doc
= load(url
, false);
37 Element genre
= doc
.getElementsByClass("genre").first();
39 for (Element el
: genre
.getElementsByAttributeValueStarting("for",
41 tags
.add(new SearchableTag(el
.attr("for"), el
.text(), true));
49 public void fillTag(SearchableTag tag
) throws IOException
{
50 // Tags are always complete
54 public List
<MetaData
> search(String search
, int page
) throws IOException
{
55 String url
= BASE_URL
+ "?nomProjet="
56 + URLEncoder
.encode(search
, "utf-8")
57 + "&nomAuteur=&nomTeam=&page=recherche&truc=truc";
60 return getResults(url
);
64 public List
<MetaData
> search(SearchableTag tag
, int page
)
66 String url
= BASE_URL
+ "?nomProjet=&nomAuteur=&nomTeam=&"
67 + tag
.getId() + "=on&page=recherche&truc=truc";
70 return getResults(url
);
74 public int searchPages(String search
) throws IOException
{
80 public int searchPages(SearchableTag tag
) throws IOException
{
89 private List
<MetaData
> getResults(String sourceUrl
) throws IOException
{
90 List
<MetaData
> metas
= new ArrayList
<MetaData
>();
92 Document doc
= DataUtil
.load(Instance
.getInstance().getCache().open(new URL(sourceUrl
), getSupport(), false),
95 for (Element result
: doc
.getElementsByClass("rechercheAffichage")) {
96 Element a
= result
.getElementsByTag("a").first();
100 MetaData meta
= new MetaData();
103 // http://mangas-lecture-en-ligne.fr/index_lel.php?page=presentationProjet&idProjet=218
106 // http://mangas-lecture-en-ligne.fr/index_lel?onCommence=oui&idChapitre=2805
108 // ...but we need the PROJECT id, not the CHAPTER id -> use
111 Elements infos
= result
.getElementsByClass("texte");
113 String
[] tab
= infos
.outerHtml().split("<br>");
116 meta
.setSource(getType().getSourceName());
117 meta
.setPublisher(getType().getSourceName());
118 meta
.setType(getType().toString());
119 meta
.setSubject("manga");
120 meta
.setImageDocument(true);
121 meta
.setTitle(getVal(tab
, 0));
122 meta
.setAuthor(getVal(tab
, 1));
123 meta
.setTags(Arrays
.asList(getVal(tab
, 2).split(" ")));
125 meta
.setResume(getSupport().makeChapter(new URL(sourceUrl
), 0,
126 Instance
.getInstance().getTrans().getString(StringId
.DESCRIPTION
), getVal(tab
, 5)));
129 Element img
= result
.getElementsByTag("img").first();
132 String
[] tab
= img
.attr("src").split("/");
133 String str
= tab
[tab
.length
- 1];
134 tab
= str
.split("\\.");
136 projectId
= Integer
.parseInt(str
);
138 String coverUrl
= img
.absUrl("src");
140 InputStream in
= Instance
.getInstance().getCache().open(new URL(coverUrl
), getSupport(),
143 meta
.setCover(new Image(in
));
147 } catch (Exception e
) {
148 // Happen often on MangaLEL...
149 Instance
.getInstance().getTraceHandler().trace(
150 "Cannot download cover for MangaLEL story in search mode: " + meta
.getTitle());
152 } catch (Exception e
) {
153 // no project id... cannot use the story :(
154 Instance
.getInstance().getTraceHandler()
155 .error("Cannot find ProjectId for MangaLEL story in search mode: " + meta
.getTitle());
159 if (projectId
>= 0) {
160 meta
.setUrl("http://mangas-lecture-en-ligne.fr/index_lel.php?page=presentationProjet&idProjet="
162 meta
.setUuid(meta
.getUrl());
171 private String
getVal(String
[] tab
, int i
) {
174 if (i
< tab
.length
) {
175 val
= StringUtils
.unhtml(tab
[i
]);
176 int pos
= val
.indexOf(":");
178 val
= val
.substring(pos
+ 1).trim();