[WIP] Now it is possible to get all subtitles from the database (including language and films) and to print them through the logger.
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
9890b005fd
commit
4490eff40c
@ -5,6 +5,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.vallat.louis.codes.ExitCodes;
|
||||
import xyz.vallat.louis.database.DBManager;
|
||||
import xyz.vallat.louis.database.SubtitleManager;
|
||||
import xyz.vallat.louis.discord.DiscordManager;
|
||||
import xyz.vallat.louis.sockets.CommandsClient;
|
||||
import xyz.vallat.louis.sockets.CommandsServer;
|
||||
@ -94,8 +95,12 @@ public class MoviesQuoteBot {
|
||||
}
|
||||
|
||||
private static void reimportAllSubtitleLines() {
|
||||
logger.info("Reimporting all subtitle lines.");
|
||||
CommandsClient.checkVersions();
|
||||
CommandsClient.setMaintenanceMode(true);
|
||||
SubtitleManager.getSubtitles().forEach(subtitle ->
|
||||
logger.debug("[{}] - '{}' in {}.", subtitle.getId(), subtitle.getMovie(), subtitle.getLang().getEnglish())
|
||||
);
|
||||
CommandsClient.setMaintenanceMode(false);
|
||||
System.exit(0);
|
||||
}
|
||||
|
@ -4,11 +4,12 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.vallat.louis.codes.ExitCodes;
|
||||
import xyz.vallat.louis.omdb.objects.Movie;
|
||||
import xyz.vallat.louis.subtitles.dao.Lang;
|
||||
import xyz.vallat.louis.subtitles.dao.Subtitle;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class SubtitleManager {
|
||||
|
||||
@ -33,6 +34,46 @@ public final class SubtitleManager {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static List<Subtitle> getSubtitles() {
|
||||
logger.debug("Getting all subtitles in database.");
|
||||
List<Subtitle> subtitles = new ArrayList<>();
|
||||
try (Connection connection = DBManager.getConnection()) {
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
String query = """
|
||||
SELECT films.id AS film_id, imdb_id, title, year, film_type, poster_link,
|
||||
languages.id AS language_id, alpha3_b, alpha3_t, alpha2, english, french, subtitles.id AS subtitle_id
|
||||
FROM subtitles INNER JOIN films ON subtitles.film_id = films.id
|
||||
INNER JOIN languages ON subtitles.language_id = languages.id ORDER BY subtitles.id;""";
|
||||
stmt.executeQuery(query);
|
||||
while (stmt.getResultSet().next()) {
|
||||
ResultSet set = stmt.getResultSet();
|
||||
Movie movie = new Movie(
|
||||
set.getString("title"),
|
||||
set.getString("imdb_id"),
|
||||
set.getString("film_type"),
|
||||
set.getString("poster_link")
|
||||
);
|
||||
movie.setId(set.getInt("film_id"));
|
||||
if (set.getObject("year") == null) movie.setYear(set.getInt("year"));
|
||||
Lang lang = new Lang(
|
||||
set.getInt("language_id"),
|
||||
set.getString("alpha3_b"),
|
||||
set.getString("alpha3_t"),
|
||||
set.getString("alpha2"),
|
||||
set.getString("english"),
|
||||
set.getString("french")
|
||||
);
|
||||
subtitles.add(new Subtitle(set.getInt("subtitle_id"), movie, lang));
|
||||
}
|
||||
return subtitles;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Could not connect to the database right now. Reason: {}", e.getMessage());
|
||||
System.exit(ExitCodes.CANNOT_CONNECT_TO_DB.getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getNumberOfSubtitlesByGuild(String guild_id) {
|
||||
logger.debug("Getting the number of subtitles in database from guild '{}'.", guild_id);
|
||||
try (Connection connection = DBManager.getConnection()) {
|
||||
|
28
src/main/java/xyz/vallat/louis/subtitles/dao/Subtitle.java
Normal file
28
src/main/java/xyz/vallat/louis/subtitles/dao/Subtitle.java
Normal file
@ -0,0 +1,28 @@
|
||||
package xyz.vallat.louis.subtitles.dao;
|
||||
|
||||
import xyz.vallat.louis.omdb.objects.Movie;
|
||||
|
||||
public class Subtitle {
|
||||
|
||||
private final int id;
|
||||
private final Movie movie;
|
||||
private final Lang lang;
|
||||
|
||||
public Subtitle(int id, Movie movie, Lang lang) {
|
||||
this.id = id;
|
||||
this.movie = movie;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Movie getMovie() {
|
||||
return movie;
|
||||
}
|
||||
|
||||
public Lang getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user