PHP quickly realizes parsing of URL without watermark playback address-fast hand

PHP quickly realizes parsing of URL without watermark playback address-fast hand

Principle analysis

Get the video sharing link from Kuaishou App and visit it in the browser, such as the address f.kuaishou.com/1mqmxe and then redirect, open the browser console and click on the phone picture in the upper left corner to refresh the simulated phone request. Observe the console source code. See the following piece of code that contains an MP4 video address with the srcNoWark field, extract it and visit it in the browser to see that the video is dirty.

Complete code

Download the Guzzle library and import it

composer require guzzlehttp/guzzle

require __DIR__.'/vendor/autoload.php';
$url = $_GET['url'] ?? '';
$headers = [  
    'Connection' => 'keep-alive',  
    'User-Agent'=>'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1'
];
$client = new/GuzzleHttp\Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false,]);
$data['headers'] = $headers;
$jar = new/GuzzleHttp\Cookie\CookieJar;
$data['cookies'] = $jar;
$response = $client->request('GET', $url, $data);
$body = $response->getBody();
if ($body instanceof/GuzzleHttp\Psr7\Stream) {  
    $body = $body->getContents();
}
$result = htmlspecialchars_decode($body);
$pattern = '#"srcNoMark":"(.*?)"#';
preg_match($pattern, $result, $match);
$data['video_src'] = $match[1];
$pattern = '#"poster":"(.*?)"#';
preg_match($pattern, $result, $match);
if (!empty($match[1])) {  
    $data['cover_image'] = $match[1];
    echo json_encode($data);die();
}
 

Download and install and import the guzzle request PHP package, and initialize the request header and cookie that are passed in to the simulated mobile browser. Regularly match the html page returned by the request to get a non-watermark playback URL

Series of articles

  • Dewatering tutorial series, including Douyin, Weishi, Watermelon, YouTube, etc.

Follow the "Yiyi Code" official account to send Douyin to get the complete source code