Beispiel #1
0
  public static int adjustVideoScoreForLanguage(
      int currentScore,
      SearchResult searchResult,
      Language wantedAudioLanguage,
      Language wantedSubtitlesLanguage) {

    int score = currentScore;

    if (wantedAudioLanguage != null && wantedAudioLanguage.getSubTokens() != null) {
      for (String subToken : wantedAudioLanguage.getSubTokens()) {
        if (StringUtils.containsIgnoreCase(searchResult.getTitle(), subToken)) {
          score -= 10;
          break;
        }
      }
    }

    if ((wantedAudioLanguage != null && wantedAudioLanguage != Language.FR)
        && StringUtils.containsIgnoreCase(searchResult.getTitle(), "FRENCH")) {
      score -= 10;
    }

    if (wantedSubtitlesLanguage != null && wantedSubtitlesLanguage.getSubTokens() != null) {
      for (String subToken : wantedSubtitlesLanguage.getSubTokens()) {
        if (StringUtils.containsIgnoreCase(searchResult.getTitle(), subToken)) {
          score += 5; // already subtitled in the language we want
          break;
        }
      }
    }

    return score;
  }
Beispiel #2
0
  @Override
  public RemoteSubTitles downloadSubtitle(VideoDetails details, Language language)
      throws Exception {

    String showName = details.getName().toLowerCase();
    if (!seriesMap.containsKey(showName)) {
      warn("Show " + showName + " not found");
      return null;
    }

    String url =
        "http://www.tvsubtitles.net/tvshow-"
            + seriesMap.get(showName)
            + "-"
            + details.getSeason()
            + ".html";

    WebDocument document = client.getDocument(url, HTTPClient.REFRESH_ONE_HOUR);
    Elements rows = document.jsoup("table#table5 tr");

    int maxScore = -100;
    Element selectedSubtitle = null;
    String subTitlesURL = null;

    for (Element row : rows) {
      if (row.select("td").isEmpty()) {
        continue;
      }
      String episode = row.select("td").first().text();
      if (!SubTitlesUtils.isExactMatch(episode, details.getSeason(), details.getEpisode())) {
        continue;
      }
      subTitlesURL = row.select("a").first().absUrl("href");
      document = client.getDocument(subTitlesURL, HTTPClient.REFRESH_ONE_HOUR);

      Elements subtitles =
          document.jsoup(String.format("a:has(h5 img[src*=%s])", language.getShortName()));
      if (subtitles.isEmpty()) {
        continue;
      }
      for (Element subtitle : subtitles) {
        int score =
            SubTitlesZip.evaluateScore(subtitle.select("h5").first().text(), language, details, 0);
        if (score > maxScore) {
          selectedSubtitle = subtitle;
          maxScore = score;
        }
      }
      break;
    }

    if (selectedSubtitle != null) {
      String href = selectedSubtitle.absUrl("href");
      document = client.getDocument(href, url, HTTPClient.REFRESH_ONE_HOUR);
      String downloadURL = document.jsoup("a:has(h3)").first().absUrl("href");

      SimpleResponse response = client.get(downloadURL, null);
      return SubTitlesZip.extractSubTitleFromZip(
          url, response.getByteContents(), details, language, 0);
    }

    return null;
  }