吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4485|回复: 23
收起左侧

[其他原创] 【php】下载抖音无水印视频接口

  [复制链接]
yangxingyu 发表于 2020-4-21 23:55
本帖最后由 yangxingyu 于 2020-5-4 22:15 编辑

更新了一下哈
首先感谢@Quincy_007 提供思路哈!
废话不多说,直接上代码!
如果要看抓取过程请看这个帖子下载抖音无水印视频
[PHP] 纯文本查看 复制代码
<?php
if ($_REQUEST['url']) {
    $ids       = explode('/', parse_url(restoreUrl(matchUrl($_REQUEST['url'])))['path'])[3];
    $videoinfo = get_curl('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $ids)->item_list[0];
    $video     = geturl(str_ireplace('playwm', 'play', $videoinfo->video->play_addr->url_list[0]));
    $code      = $videoinfo->status_code;
    if ($code == 0) {
        $pic           = $videoinfo->video->cover->url_list[0];
        $desc          = $videoinfo->desc;
        $data['code']  = 'success';
        $data['title'] = $desc;
        $data['pic']   = $pic;
        $data['video'] = json_decode($video)->longUrl;
    } else {
        $data['code'] = 'error';
        $data['msg']  = '接口异常,请联系接口管理员!';
    }
    echo json_encode($data);
} else {
    $data['code'] = 'error';
    $data['msg']  = '请输入抖音链接!';
    die(json_encode($data));
}// 短网址转换长网址
function restoreUrl($shortUrl)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $shortUrl);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_USERAGENT, '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');
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_NOBODY, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 15);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
    $data     = curl_exec($curl);
    $curlInfo = curl_getinfo($curl);
    curl_close($curl);
    if ($curlInfo['http_code'] == 301 || $curlInfo['http_code'] == 302) {
        return $curlInfo['redirect_url'];
    } else {
        return;
    }
}
//curl
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept: */*";
    $httpheader[] = "Accept-Encoding: gzip,deflate,sdch";
    $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
    $httpheader[] = "Connection: close";
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($header) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($cookie) {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if ($referer) {
        if ($referer == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $referer);
        }
    }
    if ($ua) {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36');
    }
    if ($nobaody) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}
?>

TIM截图20200421234746.png
本人也是个php小白,代码混乱请谅解,欢迎在评论区指出我的过错哈!

免费评分

参与人数 4吾爱币 +3 热心值 +3 收起 理由
geniusrot + 1 感谢大佬分享
wwpp + 1 我很赞同!
961952819 + 1 + 1 谢谢@Thanks!
a2204297 + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| yangxingyu 发表于 2020-4-25 15:54
geniusrot 发表于 2020-4-22 23:41
好多代码呀!!同等效果,我选择易语言???

其实代码真的不多,大部分是函数,比如CURL,还有取文本中间,这些php都没有,需要自己写,而易语言直接有取文本中间呢,确实省了不少事,但是php也有它的好处【php是世界上最好的语言,狗头保命.jpg】
勤勤学长 发表于 2020-4-25 21:42
这代码让人窒息。。。这个curl是拷贝网上的吧?为什么要按着易语言的写法呢?取文本中间直接正则就好了呀。
看看我的https://www.52pojie.cn/thread-1165125-1-1.html
gouzi23 发表于 2020-4-21 23:59
Oohuo 发表于 2020-4-22 02:33
偶哟,我来试试看
致远英才 发表于 2020-4-22 05:40
谢谢分享!来学习一下!
jwpiaoi 发表于 2020-4-22 07:01
学习学习,下来试试看
炖锅 发表于 2020-4-22 07:34
最近在学vue,正好缺接口,谢谢分享。
日后提拔 发表于 2020-4-22 07:44
纯支持一下
坐久落花多 发表于 2020-4-22 07:54

不错,就喜欢这种简单直接的办法
inthepeace 发表于 2020-4-22 07:55
技术流支持下,感谢分享。
斩风 发表于 2020-4-22 08:10
感谢分享,学习了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-1 09:10

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表