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);
}
}
}
Aggregations