Skip to content

Commit

Permalink
Merge pull request #28 from JasonHHouse/issue/22
Browse files Browse the repository at this point in the history
Issue/22
  • Loading branch information
Knoxie authored Feb 6, 2019
2 parents 9c03573 + 3a3f494 commit 4bf0197
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 18 deletions.
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,36 @@ 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.
```yaml
gaps:
#Put your Plex Movie All URLs here
#Gaps supports a single movie URL or multiple.
#Single
#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:

#Should Gaps write out to a file as well as console
writeToFile: true

# Optional
# Go to https://www.themoviedb.org and make a custom list for GAPS https://www.themoviedb.org/list/<id number>
# enter the <id number> below if you want GAPS to populate the list
movieDbListId:

#Should Gaps write out to a file as well as console
writeToFile: true

#Plex connection timeouts when querying for all movies in the Plex section. Time is in seconds. Default is 180 seconds
plex:
connectTimeout: 180
writeTimeout: 180
readTimeout: 180
```
##### movieDbListId: \<list id>
Expand Down Expand Up @@ -88,6 +95,21 @@ 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

CONNECT_TIMEOUT

WRITE_TIMEOUT

READ_TIMEOUT

These are optional properties to help with Plex Sections that are very large. Timeouts can be set longer to help when parsing the big XML returned by Plex. They are not required and will default to 180 seconds.

```bash
docker run -t -e DBAPIKEY=myapikey -e PLEXADDRESS=http://192.168.0.10:32400/library/sections/1/all/?X-Plex-Token=plextoken -e WRITETOFILE=true -e CONNECT_TIMEOUT=180 -e WRITE_TIMEOUT=180 -e READ_TIMEOUT=180 gaps
```


## License
Copyright 2019 Jason H House

Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
<version>6.0.14.Final</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/jasonhhouse/Gaps/GapsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class GapsApplication implements CommandLineRunner {

private final Set<Movie> recommended;

private Set<Movie> plexMovies;
private final Set<Movie> plexMovies;

@Autowired
public GapsApplication(Properties properties) {
Expand Down Expand Up @@ -183,7 +184,11 @@ private void createTmdbList() {
*/
private void findAllPlexMovies() {
logger.info("Searching for Plex Movies...");
OkHttpClient client = new OkHttpClient();
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(properties.getPlex().getConnectTimeout(), TimeUnit.SECONDS)
.writeTimeout(properties.getPlex().getWriteTimeout(), TimeUnit.SECONDS)
.readTimeout(properties.getPlex().getReadTimeout(), TimeUnit.SECONDS)
.build();
List<String> urls = properties.getMovieUrls();

if (CollectionUtils.isEmpty(urls)) {
Expand Down Expand Up @@ -429,13 +434,10 @@ private void writeToFile() {
String output = movie.toString() + System.lineSeparator();
outputStream.write(output.getBytes());
}
return;
} catch (FileNotFoundException e) {
logger.error("Can't find file gaps_recommended_movies.txt", e);
return;
} catch (IOException e) {
logger.error("Can't write to file gaps_recommended_movies.txt", e);
return;
}
}

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/jasonhhouse/Gaps/PlexProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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;

public class PlexProperties {

private Integer connectTimeout;

private Integer writeTimeout;

private Integer readTimeout;

public Integer getConnectTimeout() {
return connectTimeout;
}

public void setConnectTimeout(Integer connectTimeout) {
this.connectTimeout = connectTimeout;
}

public Integer getWriteTimeout() {
return writeTimeout;
}

public void setWriteTimeout(Integer writeTimeout) {
this.writeTimeout = writeTimeout;
}

public Integer getReadTimeout() {
return readTimeout;
}

public void setReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
}

}
14 changes: 12 additions & 2 deletions src/main/java/com/jasonhhouse/Gaps/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import java.util.List;
import javax.validation.constraints.NotNull;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "gaps")
@Component
@Validated
Expand All @@ -34,8 +32,12 @@ public class Properties {
@NotNull(message = "Write to file boolean cannot be null")
private Boolean writeToFile;

@NotNull(message = "Plex property cannot be null")
private PlexProperties plex;

private String movieDbListId;


public List<String> getMovieUrls() {
return movieUrls;
}
Expand All @@ -60,6 +62,14 @@ public void setWriteToFile(Boolean writeToFile) {
this.writeToFile = writeToFile;
}

public PlexProperties getPlex() {
return plex;
}

public void setPlex(PlexProperties plex) {
this.plex = plex;
}

public String getMovieDbListId() {
return movieDbListId;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ gaps:
#Should Gaps write out to a file as well as console
writeToFile: true

#Plex connection timeouts when querying for all movies in the Plex section. Time is in seconds. Default is 180 seconds
plex:
connectTimeout: 180
writeTimeout: 180
readTimeout: 180

#Adjust logging as you see fit
logging:
level:
Expand Down
31 changes: 28 additions & 3 deletions startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,35 @@ 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=""
PREFIX='- '
NEW_LINE=$'\n '

REGEX='\,'
#echo $PLEXADDRESS
if [[ $PLEXADDRESS =~ $REGEX ]]; then
IFS=$REGEX read -r -a array <<< "$PLEXADDRESS"
for element in "${array[@]}"
Expand All @@ -36,19 +59,21 @@ else
URL=$PREFIX$PLEXADDRESS
fi


cat > /usr/src/app/src/main/resources/application.yaml <<EOF
gaps:
movieUrls:
${URL}
movieDbApiKey: ${DBAPIKEY}
writeToFile: ${WRITETOFILE}
plex:
connectTimeout: ${DEFAULT_CONNECT_TIMEOUT}
writeTimeout: ${DEFAULT_WRITE_TIMEOUT}
readTimeout: ${DEFAULT_READ_TIMEOUT}
movieDbListId: $TMDBLISTID
logging:
level:
root: INFO
EOF

cat /usr/src/app/src/main/resources/application.yaml
exec mvn spring-boot:run

0 comments on commit 4bf0197

Please sign in to comment.