-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from DrRename/feature/fixable-items
Feature/fixable items
- Loading branch information
Showing
133 changed files
with
3,977 additions
and
1,115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.