获取火山无水印视频方法

抖音短视频去水印咱们聊过了,今天来看看它兄弟火山短视频怎么去水印,也就是抖音火山版。

👉老规矩先通过分享获取视频分享短链接。

https://share.huoshan.com/hotsoon/s/Q5J3WUgvMk8/

👉然后将链接复制到浏览器打开,啪,出来了,很快哈,而且特别清晰明了,让人很快就能找到自己想要的数据,而且从参数名就可以看出来cover代表的是封面,url代表的是视频链接。
在这里插入图片描述

👉现在我们要做的就是把视频链接复制到浏览器打开看看,如果直接是无水印的就更好,不过我觉得不可能。😜😜
在这里插入图片描述

👉很好,果然是带水印的,现在要做的就是把带水印的链接变成无水印的。

巴啦啦小魔仙变( ̄︶ ̄)↗

👉带水印链接:

https://api.huoshan.com/hotsoon/item/video/_reflow/?video_id=v0d00fg10000c3ptnijc77udb72m3230&line=0&app_id=0&vquality=normal&watermark=2&long_video=0&sf=5&ts=1628838766&item_id=6986180881278962975

👉无水印链接:

https://api.huoshan.com/hotsoon/item/video/_playback/?video_id=v0d00fg10000c3ptnijc77udb72m3230

👉将链接复制到浏览器打开就是没有水印的视频。

在这里插入图片描述

👉神奇吧,神奇就对了。本期只做思路分析和源码分享所以对复杂的技术就不分析了。

👉处理重定向链接代码:

    public static String hSMatchNo(String redirectUrl) {
        List<String> results = new ArrayList<>();
        Pattern p = Pattern.compile("item_id=([\\w/\\.]*)&");
        Matcher m = p.matcher(redirectUrl);
        while (!m.hitEnd() && m.find()) {
            results.add(m.group(1));
        }
        return results.get(0);
    }

👉封装的get请求代码:

    /**
     * 请求并获取返回值
     *
     * @param urlStr
     * @return
     * @throws Exception
     */
    public static String httpGet(String urlStr) throws Exception {
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type", "text/json;charset=utf-8");
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
        StringBuffer buf = new StringBuffer();
        String inputLine = in.readLine();
        while (inputLine != null) {
            buf.append(inputLine).append("\r\n");
            inputLine = in.readLine();
        }
        in.close();
        return buf.toString();
    }

👉全部代码:

package com.smile.utils;


import com.alibaba.fastjson.JSON;
import com.smile.wechat.domain.VideoInfo;
import com.smile.wechat.dto.HSResultDto;
import com.smile.common.exception.CustomException;
import com.smile.common.utils.StringUtils;

/**
 * 火山小视频去水印
 */
public class HuoShan {

    public static VideoInfo getVideo(String url) {
        String redirectUrl = HttpUtils.getLocation(url);
        if (!redirectUrl.contains("http")) {
            throw new CustomException("请复制正确的链接!");
        }
        try {
            if (!StringUtils.isEmpty(redirectUrl)) {
                VideoInfo videoInfo = new VideoInfo();
                /**
                 * 1、拿到itemId
                 */
                String itemId = HttpUtils.hSMatchNo(redirectUrl);

                StringBuilder sb = new StringBuilder();
                sb.append(HttpUtils.HUO_SHAN_BASE_URL).append(itemId);

                /**
                 * 2、itemId 拼接视频详情接口
                 */
                String videoResult = HttpUtils.httpGet(sb.toString());

                HSResultDto hsResult = JSON.parseObject(videoResult, HSResultDto.class);

                videoInfo.setVideoPic(hsResult.getData().getItem_info().getCover());

                /**
                 * 3、替换URL地址
                 */
                String replace = hsResult.getData().getItem_info().getUrl().replace("_reflow", "_playback");

                videoInfo.setVideoUrl(replace.substring(0, replace.indexOf("&")));

                videoInfo.setVideoDescribe("火山小视频");
                videoInfo.setAuthor("火山小视频");
                return videoInfo;
            } else {
                throw new CustomException("解析失败!");
            }
        } catch (Exception e) {
            throw new CustomException("请复制正确的链接!");
        }
    }
}

👉结果展示:
在这里插入图片描述
大家关注下我公众号呗,里面分享这种源码更多,csdn一个劲被举报,简单的没事,只要获取难度大点的就被举报,也不知道为啥。
在这里插入图片描述

👉作者的话:
​ 谢谢能耐心看完的童鞋,如果这篇文章能对你有帮忙更好。代码仅供学习与参考,切勿用于商业用途。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值