抖音解析PHP源代码

  • 内容
  • 相关

代码:

<?php 
header("Content-type: text/html; charset=utf-8"); 
$url_g=@$_GET['url'];//抖音视频地址
$api="https://api-hl.amemv.com/aweme/v1/aweme/detail/?retry_type=no_retry&iid=43619087057&device_id=57318346369&ac=wifi&channel=update&aid=1128&app_name=aweme&version_code=251&version_name=2.5.1&device_platform=android&ssmix=a&device_type=MI+8&device_brand=xiaomi&language=zh&os_api=22&os_version=5.1.1&uuid=865166029463703&openudid=ec6d541a2f7350cd&manifest_version_code=251&resolution=1080*1920&dpi=480&update_version_code=2512&_rticket=1559206461097&ts=1559206460&as=a115996edcf39c7adf4355&cp=9038c058c7f6e4ace1IcQg&mas=01af833c02eb8913ecc7909389749e6d89acaccc2c662686ecc69c&aweme_id=";//6691388713936653576
$cookie="odin_tt=9a16fa42e650a96379a5901a3d146c7c244dc0c35971927f6e13c208fc4bcf9cc952542516f78dc9098ac4d179f3b127cddfdff2942d259dda9ca33de8ae7677; install_id=43619087057; ttreq=1$4c4b4cc4b31e6f2f4203b62a1df12b43e224434c; qh[360]=1";
$user_agent="Mozilla/5.0 (Linux; Android 8.0.0; MI 6 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36";
function getLinkFromDouyinShareText($shareOrUrl){
    $url="http".explode("http",$shareOrUrl)[1];
    $url=explode("复制此链接,",$url)[0];
    return $url;
}
function getAwemeId($link,$UA){
    $context=stream_context_create(array('http'=>array('header'=>'User-Agent:'.$UA)));
    $html_text= file_get_contents($link,0,$context);
    $str=explode("itemId: \"",$html_text)[1];
    $str=explode("\",",$str)[0];
    return $str;
}
function doCurlGetRequest($url,$headers,$timeout = 5){
    if($url == '' || $timeout <=0){
        return false;
    }
    $con = curl_init((string)$url);
    curl_setopt($con, CURLOPT_HEADER, false);
    curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($con,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($con, CURLOPT_TIMEOUT,(int)$timeout);
    return curl_exec($con);
}
function getVideoData($api,$cookie,$awemeId){
    $header=array("Accept-Encoding: utf-8",
                "Cookie: ".$cookie,
                "Host: api-hl.amemv.com",
                "Connection: Keep-Alive",
                "User-Agent: okhttp/3.10.0.1");
    $data=json_decode(doCurlGetRequest($api.$awemeId,$header),true);
    $info=$data['aweme_detail']['share_info'];//视频描述
    $user_name=$data['aweme_detail']['author']['nickname'];//作者昵称
    $user_headImg=$data['aweme_detail']['author']['avatar_medium']['url_list'][0];//作者头像
    $image=$data['aweme_detail']['video']['origin_cover']['url_list'][0];//封面图片
    $urls=$data['aweme_detail']['video']['play_addr']['url_list'];//无水印地址
    $music_urls=$data['aweme_detail']['music']['play_url']['url_list'];//音乐地址
    $douyin=[
        'status'=>true,
        'nickname'=>$user_name,
        'awemeId'=>$awemeId,
        'headImage'=>$user_headImg,
        'image'=>$image,
        'videoUrl'=>$urls,
        'music_urls'=>$music_urls,
        'info'=>$info,
        'time'=>time()
    ];
    return json_encode($douyin);
}
if(strstr($url_g,'http://v.douyin.com/')) {
    $url_g = getLinkFromDouyinShareText($url_g);
    $awemeId=getAwemeId($url_g,$user_agent);
    echo getVideoData($api,$cookie,$awemeId);
}else{
    echo json_encode(["status"=>false,"message"=>"地址无效"]);
}

接口:https://api.moonwl.cn/api/dou/dou.php?url=

实例:https://api.moonwl.cn/api/dou/dou.php?url=http://v.douyin.com/rJjgX8/

返回:

{"status":true,"nickname":"\u51af\u5bfc\u73a9\u6e38\u620f","awemeId":"6697499584689655052","headImage":"https:\/\/p3-dy.byteimg.com\/aweme\/720x720\/1ca510002f106219c6a25.jpeg","image":"http:\/\/p1-dy.byteimg.com\/large\/26b610000ebd09462826a.jpeg","videoUrl":["http:\/\/v6-dy.ixigua.com\/f8d56a5f0c2e6125c37c4cae6e6520a4\/5cf3860a\/video\/m\/2209c36709d08f346d6b848f341ef203da2116255dc100004e550a0e9e7d\/?rc=amhpZWprZGZsbTMzPGkzM0ApQHRAb0k4NTk0ODszNDs5ODU5PDNAKXUpQGczdSlAZjN2KUBmaHV5cTFmc2hoZGY7NEBqb25xXi40a21fLS0uLS9zcy1vI28jQDYvMjQtLy0tMi4uLS0uL2k6Yi5wIzphLXEjOmAtbyNwYmZyaF4ranQ6Iy8uXg%3D%3D","http:\/\/v9-dy.ixigua.com\/e8315b25e1ab839440724d890cd30276\/5cf3860a\/video\/m\/2209c36709d08f346d6b848f341ef203da2116255dc100004e550a0e9e7d\/","https:\/\/aweme-hl.snssdk.com\/aweme\/v1\/play\/?video_id=v0200f190000bjpinc7a1hagtbqfremg&line=0&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0","https:\/\/api-hl.amemv.com\/aweme\/v1\/play\/?video_id=v0200f190000bjpinc7a1hagtbqfremg&line=1&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0"],"music_urls":["http:\/\/p3-dy.byteimg.com\/obj\/ies-music\/1635154703940663.mp3"],"info":{"bool_persist":0,"share_title_other":"","share_signature_desc":"TikTok: Make Every Second Count","share_quote":"","share_weibo_desc":"#\u5728\u6296\u97f3\uff0c\u8bb0\u5f55\u7f8e\u597d\u751f\u6d3b#\u9732\u897f\u9ad8\u5c14\u592b\u821e#\u8f7b\u6f2b\u8ba1\u5212 @\u6296\u97f3\u52a8\u6f2b","share_desc":"\u5728\u6296\u97f3\uff0c\u8bb0\u5f55\u7f8e\u597d\u751f\u6d3b","share_title":"\u9732\u897f\u9ad8\u5c14\u592b\u821e#\u8f7b\u6f2b\u8ba1\u5212 @\u6296\u97f3\u52a8\u6f2b","share_title_myself":"","share_link_desc":"#\u5728\u6296\u97f3\uff0c\u8bb0\u5f55\u7f8e\u597d\u751f\u6d3b#\u9732\u897f\u9ad8\u5c14\u592b\u821e#\u8f7b\u6f2b\u8ba1\u5212 @\u6296\u97f3\u52a8\u6f2b %s \u590d\u5236\u6b64\u94fe\u63a5\uff0c\u6253\u5f00\u3010\u6296\u97f3\u77ed\u89c6\u9891\u3011\uff0c\u76f4\u63a5\u89c2\u770b\u89c6\u9891\uff01","share_signature_url":"https:\/\/tiktokv.com\/","share_url":"https:\/\/www.iesdouyin.com\/share\/video\/6697499584689655052\/?region=CN&mid=6697578960856845063&u_code=gj49fkd1&titleType=title"},"time":1559459768}

解码:

{
    "status": true, 
    "nickname": "冯导玩游戏", 
    "awemeId": "6697499584689655052", 
    "headImage": "https://p3-dy.byteimg.com/aweme/720x720/1ca510002f106219c6a25.jpeg", 
    "image": "http://p1-dy.byteimg.com/large/26b610000ebd09462826a.jpeg", 
    "videoUrl": [
        "http://v6-dy.ixigua.com/f8d56a5f0c2e6125c37c4cae6e6520a4/5cf3860a/video/m/2209c36709d08f346d6b848f341ef203da2116255dc100004e550a0e9e7d/?rc=amhpZWprZGZsbTMzPGkzM0ApQHRAb0k4NTk0ODszNDs5ODU5PDNAKXUpQGczdSlAZjN2KUBmaHV5cTFmc2hoZGY7NEBqb25xXi40a21fLS0uLS9zcy1vI28jQDYvMjQtLy0tMi4uLS0uL2k6Yi5wIzphLXEjOmAtbyNwYmZyaF4ranQ6Iy8uXg%3D%3D", 
        "http://v9-dy.ixigua.com/e8315b25e1ab839440724d890cd30276/5cf3860a/video/m/2209c36709d08f346d6b848f341ef203da2116255dc100004e550a0e9e7d/", 
        "https://aweme-hl.snssdk.com/aweme/v1/play/?video_id=v0200f190000bjpinc7a1hagtbqfremg&line=0&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0", 
        "https://api-hl.amemv.com/aweme/v1/play/?video_id=v0200f190000bjpinc7a1hagtbqfremg&line=1&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0"
    ], 
    "music_urls": [
        "http://p3-dy.byteimg.com/obj/ies-music/1635154703940663.mp3"
    ], 
    "info": {
        "bool_persist": 0, 
        "share_title_other": "", 
        "share_signature_desc": "TikTok: Make Every Second Count", 
        "share_quote": "", 
        "share_weibo_desc": "#在抖音,记录美好生活#露西高尔夫舞#轻漫计划 @抖音动漫", 
        "share_desc": "在抖音,记录美好生活", 
        "share_title": "露西高尔夫舞#轻漫计划 @抖音动漫", 
        "share_title_myself": "", 
        "share_link_desc": "#在抖音,记录美好生活#露西高尔夫舞#轻漫计划 @抖音动漫 %s 复制此链接,打开【抖音短视频】,直接观看视频!", 
        "share_signature_url": "https://tiktokv.com/", 
        "share_url": "https://www.iesdouyin.com/share/video/6697499584689655052/?region=CN&mid=6697578960856845063&u_code=gj49fkd1&titleType=title"
    }, 
    "time": 1559459768
}

作者头像:https://p3-dy.byteimg.com/aweme/720x720/1ca510002f106219c6a25.jpeg

视频封面:http://p1-dy.byteimg.com/large/26b610000ebd09462826a.jpeg

视频地址:http://v9-dy.ixigua.com/e8315b25e1ab839440724d890cd30276/5cf3860a/video/m/2209c36709d08f346d6b848f341ef203da2116255dc100004e550a0e9e7d/

BGM地址:http://p3-dy.byteimg.com/obj/ies-music/1635154703940663.mp3

 

本文标签:

版权声明:若无特殊注明,本文皆为《猫月灵》原创,转载请保留文章出处。

本文链接:抖音解析PHP源代码 - https://www.moonwl.cn/post-131.html

站长之家:90105406,欢迎大佬入驻!点我快速加入

发表评论

电子邮件地址不会被公开。 必填项已用*标注

未显示?请点击刷新

允许邮件通知

评论

2条评论
  1. avatar

    工作QQ Lv.1 Chrome 74.0.3729.131 Windows 回复

    代码运行后地址是空的,不能用!

    四川省成都市 电信

    1. avatar

      slot Lv.1 Chrome 66.0.3359.117 Mac OS X 10.12.6 回复

      Thanks for sharing your thoughts about 月灵博客 喜你为疾,药石无医   IT技术博客 互联网 PS 易语言 电脑 安卓 苹果
      记录个人生活. Regards

      印度