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:

 https://v.kuaishou.com/aU7PCz

(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

https://www.kuaishou.com/short-video/3xte53diytuu28g?fid=433527594&cc=share_copylink&followRefer=151&shareMethod=TOKEN&docId=10&kpn=KUAISHOU&subBiz=BROWSE_SLIDE_PHOTO&photoId=3xte53diytuu28g&shareId=16414084109664&shareToken=X1KCROiOhf2y1NY&shareResourceType=PHOTO_SELF&userId=3xe6mvxkxk8hrvc&shareType=2&et=1_a%2F2003086636508528529_p0&shareMode=APP&originShareId=16414084109664&appType=21&shareObjectId=5191243054590022521&shareUrlOpened=0&timestamp=1630310980813&utm_source=app_share&utm_medium=app_share&utm_campaign=app_share&location=app_share

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 https://www.bejson.com/jsonviewernew 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:

https://v1.kwaicdn.com/upic/2021/08/30/15/BMjAyMTA4MzAxNTI0NTRfNDMzNTI3NTk0XzU2Mjc4MzczOTkyXzJfMw==_b_Bb399be45c609cbee38697a810b87aba5.mp4?pkey=AAUTdcbRxTfi7NdDHC3B_Iti4GkunwxeU-jvuee4Ud-9XysaH7mY53hGPZEj27LBoxC1PCO6uU7zObemeGu69xqlnw7Ii56y1hdCqQ90Nha8yqKJKlZfCjXAbfeqC8-kXSc&tag=1-1630311176-xpcwebdetail-0-qdg9js2xoq-b4ee34ca5bf0fa38&clientCacheKey=3xte53diytuu28g_b.mp4&tt=b&di=JA4DeUTZpQAN0A3KUfOZPg==&bp=10004

Write interface

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

<?php
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

<?php
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: https://qsy.ludeqi.com/?url= https://v.kuaishou.com/aU7PCz/');
            break;
            case 'v.kuaishou.com':
                return self::kuaishou($url);
            break;
            default:
                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('https://video.kuaishou.com/graphql', '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);
                }
            break;
            default:
                curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method);
            break;
        }
        $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);
        curl_close($ci);
        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)= https://v.kuaishou.com/aU7PCz/ )

This parsing algorithm belongs to json parsing mode https://www.bejson.com/jsonviewernew 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