V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
MiLoucius
V2EX  ›  Python

you-get 如何从 playlist 中下载单独的视频?

  •  
  •   MiLoucius · 2018-11-10 13:57:39 +08:00 · 7443 次点击
    这是一个创建于 1993 天前的主题,其中的信息可能已经有所发展或是发生改变。

    b 站很多视频都是一个 playlist 的,you-get 解析 b 站的 url 只解析到 av 号,而忽略了后面的?p=**

    所以,you-get 只能解析到 playlist 中的第一个视频。

    e.g. 这里解析 playlist 的

    >you-get -i https://www.bilibili.com/video/av35557055?p=3
    >you-get: This page contains a playlist. (use --playlist to download all videos.)
    >site:                Bilibili
    >title:                [ 1080 60 帧]  9 兔 8 蛋回归初舞台,IZONE 初 1 位! 181108 M!Countdown 女团 LIVE 现场合集 #3. >IZONE - La Vie en Rose
    >streams:             # Available quality and codecs
    >    [ DEFAULT ] _________________________________
    >    - format:        hdflv
    >      container:     flv
    >      size:          116.2 MiB (121878947 bytes)
    >    # download-with: you-get --format=hdflv [URL]
    

    虽然 title 是对的,但从 size 可以看出依然是 playlist 中的第一个视频的。

    可以看到有提示的参数使用:

    This page contains a playlist. (use --playlist to download all videos.)

    利用提示的--playlist参数,是将整个 playlist 下载的,但我只想下载第三个视频,这个该怎么办? ( github 的 wiki 里根本没有提到--playlist 参数还有什么骚操作)

    6 条回复    2018-11-11 13:17:27 +08:00
    expy
        1
    expy  
       2018-11-10 14:04:14 +08:00
    https://github.com/iawia002/annie
    这个软件能识别 p 参数。
    V2tizen
        2
    V2tizen  
       2018-11-10 14:08:25 +08:00
    我上次是改了下 bilibili.py 里面的代码就可以下了,不过好像没法合并(雾),手动 ffmpeg 合并的
    MiLoucius
        3
    MiLoucius  
    OP
       2018-11-10 14:25:10 +08:00
    @expy 猴,我去试试。谢谢了
    MiLoucius
        4
    MiLoucius  
    OP
       2018-11-10 14:26:44 +08:00
    @V2tizen 刚才借用油猴的脚本,还行,就是步骤有点多。现在打算试试 @expy 推荐的 annie
    airdge
        5
    airdge  
       2018-11-10 16:43:45 +08:00
    带?p 的 但只匹配了 id/?p=page
    改成 https://www.bilibili.com/video/av35557055/?p=3 试下

    class BiliVideo(BiliBase):
    name = u'哔哩哔哩 (Bilibili)'

    def get_vid_title(self):
    av_id = match1(self.url, '(?:/av|aid=)(\d+)')
    page_index = '1'
    if "#page=" in self.url or "?p=" in self.url or 'index_' in self.url:
    page_index = match1(self.url, '(?:#page|\?p)=(\d+)', 'index_(\d+)\.')
    if page_index == '1':
    self.url = 'https://www.bilibili.com/av{}/'.format(av_id)
    else:
    self.url = 'https://www.bilibili.com/av{}/?p={}'.format(av_id, page_index)
    MiLoucius
        6
    MiLoucius  
    OP
       2018-11-11 13:17:27 +08:00
    @airdge 经你这么提醒,去看了下代码,发现是 b 站的 url 格式变了

    源代码:
    ```python
    frag = urllib.parse.urlparse(self.url).fragment
    # http://www.bilibili.com/video/av3141144/index_2.html#page=3
    if frag:
    hit = re.search(r'page=(\d+)', frag)
    if hit is not None:
    page = hit.group(1)
    aid = re.search(r'av(\d+)', self.url).group(1)
    self.url = 'http://www.bilibili.com/video/av{}/index_{}.html'.format(aid, page)
    ```

    代码中解析的是`/index_{}.html`,而现在 b 站显示的是`p={}`
    特意去试了下,旧的 url 格式还是可以用的

    所以,要下载 playlist 中的单独的视频,只需把`p={}`换成`/index_{}.html`就 OK 了(不要忘记了.html )
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3247 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:20 · PVG 22:20 · LAX 07:20 · JFK 10:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.