PHP采集短视频 无水印

Anderyly
2019-09-20 / 0 评论 / 7 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2024年02月27日,已超过221天没有更新,若内容或图片失效,请留言反馈。

因为一些原因需要采集短视频,要无水印的那种,没办法只好找了一个平台抓包看看

思路:

首先fd安卓抓包获取视频列表接口以及分页接口

操作

很庆幸的是抓到了通过post访问正常

2019-09-19 18-30-22屏幕截图.png

可惜的是并没有短视频地址,只有标题等一些参数,这个时候灵机一动找分享接口,众所周之网页端加密是不行的,只要能播放就能获取到视频地址,于是新的一轮开始了

2019-09-19 18-31-36屏幕截图.png

上图的url参数就是视频地址,访问ok,下面可以做采集操作了,代码如下:

源码

    <?php
    /**
     * @author anderyly
     * @email admin@aaayun.cc
     * @link https://blog.aaayun.cc/
     * @copyright Copyright (c) 2019
     */
    
    set_time_limit(0);
    
    include_once "Curl.php";
    include_once "Db.php";
    
    $curl = new Curl();
    $db = new Db();
    
    $api = 'http://api.cray.inf.miui.com/content/videoList';
    $page = 0;
    
    $header = [
        'Cookie' => 'UM_distinctid=16c8455b31b1c4-0dfaf82ea6a25f-30760d58-1fa400-16c8455b31c215; CNZZDATA1272902400=401331908-1565588304-%7C1565588304; CNZZDATA1277592072=1290948318-1565593164-%7C1565593164; Hm_lvt_d214947968792b839fd669a4decaaffc=1568015305,1568191237,1568269922,1568687357',
    
    ];
    
    $i = 1;
    
    while (true) {
        $param = [
            'data' => '{"header":{"token":"","deviceId":"XWDyRwJadFYDAHnE+F5Hzlct","imeiMd5":"49A22D4E49F5B97EDFD236BA2173E37B","apkVersion":"2.0.0","apkChannel":"xiaomi"},"data":{"after":"0","pageNum":"' . $page . '"}}',
        ];
        $res = $curl->url($api)->header($header)->param($param)->post();
        if (!$res) {
            var_dump('video is null');
            break;
        }
    
        $arr = json_decode($res, true);
    
        if (!isset($arr['data']['items'])) continue;
        $list = $arr['data']['items'];
    
        foreach ($list as $k => $v) {
            if (!isset($v['id'])) {
                var_dump('End');
                exit;
            }
            $row = $db->name('video')->field('id')->where('cid', $v['id'])->find();
            if ($row) continue;
    
            // 视频id
            $data['cid'] = $v['id'];
            // 视频发布时间 13位时间戳
            $data['createTime'] = strtotime(date('Y-m-d H:i:s', $v['createTime']));
            // 视频标题
            $data['title'] = $v['videoInfo']['desc'];
            // 视频封面图
            $data['vthumb'] = $v['videoInfo']['coverUrl'];
            $data['thumb'] = str_replace('http://cdn.cnbj1.fds.api.mi-img.com/', '/public/video/thumb/', $v['videoInfo']['coverUrl']);
            // 视频地址
            $link = getVideo($v['id']);
            $data['vlink'] = $link;
            $data['link'] = str_replace('http://mic.w.xk.miui.com/', '/public/video/video/', $link);
            $data['page'] = $page;
            $db->name('video')->insert($data);
            var_dump($i);
            $i++;
        }
    
        $page++;
    }
    
    
    // 获取视频地址
    function getVideo($id)
    {
        global $curl;
        global $header;
        if ($id == '') return false;
        $url = 'https://longxia.music.xiaomi.com/api/share?contentType=video&contentId=' . $id;
        $res = $curl->url($url)->header($header)->get();
        $arr = json_decode($res, true);
        if (!isset($arr['data']['videoInfo']['contentType']) and $arr['data']['videoInfo']['contentType'] != 'VIDEO') return false;
        $videoInfo = $arr['data']['videoInfo']['videoInfo'];
        return $videoInfo['url'];
    
    }

源码并没有作下载功能有需要的可以自己写

0

评论 (0)

取消