package com.newvideo.letv;
|
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Component;
|
|
import com.newvideo.domain.VideoDetailInfo;
|
import com.newvideo.domain.VideoInfo;
|
import com.newvideo.letv.entity.LeTVAlbum;
|
import com.newvideo.letv.entity.LeTVVideo;
|
import com.newvideo.service.imp.juhe.LeService;
|
import com.newvideo.util.StringUtil;
|
import com.newvideo.util.TimeUtil;
|
|
import net.sf.json.JSONObject;
|
|
@Component
|
public class LeTVUtil {
|
public final static String KEY = "a9d8aaabe16ea397f11a359672b26a34";
|
public final static String UID = "870919";
|
public final static String UUID = "ztereukows";
|
|
public static String getSign() {
|
return StringUtil.Md5(UID + KEY);
|
}
|
|
@Resource
|
private LeService leService;
|
|
// ר������
|
@SuppressWarnings("unchecked")
|
public void startParseAlbum() {
|
for (int p = 3; p < 10; p++) {
|
List<LeTVAlbum> list = LeAPI.albumList(p);
|
for (LeTVAlbum album : list) {
|
Map<String, Object> map = LeAPI.albumVideoList(album.getAlbumId(), 1);
|
int count = Integer.parseInt(map.get("count") + "");
|
int page = count % 20 == 0 ? count / 20 : count / 20 + 1;
|
List<LeTVVideo> videoList = new ArrayList<LeTVVideo>();
|
videoList.addAll((List<LeTVVideo>) map.get("data"));
|
if (page > 1)
|
for (int i = 2; i <= page; i++) {
|
map = LeAPI.albumVideoList(album.getAlbumId(), i);
|
videoList.addAll((List<LeTVVideo>) map.get("data"));
|
}
|
album.setVideoList(videoList);
|
// ������ݿ�
|
addLeTVAlbum(album);
|
}
|
}
|
}
|
|
public void startParseVideo() {
|
for (int p = 1; p < 10; p++) {
|
List<LeTVVideo> list = LeAPI.videoList(p);
|
// ������ݿ�
|
}
|
}
|
|
public void addLeTVVideo(LeTVVideo tv) {
|
String id = leService.addLeTVVideo(tv) + "";
|
if (!StringUtil.isNullOrEmpty(id)) {
|
tv.setId(id);
|
leService.addToVideo(tv);
|
}
|
}
|
|
public void addLeTVAlbum(LeTVAlbum album) {
|
String id = leService.addLeTVAlbum(album) + "";
|
if (!StringUtil.isNullOrEmpty(id))
|
album.setId(id);
|
leService.addToVideo(album, leService.isUpdate(album));
|
}
|
|
public static VideoInfo convertToVideoInfo(LeTVAlbum album) {
|
Calendar ca = Calendar.getInstance();
|
ca.setTimeInMillis(TimeUtil.convertDateToTemp(album.getReleaseDate()));
|
int year = ca.get(Calendar.YEAR);
|
int month = ca.get(Calendar.MONTH) + 1;
|
int day = ca.get(Calendar.DAY_OF_MONTH);
|
Comparator<LeTVVideo> cm = new Comparator<LeTVVideo>() {
|
|
public int compare(LeTVVideo o1, LeTVVideo o2) {
|
|
return Integer.parseInt(o2.getEpisode()) - Integer.parseInt(o1.getEpisode());
|
}
|
};
|
Collections.sort(album.getVideoList(), cm);
|
|
JSONObject obj = new JSONObject();
|
try {
|
obj = JSONObject.fromObject(album.getExtendPropertiesStr());
|
} catch (Exception e) {
|
|
}
|
String tag = "";
|
if (album.getCategoryName().contains("��Ӱ")) {
|
tag = "���֣�" + album.getScore();
|
} else if (album.getCategoryName().contains("���Ӿ�")) {
|
if (Integer.parseInt(album.getEpisodeCount()) > Integer.parseInt(album.getEpisodeNow()))
|
tag = "������" + album.getEpisodeNow() + "��";
|
else
|
tag = album.getEpisodeNow() + "��ȫ";
|
} else if (album.getCategoryName().contains("����")) {
|
if (Integer.parseInt(album.getEpisodeCount()) > Integer.parseInt(album.getEpisodeNow()))
|
tag = "������" + album.getEpisodeNow() + "��";
|
else
|
tag = album.getEpisodeNow() + "��ȫ";
|
} else if (album.getCategoryName().contains("����")) {
|
tag = "������" + album.getEpisodeNow();
|
}
|
|
VideoInfo vi = new VideoInfo();
|
vi.setArea(album.getArea());
|
vi.setBaseurl("");
|
vi.setCanSave(false);
|
vi.setCommentCount(0);
|
vi.setContentType(1);
|
vi.setCreatetime(System.currentTimeMillis());
|
vi.setDay(day + "");
|
vi.setDirector(obj.optString("director"));
|
vi.setFocus("");
|
vi.setHpicture(album.getAlbumCover());
|
vi.setIntroduction(album.getSynopsis());
|
vi.setLatestHpicture(album.getVideoList().get(0).getCover());
|
vi.setLatestVpicture("");
|
vi.setMainActor(obj.optString("actor"));
|
vi.setMonth(month + "");
|
vi.setName(album.getAlbumName());
|
vi.setNowNumber(0 + "");
|
vi.setOrderby("0");
|
vi.setPicture(album.getAlbumCover());
|
vi.setScore(album.getScore());
|
vi.setShare("0");
|
vi.setShow(1 + "");
|
vi.setTag(tag);
|
vi.setVpicture(album.getVideoList().get(0).getCover());
|
vi.setWatchCount(0 + "");
|
vi.setYear(year + "");
|
vi.setUpdatetime(TimeUtil.convertDateToTemp2(album.getCreateTime()) + "");
|
vi.setVideocount(album.getVideoList() != null ? album.getVideoList().size() : 1);
|
return vi;
|
}
|
|
public static VideoInfo convertToVideoInfo(LeTVVideo tv) {
|
Calendar ca = Calendar.getInstance();
|
ca.setTimeInMillis(TimeUtil.convertDateToTemp2(tv.getCreateTime()));
|
int year = ca.get(Calendar.YEAR);
|
int month = ca.get(Calendar.MONTH) + 1;
|
int day = ca.get(Calendar.DAY_OF_MONTH);
|
|
JSONObject obj = JSONObject.fromObject(tv.getExtendPropertiesStr());
|
String tag = "";
|
if (tv.getCategoryName().contains("��Ӱ")) {
|
tag = "���֣�" + tv.getScore();
|
} else
|
tag = "���֣�" + tv.getScore();
|
VideoInfo vi = new VideoInfo();
|
vi.setArea(tv.getArea());
|
vi.setBaseurl("");
|
vi.setCanSave(false);
|
vi.setCommentCount(0);
|
vi.setContentType(1);
|
vi.setCreatetime(System.currentTimeMillis());
|
vi.setDay(day + "");
|
vi.setDirector(obj.optString("director"));
|
vi.setFocus("");
|
vi.setHpicture(tv.getCover());
|
vi.setIntroduction(tv.getSynopsis());
|
vi.setLatestHpicture(tv.getCover());
|
vi.setLatestVpicture("");
|
vi.setMainActor(obj.optString("actor"));
|
vi.setMonth(month + "");
|
vi.setName(tv.getVideoName());
|
vi.setNowNumber(0 + "");
|
vi.setOrderby("0");
|
vi.setPicture(tv.getCover());
|
vi.setScore(tv.getScore());
|
vi.setShare("0");
|
vi.setShow(1 + "");
|
vi.setTag(tag);
|
vi.setVpicture(tv.getCover());
|
vi.setWatchCount(0 + "");
|
vi.setYear(year + "");
|
vi.setUpdatetime(ca.getTimeInMillis() + "");
|
vi.setVideocount(1);
|
return vi;
|
}
|
|
public static int getVideoType(String categoryName) {
|
if (categoryName.contains("��Ӱ")) {
|
return 151;
|
} else if (categoryName.contains("���Ӿ�")) {
|
return 150;
|
} else if (categoryName.contains("����")) {
|
return 153;
|
} else if (categoryName.contains("����")) {
|
return 152;
|
} else {
|
return 299;
|
}
|
}
|
|
public static boolean isSameVideo(VideoInfo first, VideoInfo second) {
|
if (first.getPicture().equalsIgnoreCase(second.getPicture()))
|
return true;
|
if (first.getYear().equalsIgnoreCase(second.getYear()))
|
return true;
|
return false;
|
}
|
|
public static VideoDetailInfo convertLeTVVideoToVideoDetail(LeTVVideo video) {
|
VideoDetailInfo info = new VideoDetailInfo();
|
if (video.getCategoryName().contains("����"))
|
info.setTag(video.getVideoName());
|
else if (video.getCategoryName().contains("��Ӱ")) {
|
info.setTag(video.getVideoName());
|
} else if (video.getCategoryName().contains("���Ӿ�")) {
|
info.setTag(video.getEpisode());
|
} else if (video.getCategoryName().contains("����")) {
|
info.setTag(video.getEpisode());
|
} else
|
info.setTag(video.getVideoName());
|
info.setId(Long.parseLong(video.getVideoId()));
|
info.setExtraId(video.getVideoId());
|
info.setType("letv");
|
return info;
|
}
|
|
}
|