Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added images/1047883_1711005940.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1047883_1711005940.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/104992_1711005934.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/104992_1711005934.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1219149_1711005919.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1219149_1711005919.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1311078_1711005805.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1311078_1711005805.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1338480_1711005954.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1338480_1711005954.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1396687_1711005696.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1396687_1711005696.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1405959_1711005703.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1405959_1711005703.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1435343_1711005913.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1435343_1711005913.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005829_bez-nazvanija.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005829_bez-nazvanija.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005866_180266.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1711005866_180266.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1993_1711005947.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1993_1711005947.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2213_1711005981.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/2213_1711005981.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/403_1711005928.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/403_1711005928.webp
Binary file added images/4482093_1711005725.png
Binary file added images/4482093_1711005725.webp
Binary file added images/4511631_1711005878.png
Binary file added images/4511631_1711005878.webp
Binary file added images/4540126_1711005740.png
Binary file added images/4540126_1711005740.webp
Binary file added images/4878248_1711005974.png
Binary file added images/4878248_1711005974.webp
Binary file added images/5024491_1711005884.png
Binary file added images/5024491_1711005884.webp
Binary file added images/5120138_1711005811.png
Binary file added images/5120138_1711005811.webp
Binary file added images/5144406_1711005839.png
Binary file added images/5144406_1711005839.webp
Binary file added images/5364708_1711005849.png
Binary file added images/5364708_1711005849.webp
Binary file added images/5437562_1711005900.png
Binary file added images/5437562_1711005900.webp
Binary file added images/804476_1711005789.png
Binary file added images/804476_1711005789.webp
Binary file added images/817324_1711005962.png
Binary file added images/817324_1711005962.webp
Binary file added images/891578_1711005797.png
Binary file added images/891578_1711005797.webp
Binary file added images/913425_1711005908.png
Binary file added images/913425_1711005908.webp
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
</properties>

<dependencies>
<dependency>
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.sejda.imageio/webp-imageio -->
<dependency>
<groupId>org.sejda.imageio</groupId>
<artifactId>webp-imageio</artifactId>
<version>0.1.6</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mdkefir/filmlibrary/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
193 changes: 154 additions & 39 deletions src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -57,21 +70,89 @@ private void handleSearch() {

@FXML
private ToggleGroup categoryToggleGroup = new ToggleGroup();
@FXML
private List<Movie> 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<Movie> 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<Movie> parseKinopoisk() {
List<Movie> 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<Series> getSeries() {
Expand Down Expand Up @@ -99,9 +180,6 @@ private List<SportEvent> getSportEvents() {
// Добавьте больше спортивных событий
);
}
private Node getContentForMovies() {
return createContentTilePane(getMovies());
}

private Node getContentForSeries() {
return createContentTilePane(getSeries());
Expand All @@ -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
Expand All @@ -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<VBox> filmBoxes = moviesTilePane.getChildren().stream()
Expand Down Expand Up @@ -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<Movie> movies = parseKinopoisk();
Platform.runLater(() -> {
try {
updateTilePaneContent(movies);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
});
}).start();
}
// Этот метод теперь принимает List<Movie> и обновляет moviesTilePane
public void updateTilePaneContent(List<Movie> 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<Movie> 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();

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox fx:id="mainVBox" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="900.0" style="-fx-background-color: #151a1e;" stylesheets="@../css/style.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.mdkefir.filmlibrary.controllers.MainController">
<VBox fx:id="mainVBox" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="960.0" style="-fx-background-color: #151a1e;" stylesheets="@../css/style.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.mdkefir.filmlibrary.controllers.MainController">
<children>
<MenuBar style="-fx-background-color: #151a1e;" VBox.vgrow="NEVER">
<menus>
Expand Down Expand Up @@ -144,9 +144,9 @@
</AnchorPane>
<ScrollPane fitToHeight="true" fitToWidth="true" style="-fx-background-color: #1e252b;">
<content>
<TilePane fx:id="moviesTilePane" alignment="TOP_LEFT" hgap="10" prefColumns="3" prefRows="3" style="-fx-background-color: #1e252b;" vgap="10">
<TilePane fx:id="moviesTilePane" alignment="TOP_LEFT" hgap="-110" prefColumns="3" prefRows="3" style="-fx-background-color: #1e252b;" vgap="10">
<padding>
<Insets bottom="5" left="10" right="10" top="5" />
<Insets bottom="5" left="-60" right="-70" top="5" />
</padding>
<!-- Ваши элементы VBox здесь -->
</TilePane>
Expand Down