rss checkboxes working, rss writing per lib now

This commit is contained in:
TheHouseWrecker
2020-02-15 12:11:15 +09:00
parent 64eae1d0e5
commit 8f53b2fe21
4 changed files with 46 additions and 102 deletions

View File

@@ -10,14 +10,13 @@
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.GapsService;
import com.jasonhhouse.gaps.service.IoService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@RestController
@@ -26,19 +25,25 @@ public class RSSController {
private static final Logger LOGGER = LoggerFactory.getLogger(RSSController.class);
private final IoService ioService;
private final GapsService gapsService;
@Autowired
public RSSController(IoService ioService) {
public RSSController(IoService ioService, GapsService gapsService) {
this.ioService = ioService;
this.gapsService = gapsService;
}
@RequestMapping(method = RequestMethod.GET,
path = "/rss")
public String getRss() {
LOGGER.info("getRss()");
public String getRss(@RequestParam("library") String library) {
LOGGER.info("getRss( " + library + " )");
String[] keys = library.split("_");
String machineIdentifier = keys[0];
int libraryKey = Integer.parseInt(keys[1]);
String rss = null;
if (ioService.doesRssFileExist()) {
rss = ioService.getRssFile();
if (ioService.doesRssFileExist(machineIdentifier, libraryKey)) {
rss = ioService.getRssFile(machineIdentifier, libraryKey);
}
LOGGER.info("rss:" + rss);
@@ -56,17 +61,10 @@ public class RSSController {
path = "/rssCheck")
public ModelAndView getRssCheck() {
LOGGER.info("getRssCheck()");
String rss = null;
if (ioService.doesRssFileExist()) {
rss = ioService.getRssFile();
}
if (StringUtils.isEmpty(rss)) {
//Show empty page
return new ModelAndView("emptyState");
} else {
return new ModelAndView("rss");
}
ModelAndView modelAndView = new ModelAndView("rssCheck");
modelAndView.addObject("plexServers", gapsService.getPlexSearch().getPlexServers());
return modelAndView;
}
}

View File

@@ -118,7 +118,7 @@ public class GapsSearchService implements GapsSearch {
try {
StopWatch watch = new StopWatch();
watch.start();
searchForMovies(ownedMovies, everyMovie, recommended, searched, searchedMovieCount);
searchForMovies(machineIdentifier, key, ownedMovies, everyMovie, recommended, searched, searchedMovieCount);
watch.stop();
LOGGER.info("Time Elapsed: " + TimeUnit.MILLISECONDS.toSeconds(watch.getTime()) + " seconds.");
LOGGER.info("Times used TVDB ID: " + tempTvdbCounter);
@@ -168,7 +168,7 @@ public class GapsSearchService implements GapsSearch {
* 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 searchForMovies(Set<Movie> ownedMovies, List<Movie> everyMovie, Set<Movie> recommended, Set<Movie> searched,
private void searchForMovies(String machineIdentifier, Integer key, Set<Movie> ownedMovies, List<Movie> everyMovie, Set<Movie> recommended, Set<Movie> searched,
AtomicInteger searchedMovieCount) throws SearchCancelledException, IOException {
LOGGER.info("searchForMovies()");
OkHttpClient client = new OkHttpClient();
@@ -214,12 +214,12 @@ public class GapsSearchService implements GapsSearch {
if (movie.getTvdbId() != -1 && movie.getCollectionId() != -1) {
LOGGER.info("Used Collection ID to get " + movie.getName());
tempTvdbCounter.incrementAndGet();
handleCollection(ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
handleCollection(machineIdentifier, key, ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
continue;
} else if (movie.getTvdbId() != -1) {
LOGGER.info("Used TVDB ID to get " + movie.getName());
tempTvdbCounter.incrementAndGet();
searchMovieDetails(ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
searchMovieDetails(machineIdentifier, key, ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
continue;
} else if (StringUtils.isNotBlank(movie.getImdbId())) {
LOGGER.info("Used 'find' to search for " + movie.getName());
@@ -288,7 +288,7 @@ public class GapsSearchService implements GapsSearch {
everyMovie.add(newMovie);
}
searchMovieDetails(ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
searchMovieDetails(machineIdentifier, key, ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing movie " + movie + ". " + e.getMessage());
LOGGER.error("URL: " + searchMovieUrl);
@@ -321,7 +321,7 @@ public class GapsSearchService implements GapsSearch {
}
}
private void searchMovieDetails(Set<Movie> ownedMovies, List<Movie> everyMovie, Set<Movie> recommended, Set<Movie> searched,
private void searchMovieDetails(String machineIdentifier, Integer key, Set<Movie> ownedMovies, List<Movie> everyMovie, Set<Movie> recommended, Set<Movie> searched,
AtomicInteger searchedMovieCount, Movie movie, OkHttpClient client, String languageCode) {
LOGGER.info("searchMovieDetails()");
HttpUrl movieDetailUrl = urlGenerator.generateMovieDetailUrl(gapsService.getPlexSearch().getMovieDbApiKey(), String.valueOf(movie.getImdbId()), languageCode);
@@ -368,14 +368,14 @@ public class GapsSearchService implements GapsSearch {
everyMovie.add(newMovie);
}
handleCollection(ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
handleCollection(machineIdentifier, key, ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
} catch (IOException e) {
LOGGER.error("Error getting movie details " + movie, e);
}
}
private void handleCollection(Set<Movie> ownedMovies, List<Movie> everyMovie, Set<Movie> recommended, Set<Movie> searched,
private void handleCollection(String machineIdentifier, Integer key, Set<Movie> ownedMovies, List<Movie> everyMovie, Set<Movie> recommended, Set<Movie> searched,
AtomicInteger searchedMovieCount, Movie movie, OkHttpClient client, String languageCode) {
LOGGER.info("handleCollection()");
HttpUrl collectionUrl = urlGenerator.generateCollectionUrl(gapsService.getPlexSearch().getMovieDbApiKey(), String.valueOf(movie.getCollectionId()), languageCode);
@@ -517,7 +517,7 @@ public class GapsSearchService implements GapsSearch {
if (recommended.add(recommendedMovie)) {
// Write current list of recommended movies to file.
ioService.writeRssFile(recommended);
ioService.writeRssFile(machineIdentifier, key, recommended);
LOGGER.info("/newMovieFound:" + recommendedMovie.toString());

View File

@@ -18,6 +18,7 @@ import com.jasonhhouse.gaps.PlexLibrary;
import com.jasonhhouse.gaps.PlexSearch;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.Rss;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -36,6 +37,7 @@ import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@@ -77,10 +79,6 @@ public class IoService {
}
}
public boolean doesRecommendedFileExist() {
return new File(STORAGE_FOLDER + RECOMMENDED_MOVIES).exists();
}
public @NotNull List<Movie> readRecommendedMovies(String machineIdentifier, int key) {
LOGGER.info("readRecommendedMovies( " + machineIdentifier + ", " + key + " )");
@@ -109,13 +107,13 @@ public class IoService {
return Collections.emptyList();
}
public boolean doesRssFileExist() {
return new File(STORAGE_FOLDER + RSS_FEED_JSON_FILE).exists();
public boolean doesRssFileExist(String machineIdentifier, int key) {
return new File(STORAGE_FOLDER + machineIdentifier + File.separator + key + File.separator + RSS_FEED_JSON_FILE).exists();
}
public @NotNull String getRssFile() {
public @NotNull String getRssFile(String machineIdentifier, int key) {
try {
Path path = new File(STORAGE_FOLDER + RSS_FEED_JSON_FILE).toPath();
Path path = new File(STORAGE_FOLDER + machineIdentifier + File.separator + key + File.separator + RSS_FEED_JSON_FILE).toPath();
return new String(Files.readAllBytes(path));
} catch (IOException e) {
LOGGER.error("Check for RSS file next time", e);
@@ -128,13 +126,13 @@ public class IoService {
*
* @param recommended The recommended movies. (IMDB ID is required.)
*/
public void writeRssFile(Set<Movie> recommended) {
File file = new File(STORAGE_FOLDER + RSS_FEED_JSON_FILE);
public void writeRssFile(String machineIdentifier, int key, Set<Movie> recommended) {
File file = new File(STORAGE_FOLDER + machineIdentifier + File.separator + key + File.separator + RSS_FEED_JSON_FILE);
if (file.exists()) {
boolean deleted = file.delete();
if (!deleted) {
LOGGER.error("Can't delete existing file " + STORAGE_FOLDER + RSS_FEED_JSON_FILE);
LOGGER.error("Can't delete existing file " + file.getPath());
return;
}
}
@@ -142,11 +140,11 @@ public class IoService {
try {
boolean created = file.createNewFile();
if (!created) {
LOGGER.error("Can't create file " + STORAGE_FOLDER + RSS_FEED_JSON_FILE);
LOGGER.error("Can't create file " + file.getPath());
return;
}
} catch (IOException e) {
LOGGER.error("Can't create file " + STORAGE_FOLDER + RSS_FEED_JSON_FILE, e);
LOGGER.error("Can't create file " + file.getPath(), e);
return;
}
@@ -191,19 +189,6 @@ public class IoService {
writeMovieIdsToFile(recommended, file);
}
/**
* Prints out all recommended movies to recommendedMovies.json
*/
public void writeOwnedMoviesToFile(Set<Movie> ownedMovies, String machineIdentifier, int key) {
LOGGER.info("writeOwnedMoviesToFile()");
final String fileName = STORAGE_FOLDER + machineIdentifier + File.separator + key + File.separator + OWNED_MOVIES;
makeFolder(machineIdentifier, key);
File file = new File(fileName);
writeMovieIdsToFile(ownedMovies, file);
}
/**
* Prints out all recommended movies to recommendedMovies.json
*/
@@ -225,22 +210,6 @@ public class IoService {
}
public boolean doOwnedMoviesFilesExist(List<PlexServer> plexServers) {
LOGGER.info("doOwnedMoviesFilesExist()");
for (PlexServer plexServer : plexServers) {
for (PlexLibrary plexLibrary : plexServer.getPlexLibraries()) {
final File ownedMovieFile = new File(STORAGE_FOLDER + plexServer.getMachineIdentifier() + File.separator + plexLibrary.getKey() + File.separator + OWNED_MOVIES);
if (ownedMovieFile.exists()) {
return true;
}
}
}
return false;
}
public List<Movie> readOwnedMovies(String machineIdentifier, Integer key) {
LOGGER.info("readOwnedMovies( " + machineIdentifier + ", " + key + " )");

View File

@@ -8,7 +8,7 @@
- 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.
-->
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Gaps</title>
@@ -49,39 +49,16 @@
<p class="top-margin">Select the RSS feed to open.</p>
<form action="/rss" class="top-margin">
<div class="form-check">
<input checked class="form-check-input" id="exampleRadios1" name="exampleRadios" type="radio"
value="option1">
<label class="form-check-label" for="exampleRadios1">
All
</label>
<form action="/rss" class="top-margin" method="get">
<div th:each="plexServer : ${plexServers}" th:remove="tag">
<div class="form-check" th:each="plexLibrary : *{plexServer.getPlexLibraries()}">
<input class="form-check-input" id="library" name="library" type="radio" th:value="${plexServer.getMachineIdentifier() + '_' + plexLibrary.getKey()}">
<label class="form-check-label" for="library"
th:text="${plexServer.getFriendlyName() + ' - ' + plexLibrary.getTitle()}">
</label>
</div>
</div>
<div class="form-check">
<input class="form-check-input" id="exampleRadios2" name="exampleRadios" type="radio" value="option2">
<label class="form-check-label" for="exampleRadios2">
KnoxServer - Disney Classic Movies
</label>
</div>
<div class="form-check">
<input class="form-check-input" id="exampleRadios3" name="exampleRadios" type="radio" value="option4">
<label class="form-check-label" for="exampleRadios3">
KnoxServer - Movies
</label>
</div>
<div class="form-check">
<input class="form-check-input" id="exampleRadios4" name="exampleRadios" type="radio" value="option5">
<label class="form-check-label" for="exampleRadios4">
Joker - 4k Movies
</label>
</div>
<div class="form-check">
<input class="form-check-input" id="exampleRadios5" name="exampleRadios" type="radio" value="option6">
<label class="form-check-label" for="exampleRadios5">
Joker - Movies
</label>
</div>
<button class="btn btn-primary" type="submit">Open</button>
<button class="btn btn-primary top-margin" type="submit">Open</button>
</form>
</div>