@@ -2,7 +2,6 @@ package kinosearch.core;
|
|||||||
|
|
||||||
import kinosearch.core.browser.Browser;
|
import kinosearch.core.browser.Browser;
|
||||||
import kinosearch.core.browser.ApacheHttpBrowser;
|
import kinosearch.core.browser.ApacheHttpBrowser;
|
||||||
import kinosearch.core.warez.Hdrezka;
|
|
||||||
import kinosearch.core.warez.KinoWarez;
|
import kinosearch.core.warez.KinoWarez;
|
||||||
import kinosearch.core.warez.Onlinelife;
|
import kinosearch.core.warez.Onlinelife;
|
||||||
|
|
||||||
@@ -46,7 +45,6 @@ public class Tools {
|
|||||||
kinoWarezSet = new HashSet<>();
|
kinoWarezSet = new HashSet<>();
|
||||||
|
|
||||||
kinoWarezSet.add(new Onlinelife());
|
kinoWarezSet.add(new Onlinelife());
|
||||||
kinoWarezSet.add(new Hdrezka());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return kinoWarezSet;
|
return kinoWarezSet;
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
package kinosearch.core.warez;
|
|
||||||
|
|
||||||
import kinosearch.core.Kino;
|
|
||||||
import kinosearch.core.Tools;
|
|
||||||
import kinosearch.core.browser.Browser;
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
import org.jsoup.select.Elements;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class Hdrezka implements KinoWarez {
|
|
||||||
private static final String DOMAIN = "http://hdrezka.me";
|
|
||||||
private static final String NAME = "HDREZKA";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomain() {
|
|
||||||
return DOMAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Kino> search(String nameKino, boolean strong) {
|
|
||||||
Browser browser = Tools.createBrowser();
|
|
||||||
browser.setEncoding("UTF-8");
|
|
||||||
|
|
||||||
String html = browser.get(DOMAIN + "/?do=search&subaction=search&q=" + Tools.SafeUrlEncode(nameKino, "UTF-8"));
|
|
||||||
if (html.isEmpty()) return Collections.emptyList();
|
|
||||||
|
|
||||||
Document document = Jsoup.parse(html);
|
|
||||||
Pattern pattern = null;
|
|
||||||
if (strong) {
|
|
||||||
String nk = nameKino.toLowerCase();
|
|
||||||
pattern = Tools.getStrongPattern(nk);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Kino> outList = new ArrayList<>();
|
|
||||||
Elements elements = document.getElementsByClass("b-content__inline_item-cover");
|
|
||||||
for (Element element : elements) {
|
|
||||||
Element childElement = element.child(0);
|
|
||||||
String url = childElement.attr("href");
|
|
||||||
|
|
||||||
childElement = childElement.child(0);
|
|
||||||
String name = childElement.attr("alt");
|
|
||||||
|
|
||||||
if (strong) {
|
|
||||||
Matcher matcher = pattern.matcher(name.toLowerCase());
|
|
||||||
if (!matcher.find()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
outList.add(new Kino(name, url, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
return outList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String player(String page) {
|
|
||||||
//TODO ignore
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package core.warez;
|
|
||||||
|
|
||||||
import kinosearch.core.Kino;
|
|
||||||
import kinosearch.core.warez.Hdrezka;
|
|
||||||
import kinosearch.core.warez.KinoWarez;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class TestHdrezka {
|
|
||||||
@Test
|
|
||||||
public void testNormal() {
|
|
||||||
search(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStrong() {
|
|
||||||
search(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void search(boolean strong) {
|
|
||||||
KinoWarez kinoWarez = new Hdrezka();
|
|
||||||
|
|
||||||
String titleKino = "рик и морти";
|
|
||||||
List<Kino> kinoList = kinoWarez.search(titleKino, strong);
|
|
||||||
|
|
||||||
assertTrue(kinoList.size() > 0);
|
|
||||||
|
|
||||||
Kino kino = kinoList.get(0);
|
|
||||||
// System.out.printf("\"%s\" (%s)", kino.getName(), kino.getUrl()); //DEBUG
|
|
||||||
assertTrue(kino.getName().toLowerCase().contains(titleKino.toLowerCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user