Skip to content

Commit

Permalink
Merge pull request #36 from DrRename/feature/fixable-items
Browse files Browse the repository at this point in the history
Feature/fixable items
  • Loading branch information
kerner1000 authored Oct 25, 2022
2 parents e24176e + b3728e9 commit 09ab476
Show file tree
Hide file tree
Showing 133 changed files with 3,977 additions and 1,115 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<main-class>org.springframework.boot.loader.JarLauncher</main-class>
<java.version>17</java.version>
<javafx.version>19</javafx.version>
<spring-cloud-version>3.1.14</spring-cloud-version>
<sonar.coverage.exclusions>src/main/java/drrename/PrimaryStageInitializer.java</sonar.coverage.exclusions>
</properties>
<scm>
Expand Down Expand Up @@ -127,6 +128,11 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-maven-plugin</artifactId>
<version>3.0.3</version>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down Expand Up @@ -189,6 +195,20 @@
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/drrename/DrRenameApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

@Slf4j
public class DrRenameApplication extends Application {

private ConfigurableApplicationContext applicationContext;
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/drrename/FileTypeByMimeProvider.java

This file was deleted.

20 changes: 9 additions & 11 deletions src/main/java/drrename/GeneralExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

@Slf4j
@Component
Expand All @@ -22,21 +20,21 @@ private class Handler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
log.error("Uncaught exception on thread {}", t, e);
Platform.runLater(() -> showAlertDialog(e));
}

private void showAlertDialog(Throwable e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(String.format(resourceBundle.getString(ALERT_TITLE)));
alert.setHeaderText(e.toString());

TextArea area = new TextArea(Arrays.stream(e.getStackTrace())
.map(StackTraceElement::toString)
.collect(Collectors.joining("\n")));

alert.setHeaderText(e.getLocalizedMessage());
TextArea area = new TextArea(RenameUtil.stackTraceToString(e));
alert.getDialogPane().setContent(area);
area.setWrapText(true);
area.setEditable(false);
alert.setResizable(true);


Platform.runLater(alert::showAndWait);
alert.getDialogPane().setPrefHeight(300);
alert.getDialogPane().setPrefWidth(400);
alert.showAndWait();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/drrename/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package drrename;

import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import drrename.ui.ResourceBundleAwareLazyFxControllerAndViewResolver;
import javafx.scene.Node;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -9,13 +10,16 @@
import org.springframework.beans.factory.InjectionPoint;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

import java.util.ResourceBundle;

@Slf4j
@EnableFeignClients
@EnableEncryptableProperties
@SpringBootApplication
public class Launcher {

Expand Down
110 changes: 110 additions & 0 deletions src/main/java/drrename/MovieDbChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Dr.Rename - A Minimalistic Batch Renamer
*
* Copyright (C) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package drrename;

import drrename.config.TheMovieDbConfig;
import drrename.kodi.nfo.MovieDbCheckType;
import drrename.model.themoviedb.SearchResultDto;
import drrename.model.themoviedb.TranslationDto;
import drrename.model.themoviedb.TranslationsDto;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.io.IOError;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;

@Getter
@Setter
@Slf4j
@Component
@Scope("prototype")
public class MovieDbChecker {

private final MovieDbClient client;

private final TheMovieDbConfig config;

private final ResourceBundle resourceBundle;

private Set<String> onlineTitles;

private String theMovieDbId;

public MovieDbChecker(MovieDbClient client, TheMovieDbConfig config, ResourceBundle resourceBundle) {
this.client = client;
this.config = config;
this.resourceBundle = resourceBundle;
}

protected void reset(){
this.onlineTitles = new LinkedHashSet<>();
this.theMovieDbId = null;
}

public MovieDbCheckType check(String searchString, Integer year) throws IOException {
reset();
var searchResult = client.searchMovie(config.getApiKey(), null, config.isIncludeAdult(), searchString, year);
ResponseEntity<TranslationsDto> translatinos;
if(searchResult.getBody() != null && !searchResult.getBody().getResults().isEmpty()){
SearchResultDto firstResult = searchResult.getBody().getResults().get(0);
getOnlineTitles().add(buildNameString(firstResult.getTitle(), firstResult.getReleaseDate()));
getOnlineTitles().add(buildNameString(firstResult.getOriginalTitle(), firstResult.getReleaseDate()));
if(searchString.equals(firstResult.getTitle())){
theMovieDbId = firstResult.getPosterPath();
return MovieDbCheckType.ORIGINAL_TITEL;
}
if(searchString.equals(firstResult.getOriginalTitle())){
theMovieDbId = firstResult.getPosterPath();
return MovieDbCheckType.ORIGINAL_TITEL;
}
translatinos = client.getTranslations(firstResult.getId(), config.getApiKey());
if(translatinos.getBody() != null){
for(TranslationDto translationDto : translatinos.getBody().getTranslations()){
String iso1 = translationDto.getIso3166();
String iso2 = translationDto.getIso639();
String title = translationDto.getData().getTitle();
if(resourceBundle.getLocale().getLanguage().equals(iso1) || resourceBundle.getLocale().getLanguage().equals(iso2)){
getOnlineTitles().add(buildNameString(translationDto.getData().getTitle(), firstResult.getReleaseDate()));
}
if(searchString.equals(title)){
theMovieDbId = firstResult.getPosterPath();
return MovieDbCheckType.LOCALIZED_TITLE;
}
}
} else {
log.warn("Translations body is null");
}
}
return MovieDbCheckType.NOT_FOUND;
}

private String buildNameString(String title, LocalDate date) {
if(date == null){
return title;
}
return title + " (" + date.getYear() + ")";
}
}
39 changes: 39 additions & 0 deletions src/main/java/drrename/MovieDbClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Dr.Rename - A Minimalistic Batch Renamer
*
* Copyright (C) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package drrename;

import drrename.model.themoviedb.SearchResultsDto;
import drrename.model.themoviedb.TranslationsDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "moviedb", url = "${app.kodi.themoviedb.baseurl}", configuration = MovieDbClientConfig.class)
public interface MovieDbClient {

@RequestMapping(method = RequestMethod.GET, value = "/search/movie", produces = "application/json")
ResponseEntity<SearchResultsDto> searchMovie(@RequestParam(name = "api_key") String apiKey, @RequestParam(name = "langauge", required = false) String language, @RequestParam(name = "include_adult", required = false) Boolean includeAdult, @RequestParam(name = "query") String query, @RequestParam(name = "year") Number year);

@RequestMapping(method = RequestMethod.GET, value = "/movie/{id}/translations", produces = "application/json")
ResponseEntity<TranslationsDto> getTranslations(@PathVariable(name = "id") Number id, @RequestParam(name = "api_key") String apiKey);
}
34 changes: 34 additions & 0 deletions src/main/java/drrename/MovieDbClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Dr.Rename - A Minimalistic Batch Renamer
*
* Copyright (C) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package drrename;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;

public class MovieDbClientConfig {

@Bean
ObjectMapper objectMapper(){
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
}
}
36 changes: 36 additions & 0 deletions src/main/java/drrename/MovieDbImagesClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Dr.Rename - A Minimalistic Batch Renamer
*
* Copyright (C) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package drrename;

import drrename.model.themoviedb.SearchResultsDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "moviedb-images", url = "${app.kodi.themoviedb.images.baseurl}", configuration = MovieDbClientConfig.class)
public interface MovieDbImagesClient {

@RequestMapping(method = RequestMethod.GET, value = "/w500/{poster_path}", produces = MediaType.IMAGE_JPEG_VALUE)
ResponseEntity<byte[]> searchMovie(@RequestParam(name = "api_key") String apiKey, @RequestParam(name = "langauge", required = false) String language, @RequestParam(name = "include_adult", required = false) Boolean includeAdult, @PathVariable(name = "poster_path") String posterPath);
}
Loading

0 comments on commit 09ab476

Please sign in to comment.