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<String, String> 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<String, String> getMapFromStr(String str) {
        if (str == null || "".equalsIgnoreCase(str)) {
            return null;
        }
        String[] arr = str.split("\\&");
        Map<String, String> map = new HashMap<>();
        for (String item : arr) {
            String[] itemArr = item.split("=", 2);
            map.put(itemArr[0], itemArr[1]);
        }
        return map;
    }
}

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值