Search in sources :

Example 1 with YouTubeCrawledSearchResult

use of com.frostwire.search.youtube.YouTubeCrawledSearchResult in project frostwire by frostwire.

the class KeywordDetector method feedSearchResults.

public void feedSearchResults(final List<? extends SearchResult> copiedResults) {
    for (SearchResult sr : copiedResults) {
        addSearchTerms(KeywordDetector.Feature.SEARCH_SOURCE, sr.getSource().toLowerCase());
        if (sr instanceof FileSearchResult) {
            String fileName = ((FileSearchResult) sr).getFilename().toLowerCase();
            String ext = FilenameUtils.getExtension(fileName);
            if (fileName != null && !fileName.isEmpty()) {
                addSearchTerms(KeywordDetector.Feature.FILE_NAME, fileName);
            }
            // Check file extensions for YouTubeSearch results.
            // If we find files with extensions other than ".youtube", we make their mt = null and don't include them
            // in the keyword detector. IDEA: Make FileSearchResults have a .getMediaType() method and put this logic there.
            KeywordMediaType mt;
            String extension = FilenameUtils.getExtension(((FileSearchResult) sr).getFilename());
            mt = KeywordMediaType.getMediaTypeForExtension(extension);
            if ("youtube".equals(extension)) {
                mt = KeywordMediaType.getVideoMediaType();
            } else if (mt != null && mt.equals(KeywordMediaType.getVideoMediaType()) && sr instanceof YouTubeCrawledSearchResult) {
                // NOTE: this excludes all non .youtube youtube search results (e.g. 3gp, webm) from appearing on results
                mt = null;
            }
            if (ext != null && !ext.isEmpty() && mt != null) {
                addSearchTerms(KeywordDetector.Feature.FILE_EXTENSION, ext);
            }
        }
    }
}
Also used : YouTubeCrawledSearchResult(com.frostwire.search.youtube.YouTubeCrawledSearchResult) YouTubeCrawledSearchResult(com.frostwire.search.youtube.YouTubeCrawledSearchResult)

Example 2 with YouTubeCrawledSearchResult

use of com.frostwire.search.youtube.YouTubeCrawledSearchResult in project frostwire by frostwire.

the class SearchResultListAdapter method filter.

public FilteredSearchResults filter(List<SearchResult> results) {
    FilteredSearchResults fsr = new FilteredSearchResults();
    ArrayList<SearchResult> mediaTypedFiltered = new ArrayList<>();
    ArrayList<SearchResult> keywordFiltered = new ArrayList<>();
    List<KeywordFilter> keywordFilters = getKeywordFiltersPipeline();
    for (SearchResult sr : results) {
        String extension = FilenameUtils.getExtension(((FileSearchResult) sr).getFilename());
        MediaType mt = MediaType.getMediaTypeForExtension(extension);
        if ("youtube".equals(extension)) {
            mt = MediaType.getVideoMediaType();
        } else if (mt != null && mt.equals(MediaType.getVideoMediaType()) && sr instanceof YouTubeCrawledSearchResult) {
            // NOTE: this excludes all non .youtube youtube search results (e.g. 3gp, webm) from appearing on results
            mt = null;
        }
        boolean passedKeywordFilter = KeywordFilter.passesFilterPipeline(sr, keywordFilters);
        if (isFileSearchResultMediaTypeMatching(sr, mt)) {
            if (keywordFilters.isEmpty() || passedKeywordFilter) {
                mediaTypedFiltered.add(sr);
                keywordFiltered.add(sr);
            }
        } else if (mt != null && passedKeywordFilter) {
            keywordFiltered.add(sr);
        }
        fsr.increment(mt, passedKeywordFilter);
    }
    fsr.filtered = mediaTypedFiltered;
    fsr.keywordFiltered = keywordFiltered;
    return fsr;
}
Also used : YouTubeCrawledSearchResult(com.frostwire.search.youtube.YouTubeCrawledSearchResult) KeywordFilter(com.frostwire.search.KeywordFilter) ArrayList(java.util.ArrayList) MediaType(com.frostwire.android.core.MediaType) SoundcloudSearchResult(com.frostwire.search.soundcloud.SoundcloudSearchResult) YouTubePackageSearchResult(com.frostwire.search.youtube.YouTubePackageSearchResult) SearchResult(com.frostwire.search.SearchResult) TorrentSearchResult(com.frostwire.search.torrent.TorrentSearchResult) FileSearchResult(com.frostwire.search.FileSearchResult) StreamableSearchResult(com.frostwire.search.StreamableSearchResult) YouTubeCrawledStreamableSearchResult(com.frostwire.search.youtube.YouTubeCrawledStreamableSearchResult) YouTubeCrawledSearchResult(com.frostwire.search.youtube.YouTubeCrawledSearchResult)

Aggregations

YouTubeCrawledSearchResult (com.frostwire.search.youtube.YouTubeCrawledSearchResult)2 MediaType (com.frostwire.android.core.MediaType)1 FileSearchResult (com.frostwire.search.FileSearchResult)1 KeywordFilter (com.frostwire.search.KeywordFilter)1 SearchResult (com.frostwire.search.SearchResult)1 StreamableSearchResult (com.frostwire.search.StreamableSearchResult)1 SoundcloudSearchResult (com.frostwire.search.soundcloud.SoundcloudSearchResult)1 TorrentSearchResult (com.frostwire.search.torrent.TorrentSearchResult)1 YouTubeCrawledStreamableSearchResult (com.frostwire.search.youtube.YouTubeCrawledStreamableSearchResult)1 YouTubePackageSearchResult (com.frostwire.search.youtube.YouTubePackageSearchResult)1 ArrayList (java.util.ArrayList)1