Search in sources :

Example 1 with MediaType

use of com.frostwire.android.core.MediaType in project frostwire by frostwire.

the class Librarian method getFileType.

private byte getFileType(String filename, boolean returnTorrentsAsDocument) {
    byte result = Constants.FILE_TYPE_DOCUMENTS;
    MediaType mt = MediaType.getMediaTypeForExtension(FilenameUtils.getExtension(filename));
    if (mt != null) {
        result = (byte) mt.getId();
    }
    if (returnTorrentsAsDocument && result == Constants.FILE_TYPE_TORRENTS) {
        result = Constants.FILE_TYPE_DOCUMENTS;
    }
    return result;
}
Also used : MediaType(com.frostwire.android.core.MediaType)

Example 2 with MediaType

use of com.frostwire.android.core.MediaType 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

MediaType (com.frostwire.android.core.MediaType)2 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 YouTubeCrawledSearchResult (com.frostwire.search.youtube.YouTubeCrawledSearchResult)1 YouTubeCrawledStreamableSearchResult (com.frostwire.search.youtube.YouTubeCrawledStreamableSearchResult)1 YouTubePackageSearchResult (com.frostwire.search.youtube.YouTubePackageSearchResult)1 ArrayList (java.util.ArrayList)1