uc浏览器解析视频源码,不废话直接源码
文章来源:企鹅号 - 兮兮明月光
package cn.rs.blog.service.jiexi;
import com.jfinal.kit.HttpKit;import org.apache.http.client.CookieStore;import org.apache.http.client.config.CookieSpecs;import org.apache.http.client.config.RequestConfig;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.protocol.HttpClientContext;import org.apache.http.cookie.Cookie;import org.apache.http.impl.client.BasicCookieStore;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.json.JSONObject;
import java.io.IOException;import java.util.HashMap;import java.util.Map;
/** * java微技术 2020/6/10 */public class UcUtil { public String getUcUrl(String s) { // String s = ("https://mparticle.uc.cn/video.html?uc_param_str=frdnsnpfvecpntnwprdssskt&btifl=10016&app=smds-iflow&title_type=1&wm_id=1c4c29e197e54fa6bccf325098bd20bb&wm_cid=305663355587135488&pagetype=share&client=&uc_share_depth=1"); // 全局请求设置 RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); // 创建cookie store的本地实例 CookieStore cookieStore = new BasicCookieStore(); // 创建HttpClient上下文 HttpClientContext context = HttpClientContext.create(); context.setCookieStore(cookieStore);
// 创建一个HttpClient CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig) .setDefaultCookieStore(cookieStore).build();
CloseableHttpResponse res = null;
// 创建本地的HTTP内容 try { try { // 创建一个get请求用来获取必要的Cookie,如_xsrf信息 HttpGet get = new HttpGet(s);
res = httpClient.execute(get, context); // 获取常用Cookie,包括_xsrf信息 System.out.println("访问uc的获取的常规Cookie:==============="); String nametempvpstoken = null; for (Cookie c : cookieStore.getCookies()) { String nametemp = c.getName(); if ("vpstoken".equalsIgnoreCase(nametemp)) { nametempvpstoken = c.getValue(); } System.out.println(c.getName() + ": " + c.getValue()); } res.close(); if(nametempvpstoken ==null){ return null; }
Map mapFromStr = getMapFromStr(s); String wm_id = mapFromStr.get("wm_id"); String wm_cid = mapFromStr.get("wm_cid"); String s1 = HttpKit.get("https://ff.dayu.com/contents/" + wm_cid + "?biz_id=1002"); JSONObject jsonObject = new JSONObject(s1); String ums_id = jsonObject.getJSONObject("data").getJSONObject("body").getJSONArray("videos").getJSONObject(0).getString("ums_id"); String requestUrl = "https://mparticle.uc.cn/api/vps?token=" + nametempvpstoken + "&ums_id=" + ums_id + "&wm_cid=" + wm_cid + "&wm_id=" + wm_id + "&resolution=high"; s1 = HttpKit.get(requestUrl); jsonObject = new JSONObject(s1); s1 = jsonObject.getJSONObject("data").getString("url"); return s1;
} finally { httpClient.close(); } } catch (IOException e) {
} return null; }
public Map getMapFromStr(String str) { if (str == null || "".equalsIgnoreCase(str)) { return null; } String[] arr = str.split("\\&"); Map map = new HashMap(); for (String item : arr) { String[] itemArr = item.split("=", 2); map.put(itemArr[0], itemArr[1]); } return map; }}
发表于: 2020-06-11
原文链接:https://kuaibao.qq.com/s/20200611A06D1C00?refer=cp_1026
腾讯「云+社区」是腾讯内容开放平台账号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
如有侵权,请联系 yunjia_community@tencent.com 删除。