Exemplo n.º 1
0
  @Test
  public void testUpdateMediaInfoPlot02() {
    Movie movie = new Movie();
    int plotLength = PropertiesUtil.getIntProperty("movie.plot.maxLength", 500);
    movie.setId(FilmwebPlugin.FILMWEB_PLUGIN_ID, "http://www.filmweb.pl/film/Agenci-2013-612342");
    filmwebPlugin.setRequestResult(
        "<div class=\"filmDescription comBox\">\n  \t<h2>\n  \t\t<a href=\"/Waleczne.Serce/descs\" class=\"hdrBig icoBig icoBigArticles\">\n  \t\t\t opisy filmu   \t\t</a>\t\t\n\t\t\t\t\t<span class=\"hdrAddInfo\">(10)</span>\n\t\t\t\t\n  \t\t  \t\t<a href=\"\t\t\t/Waleczne.Serce/contribute/descriptions\t\" class=\"add-button\" title=\"dodaj  opis filmu \" rel=\"nofollow\">  \t\t\t<span>dodaj  opis filmu </span>\n\n  \t\t</a>\n\t\t<span class=\"imgRepInNag\">Braveheart - Waleczne Serce</span>\n  \t</h2>\n\t\n\t\t\t\t\t   \t   \t\t<p class=\"cl\"><span class=\"filmDescrBg\" property=\"v:summary\">Pod koniec XIII wieku Szkocja dostaje się pod panowanie angielskiego króla, Edwarda I. Przejęcie władzy odbywa się w wyjątkowo krwawych okolicznościach. Jednym ze świadków gwałtów i morderstw jest kilkunastoletni chłopak, William Wallace. Po latach spędzonych pod opieką wuja dorosły William wraca do rodzinnej wioski. Jedną z pierwszych osób, które spotyka, jest Murron - przyjaciółka z lat dzieciństwa. Dawne uczucie przeradza się w wielką i szczerą miłość. Niestety wkrótce dziewczyna ginie z rąk<span> angielskich żołnierzy. Wydarzenie to staje się to momentem przełomowym w życiu młodego Szkota. William decyduje się bowiem na straceńczą walkę z okupantem i po brawurowym ataku zdobywa warownię wroga. Dzięki ogromnej odwadze zostaje wykreowany na przywódcę powstania przeciw angielskiej tyranii...</span> <a href=\"#\" class=\"see-more\">więcej </a></span></p>\n   \t\t  </div>");
    filmwebPlugin.updateMediaInfo(movie, movie.getId(FilmwebPlugin.FILMWEB_PLUGIN_ID));

    assertEquals(
        StringTools.trimToLength(
            "Agent wydziału do walki z przemytem narkotyków i oficer wywiadu marynarki są w sytuacji bez wyjścia. Kradną pieniądze gangsterów i zamierzają je przekazać na dobre cele. Okazuje się jednak, że w rzeczywistości ukradli pieniądze CIA, a zleceniodawcami są mafiosi.",
            plotLength),
        movie.getPlot());
  }
Exemplo n.º 2
0
  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));
    }
  }