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);
}
}
}
}
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;
}
Aggregations