Search in sources :

Example 1 with DefHttpUtility

use of org.aisen.android.network.http.DefHttpUtility in project AisenWeiBo by wangdan.

the class VideoService method getPicture.

public static void getPicture(VideoBean video) throws Exception {
    if (TextUtils.isEmpty(AppContext.getAccount().getCookie())) {
        throw new TaskException("123", "解析链接失败");
    }
    HttpConfig config = new HttpConfig();
    config.baseUrl = video.getShortUrl();
    config.cookie = AppContext.getAccount().getCookie();
    config.addHeader("Content-Type", "text/html;charset=utf-8");
    Setting action = new Setting();
    action.setType("");
    action.setValue("");
    action.setDescription("");
    String response = new DefHttpUtility().doGet(config, action, null, String.class);
    Document dom = Jsoup.parse(response);
    video.setIdStr(KeyGenerator.generateMD5(video.getShortUrl()));
    Elements divs = dom.select("img");
    if (divs != null && divs.size() > 0) {
        video.setImage(divs.get(0).attr("src"));
        video.setImage(video.getImage().replace("bmiddle", "small").replace("thumbnail", "small"));
    }
    if (TextUtils.isEmpty(video.getImage())) {
        String longUrl = video.getLongUrl();
        if (TextUtils.isEmpty(longUrl)) {
            UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(video.getShortUrl());
            if (urlsBean.getUrls() != null && urlsBean.getUrls().size() > 0) {
                longUrl = urlsBean.getUrls().get(0).getUrl_long();
                longUrl.replace("bmiddle", "small").replace("thumbnail", "small");
            }
        }
        if (!TextUtils.isEmpty(longUrl)) {
            video.setImage(longUrl);
        }
    }
}
Also used : TaskException(org.aisen.android.network.task.TaskException) Setting(org.aisen.android.common.setting.Setting) HttpConfig(org.aisen.android.network.http.HttpConfig) SpannableString(android.text.SpannableString) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) UrlsBean(org.aisen.weibo.sina.sinasdk.bean.UrlsBean) DefHttpUtility(org.aisen.android.network.http.DefHttpUtility)

Aggregations

SpannableString (android.text.SpannableString)1 Setting (org.aisen.android.common.setting.Setting)1 DefHttpUtility (org.aisen.android.network.http.DefHttpUtility)1 HttpConfig (org.aisen.android.network.http.HttpConfig)1 TaskException (org.aisen.android.network.task.TaskException)1 UrlsBean (org.aisen.weibo.sina.sinasdk.bean.UrlsBean)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1