用python3下载youku,bilibili等视频

  1. step1 命令行安装you-get包
$ pip install you-get

Collecting you-get
  Downloading https://files.pythonhosted.org/packages/89/86/359cb6d3720aded1e21acf090ba411d14c0fa94d401ff25780837b58c085/you_get-0.4.1355-py3-none-any.whl (207kB)
    100% |████████████████████████████████| 215kB 595kB/s 
Installing collected packages: you-get
Successfully installed you-get-0.4.1355
  1. step2 命令行下载视频
    you-get -i video_url:查看可下载的视频格式/清晰度
    you-get --format=xx video_url:下载指定格式的视频

查看视频格式:

$ you-get -i https://v.youku.com/v_show/id_XNDQ0NDM0ODgwNA\=\=.html\?spm\=a2hzp.8253869.0.0 

site:                优酷 (Youku)
title:               VogueFilm短片《一己之恋》完整版
streams:             # Available quality and codecs
    [ DEFAULT ] _________________________________
    - format:        mp4hd3v2
      container:     mp4
      video-profile: 1080P
      size:          101.4 MiB (106329910 bytes)
      m3u8_url:      http://pl-ali.youku.com/playlist/m3u8?vid=XNDQ0NDM0ODgwNA&type=hd3&ups_client_netip=3af727d2&utid=hepgFmAFkTUCATr3J9ITf2K2&ccode=0519&psid=96b453e0427c7f461827dae91813be4d&duration=301&expire=18000&drm_type=1&drm_device=0&ups_ts=1574567048&onOff=0&encr=0&ups_key=d859e5bfe9667595f94f41ed756b8262
    # download-with: you-get --format=mp4hd3v2 [URL]

    - format:        mp4hd2v2
      container:     mp4
      video-profile: 超清
      size:          43.3 MiB (45406583 bytes)
      m3u8_url:      http://pl-ali.youku.com/playlist/m3u8?vid=XNDQ0NDM0ODgwNA&type=hd2&ups_client_netip=3af727d2&utid=hepgFmAFkTUCATr3J9ITf2K2&ccode=0519&psid=96b453e0427c7f461827dae91813be4d&duration=301&expire=18000&drm_type=1&drm_device=0&ups_ts=1574567048&onOff=0&encr=0&ups_key=d859e5bfe9667595f94f41ed756b8262
    # download-with: you-get --format=mp4hd2v2 [URL]

    - format:        mp4hd
      container:     mp4
      video-profile: 高清
      size:          23.5 MiB (24616118 bytes)
      m3u8_url:      http://pl-ali.youku.com/playlist/m3u8?vid=XNDQ0NDM0ODgwNA&type=hd&ups_client_netip=3af727d2&utid=hepgFmAFkTUCATr3J9ITf2K2&ccode=0519&psid=96b453e0427c7f461827dae91813be4d&duration=301&expire=18000&drm_type=1&drm_device=0&ups_ts=1574567048&onOff=0&encr=0&ups_key=d859e5bfe9667595f94f41ed756b8262
    # download-with: you-get --format=mp4hd [URL]

    - format:        3gphd
      container:     mp4
      video-profile: 渣清
      size:          6.2 MiB (6461333 bytes)
      m3u8_url:      http://pl-ali.youku.com/playlist/m3u8?vid=XNDQ0NDM0ODgwNA&type=mp4&ups_client_netip=3af727d2&utid=hepgFmAFkTUCATr3J9ITf2K2&ccode=0519&psid=96b453e0427c7f461827dae91813be4d&duration=301&expire=18000&drm_type=1&drm_device=0&ups_ts=1574567048&onOff=0&encr=0&ups_key=d859e5bfe9667595f94f41ed756b8262
    # download-with: you-get --format=3gphd [URL]

    - format:        mp4sd
      container:     mp4
      video-profile: 标清
      size:          9.8 MiB (10272638 bytes)
      m3u8_url:      http://pl-ali.youku.com/playlist/m3u8?vid=XNDQ0NDM0ODgwNA&type=flv&ups_client_netip=3af727d2&utid=hepgFmAFkTUCATr3J9ITf2K2&ccode=0519&psid=96b453e0427c7f461827dae91813be4d&duration=301&expire=18000&drm_type=1&drm_device=0&ups_ts=1574567048&onOff=0&encr=0&ups_key=d859e5bfe9667595f94f41ed756b8262
    # download-with: you-get --format=mp4sd [URL]

选择标清格式进行下载:

$ you-get --format=mp4sd https://v.youku.com/v_show/id_XNDQ0NDM0ODgwNA\=\=.html\?spm\=a2hzp.8253869.0.0

site:                优酷 (Youku)
title:               VogueFilm短片《一己之恋》完整版
stream:
    - format:        mp4sd
      container:     mp4
      video-profile: 标清
      size:          9.8 MiB (10272638 bytes)
      m3u8_url:      http://pl-ali.youku.com/playlist/m3u8?vid=XNDQ0NDM0ODgwNA&type=flv&ups_client_netip=3af727d2&utid=tepgFkRmQGkCATr3J9KZ2DQA&ccode=0519&psid=32e83d5fdef6a27f655da3eed16feea3&duration=301&expire=18000&drm_type=1&drm_device=0&ups_ts=1574567096&onOff=0&encr=0&ups_key=6681ea63df6d44158acc33d7e0adc276
    # download-with: you-get --format=mp4sd [URL]

you-get 相似的一个包是 youtube-dl,支持1000+网站下载。但是 you-get 对国内支持更友好,下载速度极快,支持100+网站。

你可能感兴趣的:(工具)