@Test public void testUpdateMediaInfoTitle01() { Movie movie = new Movie(); movie.setId(FilmwebPlugin.FILMWEB_PLUGIN_ID, "http://www.filmweb.pl/Seksmisja"); filmwebPlugin.setRequestResult("<title>Seksmisja (1984) - Film - FILMWEB.pl</title>"); filmwebPlugin.updateMediaInfo(movie, movie.getId(FilmwebPlugin.FILMWEB_PLUGIN_ID)); assertEquals("Seksmisja", movie.getTitle()); assertEquals("Seksmisja", movie.getOriginalTitle()); }
// @Test public void testUpdateMediaInfoTitle02() { Movie movie = new Movie(); movie.setId(FilmwebPlugin.FILMWEB_PLUGIN_ID, "http://www.filmweb.pl/John.Rambo"); filmwebPlugin.setRequestResult( "<title>John Rambo (2008) - Filmweb</title><meta property=\"og:title\" content=\"John Rambo / Rambo\">"); filmwebPlugin.updateMediaInfo(movie, movie.getId(FilmwebPlugin.FILMWEB_PLUGIN_ID)); assertEquals("John Rambo", movie.getTitle()); assertEquals("Rambo", movie.getOriginalTitle()); }
@Test public void testUpdateMediaInfoTitleWithOriginalTitle() { Movie movie = new Movie(); movie.setId(FilmwebPlugin.FILMWEB_PLUGIN_ID, "http://www.filmweb.pl/Ojciec.Chrzestny"); filmwebPlugin.setRequestResult( "<title>Ojciec chrzestny (1972) - Filmweb</title><meta property=\"og:title\" content=\"Ojciec chrzestny / Godfather, The\">"); filmwebPlugin.updateMediaInfo(movie, movie.getId(FilmwebPlugin.FILMWEB_PLUGIN_ID)); assertEquals("Ojciec chrzestny", movie.getTitle()); assertEquals("The Godfather", movie.getOriginalTitle()); }
private void getHunPlot(Movie movie) { String filmKatURL = "http://filmkatalogus.hu"; try { if (StringTools.isNotValidString(movie.getId(FILMKAT_PLUGIN_ID))) { LOG.debug("Movie title for filmkatalogus search = {}", movie.getTitle()); HttpClient httpClient = new DefaultHttpClient(); // httpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false); httpClient .getParams() .setParameter( "http.useragent", "Mozilla/5.25 Netscape/5.0 (Windows; I; Win95)"); // User-Agent header should be // overwrittem with somehting // Apache is not accepted by // filmkatalogus.hu if (mjbProxyHost != null) { HttpHost proxy = new HttpHost(mjbProxyHost, Integer.parseInt(mjbProxyPort)); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } HttpPost httppost = new HttpPost("http://www.filmkatalogus.hu/kereses"); List<NameValuePair> nameValuePairs = new ArrayList<>(); nameValuePairs.add(new BasicNameValuePair("gyorskeres", "0")); nameValuePairs.add(new BasicNameValuePair("keres0", "1")); nameValuePairs.add(new BasicNameValuePair("szo0", movie.getTitle())); httppost.addHeader("Content-type", "application/x-www-form-urlencoded"); httppost.addHeader("Accept", "text/plain"); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "ISO-8859-2")); } catch (UnsupportedEncodingException ex) { // writing error to Log LOG.error(SystemTools.getStackTrace(ex)); return; } try { HttpResponse response = httpClient.execute(httppost); switch (response.getStatusLine().getStatusCode()) { case 302: filmKatURL = filmKatURL.concat(response.getHeaders("location")[0].getValue()); LOG.debug("FilmkatalogusURL = {}", filmKatURL); break; case 200: HttpEntity body = response.getEntity(); if (body == null) { return; } String xml = EntityUtils.toString(body); int beginIndex = xml.indexOf("Találat(ok) filmek között"); if (beginIndex != -1) { // more then one entry found use the first one beginIndex = xml.indexOf("HREF='/", beginIndex); int endIndex = xml.indexOf("TITLE", beginIndex); filmKatURL = "http://filmkatalogus.hu"; filmKatURL = filmKatURL.concat(xml.substring((beginIndex + 6), endIndex - 2)); LOG.debug("FilmkatalogusURL = {}", filmKatURL); } else { return; } break; default: return; } } catch (ClientProtocolException ex) { // writing exception to log LOG.error(SystemTools.getStackTrace(ex)); return; } catch (IOException ex) { // writing exception to log LOG.error(SystemTools.getStackTrace(ex)); return; } } else { filmKatURL = "http://filmkatalogus.hu/f"; filmKatURL = filmKatURL.concat(movie.getId(FilmKatalogusPlugin.FILMKAT_PLUGIN_ID)); LOG.debug("FilmkatalogusURL = {}", filmKatURL); } String xml = webBrowser.request(filmKatURL); // name int beginIndex = xml.indexOf("<H1>"); if (beginIndex > 0) { // exact match is found if (OverrideTools.checkOverwriteTitle(movie, FILMKAT_PLUGIN_ID)) { int endIndex = xml.indexOf("</H1>", beginIndex); movie.setTitle(xml.substring((beginIndex + 4), endIndex), FILMKAT_PLUGIN_ID); LOG.trace("Title: {}", movie.getTitle()); } // PLOT if (OverrideTools.checkOverwritePlot(movie, FILMKAT_PLUGIN_ID)) { beginIndex = xml.indexOf("<DIV ALIGN=JUSTIFY>", beginIndex); if (beginIndex > 0) { int endIndex = xml.indexOf("</DIV>", beginIndex); String plot = xml.substring((beginIndex + 19), endIndex); movie.setPlot(plot, FILMKAT_PLUGIN_ID); LOG.trace("Plot: {}", movie.getPlot()); } } } } catch (NumberFormatException | ParseException | IOException error) { LOG.error("Failed retreiving information for {}", movie.getTitle()); LOG.error(SystemTools.getStackTrace(error)); } }