Exemplo n.º 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;
  }
Exemplo n.º 2
0
  @Override
  public void suggestMovies() throws Exception {

    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);

    WebDocument currentDocument =
        client.getDocument(
            String.format("%s/recherche/1080p/%d/page-0", BASE_URL, year),
            HTTPClient.REFRESH_ONE_DAY);

    int pagesToRetrieve = 4;
    int currentPage = 0;

    while (currentDocument != null && currentPage < pagesToRetrieve) {

      List<SearchResult> results = extractResults(currentDocument, null);
      for (SearchResult searchResult : results) {
        ParsedMovieInfo info = VideoNameParser.getMovieInfo(searchResult.getTitle());
        if (info != null) {
          try {
            MovieManager.getInstance()
                .suggestByName(info.getName(), year, null, Language.FR, false, null);
          } catch (Exception e) {
            ErrorManager.getInstance().reportThrowable(e);
          }
        }
      }
      currentPage++;
      currentDocument =
          client.getDocument(
              String.format("%s/recherche/1080p/%d/page-%d", BASE_URL, year, currentPage),
              HTTPClient.REFRESH_ONE_DAY);
    }
  }
Exemplo n.º 3
0
  public int evaluateResultForSeries(ManagedSeries series, SearchResult searchResult) {

    int score = 0;

    score =
        adjustVideoScoreForLanguage(
            score, searchResult, series.getAudioLanguage(), series.getSubtitleLanguage());

    VideoQuality resultQuality = VideoNameParser.getQuality(searchResult.getTitle());
    for (VideoQuality quality : series.getQualities()) {
      if (quality.equals(resultQuality)) {
        score += 5; // requested quality
      }
    }

    if (StringUtils.containsIgnoreCase(searchResult.getTitle(), "PROPER")) {
      score += 1;
    }

    return score;
  }
Exemplo n.º 4
0
  protected void selectResult(SearchResult selectedResult) {
    searchResultDAO.save(
        selectedResult.getUrl(),
        selectedResult.getProviderName(),
        selectedResult.getProviderClass(),
        selectedResult.getReferer(),
        selectedResult.getSizeInMegs(),
        selectedResult.getTitle(),
        selectedResult.getType(),
        getDownloadable().getId(),
        selectedResult.getClientId());

    BackLogProcessor.getInstance()
        .schedule(new DownloadSearchResultTask(selectedResult, getDownloadable()), false);
  }
Exemplo n.º 5
0
  @Override
  public void execute() throws IOException, URISyntaxException {

    Collection<String> blackList = getWordsBlackList(getDownloadable());

    SearchResult selectedResult = null;

    Set<String> blackListedUrls = new HashSet<>();
    List<SearchResult> existingResults =
        searchResultDAO.getSearchResults(getDownloadable().getId());
    for (SearchResult searchResult : existingResults) {
      if (searchResult.isBlackListed()) {
        blackListedUrls.add(searchResult.getUrl());
      } else {
        if (searchResult.getType() != SearchResultType.HTTP) {
          // TODO : implement HTTP downloads
          selectedResult = searchResult; // auto download this one
        }
        break;
      }
    }

    if (selectedResult == null) {

      String baseLabel = getCurrentLabel();

      int currentScore = -1;

      List<DownloadFinder> providers = (List<DownloadFinder>) getProviders();
      if (providers != null) {

        totalItems = providers.size();

        for (DownloadFinder provider : providers) {
          if (!provider.isEnabled()) {
            continue;
          }

          if (cancelled) {
            break;
          }

          setCurrentLabel(String.format("%s - Searching from %s", baseLabel, provider.toString()));

          while (!provider.isReady()) {
            try {
              Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
          }

          List<SearchResult> resultsForProvider = getResults(provider, getDownloadable());
          if (resultsForProvider != null && resultsForProvider.size() > 0) {
            for (Iterator<SearchResult> iterator = resultsForProvider.iterator();
                iterator.hasNext(); ) {
              SearchResult searchResult = iterator.next();
              // remove blacklisted results

              if (blackListedUrls != null && blackListedUrls.contains(searchResult.getUrl())) {
                iterator.remove();
                continue;
              }

              if (blackList != null) {
                for (String word : blackList) {
                  if (StringUtils.isNoneBlank(word)
                      && StringUtils.containsIgnoreCase(searchResult.getTitle(), word)) {
                    iterator.remove();
                    break;
                  }
                }
              }
            }

            if (resultsForProvider.size() > 0) {
              filterResults(resultsForProvider);
              for (SearchResult searchResult : resultsForProvider) {
                int score = evaluateResult(searchResult);
                if (score > currentScore) {
                  selectedResult = searchResult;
                  currentScore = score;
                }
              }

              if (currentScore >= SCORE_THRESHOLD) {
                break;
              }
            }
          }
          itemsDone++;
        }
      }
    }

    if (!cancelled) {

      if (selectedResult != null) {
        selectResult(selectedResult);
      } else {
        mustReschedule = true;
      }
    }
  }