Filmy Filmy

抖音短视频无水印解析接口源码

in 代码相关 文章转载请注明来源!

前言

emmm,这个没啥好说的了 功能应该都懂 直接上代码

演示接口:http://pic.mlooc.cn/analysis?url=http://v.douyin.com/Ngon78/

代码

<?php
/**
 * Created by PhpStorm.
 * User: Filmy
 * Ver: 1.0.0
 * Date: 2019/1/16
 * Time: 8:56
 */

header("Content-Type: application/json");
$url = isset($_GET['url']) ? $_GET['url'] : die("参数不能为空");
$UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
$html = MloocCurlGet($url,true,$UserAgent);
preg_match('~video_id=(.*?)&line~', $html, $video_id);
preg_match('~cover: "(.*?)"~', $html, $cover);
if(!isset($video_id[1]) || !isset($cover[1])){
      $result['code'] = 400;
      $result['msg'] = "获取失败";
    exit(json_encode($result));
}
$video_id = trim($video_id[1]);
$cover = trim($cover[1]);

$html = MloocCurlGet("https://aweme.snssdk.com/aweme/v1/play/?video_id=$video_id");

preg_match('~Location: (.*?)\n~', $html, $location);
if(!isset($location[1])){
      $result['code'] = 400;
      $result['msg'] = "获取失败";
    exit(json_encode($result));
}
$location = trim($location[1]);
$result['code'] = 200;
$result['msg'] = "获取成功";
$result['playAddr'] = $location;
$result['cover'] = $cover;
exit(json_encode($result));

function MloocCurlGet($url, $idFllow=false, $UserAgent = '')
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    #关闭重定向
      if($idFllow){
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    }
      if($UserAgent){
        curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
    }
      
      curl_setopt($curl, CURLOPT_HEADER, 1);
      if($cookie!=""){
        curl_setopt($curl, CURLOPT_COOKIE, $cookie);
    }
  
    #关闭SSL
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    #返回数据不直接显示
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}
MHan WeChat Pay

微信打赏

Mhan Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

本文基于《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
文章链接:https://mlooc.cn/archives/douyin.html (转载时请注明本文出处及文章链接)

代码相关
发表新评论
雷姆
拉姆