抖音獲取無(wú)水印視頻及圖片集

如題,具體分析如何通過(guò)視頻分享的短鏈接獲取無(wú)水印視頻鏈接網(wǎng)上有太多的方法了,本文就不過(guò)多的敘述【可私聊交流】,直接上干貨。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class douyinUtils {
    public static String DOU_YIN_BASE_URL = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=";

    public static String getLocation(String url) {
        try {
            URL serverUrl = new URL(url);
            HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();
            conn.setRequestMethod("GET");
            conn.setInstanceFollowRedirects(false);
            conn.setRequestProperty("User-agent", "ua");//模擬手機(jī)連接
            conn.connect();
            conn.setConnectTimeout(60000);
            String location = conn.getHeaderField("Location");
            return location;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

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

    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);
    }

    public static String httpGet2(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();
    }

    /**
     * 使用Get方式獲取數(shù)據(jù)
     *
     * @param url URL包括參數(shù),http://HOST/XX?XX=XX&XXX=XXX
     * @return
     */
    public static String httpGet(String url) {
        String result = "";
        BufferedReader in = null;
        try {
            URL realUrl = new URL(url);
            // 打開(kāi)和URL之間的連接
            URLConnection connection = realUrl.openConnection();
            // 設(shè)置通用的請(qǐng)求屬性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立實(shí)際的連接
            connection.connect();
            // 定義 BufferedReader輸入流來(lái)讀取URL的響應(yīng)
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream(), "UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("發(fā)送GET請(qǐng)求出現(xiàn)異常!" + e);
            e.printStackTrace();
        }
        // 使用finally塊來(lái)關(guān)閉輸入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }

    public static String parseUrl(String url) {

        String host = "";
        Pattern p = Pattern.compile("http[:|/|\\w|\\.]+");
        Matcher matcher = p.matcher(url);
        if (matcher.find()) {
            host = matcher.group();
        }

        return host.trim();
    }

    /**
     * 查找域名(以 https開(kāi)頭 com結(jié)尾)
     *
     * @param url
     * @return
     */
    public static String getDomainName(String url) {

        String host = "";
        Pattern p = Pattern.compile("https://.*\\.com");
        Matcher matcher = p.matcher(url);
        if (matcher.find()) {
            host = matcher.group();
        }

        return host.trim();
    }

    public static void main(String[] args) {
        String redirectUrl = getLocation("https://v.douyin.com/2Yq8gaL/");

        System.out.println(redirectUrl);

        String itemId = matchNo(redirectUrl);
        System.out.println(itemId);

        StringBuilder sb = new StringBuilder();
        sb.append(DOU_YIN_BASE_URL).append(itemId);

        String videoResult = httpGet(sb.toString());

        System.out.println(videoResult);

        //無(wú)水印視頻 url
        String videoUrl = dyResult.getItem_list().get(0)
                .getVideo().getPlay_addr().getUrl_list().get(0)
                .replace("playwm", "play");
        String videoRedirectUrl = getLocation(videoUrl);

        // 循環(huán)加入無(wú)水印圖片
        if (dyResult.getItem_list().get(0).getImages() != null) {
            List<String> imgList = new ArrayList<>();
            for (com.media.domain.dyResult.Images img : dyResult.getItem_list().get(0).getImages()) {
                imgList.add(img.getUrl_list().get(0));
            }
            resData.setImgList(imgList);
        }
    }
}

此外,還找到一款去免費(fèi)水印小程序【光頭去水印工具】,無(wú)需積分、注冊(cè)、費(fèi)用、無(wú)廣告,完全免費(fèi),需要白嫖的老鐵趕快白嫖,全面支持絕大多數(shù)視頻app平臺(tái),如斗音、西關(guān)、霍山、筷手、皮皮瞎等

筷手.png
斗音.png

本文只作為學(xué)習(xí)使用。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容