zoukankan      html  css  js  c++  java
  • 下载梨视频

    import time
    import requests
    
    
    # 返回视频的真实下载地址
    def get_real_video_url(video_id):
        # 视频地址解析接口
        url = 'https://www.pearvideo.com/videoStatus.jsp?contId={}'.format(video_id)
        headers = {
            'Referer': 'https://www.pearvideo.com/video_{}'.format(video_id),  # 防盗链,溯源这次请求的上一次请求的url
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
        }
        response = requests.get(url, headers=headers)
        system_time = response.json()['systemTime']
        # 假链接 https://video.pearvideo.com/mp4/adshort/20211111/1637987795364-15793700_adpkg-ad_hd.mp4
        fake_src_url = response.json()['videoInfo']['videos']['srcUrl']
        # 真链接 https://video.pearvideo.com/mp4/adshort/20211111/cont-1746412-15793700_adpkg-ad_hd.mp4
        real_src_url = fake_src_url.replace(system_time, 'cont-{}'.format(video_id))
        return real_src_url
    
    
    def download_video(url):
        video_id = url.split('-')[1]
        # file_name = str('.\\Video\\') + str(video_id) + '.mp4'
        file_name = str(video_id) + '.mp4'
        try:
            with open(file_name, mode='wb') as f:
                f.write(requests.get(url).content)
            print(video_id, 'success')
        except:
            print(video_id, 'error')
    
    
    if __name__ == '__main__':
        # url = input('输入视频的url:')
        start = time.time()
        url = 'https://www.pearvideo.com/video_1746036'
        v_id = url.split('_')[1]
        real_url = get_real_video_url(v_id)
        download_video(real_url)
        end = time.time()
        print('用时{:.2f}秒'.format(end - start))
    
  • 相关阅读:
    mysql prepare语句使用
    mysql 存储过程中的declare 和 set @的两种变量的区别
    Redis命令总结
    系统架构师
    php 大数组的POST问题解决
    ubuntu设置系统时间与网络时间同步
    JAVA开发者最常去的20个英文网站
    文件上传之一句话木马原理及制作
    Postman怎么进行参数化
    单元测试、接口测试、功能测试的区别
  • 原文地址:https://www.cnblogs.com/xuecl/p/15641402.html
Copyright © 2011-2022 走看看