| | |
| | | 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 { |
| | |
| | | private VideoResourceDao videoResourceDao; |
| | | |
| | | static Logger logger = Logger.getLogger(IqiyiUtil.class); |
| | | |
| | | |
| | | public final static int RESOURCE_ID = 13; |
| | | public final static String RESOURCE_NAME = "爱奇艺"; |
| | | |
| | | public final int PLAY_NONE = 0;// 不能播放 |
| | | public final int PLAY_HTML = 1;// 跳转移动端网页播放 |
| | |
| | | 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的视频 |
| | | */ |
| | |
| | | |
| | | } |
| | | |
| | | public static String getAlbumIdFromPlayUrl(String url) { |
| | | try { |
| | | Document doc = Jsoup.connect(url) |
| | | .userAgent( |
| | | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36") |
| | | .timeout(6000).get(); |
| | | |
| | | try { |
| | | Elements els = doc.getElementsByTag("script"); |
| | | String albumId = null; |
| | | for (int i = 0; i < els.size(); i++) { |
| | | System.out.println(els.get(i).toString()); |
| | | if (els.get(i).toString().contains("Q.PageInfo.playPageInfo") |
| | | && els.get(i).toString().contains("albumId")) { |
| | | String content = els.get(i).html(); |
| | | content = content.substring(content.indexOf("albumId"), content.length()); |
| | | albumId = content.split(",")[0].replace("albumId", "").replace("\"", "").replace(":", "") |
| | | .replace(";", "").trim(); |
| | | if (!StringUtil.isNullOrEmpty(albumId) && Long.parseLong(albumId) > 0) |
| | | return albumId; |
| | | } |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(albumId) || Long.parseLong(albumId) <= 0) { |
| | | for (int i = 0; i < els.size(); i++) { |
| | | if (els.get(i).toString().contains("window.QiyiPlayerLoader") |
| | | && els.get(i).toString().contains("param['albumid']")) { |
| | | String content = els.get(i).html(); |
| | | content = content.substring(content.indexOf("param['albumid'] ="), content.length()); |
| | | albumId = content.split(";")[0].replace("param['albumid'] =", "").replace("\"", "").trim(); |
| | | return albumId; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | String json = doc.getElementById("iqiyi-main").getElementsByTag("div").get(0).attr(":page-info"); |
| | | return JSONObject.fromObject(json).optString("albumId"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 添加爱奇艺小视频 |
| | | * |
| | | * @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()) { |
| | |
| | | } else { |
| | | return url; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | 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()) { |