use of org.aisen.weibo.sina.sinasdk.bean.UrlsBean in project AisenWeiBo by wangdan.
the class VideoPlayerActivity method playWithShort.
private void playWithShort(final String url) {
shortUri = Uri.parse(url);
Logger.d(TAG, "short : " + url);
new WorkTask<Void, Void, VideoBean>() {
@Override
protected void onPrepare() {
super.onPrepare();
layoutContent.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public VideoBean workInBackground(Void... params) throws TaskException {
String id = KeyGenerator.generateMD5(url);
// VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
// if (videoBean != null && !TextUtils.isEmpty(videoBean.getImage()) && !TextUtils.isEmpty(videoBean.getVideoUrl())) {
// return videoBean;
// }
UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(url);
if (urlsBean != null && urlsBean.getUrls() != null && urlsBean.getUrls().size() > 0) {
UrlBean urlBean = urlsBean.getUrls().get(0);
VideoBean videoBean = new VideoBean();
videoBean.setIdStr(KeyGenerator.generateMD5(url));
videoBean.setShortUrl(urlBean.getUrl_short());
videoBean.setLongUrl(urlBean.getUrl_long());
int repeat = 8;
while (repeat-- > 0) {
try {
if (VideoService.isSinaVideo(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_SINA);
videoBean = VideoService.getVideoFromSinaVideo(videoBean);
} else if (VideoService.isWeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_WEIPAI);
videoBean = VideoService.getVideoFromWeipai(videoBean);
} else if (VideoService.isMeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_MEIPAI);
videoBean = VideoService.getVideoFromMeipai(videoBean);
}
repeat = 0;
if (!TextUtils.isEmpty(videoBean.getVideoUrl())) {
if (!TextUtils.isEmpty(videoBean.getImage())) {
SinaDB.getDB().update(null, videoBean);
}
return videoBean;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
throw new TaskException("解析短链接失败");
}
@Override
protected void onSuccess(VideoBean videoBean) {
super.onSuccess(videoBean);
playWithVideo(url, videoBean);
}
@Override
protected void onFailure(TaskException exception) {
super.onFailure(exception);
if (isDestory())
return;
new MaterialDialog.Builder(VideoPlayerActivity.this).forceStacking(true).content(R.string.video_short_faild).positiveText(R.string.video2browser).negativeText(R.string.video_again).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
toBrowser(url);
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
playWithShort(url);
}
}).show();
}
}.execute();
}
use of org.aisen.weibo.sina.sinasdk.bean.UrlsBean in project AisenWeiBo by wangdan.
the class VideoService method parseCommentURL.
public static void parseCommentURL(List<StatusComment> comments) throws TaskException {
if (comments.size() == 0)
return;
List<String> shortUrlList = new ArrayList<>();
Map<String, List<StatusComment>> url2status = new HashMap<>();
// 把未解析的短连接拎出来
for (StatusComment comment : comments) {
String content = comment.getText();
if (!TextUtils.isEmpty(content)) {
SpannableString spannableString = SpannableString.valueOf(content);
Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
if (!urlSpan.getURL().startsWith("http://t.cn/"))
continue;
shortUrlList.add(urlSpan.getURL());
List<StatusComment> l = url2status.get(urlSpan.getURL());
if (l == null) {
l = new ArrayList<>();
url2status.put(urlSpan.getURL(), l);
}
if (!l.contains(comment))
l.add(comment);
}
}
}
if (shortUrlList.size() > 0) {
do {
String[] parseArr = new String[20];
for (int i = 0; i < parseArr.length; i++) {
if (shortUrlList.size() > 0) {
parseArr[i] = shortUrlList.remove(0);
}
}
Logger.w(TAG, parseArr);
UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(parseArr);
for (UrlBean urlBean : urlsBean.getUrls()) {
String id = KeyGenerator.generateMD5(urlBean.getUrl_short());
List<StatusComment> statusList = url2status.get(urlBean.getUrl_short());
for (StatusComment s : statusList) {
s.setVideoUrl(urlBean);
VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
boolean isNew = false;
if (videoBean == null) {
videoBean = new VideoBean();
isNew = true;
}
videoBean.setIdStr(id);
videoBean.setShortUrl(urlBean.getUrl_short());
videoBean.setLongUrl(urlBean.getUrl_long());
if (isSinaVideo(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_SINA);
s.setPicture(true);
} else if (isWeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_WEIPAI);
s.setPicture(true);
} else if (isPhoto(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_PHOTO);
s.setPicture(true);
} else {
videoBean.setType(VideoService.TYPE_VIDEO_NONE);
}
if (isNew) {
SinaDB.getDB().insert(null, videoBean);
} else {
SinaDB.getDB().update(null, videoBean);
}
Logger.v(TAG, "Id[%s], Type[%d], 短链[%s], 长链[%s]", videoBean.getIdStr(), videoBean.getType(), urlBean.getUrl_short(), urlBean.getUrl_long());
}
}
} while (shortUrlList.size() > 0);
}
}
use of org.aisen.weibo.sina.sinasdk.bean.UrlsBean 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);
}
}
}
use of org.aisen.weibo.sina.sinasdk.bean.UrlsBean in project AisenWeiBo by wangdan.
the class VideoService method parseStatusURL.
public static void parseStatusURL(List<StatusContent> statusContents) throws TaskException {
if (statusContents.size() == 0)
return;
List<String> shortUrlList = new ArrayList<>();
Map<String, List<StatusContent>> url2status = new HashMap<>();
// 把未解析的短连接拎出来
for (StatusContent statusContent : statusContents) {
String content = statusContent.getText();
if (!TextUtils.isEmpty(content)) {
SpannableString spannableString = SpannableString.valueOf(content);
Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
if (!urlSpan.getURL().startsWith("http://t.cn/"))
continue;
shortUrlList.add(urlSpan.getURL());
List<StatusContent> l = url2status.get(urlSpan.getURL());
if (l == null) {
l = new ArrayList<>();
url2status.put(urlSpan.getURL(), l);
}
if (!l.contains(statusContent))
l.add(statusContent);
}
}
if (statusContent.getRetweeted_status() != null) {
statusContent = statusContent.getRetweeted_status();
content = statusContent.getText();
if (!TextUtils.isEmpty(content)) {
SpannableString spannableString = SpannableString.valueOf(content);
Linkify.addLinks(spannableString, Pattern.compile("http://[a-zA-Z0-9+&@#/%?=~_\\-|!:,\\.;]*[a-zA-Z0-9+&@#/%=~_|]"), "http://");
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
if (!urlSpan.getURL().startsWith("http://t.cn/"))
continue;
shortUrlList.add(urlSpan.getURL());
List<StatusContent> l = url2status.get(urlSpan.getURL());
if (l == null) {
l = new ArrayList<>();
url2status.put(urlSpan.getURL(), l);
}
if (!l.contains(statusContent))
l.add(statusContent);
}
}
}
}
if (shortUrlList.size() > 0) {
do {
String[] parseArr = new String[20];
for (int i = 0; i < parseArr.length; i++) {
if (shortUrlList.size() > 0) {
parseArr[i] = shortUrlList.remove(0);
}
}
Logger.w(TAG, parseArr);
UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(parseArr);
for (UrlBean urlBean : urlsBean.getUrls()) {
String id = KeyGenerator.generateMD5(urlBean.getUrl_short());
List<StatusContent> statusList = url2status.get(urlBean.getUrl_short());
for (StatusContent s : statusList) {
s.setVideoUrl(urlBean);
boolean isNew = false;
VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
if (videoBean == null) {
videoBean = new VideoBean();
isNew = true;
}
videoBean.setIdStr(id);
videoBean.setShortUrl(urlBean.getUrl_short());
videoBean.setLongUrl(urlBean.getUrl_long());
if (isSinaVideo(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_SINA);
s.setVideo(true);
} else if (isWeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_WEIPAI);
s.setVideo(true);
} else if (isMeipai(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_VIDEO_MEIPAI);
s.setVideo(true);
} else if (isPhoto(urlBean.getUrl_long())) {
videoBean.setType(VideoService.TYPE_PHOTO);
} else {
videoBean.setType(VideoService.TYPE_VIDEO_NONE);
}
if (isNew) {
SinaDB.getDB().insert(null, videoBean);
} else {
SinaDB.getDB().update(null, videoBean);
}
Logger.v(TAG, "Id[%s], Type[%d], 短链[%s], 长链[%s]", videoBean.getIdStr(), videoBean.getType(), urlBean.getUrl_short(), urlBean.getUrl_long());
}
}
} while (shortUrlList.size() > 0);
}
}
Aggregations