use of org.aisen.weibo.sina.support.bean.VideoBean 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);
}
}
use of org.aisen.weibo.sina.support.bean.VideoBean 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.support.bean.VideoBean in project AisenWeiBo by wangdan.
the class VideoDownloader method downloadBitmap.
@Override
public byte[] downloadBitmap(Context context, String url, ImageConfig config) throws Exception {
WebDownloader webDownloader = new WebDownloader();
String id = KeyGenerator.generateMD5(url);
VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
if (videoBean != null) {
if (TextUtils.isEmpty(videoBean.getImage()) || TextUtils.isEmpty(videoBean.getVideoUrl())) {
int repeat = 8;
while (repeat-- > 0) {
try {
if (videoBean.getType() == VideoService.TYPE_VIDEO_WEIPAI) {
videoBean = VideoService.getVideoFromWeipai(videoBean);
} else if (videoBean.getType() == VideoService.TYPE_VIDEO_SINA) {
videoBean = VideoService.getVideoFromSinaVideo(videoBean);
} else if (videoBean.getType() == VideoService.TYPE_VIDEO_MEIPAI) {
videoBean = VideoService.getVideoFromMeipai(videoBean);
}
Logger.d("VidewDownloader", "video = " + videoBean.getVideoUrl() + ", long = " + videoBean.getLongUrl() + ", short = " + videoBean.getShortUrl() + ", image = " + videoBean.getImage());
SinaDB.getDB().update(null, videoBean);
break;
} catch (Exception e) {
e.printStackTrace();
}
}
Logger.d(videoBean);
}
if (!TextUtils.isEmpty(videoBean.getImage())) {
return webDownloader.downloadBitmap(context, videoBean.getImage(), config);
}
}
return null;
}
use of org.aisen.weibo.sina.support.bean.VideoBean 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.support.bean.VideoBean in project AisenWeiBo by wangdan.
the class VideoPlayerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ui_video_player);
mVideoPlayer = (VideoView) findViewById(R.id.videoView);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setTitle("");
if (getResources().getConfiguration().orientation == 2) {
getToolbar().setVisibility(View.GONE);
}
mPlayingWhenPaused = true;
String action = getIntent().getAction();
if (Intent.ACTION_VIEW.equalsIgnoreCase(action) && getIntent().getData() != null) {
Uri uri = getIntent().getData();
if ("videoshort".equals(uri.getScheme())) {
playWithShort(uri.toString().replace("videoshort://", ""));
} else if ("videopath".equals(uri.getScheme())) {
VideoBean bean = (VideoBean) getIntent().getSerializableExtra("bean");
playWithVideo(uri.toString().replace("videopath://", ""), bean);
}
} else {
finish();
}
}
Aggregations