| | |
| | | package com.yeshi.buwan.util.video.shortvideo; |
| | | |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | |
| | | import org.yeshi.utils.HttpUtil; |
| | | |
| | | import java.net.URLDecoder; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class TencentWebUtil { |
| | | |
| | | public static class TencentWebVideoInfo { |
| | | private String playUrl; |
| | | private String id; |
| | | private String title; |
| | | private String picture; |
| | | private String duration; |
| | | |
| | | public String getPlayUrl() { |
| | | return playUrl; |
| | | } |
| | | |
| | | public void setPlayUrl(String playUrl) { |
| | | this.playUrl = playUrl; |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public String getPicture() { |
| | | return picture; |
| | | } |
| | | |
| | | public void setPicture(String picture) { |
| | | this.picture = picture; |
| | | } |
| | | |
| | | public String getDuration() { |
| | | return duration; |
| | | } |
| | | |
| | | public void setDuration(String duration) { |
| | | this.duration = duration; |
| | | } |
| | | } |
| | | |
| | | |
| | | public static Map<String, String> parseParams(String url) { |
| | |
| | | } |
| | | |
| | | |
| | | public static void getVideoList(Map<String, String> params, int page) throws Exception { |
| | | /** |
| | | * 获取短视频列表 |
| | | * |
| | | * @param params |
| | | * @param page |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static List<TencentWebVideoInfo> getVideoList(Map<String, String> params, int page) throws Exception { |
| | | if (params == null) |
| | | throw new Exception("参数为空"); |
| | | int pageSize = 30; |
| | |
| | | String result = HttpUtil.get(url, params, headers); |
| | | Document document = Jsoup.parse(result); |
| | | Elements els = document.getElementsByClass("list_item"); |
| | | |
| | | List<TencentWebVideoInfo> list = new ArrayList<>(); |
| | | for (int i = 0; i < els.size(); i++) { |
| | | Element ele = els.get(i); |
| | | String href = ele.getElementsByTag("a").get(0).attr("href"); |
| | |
| | | picture = picture.startsWith("http") ? picture : "https:" + picture; |
| | | String duration = ele.getElementsByClass("figure_caption").get(0).ownText(); |
| | | System.out.println(duration); |
| | | } |
| | | |
| | | TencentWebVideoInfo videoInfo = new TencentWebVideoInfo(); |
| | | videoInfo.setDuration(duration); |
| | | videoInfo.setId(id); |
| | | videoInfo.setPicture(picture); |
| | | videoInfo.setPlayUrl(href); |
| | | videoInfo.setTitle(title); |
| | | list.add(videoInfo); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | getVideoList(parseParams("https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&itype=-1&listpage=1&sort=40"), 1); |
| | | List<TencentWebVideoInfo> videoInfos = getVideoList(parseParams("https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&itype=-1&listpage=1&sort=40"), 1); |
| | | System.out.println(videoInfos); |
| | | } |
| | | } |