Search in sources :

Example 1 with LinkInfo

use of com.frostwire.search.youtube.YouTubeExtractor.LinkInfo in project frostwire by frostwire.

the class YouTubeSearchPerformer method crawlResult.

@Override
protected List<? extends SearchResult> crawlResult(YouTubeSearchResult sr, byte[] data) throws Exception {
    List<SearchResult> list = new LinkedList<>();
    String detailsUrl = sr.getDetailsUrl();
    List<LinkInfo> infos = new YouTubeExtractor().extract(detailsUrl, false);
    LinkInfo dashVideo = null;
    LinkInfo dashAudio = null;
    LinkInfo demuxVideo = null;
    LinkInfo minQuality = null;
    for (LinkInfo inf : infos) {
        if (inf.fmt == 18) {
            // save this format for the heuristic of selecting audio
            // from dash or demuxing a video one
            demuxVideo = inf;
        }
        if (!isDash(inf)) {
            if (inf.fmt == 18) {
                minQuality = inf;
            }
            list.add(new YouTubeCrawledStreamableSearchResult(sr, inf, null, minQuality));
        } else {
            if (inf.fmt == 137) {
                // 1080p
                dashVideo = inf;
            }
            if (inf.fmt == 141) {
                // 256k
                dashAudio = inf;
            }
            if (inf.fmt == 140 && dashAudio == null) {
                // 128k
                dashAudio = inf;
            }
        }
    }
    if (dashVideo != null && dashAudio != null) {
        list.add(new YouTubeCrawledSearchResult(sr, dashVideo, dashAudio));
    }
    LinkInfo infoAudio = selectFormatForAudio(sr, dashAudio, demuxVideo);
    if (infoAudio != null) {
        list.add(new YouTubeCrawledStreamableSearchResult(sr, null, infoAudio, minQuality));
    }
    YouTubePackageSearchResult packagedResult = new YouTubePackageSearchResult(sr, list);
    List<SearchResult> results = new LinkedList<>();
    results.add(packagedResult);
    results.addAll(list);
    return results;
}
Also used : SearchResult(com.frostwire.search.SearchResult) LinkInfo(com.frostwire.search.youtube.YouTubeExtractor.LinkInfo) LinkedList(java.util.LinkedList)

Aggregations

SearchResult (com.frostwire.search.SearchResult)1 LinkInfo (com.frostwire.search.youtube.YouTubeExtractor.LinkInfo)1 LinkedList (java.util.LinkedList)1