mirror of
https://github.com/JasonHHouse/gaps.git
synced 2026-05-22 18:19:33 -05:00
@@ -1,18 +1,25 @@
|
||||
# Gaps
|
||||
Searches through your Plex Server for all movies, then queries for known movies in the same collection. If those movies don't exist in your library, Gaps will recommend getting those movies, legally of course.
|
||||
Searches through your Plex Server or local folders for all movies, then queries for known movies in the same collection. If those movies don't exist in your library, Gaps will recommend getting those movies, legally of course.
|
||||
|
||||
## Usage
|
||||
### Local Requirements
|
||||
|
||||
It's a Spring Boot App and you need Java to run this. You'll need to make sure Java is accessible in your command window or terminal.
|
||||
It's a Spring Boot App and you need Java to run this if you want to use the jar. You'll need to make sure Java is accessible in your command window or terminal. You can also run as a docker container, in which case, you would need Docker.
|
||||
|
||||
#### Windows
|
||||
This is a good write up on getting Java in the path variable on [windows](https://javatutorial.net/set-java-home-windows-10).
|
||||
##### Jar
|
||||
This is a good write up on getting Java in the path variable on [windows](https://javatutorial.net/set-java-home-windows-10).
|
||||
##### Docker
|
||||
Check out https://www.docker.com/ to get docker for Windows.
|
||||
|
||||
#### Mac and Linux
|
||||
##### Jar
|
||||
You'll just need to add the Java classpath to your bash_profile.
|
||||
##### Docker
|
||||
Check out https://www.docker.com/ to get docker for Mac and Linux.
|
||||
|
||||
### Properties
|
||||
#### Plex
|
||||
You need to find your plex movie all URL. Plex has a great write up on to get the URL. But first you'll need to get your token. The write ups are below.
|
||||
|
||||
https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/
|
||||
@@ -23,6 +30,10 @@ It will look something like this.
|
||||
http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
|
||||
Gaps supports a single movie URL or multiple. You can adjust to your needs. Then you need to go make an account on https://www.themoviedb.org and generate an API Key. Add that key to the application.yaml file under the movieDbApiKey property.
|
||||
|
||||
#### Folder
|
||||
You need to list out the folders you want to read from. Review the file types for video and make sure every type you have is covered. Make sure you enable recursive search if needed. If your files aren't in the format as specified below, be sure to update the regex to match your file name structure.
|
||||
|
||||
```yaml
|
||||
gaps:
|
||||
#Put your Plex Movie All URLs here
|
||||
@@ -31,14 +42,8 @@ gaps:
|
||||
#movieUrls:
|
||||
# - http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
|
||||
#Mulitple
|
||||
#movieUrls:
|
||||
# - http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/2/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/3/all/?X-Plex-Token={My-Plex-Token}
|
||||
movieUrls:
|
||||
- #Go to https://www.themoviedb.org and make an API Key, place that key here
|
||||
#movieDbApiKey: {key}
|
||||
#Go to https://www.themoviedb.org and make an API Key, place that key here
|
||||
#movieDbApiKey: {key}
|
||||
movieDbApiKey:
|
||||
|
||||
# Optional
|
||||
@@ -49,11 +54,63 @@ gaps:
|
||||
#Should Gaps write out to a file as well as console
|
||||
writeToFile: true
|
||||
|
||||
|
||||
#######################################
|
||||
#
|
||||
#Can read from a folder, Plex, or both
|
||||
#At least, one of the two property groups needs to be filled in though
|
||||
#
|
||||
#######################################
|
||||
|
||||
#List of folders where movies can be pulled from
|
||||
folder:
|
||||
#Required
|
||||
searchFromFolder: true
|
||||
|
||||
#Required if searching from folders
|
||||
#List of folders to search in
|
||||
folders:
|
||||
- /Users/jhouse/Movies
|
||||
|
||||
#Required if searching from folders
|
||||
#If the subfolder should be searched in
|
||||
recursive: true
|
||||
|
||||
#Required if searching from folders
|
||||
#Add any movie formats as needed
|
||||
movieFormats:
|
||||
- avi
|
||||
- mkv
|
||||
- mp4
|
||||
- mov
|
||||
- webm
|
||||
- vob
|
||||
- flv
|
||||
- mts
|
||||
- m2ts
|
||||
- m4p
|
||||
- m4v
|
||||
- 3gp
|
||||
- 3g2
|
||||
|
||||
#Movie Regex
|
||||
#Expected format is Movie Name (Year)
|
||||
#Example: The Fast and the Furious (2001)
|
||||
yearRegex: \(([1-2][0-9][0-9][0-9])\)
|
||||
|
||||
#Plex connection timeouts when querying for all movies in the Plex section. Time is in seconds. Default is 180 seconds
|
||||
plex:
|
||||
searchFromPlex: false
|
||||
connectTimeout: 180
|
||||
writeTimeout: 180
|
||||
readTimeout: 180
|
||||
|
||||
#Mulitple
|
||||
#movieUrls:
|
||||
# - http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/2/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/3/all/?X-Plex-Token={My-Plex-Token}
|
||||
movieUrls:
|
||||
```
|
||||
|
||||
##### movieDbListId: \<list id>
|
||||
@@ -65,6 +122,7 @@ This property will populate a list for you in your TheMovieDB account. This list
|
||||
**_**Enabling this feature will require user input in the terminal.**_**
|
||||
|
||||
### Running
|
||||
#### Jar
|
||||
|
||||
You can run it with the run.bat or run.sh scripts. If you want to run command line you can run with.
|
||||
```bash
|
||||
@@ -72,7 +130,7 @@ java -jar Gaps.{version-number}.jar
|
||||
```
|
||||
The output will come either to a file or the console. By default the output comes to a file. Gaps will print out information about duplicate movies and movies not found in the terminal. The program takes time but in the end you will get a list of movies missing from collections you have. If you have any questions, hit me up. Feel free to put up PRs to improve this as well.
|
||||
|
||||
### Running with Docker
|
||||
#### Docker
|
||||
|
||||
First, the container must be built:
|
||||
|
||||
@@ -95,7 +153,7 @@ Multiple URL:
|
||||
docker run -t -e DBAPIKEY=myapikey -e PLEXADDRESS=http://192.168.0.10:32400/library/sections/1/all/?X-Plex-Token=plextoken,http://192.168.0.10:32400/library/sections/2/all/?X-Plex-Token=plextoken -e WRITETOFILE=true gaps
|
||||
```
|
||||
|
||||
###Option Properties in Docker
|
||||
### Option Properties in Docker
|
||||
|
||||
CONNECT_TIMEOUT
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
DB_API_KEY=myapikey
|
||||
|
||||
#Output
|
||||
WRITE_TO_FILE=true
|
||||
TMDBLISTID=id
|
||||
|
||||
#Folder
|
||||
SEARCH_FROM_FOLDER=true
|
||||
#folders=/Users/jhouse/Movies
|
||||
RECURSIVE=true
|
||||
MOVIE_FORMATS=movieFormats=avi,mkv,mp4,mov,webm,vob,flv,mts,m2ts,m4p,m4v,3gp,3g2
|
||||
YEAR_REGEX=\(([1-2][0-9][0-9][0-9])\)
|
||||
|
||||
#Plex
|
||||
#PLEX_ADDRESS=http://192.168.0.10:32400/library/sections/1/all/?X-Plex-Token=plextoken
|
||||
#CONNECT_TIMEOUT=1
|
||||
#WRITE_TIMEOUT=1
|
||||
#READ_TIMEOUT=1
|
||||
SEARCH_FROM_PLEX=false
|
||||
@@ -22,20 +22,20 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>2.1.1.RELEASE</version>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<version>2.1.1.RELEASE</version>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.12.1</version>
|
||||
<version>3.13.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -53,7 +53,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.2</version>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -74,10 +74,22 @@
|
||||
<version>27.0.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>17.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>2.1.1.RELEASE</version>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2019 Jason H House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.jasonhhouse.Gaps;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public class FolderProperties {
|
||||
|
||||
@NotNull(message = "Search from folder boolean cannot be null")
|
||||
private Boolean searchFromFolder;
|
||||
|
||||
private Boolean recursive;
|
||||
|
||||
private List<String> folders;
|
||||
|
||||
private List<String> movieFormats;
|
||||
|
||||
private String yearRegex;
|
||||
|
||||
public String getYearRegex() {
|
||||
return yearRegex;
|
||||
}
|
||||
|
||||
public void setYearRegex(String yearRegex) {
|
||||
this.yearRegex = yearRegex;
|
||||
}
|
||||
|
||||
public Boolean getRecursive() {
|
||||
return recursive;
|
||||
}
|
||||
|
||||
public void setRecursive(Boolean recursive) {
|
||||
this.recursive = recursive;
|
||||
}
|
||||
|
||||
public Boolean getSearchFromFolder() {
|
||||
return searchFromFolder;
|
||||
}
|
||||
|
||||
public void setSearchFromFolder(Boolean searchFromFolder) {
|
||||
this.searchFromFolder = searchFromFolder;
|
||||
}
|
||||
|
||||
public List<String> getFolders() {
|
||||
return folders;
|
||||
}
|
||||
|
||||
public void setFolders(List<String> folders) {
|
||||
this.folders = folders;
|
||||
}
|
||||
|
||||
public List<String> getMovieFormats() {
|
||||
return movieFormats;
|
||||
}
|
||||
|
||||
public void setMovieFormats(List<String> movieFormats) {
|
||||
this.movieFormats = movieFormats;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -36,7 +38,9 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -66,12 +70,12 @@ public class GapsApplication implements CommandLineRunner {
|
||||
|
||||
private final Set<Movie> recommended;
|
||||
|
||||
private final Set<Movie> plexMovies;
|
||||
private final Set<Movie> ownedMovies;
|
||||
|
||||
@Autowired
|
||||
public GapsApplication(Properties properties) {
|
||||
this.properties = properties;
|
||||
this.plexMovies = new HashSet<>();
|
||||
this.ownedMovies = new HashSet<>();
|
||||
this.searched = new HashSet<>();
|
||||
this.recommended = new TreeSet<>();
|
||||
}
|
||||
@@ -82,14 +86,22 @@ public class GapsApplication implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
String sessionId = null;
|
||||
// Get TMDB Authorizatoin from user,
|
||||
// requires user input so needs to be done early before user walks away
|
||||
if (properties.getMovieDbListId().length() > 0){
|
||||
getTmdbAuthorization();
|
||||
if (properties.getMovieDbListId().length() > 0) {
|
||||
sessionId = getTmdbAuthorization();
|
||||
}
|
||||
|
||||
findAllPlexMovies();
|
||||
searchForPlexMovie();
|
||||
|
||||
if (properties.getPlex().getSearchFromPlex()) {
|
||||
findAllPlexMovies();
|
||||
}
|
||||
|
||||
if (properties.getFolder().getSearchFromFolder()) {
|
||||
findAllFolderMovies();
|
||||
}
|
||||
|
||||
searchForMovies();
|
||||
|
||||
if (properties.getWriteToFile()) {
|
||||
writeToFile();
|
||||
@@ -97,14 +109,81 @@ public class GapsApplication implements CommandLineRunner {
|
||||
//Always write to command line
|
||||
printRecommended();
|
||||
|
||||
if (properties.getMovieDbListId() != null) {
|
||||
createTmdbList();
|
||||
if (StringUtils.isNotEmpty(properties.getMovieDbListId())) {
|
||||
createTmdbList(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
private String session_id = null;
|
||||
private void findAllFolderMovies() {
|
||||
if (CollectionUtils.isEmpty(properties.getFolder().getFolders())) {
|
||||
logger.error("folders property cannot be empty when searchFromFolder is true");
|
||||
return;
|
||||
}
|
||||
|
||||
private void getTmdbAuthorization() {
|
||||
if (CollectionUtils.isEmpty(properties.getFolder().getMovieFormats())) {
|
||||
logger.error("movie formats property cannot be empty when searchFromFolder is true");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String strFolder : properties.getFolder().getFolders()) {
|
||||
File folder = new File(strFolder);
|
||||
searchFolders(folder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void searchFolders(File folder) {
|
||||
if (!folder.exists()) {
|
||||
logger.warn("Folder in folders property does not exist: " + folder);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!folder.isDirectory()) {
|
||||
logger.warn("Folder in folders property is not a directory: " + folder);
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = folder.listFiles();
|
||||
if (files == null) {
|
||||
logger.warn("Folder in folders property is empty: " + folder);
|
||||
return;
|
||||
}
|
||||
|
||||
for (File file : files) {
|
||||
if (file.isDirectory() && properties.getFolder().getRecursive()) {
|
||||
searchFolders(file);
|
||||
continue;
|
||||
}
|
||||
|
||||
String extension = FilenameUtils.getExtension(file.toString());
|
||||
|
||||
if (properties.getFolder().getMovieFormats().contains(extension)) {
|
||||
String fullMovie = FilenameUtils.getBaseName(file.toString());
|
||||
Pattern pattern = Pattern.compile(properties.getFolder().getYearRegex());
|
||||
Matcher matcher = pattern.matcher(fullMovie);
|
||||
|
||||
if (!matcher.find()) {
|
||||
logger.warn("No regex matches found for " + fullMovie);
|
||||
continue;
|
||||
}
|
||||
|
||||
String year = matcher.group(matcher.groupCount()).replaceAll("[)(]", "");
|
||||
String title = fullMovie.substring(0, fullMovie.indexOf(" ("));
|
||||
|
||||
Movie movie = new Movie(-1, title, Integer.parseInt(year), "");
|
||||
ownedMovies.add(movie);
|
||||
} else {
|
||||
logger.warn("Skipping file " + file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Using TMDB api (V3), get access to user list and add recommended movies to
|
||||
*/
|
||||
private @Nullable String getTmdbAuthorization() {
|
||||
// Create the request_token request
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -132,7 +211,7 @@ public class GapsApplication implements CommandLineRunner {
|
||||
System.in.read();
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to authenticate tmdb, and add movies to list. ", e);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create the sesssion ID for MovieDB using the approved token
|
||||
@@ -149,30 +228,30 @@ public class GapsApplication implements CommandLineRunner {
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
JSONObject sessionResponse = new JSONObject(response.body().string());
|
||||
session_id = sessionResponse.getString("session_id"); // TODO: Save sessionID to file for reuse
|
||||
return sessionResponse.getString("session_id"); // TODO: Save sessionID to file for reuse
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to create session id: " + e.getMessage());
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Using TMDB api (V3), get access to user list and add recommended movies to
|
||||
*/
|
||||
private void createTmdbList() {
|
||||
private void createTmdbList(@Nullable String sessionId) {
|
||||
OkHttpClient client;
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
RequestBody body;
|
||||
|
||||
// Add item to TMDB list specified by user
|
||||
int counter = 0;
|
||||
if (session_id != null)
|
||||
if (sessionId != null)
|
||||
for (Movie m : recommended) {
|
||||
client = new OkHttpClient();
|
||||
|
||||
body = RequestBody.create(mediaType, "{\"media_id\":" + m.getMedia_id() + "}");
|
||||
String url = "https://api.themoviedb.org/3/list/" + properties.getMovieDbListId()
|
||||
+ "/add_item?session_id=" + session_id + "&api_key=" + properties.getMovieDbApiKey();
|
||||
+ "/add_item?session_id=" + sessionId + "&api_key=" + properties.getMovieDbApiKey();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
@@ -203,10 +282,10 @@ public class GapsApplication implements CommandLineRunner {
|
||||
.writeTimeout(properties.getPlex().getWriteTimeout(), TimeUnit.SECONDS)
|
||||
.readTimeout(properties.getPlex().getReadTimeout(), TimeUnit.SECONDS)
|
||||
.build();
|
||||
List<String> urls = properties.getMovieUrls();
|
||||
List<String> urls = properties.getPlex().getMovieUrls();
|
||||
|
||||
if (CollectionUtils.isEmpty(urls)) {
|
||||
logger.error("No URLs added to plexMovieUrls. Check your application.yaml file.");
|
||||
logger.info("No URLs added to plexMovieUrls. Check your application.yaml file if needed.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -233,16 +312,17 @@ public class GapsApplication implements CommandLineRunner {
|
||||
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
Node node = nodeList.item(i);
|
||||
String title = node.getAttributes().getNamedItem("title").getNodeValue();
|
||||
//Files can't have : so need to remove to find matches correctly
|
||||
String title = node.getAttributes().getNamedItem("title").getNodeValue().replaceAll(":", "");
|
||||
if (node.getAttributes().getNamedItem("year") == null) {
|
||||
logger.warn("Year not found for " + title);
|
||||
continue;
|
||||
}
|
||||
String year = node.getAttributes().getNamedItem("year").getNodeValue();
|
||||
Movie movie = new Movie(-1, title, Integer.parseInt(year), "");
|
||||
plexMovies.add(movie);
|
||||
ownedMovies.add(movie);
|
||||
}
|
||||
logger.info(plexMovies.size() + " movies found in plex");
|
||||
logger.info(ownedMovies.size() + " movies found in plex");
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("Error connecting to Plex to get Movie list", e);
|
||||
@@ -260,7 +340,7 @@ public class GapsApplication implements CommandLineRunner {
|
||||
* optimize some network calls, we add movies found in a collection and in plex to our already searched list, so we
|
||||
* don't re-query collections again and again.
|
||||
*/
|
||||
private void searchForPlexMovie() {
|
||||
private void searchForMovies() {
|
||||
logger.info("Searching for Movie Collections...");
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -270,7 +350,14 @@ public class GapsApplication implements CommandLineRunner {
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (Movie movie : plexMovies) {
|
||||
for (Movie movie : ownedMovies) {
|
||||
|
||||
//Print the count first to handle the continue if block or the regular searching case
|
||||
if (count % 10 == 0) {
|
||||
logger.info(((int) ((count) / ((double) (ownedMovies.size())) * 100)) + "% Complete. Processed " + count + " files of " + ownedMovies.size() + ". ");
|
||||
}
|
||||
count++;
|
||||
|
||||
if (searched.contains(movie)) {
|
||||
continue;
|
||||
}
|
||||
@@ -357,17 +444,18 @@ public class GapsApplication implements CommandLineRunner {
|
||||
for (int i = 0; i < parts.length(); i++) {
|
||||
JSONObject part = parts.getJSONObject(i);
|
||||
int media_id = part.getInt("id");
|
||||
String title = part.getString("original_title");
|
||||
//Files can't have : so need to remove to find matches correctly
|
||||
String title = part.getString("original_title").replaceAll(":", "");
|
||||
int year;
|
||||
try {
|
||||
year = Integer.parseInt(part.getString("release_date").substring(0, 4));
|
||||
} catch (StringIndexOutOfBoundsException | NumberFormatException e) {
|
||||
logger.warn("No year found for " + title + ". Value returned was '" + part.getString("release_date") + "'. Skipping adding the movie to recommended list.");
|
||||
logger.warn("No year found for " + title + ". Value returned was '" + part.getString("release_date") + "'. Not adding the movie to recommended list.");
|
||||
continue;
|
||||
}
|
||||
Movie movieFromCollection = new Movie(media_id, title, year, collectionName);
|
||||
|
||||
if (plexMovies.contains(movieFromCollection)) {
|
||||
if (ownedMovies.contains(movieFromCollection)) {
|
||||
searched.add(movieFromCollection);
|
||||
} else if (!searched.contains(movieFromCollection) && year != 0 && year < 2019) {
|
||||
recommended.add(movieFromCollection);
|
||||
@@ -388,7 +476,7 @@ public class GapsApplication implements CommandLineRunner {
|
||||
logger.error("Error searching for movie " + movie, e);
|
||||
logger.error("URL: " + searchMovieUrl);
|
||||
} catch (JSONException e) {
|
||||
logger.error("Error parsing movie " + movie, e);
|
||||
logger.error("Error parsing movie " + movie + ". " + e.getMessage());
|
||||
logger.error("URL: " + searchMovieUrl);
|
||||
} finally {
|
||||
try {
|
||||
@@ -398,10 +486,6 @@ public class GapsApplication implements CommandLineRunner {
|
||||
logger.error("Error sleeping", e);
|
||||
}
|
||||
|
||||
count++;
|
||||
if (count % 10 == 0) {
|
||||
logger.info(((int) ((count) / ((double) (plexMovies.size())) * 100)) + "% Complete. Processed " + count + " files of " + plexMovies.size() + ". ");
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.error("Error parsing movie URL " + movie, e);
|
||||
|
||||
@@ -10,14 +10,30 @@
|
||||
|
||||
package com.jasonhhouse.Gaps;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
public class PlexProperties {
|
||||
|
||||
@NotNull(message = "Search from plex boolean cannot be null")
|
||||
private Boolean searchFromPlex;
|
||||
|
||||
private Integer connectTimeout;
|
||||
|
||||
private Integer writeTimeout;
|
||||
|
||||
private Integer readTimeout;
|
||||
|
||||
private List<String> movieUrls;
|
||||
|
||||
public Boolean getSearchFromPlex() {
|
||||
return searchFromPlex;
|
||||
}
|
||||
|
||||
public void setSearchFromPlex(Boolean searchFromPlex) {
|
||||
this.searchFromPlex = searchFromPlex;
|
||||
}
|
||||
|
||||
public Integer getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
@@ -42,4 +58,12 @@ public class PlexProperties {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public List<String> getMovieUrls() {
|
||||
return movieUrls;
|
||||
}
|
||||
|
||||
public void setMovieUrls(List<String> movieUrls) {
|
||||
this.movieUrls = movieUrls;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
package com.jasonhhouse.Gaps;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -23,9 +22,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Validated
|
||||
public class Properties {
|
||||
|
||||
@NotNull(message = "Plex Movie Urls cannot be null")
|
||||
private List<String> movieUrls;
|
||||
|
||||
@NotNull(message = "Movie DB API Key cannot be null")
|
||||
private String movieDbApiKey;
|
||||
|
||||
@@ -35,15 +31,17 @@ public class Properties {
|
||||
@NotNull(message = "Plex property cannot be null")
|
||||
private PlexProperties plex;
|
||||
|
||||
@NotNull(message = "Folder property cannot be null")
|
||||
private FolderProperties folder;
|
||||
|
||||
private String movieDbListId;
|
||||
|
||||
|
||||
public List<String> getMovieUrls() {
|
||||
return movieUrls;
|
||||
public FolderProperties getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public void setMovieUrls(List<String> movieUrls) {
|
||||
this.movieUrls = movieUrls;
|
||||
public void setFolder(FolderProperties folder) {
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public String getMovieDbApiKey() {
|
||||
|
||||
@@ -13,15 +13,9 @@ gaps:
|
||||
#movieUrls:
|
||||
# - http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
|
||||
#Mulitple
|
||||
#movieUrls:
|
||||
# - http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/2/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/3/all/?X-Plex-Token={My-Plex-Token}
|
||||
movieUrls:
|
||||
- #Go to https://www.themoviedb.org and make an API Key, place that key here
|
||||
#movieDbApiKey: {key}
|
||||
movieDbApiKey:
|
||||
#Go to https://www.themoviedb.org and make an API Key, place that key here
|
||||
#movieDbApiKey: {key}
|
||||
movieDbApiKey: asdb-asdf
|
||||
|
||||
# Optional
|
||||
# Go to https://www.themoviedb.org and make a custom list for GAPS https://www.themoviedb.org/list/<id number>
|
||||
@@ -31,12 +25,64 @@ gaps:
|
||||
#Should Gaps write out to a file as well as console
|
||||
writeToFile: true
|
||||
|
||||
|
||||
#######################################
|
||||
#
|
||||
#Can read from a folder, Plex, or both
|
||||
#At least, one of the two property groups needs to be filled in though
|
||||
#
|
||||
#######################################
|
||||
|
||||
#List of folders where movies can be pulled from
|
||||
folder:
|
||||
#Required
|
||||
searchFromFolder: true
|
||||
|
||||
#Required if searching from folders
|
||||
#List of folders to search in
|
||||
folders:
|
||||
- /Users/jhouse/Movies
|
||||
|
||||
#Required if searching from folders
|
||||
#If the subfolder should be searched in
|
||||
recursive: true
|
||||
|
||||
#Required if searching from folders
|
||||
#Add any movie formats as needed
|
||||
movieFormats:
|
||||
- avi
|
||||
- mkv
|
||||
- mp4
|
||||
- mov
|
||||
- webm
|
||||
- vob
|
||||
- flv
|
||||
- mts
|
||||
- m2ts
|
||||
- m4p
|
||||
- m4v
|
||||
- 3gp
|
||||
- 3g2
|
||||
|
||||
#Movie Regex
|
||||
#Expected format is Movie Name (Year)
|
||||
#Example: The Fast and the Furious (2001)
|
||||
yearRegex: \(([1-2][0-9][0-9][0-9])\)
|
||||
|
||||
#Plex connection timeouts when querying for all movies in the Plex section. Time is in seconds. Default is 180 seconds
|
||||
plex:
|
||||
searchFromPlex: false
|
||||
connectTimeout: 180
|
||||
writeTimeout: 180
|
||||
readTimeout: 180
|
||||
|
||||
#Mulitple
|
||||
#movieUrls:
|
||||
# - http://127.0.0.1:32400/library/sections/1/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/2/all/?X-Plex-Token={My-Plex-Token}
|
||||
# - http://127.0.0.1:32400/library/sections/3/all/?X-Plex-Token={My-Plex-Token}
|
||||
movieUrls:
|
||||
|
||||
#Adjust logging as you see fit
|
||||
logging:
|
||||
level:
|
||||
|
||||
+105
-45
@@ -8,64 +8,124 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ -z $DBAPIKEY ]]; then
|
||||
fail "Need to specify DBAPIKEY as environment variable\nRefer to README.md"
|
||||
if [[ -z $DB_API_KEY ]]; then
|
||||
fail "Need to specify DB_API_KEY as environment variable\nRefer to README.md"
|
||||
fi
|
||||
|
||||
if [[ -z $PLEXADDRESS ]]; then
|
||||
fail "Need to specify PLEXADDRESS as environment variable\nRefer to README.md"
|
||||
#Must be plex or folder searching
|
||||
if [[ ( -z $SEARCH_FROM_FOLDER || $SEARCH_FROM_FOLDER = false ) && ( -z $SEARCH_FROM_PLEX || $SEARCH_FROM_PLEX = false ) ]]; then
|
||||
fail "One or both of SEARCH_FROM_FOLDER or SEARCH_FROM_PlEX must be true.\nRefer to README.md"
|
||||
fi
|
||||
|
||||
if [[ -z $WRITETOFILE ]]; then
|
||||
fail "Need to specify WRITETOFILE as environment variable\nRefer to README.md"
|
||||
fi
|
||||
|
||||
DEFAULT_CONNECT_TIMEOUT=180
|
||||
if [[ -z ${CONNECT_TIMEOUT} ]]; then
|
||||
echo "No connect timeout found. Defaulting to 180 seconds"
|
||||
DEFAULT_CONNECT_TIMEOUT=180
|
||||
else
|
||||
DEFAULT_CONNECT_TIMEOUT=${CONNECT_TIMEOUT}
|
||||
fi
|
||||
|
||||
DEFAULT_WRITE_TIMEOUT=180
|
||||
if [[ -z ${WRITE_TIMEOUT} ]]; then
|
||||
echo "No connect timeout found. Defaulting to 180 seconds"
|
||||
DEFAULT_WRITE_TIMEOUT=180
|
||||
else
|
||||
DEFAULT_WRITE_TIMEOUT=${WRITE_TIMEOUT}
|
||||
fi
|
||||
|
||||
DEFAULT_READ_TIMEOUT=180
|
||||
if [[ -z ${READ_TIMEOUT} ]]; then
|
||||
echo "No connect timeout found. Defaulting to 180 seconds"
|
||||
READ_TIMEOUT=180
|
||||
else
|
||||
DEFAULT_READ_TIMEOUT=${READ_TIMEOUT}
|
||||
fi
|
||||
|
||||
URL=""
|
||||
#Global to all
|
||||
PREFIX='- '
|
||||
NEW_LINE=$'\n '
|
||||
|
||||
REGEX='\,'
|
||||
if [[ $PLEXADDRESS =~ $REGEX ]]; then
|
||||
IFS=$REGEX read -r -a array <<< "$PLEXADDRESS"
|
||||
for element in "${array[@]}"
|
||||
do
|
||||
URL=$URL$PREFIX$element$NEW_LINE
|
||||
done
|
||||
|
||||
#Folder
|
||||
ALL_FOLDERS=""
|
||||
ALL_MOVIE_FORMATS=""
|
||||
DEFAULT_RECURSIVE_FLAG=false
|
||||
DEFAULT_YEAR_REGEX="\(([1-2][0-9][0-9][0-9])\)"
|
||||
if [[ test -z $SEARCH_FROM_FOLDER && $SEARCH_FROM_FOLDER = true ]]; then
|
||||
|
||||
if [[ -z $RECURSIVE ]]; then
|
||||
DEFAULT_RECURSIVE_FLAG=$RECURSIVE
|
||||
fi
|
||||
|
||||
if [[ -x $YEAR_REGEX ]]; then
|
||||
DEFAULT_YEAR_REGEX=$YEAR_REGEX
|
||||
fi
|
||||
|
||||
if [[ $FOLDERS =~ $REGEX ]]; then
|
||||
IFS=$REGEX read -r -a array <<< "$FOLDERS"
|
||||
for element in "${array[@]}"
|
||||
do
|
||||
ALL_FOLDERS=$ALL_FOLDERS$PREFIX$element$NEW_LINE
|
||||
done
|
||||
else
|
||||
ALL_FOLDERS=$PREFIX$FOLDERS
|
||||
fi
|
||||
|
||||
if [[ $MOVIE_FORMATS =~ $REGEX ]]; then
|
||||
IFS=$REGEX read -r -a array <<< "$MOVIE_FORMATS"
|
||||
for element in "${array[@]}"
|
||||
do
|
||||
ALL_MOVIE_FORMATS=$ALL_MOVIE_FORMATS$PREFIX$element$NEW_LINE
|
||||
done
|
||||
else
|
||||
ALL_MOVIE_FORMATS=$PREFIX$MOVIE_FORMATS
|
||||
fi
|
||||
|
||||
else
|
||||
URL=$PREFIX$PLEXADDRESS
|
||||
echo "Not searching from Folder."
|
||||
fi
|
||||
|
||||
|
||||
#Plex
|
||||
ALL_PLEX_ADDRESSES=""
|
||||
DEFAULT_CONNECT_TIMEOUT=180
|
||||
DEFAULT_WRITE_TIMEOUT=180
|
||||
DEFAULT_READ_TIMEOUT=180
|
||||
if [[ test -z $SEARCH_FROM_PLEX && $SEARCH_FROM_PLEX = true ]]; then
|
||||
if [[ -z $PLEX_ADDRESS ]]; then
|
||||
fail "Need to specify PLEX_ADDRESS as environment variable if setting SEARCH_FROM_PLEX true.\nRefer to README.md"
|
||||
fi
|
||||
|
||||
if [[ $PLEX_ADDRESS =~ $REGEX ]]; then
|
||||
IFS=$REGEX read -r -a array <<< "$PLEX_ADDRESS"
|
||||
for element in "${array[@]}"
|
||||
do
|
||||
ALL_PLEX_ADDRESSES=$ALL_PLEX_ADDRESSES$PREFIX$element$NEW_LINE
|
||||
done
|
||||
else
|
||||
ALL_PLEX_ADDRESSES=$PREFIX$PLEX_ADDRESS
|
||||
fi
|
||||
|
||||
if [[ -z ${CONNECT_TIMEOUT} ]]; then
|
||||
echo "No connect timeout found. Defaulting to 180 seconds"
|
||||
DEFAULT_CONNECT_TIMEOUT=180
|
||||
else
|
||||
DEFAULT_CONNECT_TIMEOUT=${CONNECT_TIMEOUT}
|
||||
fi
|
||||
|
||||
if [[ -z ${WRITE_TIMEOUT} ]]; then
|
||||
echo "No connect timeout found. Defaulting to 180 seconds"
|
||||
DEFAULT_WRITE_TIMEOUT=180
|
||||
else
|
||||
DEFAULT_WRITE_TIMEOUT=${WRITE_TIMEOUT}
|
||||
fi
|
||||
|
||||
if [[ -z ${READ_TIMEOUT} ]]; then
|
||||
echo "No connect timeout found. Defaulting to 180 seconds"
|
||||
READ_TIMEOUT=180
|
||||
else
|
||||
DEFAULT_READ_TIMEOUT=${READ_TIMEOUT}
|
||||
fi
|
||||
else
|
||||
echo "Not searching from Plex."
|
||||
fi
|
||||
|
||||
if [[ -z $WRITE_TO_FILE ]]; then
|
||||
fail "Need to specify WRITE_TO_FILE as environment variable\nRefer to README.md"
|
||||
fi
|
||||
|
||||
cat > /usr/src/app/src/main/resources/application.yaml <<EOF
|
||||
gaps:
|
||||
movieUrls:
|
||||
${URL}
|
||||
movieDbApiKey: ${DBAPIKEY}
|
||||
writeToFile: ${WRITETOFILE}
|
||||
movieDbApiKey: ${DB_API_KEY}
|
||||
writeToFile: ${WRITE_TO_FILE}
|
||||
folder:
|
||||
searchFromFolder: ${SEARCH_FROM_FOLDER}
|
||||
folders:
|
||||
${ALL_FOLDERS}
|
||||
recursive: ${DEFAULT_RECURSIVE_FLAG}
|
||||
movieFormats:
|
||||
${ALL_MOVIE_FORMATS}
|
||||
yearRegex: ${DEFAULT_YEAR_REGEX}
|
||||
plex:
|
||||
searchFromPlex: true
|
||||
movieUrls:
|
||||
${ALL_PLEX_ADDRESSES}
|
||||
connectTimeout: ${DEFAULT_CONNECT_TIMEOUT}
|
||||
writeTimeout: ${DEFAULT_WRITE_TIMEOUT}
|
||||
readTimeout: ${DEFAULT_READ_TIMEOUT}
|
||||
|
||||
Reference in New Issue
Block a user