Search in sources :

Example 16 with BaseResult

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

the class ParseMeiZiTu method parseMzPosts.

public static BaseResult<List<MeiZiTu>> parseMzPosts(String html, int page) {
    BaseResult<List<MeiZiTu>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Document doc = Jsoup.parse(html);
    Element ulPins = doc.getElementById("pins");
    Elements lis = ulPins.select("li");
    List<MeiZiTu> meiZiTuList = new ArrayList<>();
    for (Element li : lis) {
        MeiZiTu meiZiTu = new MeiZiTu();
        String contentUrl = li.select("a").first().attr("href");
        // meiZiTu.setContentUrl(contentUrl);
        int index = contentUrl.lastIndexOf("/");
        if (index >= 0 && index + 1 < contentUrl.length()) {
            String idStr = contentUrl.substring(index + 1, contentUrl.length());
            Logger.t(TAG).d(idStr);
            if (!TextUtils.isEmpty(idStr) && TextUtils.isDigitsOnly(idStr)) {
                meiZiTu.setId(Integer.parseInt(idStr));
            }
        }
        Element imageElement = li.selectFirst("img");
        String name = imageElement.attr("alt");
        meiZiTu.setName(name);
        String thumbUrl = imageElement.attr("data-original");
        meiZiTu.setThumbUrl(thumbUrl);
        Logger.t(TAG).d(thumbUrl);
        int height = Integer.parseInt(imageElement.attr("height"));
        meiZiTu.setHeight(height);
        int width = Integer.parseInt(imageElement.attr("width"));
        meiZiTu.setWidth(width);
        String date = li.getElementsByClass("time").first().text();
        meiZiTu.setDate(date);
        String viewCount = li.getElementsByClass("view").first().text();
        meiZiTu.setViewCount(viewCount);
        meiZiTuList.add(meiZiTu);
    }
    Logger.t(TAG).d("size::" + meiZiTuList.size());
    if (page == 1) {
        Elements pageElements = doc.getElementsByClass("page-numbers");
        if (pageElements != null && pageElements.size() > 3) {
            String pageStr = pageElements.get(pageElements.size() - 2).text();
            Logger.t(TAG).d("totalPage::" + pageStr);
            if (!TextUtils.isEmpty(pageStr) && TextUtils.isDigitsOnly(pageStr)) {
                baseResult.setTotalPage(Integer.parseInt(pageStr));
            }
        }
    }
    baseResult.setData(meiZiTuList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MeiZiTu(com.dante.data.model.MeiZiTu) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 17 with BaseResult

use of com.dante.data.model.BaseResult 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 18 with BaseResult

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

the class ParsePigAv method videoList.

public static BaseResult<List<PigAv>> videoList(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 19 with BaseResult

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

the class ParseProxy method parseXiCiDaiLi.

public static BaseResult<List<ProxyModel>> parseXiCiDaiLi(String html, int page) {
    BaseResult<List<ProxyModel>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Document doc = Jsoup.parse(html);
    Element ipList = doc.getElementById("ip_list");
    Elements trs = ipList.select("tr");
    int trSize = trs.size();
    List<ProxyModel> proxyModelList = new ArrayList<>();
    for (int i = 0; i < trSize; i++) {
        // 第一是标题,跳过
        if (i == 0) {
            continue;
        }
        // tr里的td
        Elements tds = trs.get(i).select("td");
        ProxyModel proxyModel = new ProxyModel();
        for (int j = 0; j < tds.size(); j++) {
            Element td = tds.get(j);
            switch(j) {
                case 0:
                    // 国家
                    break;
                case 1:
                    // ip
                    String ip = td.text();
                    proxyModel.setProxyIp(ip);
                    break;
                case 2:
                    // 端口
                    String port = td.text();
                    proxyModel.setProxyPort(port);
                    break;
                case 3:
                    // 城市
                    break;
                case 4:
                    // 匿名度
                    String anonymous = td.text();
                    proxyModel.setAnonymous(anonymous);
                    break;
                case 5:
                    // 类型 http https socket
                    String type = td.text();
                    if ("http".equalsIgnoreCase(type)) {
                        proxyModel.setType(ProxyModel.TYPE_HTTP);
                    } else if ("https".equalsIgnoreCase(type)) {
                        proxyModel.setType(ProxyModel.TYPE_HTTPS);
                    } else {
                        proxyModel.setType(ProxyModel.TYPE_SOCKS);
                    }
                    break;
                case 6:
                    // 速度
                    break;
                case 7:
                    // 连接时间
                    String responseTime = td.select("div").first().attr("title");
                    proxyModel.setResponseTime(responseTime);
                    break;
                case 8:
                    // 存活时间
                    break;
                case 9:
                    // 验证时间
                    break;
                default:
            }
        }
        proxyModelList.add(proxyModel);
    }
    baseResult.setData(proxyModelList);
    if (page == 1) {
        Elements elements = doc.getElementsByClass("pagination").first().select("a");
        if (elements.size() > 3) {
            String totalPageStr = elements.get(elements.size() - 2).text();
            Logger.t(TAG).d(totalPageStr);
            if (TextUtils.isDigitsOnly(totalPageStr)) {
                baseResult.setTotalPage(Integer.parseInt(totalPageStr));
            }
        }
    }
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) ProxyModel(com.dante.data.model.ProxyModel)

Example 20 with BaseResult

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

the class AppApiHelper method loadPorn91VideoRecentUpdates.

@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91VideoRecentUpdates(String next, int page, boolean cleanCache, boolean isLoadMoreCleanCache) {
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(next, page);
    EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache || isLoadMoreCleanCache);
    Observable<String> categoryPage = noLimit91PornServiceApi.recentUpdates(next, page, HeaderUtils.getIndexHeader(addressHelper));
    return cacheProviders.getRecentUpdates(categoryPage, 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.parseHot(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)

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