0

Отображение постеров к фильмам

This commit is contained in:
2017-05-26 01:26:08 +03:00
parent c70129ae9d
commit 3ec91237eb
5 changed files with 36 additions and 13 deletions

View File

@@ -62,13 +62,13 @@ public class OnlinelifeScanner implements ScannerCinema {
Document document = Jsoup.parse(browser.get(url));
Element element = document.getElementsByClass("full-poster").get(0);
File saveTo = new File(this.saveToDir, url.substring(url.lastIndexOf("/")+1, url.lastIndexOf("."))+".jpg");
this.fileDownloader.addFile(element.attr("src"), saveTo);
String pathFile = "onlinelife/"+url.substring(url.lastIndexOf("/")+1, url.lastIndexOf("."))+".jpg";
this.fileDownloader.addFile(element.attr("src"), new File(this.saveToDir, pathFile));
CinemaDocument cinemaDocument = new CinemaDocument();
cinemaDocument.setTitle(document.getElementsByClass("film_info").get(0).child(0).child(0).text().trim());
cinemaDocument.setDescription(document.getElementsByClass("film-description").get(0).text());
cinemaDocument.setFileName(saveTo.getAbsolutePath());
cinemaDocument.setFileName(pathFile);
cinemaDocument.setTypeWarez(this.getName());
cinemaDocument.setUrl(url);
repository.save(cinemaDocument);

View File

@@ -58,14 +58,14 @@ public class SeasonvarScanner implements ScannerCinema {
Document document = Jsoup.parse(browser.get(url));
Element element = document.getElementsByAttributeValue("itemprop", "thumbnailUrl").get(0);
File saveTo = new File(this.saveTo, url.substring(url.lastIndexOf("/")+1, url.lastIndexOf("."))+".jpg");
this.fileDownloader.addFile(element.attr("src"), saveTo);
String pathFile = "seasonvar/"+url.substring(url.lastIndexOf("/")+1, url.lastIndexOf("."))+".jpg";
this.fileDownloader.addFile(element.attr("src"), new File(this.saveTo, pathFile));
CinemaDocument cinemaDocument = new CinemaDocument();
String title = document.getElementsByClass("pgs-sinfo-title").get(0).text();
cinemaDocument.setTitle(title.replaceAll("^Сериал ", "").replaceAll(" онлайн$", ""));
cinemaDocument.setDescription(document.getElementsByAttributeValue("itemprop", "description").get(0).text());
cinemaDocument.setFileName(saveTo.getAbsolutePath());
cinemaDocument.setFileName(pathFile);
cinemaDocument.setTypeWarez(this.getName());
cinemaDocument.setUrl(url);
this.repository.save(cinemaDocument);

View File

@@ -6,27 +6,34 @@ package kinosearch.kinosearch3.webpp;
import kinosearch.kinosearch3.base.BaseRepository;
import kinosearch.kinosearch3.base.CinemaDocument;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
@Controller
@PropertySource("classpath:/application.properties")
public class WebAppController {
private final Logger logger = LoggerFactory.getLogger(WebAppController.class);
private final BaseRepository baseRepository;
private final String saveDir;
@Autowired
public WebAppController(BaseRepository baseRepository) {
public WebAppController(BaseRepository baseRepository, @Value("${saveRootDir}") String saveDir) {
this.baseRepository = baseRepository;
this.saveDir = saveDir;
}
@RequestMapping(value = "/", method = RequestMethod.GET)
@@ -45,6 +52,19 @@ public class WebAppController {
return "searchResult";
}
@RequestMapping(value = "/poster/**", method = RequestMethod.GET)
@ResponseBody
public void poster(HttpServletRequest request, HttpServletResponse response) throws IOException {
File posterFile = new File(this.saveDir, request.getPathInfo().substring("/poster/".length()));
logger.debug("poster file: {}", posterFile);
if (posterFile.exists()) {
response.setStatus(200);
IOUtils.copy(new FileInputStream(posterFile), response.getOutputStream());
} else {
response.setStatus(404);
}
}
@RequestMapping(value = "/blog.html", method = RequestMethod.GET)
public String blog() {
return "blog";

View File

@@ -43,14 +43,14 @@
<property name="encoding" value="windows-1251"/>
</bean>
</constructor-arg>
<constructor-arg name="saveToDir" value="file:${saveRootDir}/onlinelife"/>
<constructor-arg name="saveToDir" value="file:${saveRootDir}"/>
<constructor-arg name="repository" ref="repository"/>
</bean>
<bean id="seasonvarScanner" class="kinosearch.kinosearch3.cinema.SeasonvarScanner">
<constructor-arg name="fileDownloader" ref="fileDownloader"/>
<constructor-arg name="browser" ref="browser"/>
<constructor-arg name="saveTo" value="file:${saveRootDir}/seasonvar"/>
<constructor-arg name="saveTo" value="file:${saveRootDir}"/>
<constructor-arg name="repository" ref="repository"/>
</bean>

View File

@@ -7,7 +7,10 @@
[#if cindocs?has_content]
<ol>
[#list cindocs as cinema]
<li><a href="${cinema.url}" target="_blank">[${cinema.typeWarez}] ${cinema.title}</a></li>
<li>
<img src="/poster/${cinema.fileName}">
<a href="${cinema.url}" target="_blank">[${cinema.typeWarez}] ${cinema.title}</a>
</li>
[/#list]
</ol>
[#else]