PHP skills * curl crawl vibrato-free video watermark

 

Demo Address: http://dy.kder.top/

 

First, the principle

2020.03.24 valid, vibrato when the video is downloaded before adding watermark, no watermark when playing, so the principle is to use PHP or other languages to grab the video address for playback with no watermark (probably gone 3 redirects), with particular reference to: the latest vibrato resolved without watermark principle ..

Two, PHP achieve the following

<?php
// 测试地址
$url = "https://v.douyin.com/7J48Rf/";

// 模拟手机端浏览器
function http_get($url)
{
    $ch = curl_init();
    $opt = [];
    $opt[CURLOPT_URL] = $url;
    $opt[CURLOPT_RETURNTRANSFER] = true;
    $opt[CURLOPT_FOLLOWLOCATION] = true;
    $user_agent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Mobile Safari/537.36";
    $opt[CURLOPT_USERAGENT] = $user_agent;
    curl_setopt_array($ch, $opt);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

// 1.请求获取itemId、dytk
$dy_html = http_get($url);
preg_match('/itemId:\s\"([\s\S]*?)\"/i',$dy_html,$itemids_rs);
preg_match('/dytk:\s\"([\s\S]*?)\"/i',$dy_html,$dytk_rs);
$item_ids = $itemids_rs[1] ?? "获取item_ids失败";
$dytk = $dytk_rs[1] ?? "获取item_ids失败";

// 2.请求视频信息(这里所得视频地址还会被重定向到视频资源)
$url2 = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?" . http_build_query(compact('item_ids', 'dytk'));
$arr_data  = json_decode(http_get($url2), 1);
$play_url  = $arr_data["item_list"][0]["video"]["play_addr"]["url_list"][0] ?? "";

// 3.请求获取视频资源
$vedio_resources = http_get($play_url);
file_put_contents("./test.mp4", $vedio_resources);

echo "无水印视频地址:" . __DIR__ . "/test.mp4";

other

Apart made a free Demo: http://dy.kder.top/ , welcome to test (front-end code is to engage others, please contact the infringement modification)

Published 50 original articles · won praise 43 · views 50000 +

Guess you like

Origin blog.csdn.net/Phplayers/article/details/105057777