Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Last active January 19, 2025 13:41
Show Gist options
  • Select an option

  • Save fhefh2015/5ebb3dcf7bb275e65b4a000b57ecc63c to your computer and use it in GitHub Desktop.

Select an option

Save fhefh2015/5ebb3dcf7bb275e65b4a000b57ecc63c to your computer and use it in GitHub Desktop.

Revisions

  1. fhefh2015 revised this gist Jul 10, 2018. 1 changed file with 17 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions v.php
    Original file line number Diff line number Diff line change
    @@ -47,8 +47,7 @@ function getContent($url)
    $result = curl_exec($ch);

    if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
    return;
    return false;
    }

    curl_close($ch);
    @@ -63,6 +62,11 @@ function getVID($data)
    $re = '/https:\/\/aweme\.snssdk\.com\/aweme\/v1\/playwm\/\?video_id=(.*)&line=0/m';
    $match = [];
    preg_match($re, $data, $match);

    if(empty($match)) {
    return false;
    }

    $vid = $match[1];

    return $vid;
    @@ -73,8 +77,19 @@ function getDOUYIN($url)
    {

    $data = getContent($url);

    if(!$data) {
    echo "获取不到页面内容额";
    return false;
    }

    $vid = getVID($data);

    if(!$vid) {
    echo "无法获取VID";
    return false;
    }

    $v_url = "https://api.amemv.com/aweme/v1/play/?video_id=" . $vid . "&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0";

    return get_redirect_final_target($v_url);
  2. fhefh2015 created this gist Jul 10, 2018.
    87 changes: 87 additions & 0 deletions v.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,87 @@
    <?php
    /**
    * Created by PhpStorm.
    * User: aric
    * Date: 18/7/10 上午9:34
    */

    //获取重定向最终网址
    function get_redirect_final_target($url)
    {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect
    curl_exec($ch);
    $target = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    if ($target)
    return $target;
    return false;
    }

    //获取网址内容
    function getContent($url)
    {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

    $headers = array();
    $headers[] = "Dnt: 1";
    $headers[] = "Accept-Encoding: gzip, deflate, br";
    $headers[] = "Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7";
    $headers[] = "Upgrade-Insecure-Requests: 1";
    $headers[] = "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1";
    $headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
    $headers[] = "Cache-Control: max-age=0";
    $headers[] = "Authority: www.douyin.com";
    $headers[] = "Cookie: _ba=BA0.2-20180329-5199e-75UkuMgxUNaTYzfSeMOP; tt_webid=6547574875133314573";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);

    if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
    return;
    }

    curl_close($ch);

    return $result;

    }

    //获取视频ID
    function getVID($data)
    {
    $re = '/https:\/\/aweme\.snssdk\.com\/aweme\/v1\/playwm\/\?video_id=(.*)&amp;line=0/m';
    $match = [];
    preg_match($re, $data, $match);
    $vid = $match[1];

    return $vid;
    }

    //获取无水印下载地址 url为抖音分享的网址
    function getDOUYIN($url)
    {

    $data = getContent($url);
    $vid = getVID($data);

    $v_url = "https://api.amemv.com/aweme/v1/play/?video_id=" . $vid . "&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0";

    return get_redirect_final_target($v_url);

    }

    echo getDOUYIN("https://www.iesdouyin.com/share/video/6574757891381660936/?region=CN&mid=6563901515533290244&titleType=title&timestamp=1531186272&utm_campaign=client_share&app=aweme&utm_medium=ios&tt_from=copy&iid=32073908798&utm_source=copy");