| | |
| | | package com.yeshi.buwan.videos.bilibili; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.util.HttpUtil; |
| | | import com.yeshi.buwan.videos.bilibili.entity.BilibiliMediaInfo; |
| | | import com.yeshi.buwan.videos.bilibili.entity.BilibiliVideo; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | |
| | | import javax.script.ScriptEngineManager; |
| | | import javax.script.ScriptException; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class BilibiliApiUtil { |
| | | |
| | |
| | | JSONObject root = JSONObject.fromObject(result); |
| | | BilibiliMediaInfo mediaInfo = parseMedia(root); |
| | | return mediaInfo; |
| | | } |
| | | |
| | | /** |
| | | * @param type |
| | | * @param order 2-追番人数 |
| | | * @param page 0-最近更新 |
| | | * @return |
| | | */ |
| | | public static MediaUrlResult getMediaList(int type, int order, int page) { |
| | | String url = String.format("https://api.bilibili.com/pgc/season/index/result?style_id=-1&producer_id=-1&release_date=-1&season_status=-1&order=%s&st=%s&sort=0&page=%s&season_type=%s&pagesize=20&type=1", order, type, page, type); |
| | | String result = HttpUtil.get(url); |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | | if (resultJSON.optInt("code") == 0) { |
| | | JSONObject data = resultJSON.optJSONObject("data"); |
| | | int total = data.optInt("total"); |
| | | JSONArray list = data.optJSONArray("list"); |
| | | List<String> urlList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | JSONObject item = list.optJSONObject(i); |
| | | urlList.add(item.optString("link")); |
| | | } |
| | | return new MediaUrlResult(total, urlList); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | mediaJson.put("mediaRating", root.optJSONObject("mediaRating")); |
| | | mediaJson.put("newestEp", root.optJSONObject("newestEp")); |
| | | mediaJson.put("epList", root.optJSONArray("epList")); |
| | | mediaJson.put("pubInfo", root.optJSONObject("pubInfo")); |
| | | return new Gson().fromJson(mediaJson.toString(), BilibiliMediaInfo.class); |
| | | } |
| | | return null; |
| | |
| | | |
| | | |
| | | public static void main(String[] args) throws IOException, ScriptException, NoSuchMethodException { |
| | | MediaUrlResult result = getMediaList(BilibiliUtil.TYPE_DIANSHIJU, 2, 1); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | String[] urls = new String[]{ |
| | | "https://www.bilibili.com/bangumi/play/ss38129?theme=movie&from_spmid=666.7", "https://www.bilibili.com/bangumi/play/ss38611?theme=movie&from_spmid=666.7" |
| | | }; |
| | | //3-记录片 5-电视剧 4-国漫 1-番剧 2-电影 |
| | | try { |
| | | for (String url : urls) { |
| | | BilibiliMediaInfo mediaInfo = parseMediaInfo(url); |
| | | System.out.println("type:" + mediaInfo.getType()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | public static class MediaUrlResult { |
| | | private int total; |
| | | private List<String> result; |
| | | |
| | | public MediaUrlResult(int total, List<String> result) { |
| | | this.total = total; |
| | | this.result = result; |
| | | } |
| | | |
| | | public int getTotal() { |
| | | return total; |
| | | } |
| | | |
| | | public void setTotal(int total) { |
| | | this.total = total; |
| | | } |
| | | |
| | | public List<String> getResult() { |
| | | return result; |
| | | } |
| | | |
| | | public void setResult(List<String> result) { |
| | | this.result = result; |
| | | } |
| | | } |
| | | |
| | | } |