Search in sources :

Example 1 with PigAvVideo

use of com.dante.data.model.PigAvVideo in project 91Pop by DanteAndroid.

the class ParsePigAv method parserVideoUrl.

/**
 * @param html 原网页
 * @return json===
 */
public static BaseResult<PigAvVideo> parserVideoUrl(String html) {
    BaseResult<PigAvVideo> baseResult = new BaseResult<>();
    Document document = Jsoup.parse(html);
    Element videoWrapper = document.getElementsByClass("td-post-content td-pb-padding-side").first();
    String videoHtml = videoWrapper.html();
    Logger.t(TAG).d(videoHtml);
    int index = videoHtml.indexOf("setup") + 6;
    int endIndexV = videoHtml.indexOf(");");
    String videoUrl = videoHtml.substring(index, endIndexV);
    Logger.t(TAG).d(videoUrl);
    PigAvVideo pigAvVideo = new Gson().fromJson(videoUrl, PigAvVideo.class);
    Elements items = document.getElementsByClass("td-block-span12");
    List<PigAv> pigAvList = new ArrayList<>();
    for (Element element : items) {
        PigAv pigAv = new PigAv();
        Element a = element.selectFirst("a");
        String title = a.attr("title");
        pigAv.setTitle(title);
        String contentUrl = a.attr("href");
        pigAv.setContentUrl(contentUrl);
        Element img = element.selectFirst("img");
        String imgUrl = img.attr("src");
        int beginIndex = imgUrl.lastIndexOf("/");
        int endIndex = imgUrl.indexOf("-");
        String bigImg = StringUtils.subString(imgUrl, 0, endIndex);
        if (TextUtils.isEmpty(bigImg)) {
            pigAv.setImgUrl(imgUrl);
        } else {
            pigAv.setImgUrl(bigImg + ".jpg");
        }
        String pId = StringUtils.subString(imgUrl, beginIndex + 1, endIndex);
        Logger.t(TAG).d(pId);
        pigAv.setpId(pId);
        int imgWidth = Integer.parseInt(img.attr("width"));
        pigAv.setImgWidth(imgWidth);
        int imgHeight = Integer.parseInt(img.attr("height"));
        pigAv.setImgHeight(imgHeight);
        pigAvList.add(pigAv);
    }
    pigAvVideo.setPigAvList(pigAvList);
    baseResult.setData(pigAvVideo);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) PigAvVideo(com.dante.data.model.PigAvVideo) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) PigAv(com.dante.data.model.PigAv) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 2 with PigAvVideo

use of com.dante.data.model.PigAvVideo in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPigAvVideoUrl.

@Override
public Observable<PigAvVideo> loadPigAvVideoUrl(String url, String pId, boolean pullToRefresh) {
    if (TextUtils.isEmpty(pId)) {
        pId = "aaa1";
        pullToRefresh = true;
    }
    DynamicKey dynamicKey = new DynamicKey(pId);
    return cacheProviders.cacheWithNoLimitTime(pigAvServiceApi.pigAvVideoUrl(url), dynamicKey, new EvictDynamicKey(pullToRefresh)).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> stringReply) throws Exception {
            return stringReply.getData();
        }
    }).map(new Function<String, PigAvVideo>() {

        @Override
        public PigAvVideo apply(String s) throws Exception {
            return ParsePigAv.parserVideoUrl(s).getData();
        }
    });
}
Also used : Function(io.reactivex.functions.Function) PigAvVideo(com.dante.data.model.PigAvVideo) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) DynamicKey(io.rx_cache2.DynamicKey) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Aggregations

PigAvVideo (com.dante.data.model.PigAvVideo)2 BaseResult (com.dante.data.model.BaseResult)1 PigAv (com.dante.data.model.PigAv)1 FavoriteException (com.dante.exception.FavoriteException)1 MessageException (com.dante.exception.MessageException)1 Gson (com.google.gson.Gson)1 Function (io.reactivex.functions.Function)1 DynamicKey (io.rx_cache2.DynamicKey)1 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)1 Reply (io.rx_cache2.Reply)1 ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1