Search in sources :

Example 1 with BaseResult

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

the class ParsePigAv method moreVideoList.

public static BaseResult<List<PigAv>> moreVideoList(String html) {
    BaseResult<List<PigAv>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Document doc = Jsoup.parse(html);
    Elements items = doc.getElementsByClass("td-block-span4");
    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.lastIndexOf("-");
        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);
    }
    baseResult.setData(pigAvList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PigAv(com.dante.data.model.PigAv) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 2 with BaseResult

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

the class AppApiHelper method action.

private Observable<BaseResult<List<MeiZiTu>>> action(Observable<String> stringObservable, String tag, final int page, final boolean pullToRefresh) {
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(tag, page);
    EvictDynamicKeyGroup evictDynamicKeyGroup = new EvictDynamicKeyGroup(pullToRefresh);
    return cacheProviders.meiZiTu(stringObservable, dynamicKeyGroup, evictDynamicKeyGroup).map(new Function<Reply<String>, String>() {

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

        @Override
        public BaseResult<List<MeiZiTu>> apply(String s) throws Exception {
            return ParseMeiZiTu.parseMzPosts(s, page);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) MeiZiTu(com.dante.data.model.MeiZiTu) ParseMeiZiTu(com.dante.parser.ParseMeiZiTu) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 3 with BaseResult

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

the class AppApiHelper method list99Mm.

@Override
public Observable<BaseResult<List<Mm99>>> list99Mm(String category, final int page, boolean cleanCache) {
    String url = buildUrl(category, page);
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(category, page);
    EvictDynamicKeyGroup evictDynamicKeyGroup = new EvictDynamicKeyGroup(cleanCache);
    return cacheProviders.cacheWithLimitTime(mm99ServiceApi.imageList(url), dynamicKeyGroup, evictDynamicKeyGroup).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> stringReply) {
            return stringReply.getData();
        }
    }).map(new Function<String, BaseResult<List<Mm99>>>() {

        @Override
        public BaseResult<List<Mm99>> apply(String s) {
            return Parse99Mm.parse99MmList(s, page);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) Mm99(com.dante.data.model.Mm99) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup)

Example 4 with BaseResult

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

the class AppApiHelper method loadPorn91MyFavoriteVideos.

@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91MyFavoriteVideos(String userName, int page, boolean cleanCache) {
    Observable<String> favoriteObservable = noLimit91PornServiceApi.myFavoriteVideo(page, HeaderUtils.getIndexHeader(addressHelper));
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(userName, page);
    EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache);
    return cacheProviders.getFavorite(favoriteObservable, dynamicKeyGroup, evictDynamicKey).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> responseBody) throws Exception {
            return responseBody.getData();
        }
    }).map(new Function<String, BaseResult<List<UnLimit91PornItem>>>() {

        @Override
        public BaseResult<List<UnLimit91PornItem>> apply(String s) throws Exception {
            return Parse91PronVideo.parseMyFavorite(s);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 5 with BaseResult

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

the class Parse91PronVideo method parseMyFavorite.

/**
 * 解析我的收藏
 *
 * @param html html
 * @return list
 */
public static BaseResult<List<UnLimit91PornItem>> parseMyFavorite(String html) {
    int totalPage = 1;
    List<UnLimit91PornItem> unLimit91PornItemList = new ArrayList<>();
    Document doc = Jsoup.parse(html);
    Element body = doc.getElementById("leftside");
    Elements videos = doc.select("div.myvideo");
    for (Element element : videos) {
        UnLimit91PornItem unLimit91PornItem = new UnLimit91PornItem();
        String contentUrl = element.select("a").first().attr("href");
        String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1, contentUrl.length());
        unLimit91PornItem.setViewKey(viewKey);
        Logger.t(TAG).d(viewKey);
        String title = element.select("strong").first().text();
        unLimit91PornItem.setTitle(title);
        Logger.t(TAG).d(title);
        String imgUrl = element.select("img").first().attr("src");
        unLimit91PornItem.setImgUrl(imgUrl);
        Logger.t(TAG).d(imgUrl);
        String allInfo = element.text();
        Logger.t(TAG).d(allInfo);
        String duration = allInfo.substring(allInfo.indexOf("时长") + 3, allInfo.indexOf("Views") - 3);
        unLimit91PornItem.setDuration(duration);
        Logger.t(TAG).d(duration);
        String info = allInfo.substring(allInfo.indexOf("添加时间"), allInfo.length());
        unLimit91PornItem.setInfo(info);
        Logger.t(TAG).d(info);
        String rvid = element.select("input").first().attr("value");
        Logger.t(TAG).d("rvid::" + rvid);
        VideoResult videoResult = new VideoResult();
        videoResult.setId(VideoResult.OUT_OF_WATCH_TIMES);
        videoResult.setVideoId(rvid);
        unLimit91PornItem.setVideoResult(videoResult);
        unLimit91PornItemList.add(unLimit91PornItem);
    }
    // 总页数
    Element pagingnav = body.getElementById("paging");
    Elements a = pagingnav.select("a");
    if (a.size() >= 2) {
        String ppp = a.get(a.size() - 2).text();
        if (TextUtils.isDigitsOnly(ppp)) {
            totalPage = Integer.parseInt(ppp);
            Logger.d("总页数:" + totalPage);
        }
    }
    BaseResult<List<UnLimit91PornItem>> baseResult = new BaseResult<>();
    // 尝试解析删除信息
    Elements msgElements = doc.select("div.msgbox");
    if (msgElements != null) {
        String msgInfo = msgElements.text();
        if (!TextUtils.isEmpty(msgInfo)) {
            baseResult.setCode(BaseResult.SUCCESS_CODE);
            baseResult.setMessage(msgInfo);
        }
    } else {
        String errorMsg = parseErrorInfo(html);
        if (!TextUtils.isEmpty(errorMsg)) {
            baseResult.setMessage(errorMsg);
            baseResult.setCode(BaseResult.ERROR_CODE);
        }
    }
    baseResult.setTotalPage(totalPage);
    baseResult.setData(unLimit91PornItemList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) VideoResult(com.dante.data.model.VideoResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem)

Aggregations

BaseResult (com.dante.data.model.BaseResult)22 ArrayList (java.util.ArrayList)14 List (java.util.List)14 Document (org.jsoup.nodes.Document)14 Element (org.jsoup.nodes.Element)14 Elements (org.jsoup.select.Elements)14 UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)10 MessageException (com.dante.exception.MessageException)7 Function (io.reactivex.functions.Function)6 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)6 EvictDynamicKeyGroup (io.rx_cache2.EvictDynamicKeyGroup)6 Reply (io.rx_cache2.Reply)6 FavoriteException (com.dante.exception.FavoriteException)5 EvictDynamicKey (io.rx_cache2.EvictDynamicKey)4 PigAv (com.dante.data.model.PigAv)3 NonNull (android.support.annotation.NonNull)2 Forum91PronItem (com.dante.data.model.Forum91PronItem)2 MeiZiTu (com.dante.data.model.MeiZiTu)2 Mm99 (com.dante.data.model.Mm99)2 RetryWhenProcess (com.dante.rxjava.RetryWhenProcess)2