Browse Source

fixed issue #6

pull/12/head
Jannik 4 years ago
parent
commit
9f8c19ab8e
  1. 33
      src/main/java/kellerkinder/HomeFlix/controller/DBController.java

33
src/main/java/kellerkinder/HomeFlix/controller/DBController.java

@ -161,6 +161,7 @@ public class DBController {
String path = source.asObject().getString("path", "");
String mode = source.asObject().getString("mode", "");
mainWindowController.addSourceToTable(path, mode); // add source to source-table
if (mode.equals("local")) {
for (File file : new File(path).listFiles()) {
if (file.isFile() && isVideoFile(file.getPath())) {
@ -350,11 +351,11 @@ public class DBController {
int sn = 1;
for (File season : file.listFiles()) {
if (season.isDirectory()) {
int ep = 1;
int ep = getLastEpisode(cutOffEnd(file.getName()), Integer.toString(sn)) + 1;
for (File episode : season.listFiles()) {
if (!filmsdbStreamURL.contains(episode.getPath())) {
ps.setString(1, episode.getPath().replace("'", "''"));
ps.setString(2, cutOffEnd(file.getName()));
ps.setString(2, cutOffEnd(file.getName())); // the title is the series root folder's name
ps.setString(3, Integer.toString(sn));
ps.setString(4, Integer.toString(ep));
ps.setInt(5, 0);
@ -406,6 +407,34 @@ public class DBController {
}
}
/**
* gets the last episode of a season of a given series
* @param seriesTitle the actual series
* @param season the actual season
* @return the last episode number
*/
private int getLastEpisode(String seriesTitle, String season) {
int lastEpisode = 0;
try {
Statement stmt = connection.createStatement();
PreparedStatement ps = connection.prepareStatement("SELECT * FROM films WHERE title = ? AND season = ?");
ps.setString(1, seriesTitle);
ps.setString(2, season);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
if (Integer.parseInt(rs.getString("episode")) > lastEpisode)
lastEpisode = Integer.parseInt(rs.getString("episode"));
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("An error occured, while printing all entries", e);
}
return lastEpisode;
}
/**
* DEBUG
* prints all entries from the database to the console

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close