Пример #1
0
  @Override
  public IImage getPosterUrl(String id) {
    if (!StringUtils.isNumeric(id)) {
      return Image.UNKNOWN;
    }

    String posterURL = Movie.UNKNOWN;
    FilmInfo filmInfo;

    try {
      filmInfo = api.getFilm(NumberUtils.toInt(id));
      if (filmInfo.getPosters() == null || filmInfo.getPosters().getLarge() == null) {
        LOG.debug("No MovieMeter Poster URL for movie: {}", id);
      } else {
        posterURL = filmInfo.getPosters().getLarge();
      }
    } catch (MovieMeterException ex) {
      LOG.error("Failed retreiving MovieMeter Poster URL for movie: {}", id);
      LOG.error(SystemTools.getStackTrace(ex));
    }

    if (StringTools.isValidString(posterURL)) {
      return new Image(posterURL);
    }
    return Image.UNKNOWN;
  }
Пример #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));
    }
  }