Depth resolution write short video from scratch to watermark interface

Preface description

I've been traveling abroad recently, so the update has been stagnant for a long time. I'll take the time to update you today. I have been studying the short video de watermarking interface some time ago, and it has also been updated Short video de watermarking applet v1 Version 1.1 And Short video de watermarking interface vending machine , these two sets of source codes need an interface. In view of this, I began to study the watermark interface myself.

Required tools

Here I take Kwai as an example.

1, Kwai APP

2. Computer

3. Browser

Tutorial start

1, get links, Kwai to get the video sharing links, I believe you will.

2. Use the Edge browser to open the video link we got:

(of course, you can also choose other browsers. I am used to using Edge because its developer tool is Chinese, which is friendly and convenient for Xiaobai to demonstrate)
We see that the address bar has changed, indicating that the link has made a jump. At this time, the link becomes

3. To start capturing packets, we press F12 on the keyboard to display the developer tools network, select preserve log, and then press F5 to refresh the page. We will catch all the requests sent by the web page.

4. Press ctrl+F on the keyboard to search for the title, and we will see a large section of garbled code in the response.

5. Click the random code ctrl+a to select all and copy the random code. You will find a pile of JSON (generally, the official interface mostly returns JSON format). You can go Format it for easy viewing.

6. After formatting, we can press the keyboard ctrl+F to search mp4# so that we can get a video link without watermark.

The de watermark link is as follows:

Write interface

1. Create a new "index.php" file and copy the following request code

require 'qsy.php';
echo getUrl();
    function getUrl()
        $data = \Ludeqi::qsy($_GET['url']);
    return  $data;

2. Create a new "qsy.php" file in the same directory and copy the watermark algorithm code

class Ludeqi {
    static public function qsy($url) {
        preg_match('/([\w-]+\.)+\w+(\:\d{2,6})?/', $url, $domain);
        switch ($domain[0]) {
            case '':
                return self::result(500, 'Please pass in the resolution url Parameters, for example:');
            case '':
                return self::kuaishou($url);
                return self::result(500, 'Sorry, this url Not supported at the moment!');
    static public function kuaishou($url) {
        $vurl = self::httpRequest($url, 'GET');
        preg_match('/(?<=video\/)\w*(?=\?fid)/', $vurl['location'], $matches);
        $str_qury1 = 'query visionVideoDetail($photoId: String, $type: String, $page: String, $webPageArea: String)';
        $str_qury2 = '(photoId: $photoId, type: $type, page: $page, webPageArea: $webPageArea)';
        $query = array("operationName" => "visionVideoDetail", "variables" => array('photoId' => $matches[0], "page" => "detail"), "query" => $str_qury1 . "{\n visionVideoDetail" . $str_qury2 . "{\n photo {\n id\n duration\n caption\n likeCount\n realLikeCount\n coverUrl\n photoUrl\n }\n}\n}\n",);
        $query = json_encode($query, 320);
        $headers = array('content-type: application/json', 'Referer:' . $vurl['location']);
        $result = self::httpRequest('', 'POST', $query, $headers);
        if (isset($result['response']['data']['visionVideoDetail']['photo']['photoUrl'])) {
            return self::result(200, $result['response']['data']['visionVideoDetail']['photo']);
        } else {
            return self::result(500, 'Error parsing!');
    static public function httpRequest($url, $method = 'POST', $postfields = null, $headers = array()) {
        $method = strtoupper($method);
        $ci = curl_init();
        curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ci, CURLOPT_TIMEOUT, 30);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
        switch ($method) {
            case "POST":
                curl_setopt($ci, CURLOPT_POST, true);
                if (!empty($postfields)) {
                    $tmpdatastr = is_array($postfields) ? http_build_query($postfields) : $postfields;
                    curl_setopt($ci, CURLOPT_POSTFIELDS, $tmpdatastr);
                curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method);
        $ssl = preg_match('/^https:\/\//i', $url) ? TRUE : FALSE;
        curl_setopt($ci, CURLOPT_URL, $url);
        if ($ssl) {
            curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ci, CURLOPT_MAXREDIRS, 2);
        curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ci, CURLINFO_HEADER_OUT, true);
        $response = json_decode(curl_exec($ci), true);
        $requestinfo = curl_getinfo($ci);
        $http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
        $location = curl_getinfo($ci, CURLINFO_EFFECTIVE_URL);
        return array('location' => $location, 'response' => $response, 'requestinfo' => $requestinfo);
    static public function result($errno = 0, $data = '') {
        header("Content-type: application/json;charset=utf-8");
        $errno = intval($errno);
        $result = array('code' => $errno, 'message' => $data);
        return json_encode($result, 320);

3. Upload the two newly created files: "index.php" and "qsy.php" to the server.

Test method

Directly access the instance to resolve the video link without watermark

For example: (http: / / your web address /? URL)= )

This parsing algorithm belongs to json parsing mode The formatted link is consistent with the original manual packet capture.

Conclusion: other short videos are basically similar. To write the watermark interface, you need to master php regular matching rules, so you can be handy

This article comes from: Lu Da Shi source code network

The published articles and attachments are only for learning and research purposes; It shall not be used for commercial or illegal purposes; Otherwise, I will not be responsible for the legal consequences.

This article is from WeChat official account: Lu Da wet.

Keywords: PHP

Added by Gamerz on Sat, 18 Dec 2021 23:35:47 +0200