diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/images/1047883_1711005940.png b/images/1047883_1711005940.png
new file mode 100644
index 0000000..6d9ee00
Binary files /dev/null and b/images/1047883_1711005940.png differ
diff --git a/images/1047883_1711005940.webp b/images/1047883_1711005940.webp
new file mode 100644
index 0000000..43dca6b
Binary files /dev/null and b/images/1047883_1711005940.webp differ
diff --git a/images/104992_1711005934.png b/images/104992_1711005934.png
new file mode 100644
index 0000000..688c4f8
Binary files /dev/null and b/images/104992_1711005934.png differ
diff --git a/images/104992_1711005934.webp b/images/104992_1711005934.webp
new file mode 100644
index 0000000..c0c5667
Binary files /dev/null and b/images/104992_1711005934.webp differ
diff --git a/images/1219149_1711005919.png b/images/1219149_1711005919.png
new file mode 100644
index 0000000..e9fcbd2
Binary files /dev/null and b/images/1219149_1711005919.png differ
diff --git a/images/1219149_1711005919.webp b/images/1219149_1711005919.webp
new file mode 100644
index 0000000..7cad0ae
Binary files /dev/null and b/images/1219149_1711005919.webp differ
diff --git a/images/1311078_1711005805.png b/images/1311078_1711005805.png
new file mode 100644
index 0000000..99d8c10
Binary files /dev/null and b/images/1311078_1711005805.png differ
diff --git a/images/1311078_1711005805.webp b/images/1311078_1711005805.webp
new file mode 100644
index 0000000..c9cd5c0
Binary files /dev/null and b/images/1311078_1711005805.webp differ
diff --git a/images/1338480_1711005954.png b/images/1338480_1711005954.png
new file mode 100644
index 0000000..4c6a42e
Binary files /dev/null and b/images/1338480_1711005954.png differ
diff --git a/images/1338480_1711005954.webp b/images/1338480_1711005954.webp
new file mode 100644
index 0000000..178b63a
Binary files /dev/null and b/images/1338480_1711005954.webp differ
diff --git a/images/1396687_1711005696.png b/images/1396687_1711005696.png
new file mode 100644
index 0000000..def56d3
Binary files /dev/null and b/images/1396687_1711005696.png differ
diff --git a/images/1396687_1711005696.webp b/images/1396687_1711005696.webp
new file mode 100644
index 0000000..b025e84
Binary files /dev/null and b/images/1396687_1711005696.webp differ
diff --git a/images/1405959_1711005703.png b/images/1405959_1711005703.png
new file mode 100644
index 0000000..976d251
Binary files /dev/null and b/images/1405959_1711005703.png differ
diff --git a/images/1405959_1711005703.webp b/images/1405959_1711005703.webp
new file mode 100644
index 0000000..1a0021b
Binary files /dev/null and b/images/1405959_1711005703.webp differ
diff --git a/images/1435343_1711005913.png b/images/1435343_1711005913.png
new file mode 100644
index 0000000..3a761a8
Binary files /dev/null and b/images/1435343_1711005913.png differ
diff --git a/images/1435343_1711005913.webp b/images/1435343_1711005913.webp
new file mode 100644
index 0000000..cd227c4
Binary files /dev/null and b/images/1435343_1711005913.webp differ
diff --git a/images/1711005829_bez-nazvanija.png b/images/1711005829_bez-nazvanija.png
new file mode 100644
index 0000000..9966570
Binary files /dev/null and b/images/1711005829_bez-nazvanija.png differ
diff --git a/images/1711005829_bez-nazvanija.webp b/images/1711005829_bez-nazvanija.webp
new file mode 100644
index 0000000..75e5cb7
Binary files /dev/null and b/images/1711005829_bez-nazvanija.webp differ
diff --git a/images/1711005866_180266.png b/images/1711005866_180266.png
new file mode 100644
index 0000000..6431cf2
Binary files /dev/null and b/images/1711005866_180266.png differ
diff --git a/images/1711005866_180266.webp b/images/1711005866_180266.webp
new file mode 100644
index 0000000..4084303
Binary files /dev/null and b/images/1711005866_180266.webp differ
diff --git a/images/1993_1711005947.png b/images/1993_1711005947.png
new file mode 100644
index 0000000..09b96dd
Binary files /dev/null and b/images/1993_1711005947.png differ
diff --git a/images/1993_1711005947.webp b/images/1993_1711005947.webp
new file mode 100644
index 0000000..8cf752f
Binary files /dev/null and b/images/1993_1711005947.webp differ
diff --git a/images/2213_1711005981.png b/images/2213_1711005981.png
new file mode 100644
index 0000000..d5c741c
Binary files /dev/null and b/images/2213_1711005981.png differ
diff --git a/images/2213_1711005981.webp b/images/2213_1711005981.webp
new file mode 100644
index 0000000..4656038
Binary files /dev/null and b/images/2213_1711005981.webp differ
diff --git a/images/403_1711005928.png b/images/403_1711005928.png
new file mode 100644
index 0000000..fdca047
Binary files /dev/null and b/images/403_1711005928.png differ
diff --git a/images/403_1711005928.webp b/images/403_1711005928.webp
new file mode 100644
index 0000000..8df3d55
Binary files /dev/null and b/images/403_1711005928.webp differ
diff --git a/images/4482093_1711005725.png b/images/4482093_1711005725.png
new file mode 100644
index 0000000..5212c15
Binary files /dev/null and b/images/4482093_1711005725.png differ
diff --git a/images/4482093_1711005725.webp b/images/4482093_1711005725.webp
new file mode 100644
index 0000000..5611468
Binary files /dev/null and b/images/4482093_1711005725.webp differ
diff --git a/images/4511631_1711005878.png b/images/4511631_1711005878.png
new file mode 100644
index 0000000..99f3bb1
Binary files /dev/null and b/images/4511631_1711005878.png differ
diff --git a/images/4511631_1711005878.webp b/images/4511631_1711005878.webp
new file mode 100644
index 0000000..3c7357b
Binary files /dev/null and b/images/4511631_1711005878.webp differ
diff --git a/images/4540126_1711005740.png b/images/4540126_1711005740.png
new file mode 100644
index 0000000..ad38a32
Binary files /dev/null and b/images/4540126_1711005740.png differ
diff --git a/images/4540126_1711005740.webp b/images/4540126_1711005740.webp
new file mode 100644
index 0000000..44992f5
Binary files /dev/null and b/images/4540126_1711005740.webp differ
diff --git a/images/4878248_1711005974.png b/images/4878248_1711005974.png
new file mode 100644
index 0000000..22ae07a
Binary files /dev/null and b/images/4878248_1711005974.png differ
diff --git a/images/4878248_1711005974.webp b/images/4878248_1711005974.webp
new file mode 100644
index 0000000..8e7da8e
Binary files /dev/null and b/images/4878248_1711005974.webp differ
diff --git a/images/5024491_1711005884.png b/images/5024491_1711005884.png
new file mode 100644
index 0000000..a8bcc9f
Binary files /dev/null and b/images/5024491_1711005884.png differ
diff --git a/images/5024491_1711005884.webp b/images/5024491_1711005884.webp
new file mode 100644
index 0000000..ab234e7
Binary files /dev/null and b/images/5024491_1711005884.webp differ
diff --git a/images/5120138_1711005811.png b/images/5120138_1711005811.png
new file mode 100644
index 0000000..5ede1d0
Binary files /dev/null and b/images/5120138_1711005811.png differ
diff --git a/images/5120138_1711005811.webp b/images/5120138_1711005811.webp
new file mode 100644
index 0000000..50ccf2a
Binary files /dev/null and b/images/5120138_1711005811.webp differ
diff --git a/images/5144406_1711005839.png b/images/5144406_1711005839.png
new file mode 100644
index 0000000..1a362d5
Binary files /dev/null and b/images/5144406_1711005839.png differ
diff --git a/images/5144406_1711005839.webp b/images/5144406_1711005839.webp
new file mode 100644
index 0000000..16e7a59
Binary files /dev/null and b/images/5144406_1711005839.webp differ
diff --git a/images/5364708_1711005849.png b/images/5364708_1711005849.png
new file mode 100644
index 0000000..b34e1d8
Binary files /dev/null and b/images/5364708_1711005849.png differ
diff --git a/images/5364708_1711005849.webp b/images/5364708_1711005849.webp
new file mode 100644
index 0000000..643d785
Binary files /dev/null and b/images/5364708_1711005849.webp differ
diff --git a/images/5437562_1711005900.png b/images/5437562_1711005900.png
new file mode 100644
index 0000000..7966301
Binary files /dev/null and b/images/5437562_1711005900.png differ
diff --git a/images/5437562_1711005900.webp b/images/5437562_1711005900.webp
new file mode 100644
index 0000000..cce4f45
Binary files /dev/null and b/images/5437562_1711005900.webp differ
diff --git a/images/804476_1711005789.png b/images/804476_1711005789.png
new file mode 100644
index 0000000..b0873b5
Binary files /dev/null and b/images/804476_1711005789.png differ
diff --git a/images/804476_1711005789.webp b/images/804476_1711005789.webp
new file mode 100644
index 0000000..0a1d88a
Binary files /dev/null and b/images/804476_1711005789.webp differ
diff --git a/images/817324_1711005962.png b/images/817324_1711005962.png
new file mode 100644
index 0000000..6ded301
Binary files /dev/null and b/images/817324_1711005962.png differ
diff --git a/images/817324_1711005962.webp b/images/817324_1711005962.webp
new file mode 100644
index 0000000..ea8384d
Binary files /dev/null and b/images/817324_1711005962.webp differ
diff --git a/images/891578_1711005797.png b/images/891578_1711005797.png
new file mode 100644
index 0000000..c810d83
Binary files /dev/null and b/images/891578_1711005797.png differ
diff --git a/images/891578_1711005797.webp b/images/891578_1711005797.webp
new file mode 100644
index 0000000..91fcb69
Binary files /dev/null and b/images/891578_1711005797.webp differ
diff --git a/images/913425_1711005908.png b/images/913425_1711005908.png
new file mode 100644
index 0000000..ba970bb
Binary files /dev/null and b/images/913425_1711005908.png differ
diff --git a/images/913425_1711005908.webp b/images/913425_1711005908.webp
new file mode 100644
index 0000000..4ca3266
Binary files /dev/null and b/images/913425_1711005908.webp differ
diff --git a/pom.xml b/pom.xml
index e16f1b5..049fde2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,20 @@
+
+
+ org.jsoup
+ jsoup
+ 1.17.2
+
+
+
+
+ org.sejda.imageio
+ webp-imageio
+ 0.1.6
+
+
org.openjfx
javafx-controls
diff --git a/src/main/java/com/mdkefir/filmlibrary/Main.java b/src/main/java/com/mdkefir/filmlibrary/Main.java
index 763004c..b05075c 100644
--- a/src/main/java/com/mdkefir/filmlibrary/Main.java
+++ b/src/main/java/com/mdkefir/filmlibrary/Main.java
@@ -17,7 +17,7 @@ public static void main(String[] args) {
@Override
public void start(Stage primaryStage) {
try {
- primaryStage.setMinWidth(920);
+ primaryStage.setMinWidth(980);
primaryStage.setMinHeight(620);
Button closeButton = new Button("Закрыть");
closeButton.setOnAction(e -> primaryStage.close());
diff --git a/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java b/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
index b27cbd5..176d1c7 100644
--- a/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
+++ b/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
@@ -3,23 +3,36 @@
import com.mdkefir.filmlibrary.models.Movie;
import com.mdkefir.filmlibrary.models.Series;
import com.mdkefir.filmlibrary.models.SportEvent;
+import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
-import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
-import javafx.scene.layout.AnchorPane;
-import javafx.scene.layout.Region;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
-import java.io.InputStream;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import javax.imageio.ImageIO;
public class MainController {
@@ -57,21 +70,89 @@ private void handleSearch() {
@FXML
private ToggleGroup categoryToggleGroup = new ToggleGroup();
- @FXML
- private List getMovies() {
- return List.of(
- new Movie("Терминатор 2: СД", "/com/mdkefir/filmlibrary/images/movies/1.png"),
- new Movie("1+1", "/com/mdkefir/filmlibrary/images/movies/2.png"),
- new Movie("Ходячий замок", "/com/mdkefir/filmlibrary/images/movies/3.png"),
- new Movie("Список Шиндлера", "/com/mdkefir/filmlibrary/images/movies/4.png"),
- new Movie("Властелин колец", "/com/mdkefir/filmlibrary/images/movies/5.png"),
- new Movie("Бойцовский клуб", "/com/mdkefir/filmlibrary/images/movies/6.png"),
- new Movie("Интерстеллар", "/com/mdkefir/filmlibrary/images/movies/7.png"),
- new Movie("Форрест Гамп", "/com/mdkefir/filmlibrary/images/movies/8.png"),
- new Movie("Зеленая миля", "/com/mdkefir/filmlibrary/images/movies/9.png"),
- new Movie("Властелин колец 2", "/com/mdkefir/filmlibrary/images/movies/10.png")
- // Добавьте больше фильмов
- );
+
+ public void getMovies() {
+ new Thread(() -> {
+ try {
+ List movies = parseKinopoisk();
+ Platform.runLater(() -> {
+ // обновите ваш TilePane с помощью полученных данных
+ try {
+ updateTilePaneContent(movies);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }).start();
+ }
+
+ public String downloadImage(String imageUrl, String s) throws IOException {
+ // Create a URL object from the image URL string
+ URL url = new URL(imageUrl);
+ // Extract the file name from the URL
+ String fileName = Paths.get(url.getPath()).getFileName().toString();
+ // Define the path where the image will be saved
+ Path targetPath = Paths.get(System.getProperty("user.dir")).resolve("images").resolve(fileName);
+
+ // Open a stream to the image URL
+ try (InputStream in = url.openStream()) {
+ // Copy the image to the target path, replacing any existing file
+ Files.copy(in, targetPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ // Return the file path as a string
+ return targetPath.toString();
+ }
+
+ public String downloadAndConvertImage(String imageUrl, String destinationFolder) throws IOException, URISyntaxException {
+ // Скачивание изображения
+ String imageExtension = imageUrl.substring(imageUrl.lastIndexOf(".") + 1);
+ String localImagePath = downloadImage(imageUrl, destinationFolder);
+
+ // Конвертация в формат PNG, если это необходимо
+ if (!"png".equals(imageExtension) && !"jpg".equals(imageExtension)) {
+ String outputImagePath = localImagePath.substring(0, localImagePath.lastIndexOf(".")) + ".png";
+ convertToPng(localImagePath, outputImagePath);
+ return outputImagePath; // Вернуть новый путь к изображению
+ }
+
+ return localImagePath; // Вернуть исходный путь к изображению
+ }
+
+ public static void convertToPng(String inputImagePath, String outputImagePath) throws IOException {
+ BufferedImage bufferedImage = ImageIO.read(new File(inputImagePath));
+ ImageIO.write(bufferedImage, "png", new File(outputImagePath));
+ }
+
+ public List parseKinopoisk() {
+ List movies = new ArrayList<>();
+ try {
+ String baseUrl = "https://lordfilm.ai/";
+ Document doc = Jsoup.connect(baseUrl).get();
+ Elements movieElements = doc.select(".th-item"); // Обновленный селектор
+
+ for (Element movieElement : movieElements) {
+ String title = movieElement.select(".th-title").text();
+ String imageUrl = movieElement.select("img").first().absUrl("src");
+
+ if (!imageUrl.isEmpty()) {
+ // Download image and get local path
+ String localImagePath = downloadAndConvertImage(imageUrl, "/com/mdkefir/filmlibrary/images/");
+ // Use local path instead of URL
+ movies.add(new Movie(title, localImagePath));
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ return movies;
}
@FXML
private List getSeries() {
@@ -99,9 +180,6 @@ private List getSportEvents() {
// Добавьте больше спортивных событий
);
}
- private Node getContentForMovies() {
- return createContentTilePane(getMovies());
- }
private Node getContentForSeries() {
return createContentTilePane(getSeries());
@@ -119,8 +197,6 @@ private VBox createVBoxForContent(String title, String imagePath) {
}
Image image = new Image(is);
ImageView imageView = new ImageView(image);
- imageView.setFitHeight(225);
- imageView.setFitWidth(150);
Label label = new Label(title);
vbox.getChildren().addAll(imageView, label);
vbox.getStyleClass().add("filmListTile"); // Добавьте класс стилей, как в вашем FXML
@@ -135,12 +211,11 @@ public void initialize() {
sportsButton.setToggleGroup(categoryToggleGroup);
// настройка категорий для отображения
- moviesButton.setOnAction(event -> updateTilePaneContent(getContentForMovies()));
- seriesButton.setOnAction(event -> updateTilePaneContent(getContentForSeries()));
- sportsButton.setOnAction(event -> updateTilePaneContent(getContentForSports()));
+ moviesButton.setOnAction(event -> loadMovies());
+ seriesButton.setOnAction(event -> loadMovies()); // Обновите для работы с сериалами
+ sportsButton.setOnAction(event -> loadMovies()); // Обновите для работы со спортивными событиями
- // По умолчанию показываем контент для фильмов
- updateTilePaneContent(getContentForMovies());
+ loadMovies(); // Загрузка фильмов при инициализации
// Найти все VBox'ы с классом "film-box"
List filmBoxes = moviesTilePane.getChildren().stream()
@@ -195,19 +270,59 @@ private void onCountrySelected(ActionEvent event) {
private void onRatingSelected(ActionEvent event) {
// Логика обработки выбора рейтинга
}
- @FXML
- private void updateTilePaneContent(Node content) {
- if (content instanceof ScrollPane) {
- ScrollPane scrollPane = (ScrollPane) content;
- if (scrollPane.getContent() instanceof TilePane) {
- TilePane newTilePane = (TilePane) scrollPane.getContent();
-
- moviesTilePane.getChildren().clear(); // Очистка текущего содержимого TilePane
- moviesTilePane.getChildren().addAll(newTilePane.getChildren()); // Добавление нового содержимого
- }
+ public void updateMovieList() {
+ new Thread(() -> {
+ List movies = parseKinopoisk();
+ Platform.runLater(() -> {
+ try {
+ updateTilePaneContent(movies);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }).start();
+ }
+ // Этот метод теперь принимает List и обновляет moviesTilePane
+ public void updateTilePaneContent(List movies) throws FileNotFoundException, URISyntaxException {
+ moviesTilePane.getChildren().clear();
+ for (Movie movie : movies) {
+ Node movieNode = createMovieNode(movie);
+ moviesTilePane.getChildren().add(movieNode);
}
}
+ private Node createMovieNode(Movie movie) throws FileNotFoundException, URISyntaxException {
+ VBox vbox = new VBox();
+ vbox.setAlignment(Pos.CENTER);
+ // Create an Image object using the file path
+ File file = new File(movie.getImagePath());
+ Image image = new Image(file.toURI().toString());
+ ImageView imageView = new ImageView(image);
+ Label label = new Label(movie.getTitle());
+ vbox.getChildren().addAll(imageView, label);
+ imageView.setFitHeight(225);
+ imageView.setFitWidth(150);
+ return vbox;
+ }
+
+ // Этот метод вызывается при инициализации или при смене категории
+ public void loadMovies() {
+ new Thread(() -> {
+ List movies = parseKinopoisk(); // Парсинг данных
+ Platform.runLater(() -> {
+ try {
+ updateTilePaneContent(movies); // Обновление UI
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }).start();
+ }
+
private Node createContentTilePane(List> contents) {
TilePane tilePane = new TilePane();
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 0146e9c..78d5960 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -6,6 +6,8 @@
requires com.dlsc.formsfx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.bootstrapfx.core;
+ requires org.jsoup;
+ requires java.desktop;
opens com.mdkefir.filmlibrary.controllers to javafx.fxml;
exports com.mdkefir.filmlibrary;
diff --git a/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml b/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
index b12939b..5b195b7 100644
--- a/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
+++ b/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
@@ -55,7 +55,7 @@
-
+
@@ -144,9 +144,9 @@
-
+
-
+