| | |
| | | package com.yeshi.buwan.iqiyi.util; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.Serializable; |
| | | import java.math.BigInteger; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | import org.hibernate.HibernateException; |
| | | import org.hibernate.Session; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.select.Elements; |
| | | import org.springframework.orm.hibernate4.HibernateCallback; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.buwan.dao.VideoResourceDao; |
| | |
| | | import com.yeshi.buwan.domain.VideoType; |
| | | import com.yeshi.buwan.domain.entity.PlayUrl; |
| | | import com.yeshi.buwan.iqiyi.IqiYiAPI; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiChannel; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiVideoInfo; |
| | | import com.yeshi.buwan.iqiyi.entity.PlayControls; |
| | | import com.yeshi.buwan.iqiyi.entity.VideoIqiyi; |
| | | import com.yeshi.buwan.iqiyi.entity.*; |
| | | import com.yeshi.buwan.log.LogHelper; |
| | | import com.yeshi.buwan.service.imp.juhe.IqiyiService; |
| | | import com.yeshi.buwan.util.JuheVideoUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.log4j.Logger; |
| | | import org.hibernate.HibernateException; |
| | | import org.hibernate.Session; |
| | | import org.springframework.orm.hibernate4.HibernateCallback; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.math.BigInteger; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | @Component |
| | | public class IqiyiUtil { |
| | |
| | | return categoryId; |
| | | } |
| | | |
| | | // 更新聚合形式的专辑 |
| | | public void updateSourceAlbum() { |
| | | List<List<String>> list = iqiyiService.getSourceAlbumList(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Map<String, Object> map = IqiYiAPI.getAlbumList(list.get(i).get(1), list.get(i).get(0), 1, 1, -1);// addAlbum |
| | | int count = Integer.parseInt(map.get("count") + ""); |
| | | for (int n = 1; n < count / 100 + 2; n++) { |
| | | map = IqiYiAPI.getAlbumList(list.get(i).get(1), list.get(i).get(0), n, 100, -1); |
| | | List<IqiyiAlbum> dataList = (List<IqiyiAlbum>) map.get("data"); |
| | | if (dataList != null && dataList.size() > 0) |
| | | addAlbum(dataList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 更新聚合形式的专辑 |
| | | public void updateSourceAlbum(String sourceId) { |
| | |
| | | addAlbum(dataAllList); |
| | | } |
| | | |
| | | /** |
| | | * 更新所有的专辑 |
| | | */ |
| | | public void updateAllAlbum() { |
| | | List<IqiyiChannel> chalList = IqiYiAPI.getChannelList(); |
| | | for (int c = 0; c < chalList.size(); c++) { |
| | | final String channelId = chalList.get(c).getCategoryId(); |
| | | new Timer().schedule(new TimerTask() { |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | public void run() {// 两个小时更新一次 |
| | | long endt = System.currentTimeMillis(); |
| | | Map<String, Object> map = IqiYiAPI.updateAlbum( |
| | | TimeUtil.getGernalTime(endt - 1000 * 60 * 150L, "yyyyMMddHHmmss"), |
| | | TimeUtil.getGernalTime(endt, "yyyyMMddHHmmss"), null, 100, Integer.parseInt(channelId), 0); |
| | | int count = Integer.parseInt(map.get("count") + ""); |
| | | List<IqiyiAlbum> list = (List<IqiyiAlbum>) map.get("data"); |
| | | addAlbum(list); |
| | | list.clear(); |
| | | |
| | | if (count > 100) { |
| | | for (int i = 2; i < count / 100 + 2; i++) { |
| | | map = IqiYiAPI.updateAlbum( |
| | | TimeUtil.getGernalTime(endt - 1000 * 60 * 60 * 3, "yyyyMMddHHmmss"), |
| | | TimeUtil.getGernalTime(endt, "yyyyMMddHHmmss"), |
| | | list.get(list.size() - 1).getAlbumId(), 100, Integer.parseInt(channelId), 0); |
| | | list = (List<IqiyiAlbum>) map.get("data"); |
| | | addAlbum(list); |
| | | } |
| | | } |
| | | } |
| | | }, 0, 1000 * 60 * 60 * 2L); |
| | | } |
| | | } |
| | | |
| | | public void updateAll(final String key) { |
| | | List<IqiyiChannel> chalList = IqiYiAPI.getChannelList(); |
| | | LogHelper.iqiyi("更新" + chalList.size() + "个分类"); |
| | | for (int c = 0; c < chalList.size(); c++) { |
| | | final String channelId = chalList.get(c).getCategoryId(); |
| | | final IqiyiChannel channel = chalList.get(c); |
| | | // if (!channel.getCategoryId().equalsIgnoreCase("1")) |
| | | // continue; |
| | | //排除正片的更新 |
| | | boolean update = true; |
| | | String[] channelIds = new String[]{"1", "2", "4", "6"}; |
| | | for (String cId : channelIds) |
| | | if (cId.equalsIgnoreCase(channelId)) { |
| | | update = false; |
| | | break; |
| | | } |
| | | if (!update) |
| | | break; |
| | | |
| | | LogHelper.iqiyi("更新" + channel.getCategoryName()); |
| | | new Timer().schedule(new TimerTask() { |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public String getHighVerPicture(String org) { |
| | | return org.replace(".jpg", "_260_360.jpg"); |
| | | } |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | public void updateIqiyiAvaiable() { |
| | | iqiyiVideoInfoDao.excute(new HibernateCallback() { |
| | |
| | | |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public List<IqiyiAlbum> getIqiyiAlbumByCatoryIdAndContentType(final int cid, final int ctype) { |
| | | return (List<IqiyiAlbum>) videoIqiyiDao.excute(new HibernateCallback<List<IqiyiAlbum>>() { |
| | | |
| | | @Override |
| | | public List<IqiyiAlbum> doInHibernate(Session session) throws HibernateException { |
| | | return session |
| | | .createQuery("from IqiyiAlbum a where a.categoryId=" + cid + " and a.contentType=" + ctype) |
| | | .list(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 更新原来属于爱奇艺VIP的视频 |
| | | */ |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 添加爱奇艺小视频 |
| | | * |
| | | * @param aid |
| | | * @param albumId |
| | | */ |
| | | public void addShortVideo(String albumId) { |
| | | IqiyiAlbum album = IqiYiAPI.getAlbumDetail(albumId); |
| | |
| | | |
| | | } |
| | | |
| | | //http://pic7.iqiyipic.com/image/20201029/c8/70/a_100417138_m_601_m12.jpg |
| | | //http://pic7.iqiyipic.com/image/20201027/68/fb/v_154231741_m_601.jpg |
| | | public static String getHPicture(String url) { |
| | | String regex = "_m[0-9]+\\.jpg"; |
| | | String regex = "(_m[0-9]+\\.jpg)|(_m_[0-9]+\\.jpg)"; |
| | | Pattern p = Pattern.compile(regex); |
| | | Matcher m = p.matcher(url); |
| | | if (m.find()) { |
| | |
| | | } |
| | | |
| | | public static String getVPicture(String url) { |
| | | String regex = "_m[0-9]+\\.jpg"; |
| | | String regex = "(_m[0-9]+\\.jpg)|(_m_[0-9]+\\.jpg)"; |
| | | Pattern p = Pattern.compile(regex); |
| | | Matcher m = p.matcher(url); |
| | | if (m.find()) { |