You can finish this article in about 3 minutes at 🕰️

👯 preface

Ready, fire, aim… — Anonymous

The goal of this article is to provide ideas that, from a practical point of view, will provide a relatively low-cost solution. I also provide open source code for running watermarked video download for a long time.

🔭 expected

💻 body

  • Method 1: Use a watermarking platform

    • ssstik.io
    • douyin.iiilab.com/

    These sites are for short video platforms, but pay for parsing. Consider using Splinter. Set the browser as headless browser, direct simulation request parsing, can be white piao.

  • Method 2: Modify the download link directly

  public function main() {
      // The video playing address can be obtained from the Tiktok sharing link
      $url = 'https://v.douyin.com/JKgS4Vp/'
      $url = $this->getCurl($url);

      preg_match('/video\/([0-9]+)\//i'.$url.$matches);

      $result = $this->video_url($matches[1]);
      return $result;
  }
  
    /** * Get tiktok interface video information */
    private function video_url($dyid)
    {
        $getApi = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $dyid;
        $data = $this->getCurl($getApi);
        $json = json_decode($data.true);
        // Video description
        $playUrl = null;
        foreach ($json['item_list'] as $k= >$v) {
            // No watermarked URL
            $playUrl = $list['play_url'] = $this->Url($v['video'] ['play_addr'] ['url_list']);
        }
        return [
           'play_url' => urldecode($playUrl)]; }/** * modify the download link */
  public function Url($list) {
    return $list[0].replace('playwm'.'play')}/** * initiate a request */
  public function getCurl($url.$options= [].$foll = 0)
  {
      / / initialization
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url); // The url to access
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Complete silence
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); / / ignore HTTPS
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); / / ignore HTTPS
      curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([self::getRandomUserAgent()], $options)); //UA
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $foll); // $foll=0 by default.
      $output = curl_exec($ch); // Get the content
      curl_close($ch); / / close
      return $output; / / return
  }
Copy the code
  • Method 3: Set the Referer and Host of the video playing address
    public function main() {
        // The video playing address can be obtained from the Tiktok sharing link
        $url = 'https://v.douyin.com/JKgS4Vp/'
        $url = $this->getCurl($url);

        preg_match('/video\/([0-9]+)\//i'.$url.$matches);
        
        $result = $this->videoUrl($matches[1]);
        return $result;
    }
    
    /** * Get tiktok interface video information */
    private function videoUrl($dyid)
    {
        $getApi = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $dyid;
        $data = $this->getCurl($getApi);
        $json = json_decode($data.true);
        // Video description
        $playUrl = null;
        foreach ($json['item_list'] as $k= >$v) {
            // No watermarked URL
            $playUrl = $list['play_url'] = $this->Url($v['video'] ['play_addr'] ['uri']);
        }
        return [
           'play_url' => urldecode($playUrl)]; }/** * get the redirected video address */
    public function Url($videoId)
    {
        $str = $this->getCurl("https://aweme.snssdk.com/aweme/v1/play/?video_id=" . $videoId . "&line=0"['Referer'= >"https://www.iesdouyin.com".'Host'= >"www.iesdouyin.com",].0);
        preg_match('# # '.$str.$data);
        $download_url = explode("/ /".$data[1]);
        return isset($download_url[1])?'https://' . $download_url[1] : 'Parsing failed';
    }
    
    /** * initiate a request */
    public function getCurl($url.$options= [].$foll = 0)
    {
        / / initialization
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url); // The url to access
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Complete silence
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); / / ignore HTTPS
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); / / ignore HTTPS
        curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([self::getRandomUserAgent()], $options)); //UA
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $foll); // $foll=0 by default.
        $output = curl_exec($ch); // Get the content
        curl_close($ch); / / close
        return $output; / / return
    }   
Copy the code

🎉 summary

To obtain douyin’s watermarked video, you can open the packet capture tool to find the pattern, but this method is usually left to the end. At present, the most commonly used method for me is to search keywords on Github first and learn the ideas of peers. Github generally summarizes two or three solutions, and then selects the most appropriate solution based on your own context.

My technical ability is limited, if there is a wrong place to write, please leave a message as if correct, very thank 🙇

If your problem is not solved, first of all, I am very sorry for your time. You can leave a message in the comments section below, and I will reply to 🙍♂️ as soon as I see it