mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 13:59:49 -04:00
Add net.filebot.TheMovieDB.url and net.filebot.TheMovieDB.adult system properties for advanced customization of TheMovieDB API access
This commit is contained in:
parent
63f5775ada
commit
23df26fad4
@ -53,7 +53,7 @@ public final class WebServices {
|
|||||||
|
|
||||||
// movie sources
|
// movie sources
|
||||||
public static final OMDbClient OMDb = new OMDbClient(getApiKey("omdb"));
|
public static final OMDbClient OMDb = new OMDbClient(getApiKey("omdb"));
|
||||||
public static final TMDbClient TheMovieDB = new TMDbClientWithLocalSearch(getApiKey("themoviedb"), Boolean.parseBoolean(System.getProperty("net.filebot.WebServices.TheMovieDB.adult")));
|
public static final TMDbClient TheMovieDB = new TMDbClientWithLocalSearch(getApiKey("themoviedb"));
|
||||||
|
|
||||||
// episode sources
|
// episode sources
|
||||||
public static final TVMazeClient TVmaze = new TVMazeClient();
|
public static final TVMazeClient TVmaze = new TVMazeClient();
|
||||||
@ -131,8 +131,8 @@ public final class WebServices {
|
|||||||
|
|
||||||
public static class TMDbClientWithLocalSearch extends TMDbClient {
|
public static class TMDbClientWithLocalSearch extends TMDbClient {
|
||||||
|
|
||||||
public TMDbClientWithLocalSearch(String apikey, boolean adult) {
|
public TMDbClientWithLocalSearch(String apikey) {
|
||||||
super(apikey, adult);
|
super(apikey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// local TheMovieDB search index
|
// local TheMovieDB search index
|
||||||
|
@ -37,20 +37,35 @@ import net.filebot.ResourceManager;
|
|||||||
|
|
||||||
public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
|
public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
|
||||||
|
|
||||||
|
private static URL getEndpoint() {
|
||||||
|
try {
|
||||||
|
return new URL(System.getProperty("net.filebot.TheMovieDB.url", "https://api.themoviedb.org/3/"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAdultEnabled() {
|
||||||
|
return Boolean.parseBoolean(System.getProperty("net.filebot.TheMovieDB.adult"));
|
||||||
|
}
|
||||||
|
|
||||||
// X-RateLimit: 40 requests per 10 seconds => https://developers.themoviedb.org/3/getting-started/request-rate-limiting
|
// X-RateLimit: 40 requests per 10 seconds => https://developers.themoviedb.org/3/getting-started/request-rate-limiting
|
||||||
private static final FloodLimit REQUEST_LIMIT = new FloodLimit(35, 10, TimeUnit.SECONDS);
|
private static final FloodLimit REQUEST_LIMIT = new FloodLimit(35, 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
private final String host = "api.themoviedb.org";
|
private final URL api;
|
||||||
private final String version = "3";
|
private final String apikey;
|
||||||
|
private final boolean adult;
|
||||||
|
|
||||||
private String apikey;
|
public TMDbClient(URL api, String apikey, boolean adult) {
|
||||||
private boolean adult;
|
this.api = api;
|
||||||
|
|
||||||
public TMDbClient(String apikey, boolean adult) {
|
|
||||||
this.apikey = apikey;
|
this.apikey = apikey;
|
||||||
this.adult = adult;
|
this.adult = adult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TMDbClient(String apikey) {
|
||||||
|
this(getEndpoint(), apikey, isAdultEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return "TheMovieDB";
|
return "TheMovieDB";
|
||||||
@ -381,18 +396,17 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected URL getResource(String path, String language) throws Exception {
|
protected URL getResource(String resource, String language) throws Exception {
|
||||||
StringBuilder file = new StringBuilder();
|
StringBuilder path = new StringBuilder();
|
||||||
file.append('/').append(version);
|
path.append(resource);
|
||||||
file.append('/').append(path);
|
path.append(resource.lastIndexOf('?') < 0 ? '?' : '&');
|
||||||
file.append(path.lastIndexOf('?') < 0 ? '?' : '&');
|
|
||||||
|
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
file.append("language=").append(language).append('&');
|
path.append("language=").append(language).append('&');
|
||||||
}
|
}
|
||||||
file.append("api_key=").append(apikey);
|
path.append("api_key=").append(apikey);
|
||||||
|
|
||||||
return new URL("https", host, file.toString());
|
return new URL(api, path.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getLanguageCode(Locale locale) {
|
protected String getLanguageCode(Locale locale) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user