Добавлен кинотеатр seasonvar.ru
Есть проблема: в этой "киношке" сезоны разбиты на отдельные страницы, которые поиском не ищутся. Их необходимо парсить отдельно. see #19
This commit is contained in:
114
src/main/java/kinosearch/core/warez/Seasonvar.java
Normal file
114
src/main/java/kinosearch/core/warez/Seasonvar.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* DmitriyMX <mail@dmitriymx.ru>
|
||||
* 2017-01-08
|
||||
*/
|
||||
package kinosearch.core.warez;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import kinosearch.core.Kino;
|
||||
import kinosearch.core.KinoItem;
|
||||
import kinosearch.core.KinoPlay;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
public class Seasonvar implements KinoWarez {
|
||||
private static final String DOMAIN = "http://seasonvar.ru";
|
||||
private static final String NAME = "Seasonvar";
|
||||
@Autowired
|
||||
private Browser browser;
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Kino> search(String nameKino, boolean strong) {
|
||||
String html = browser.get(DOMAIN + "/search?q=" + Tools.SafeUrlEncode(nameKino, "UTF-8"));
|
||||
if (html.isEmpty()) return Collections.emptyList();
|
||||
|
||||
Pattern pattern = null;
|
||||
if (strong) {
|
||||
pattern = Tools.getStrongPattern(nameKino.toLowerCase());
|
||||
}
|
||||
|
||||
Document document = Jsoup.parse(html);
|
||||
Elements elements = document.getElementsByClass("searchName");
|
||||
List<Kino> outList = new ArrayList<>();
|
||||
for (Element element : elements) {
|
||||
Element childElement = element.child(0);
|
||||
String name = childElement.text();
|
||||
String url = childElement.attr("href");
|
||||
|
||||
if (strong) {
|
||||
Matcher matcher = pattern.matcher(name.toLowerCase());
|
||||
if (!matcher.find()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Kino kino = new Kino(name, DOMAIN + url, this);
|
||||
kino.setPlayer(true);
|
||||
outList.add(kino);
|
||||
}
|
||||
|
||||
return outList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KinoPlay player(String page) {
|
||||
Pattern pattern = Pattern.compile("^\\/serial-(\\d+)-.+");
|
||||
Matcher matcher = pattern.matcher(page);
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String movie_id = matcher.group(1);
|
||||
final String secureCode = "9459932d3ce5d6ece7cafdd9278bf79a8";
|
||||
|
||||
String json = browser.get(String.format(
|
||||
"%s/playls2/%s/trans/%s/list.xml",
|
||||
DOMAIN, secureCode, movie_id));
|
||||
|
||||
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
|
||||
|
||||
KinoPlay kinoPlay = new KinoPlay();
|
||||
kinoPlay.setType(KinoPlay.KinoType.SIMPLE_SERIAL);
|
||||
|
||||
List<KinoItem> serials = new ArrayList<>();
|
||||
JsonArray jsonArray = jsonObject.get("playlist").getAsJsonArray();
|
||||
for (JsonElement jsonElement : jsonArray) {
|
||||
jsonObject = jsonElement.getAsJsonObject();
|
||||
serials.add(new KinoItem(
|
||||
jsonObject.get("comment").getAsString().replace("<br>", ""),
|
||||
jsonObject.get("file").getAsString().replace("http://", "/proxy/seasonvar/")
|
||||
));
|
||||
}
|
||||
kinoPlay.setSerials(serials);
|
||||
|
||||
return kinoPlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomain() {
|
||||
return DOMAIN;
|
||||
}
|
||||
}
|
||||
48
src/test/java/core/warez/TestSeasonvar.java
Normal file
48
src/test/java/core/warez/TestSeasonvar.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* DmitriyMX <mail@dmitriymx.ru>
|
||||
* 2017-01-08
|
||||
*/
|
||||
package core.warez;
|
||||
|
||||
import kinosearch.core.Kino;
|
||||
import kinosearch.core.KinoPlay;
|
||||
import kinosearch.core.SpringConfig;
|
||||
import kinosearch.core.warez.KinoWarez;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {SpringConfig.class})
|
||||
public class TestSeasonvar {
|
||||
@Autowired
|
||||
@Qualifier("seasonvar")
|
||||
private KinoWarez kinoWarez;
|
||||
|
||||
@Test
|
||||
public void testSearch() {
|
||||
String titleKino = "рик и морти";
|
||||
List<Kino> kinoList = kinoWarez.search(titleKino, false);
|
||||
|
||||
assertNotNull(kinoList);
|
||||
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()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayer() {
|
||||
KinoPlay kinoPlay = kinoWarez.player("/serial-3045-GurrenLagann.html");
|
||||
assertNotNull(kinoPlay);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user