<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Steve Martin</title>
    <description>The latest articles on DEV Community by Steve Martin (@martin_88d911ba8).</description>
    <link>https://dev.to/martin_88d911ba8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3378333%2Fd9042212-56d1-4f74-b31f-d469baa100ae.png</url>
      <title>DEV Community: Steve Martin</title>
      <link>https://dev.to/martin_88d911ba8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/martin_88d911ba8"/>
    <language>en</language>
    <item>
      <title>PHP code for downloading douyin/tiktok videos without watermark</title>
      <dc:creator>Steve Martin</dc:creator>
      <pubDate>Thu, 31 Jul 2025 09:04:24 +0000</pubDate>
      <link>https://dev.to/martin_88d911ba8/php-code-for-downloading-douyintiktok-videos-without-watermark-23ba</link>
      <guid>https://dev.to/martin_88d911ba8/php-code-for-downloading-douyintiktok-videos-without-watermark-23ba</guid>
      <description>&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: For personal learning and research purposes only. Strictly prohibited for other uses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
//Example：http://xxx.com/douyin/?msg=https://v.douyin.com/iyEQf36P/
$msg = urldecode($_REQUEST['msg']); 

if (is_numeric($msg)) {
    $video_id = $msg;
} else {
    preg_match('/https?:\/\/[^\s]+/', $msg, $video_url);
    $video_url = $video_url[0];

    $redirected_url = get_redirected_url($video_url);
    preg_match('/(\d+)/', $redirected_url, $matches);
    $video_id = $matches[1];
    // echo $video_id;
}

function get_redirected_url($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    $redirected_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    return $redirected_url;
}

$headers = [
    'User-Agent: Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36',
    'Referer: https://www.douyin.com/?is_from_mobile_home=1&amp;amp;recommend=1'
];

$url = "https://www.iesdouyin.com/share/video/$video_id/";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
curl_close($ch);


preg_match('/_ROUTER_DATA\s*=\s*(\{.*?\});/', $response, $matches);
$data = $matches[1];

$jsonData = json_decode($data, true);

$itemList = $jsonData['loaderData']['video_(id)/page']['videoInfoRes']['item_list'][0];
$nickname = $itemList['author']['nickname'];
$title = $itemList['desc'];
$awemeId = $itemList['aweme_id'];
$video = $itemList['video']['play_addr']['uri'];
$videoUrl = $video !== null ? (strpos($video, 'mp3') === false ? 'https://www.douyin.com/aweme/v1/play/?video_id=' . $video : $video) : null;
$cover = $itemList['video']['cover']['url_list'][0];
$images = $itemList['images'] ?? null;

$output = [
    'msg' =&amp;gt;empty($nickname)?'Parsing failed!':'Parsing successful!',
    'name' =&amp;gt; $nickname,
    'title' =&amp;gt; $title,
    // 'aweme_id' =&amp;gt; $awemeId,
    'video' =&amp;gt; $videoUrl,
    'cover' =&amp;gt; $cover,
    'images' =&amp;gt; array_map(function($image) {
        return $image['url_list'][0];
    }, is_array($images) ? $images : []),
    'type' =&amp;gt;empty($images)?'video':'picture',
    'tips' =&amp;gt; 'api'  
];

header('Content-Type: application/json');
echo json_encode($output,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
