@Override
  public List<String> getSuggestions(String query) {
    try {
      if (artistName == null) {
        return NamedData.namedDataListToNameList(
            internetSearchEngine.searchAudios(query, maxCount, 1).elements);
      } else {
        List<String> result = new ArrayList<>();
        List<Audio> audios = internetSearchEngine.searchAudios(query, maxCount * 2, 1).elements;
        audios = NamedData.uniqueNames(audios);

        int removedCount = 0;
        for (int i = audios.size() - 1; i >= 0; i--) {
          Audio audio = audios.get(i);
          if (result.size() - removedCount > minCount
              && !Strings.equalsIgnoreCase(audio.getArtistName(), artistName)) {
            removedCount++;
          } else {
            result.add(audio.getName());
          }
        }

        Collections.reverse(result);
        return result;
      }
    } catch (IOException e) {
      return Collections.emptyList();
    }
  }
 @Override
 protected SearchResult<Audio> search(int pageNumber) throws IOException {
   InternetSearchEngine internetSearchEngine = getInternetSearchEngine();
   String artistName = getQuery();
   int elementsOfPageCount = getElementsOfPageCount();
   return internetSearchEngine.getSongsOfArtist(artistName, elementsOfPageCount, pageNumber + 1);
 }
Esempio n. 3
0
 protected final void updateAudioArts() {
   for (Audio audio : audioDatabase.getSongs()) {
     if (audio.getArtUrl(ArtSize.SMALL) == null) {
       try {
         String smallArt = internetSearchEngine.getSmallArt(audio);
         audioDatabase.downloadAndSaveAudioArt(audio, smallArt, ArtSize.SMALL);
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
 }