轻松下载大量bilibili视频

最近需要做新系列的剪辑就需要大量素材,我看中了原神的一个CG动画集,打算下载来用,结果软件不给力,经常下载失败,所以只好自己出马,找了一个学习项目

丹尼尔2022/bilibili_own_tools:学习项目 (github.com)

然后发现它不可以批量下载,然后我又不想研究代码(单纯就是懒),所以想做一个点击器来应付应付

于是在我面向CSDN的编程中找到了python模拟键盘操作_Python 模拟键盘鼠标操作详细教程

但是然后发现那个库不是很好用,所以换成了

详解Python中pyautogui库的最全使用

Python自动操作GUI神器PyAutoGUI

火速安装依赖写起代码

python -m pip install -U pyautogui

p2p.py

from time import sleep
import pyautogui
import sys

#bilibili星姮十织

def jr_cmd (data):  #把命令键入cmd并运行
    for ll in range(len(data)):
        pyautogui.press(data[ll])
    pyautogui.press('enter')


def cmd (): #打开cmd
    pyautogui.keyDown('win')
    pyautogui.keyDown('r')
    pyautogui.keyUp('win')
    pyautogui.keyUp('r')
    pyautogui.typewrite('cmd')
    pyautogui.press('enter')
ml = 0
mls = 0
#读取下载目录
with open('data.txt', 'r') as f:
    data = f.read()
    ml = ('{}'.format(data))

mling = 'python d.py'#启动下载器命令

print('下载路径:',ml)#确认下载路径

sui = '【A】下载视频\n【B】设置\n【C】软件信息\n【D】注意事项\n请输入:'

ssui = input(sui)

if (ssui == 'A'):
    hzUI = (
    '画质选择:\n'
    '4K:120(大会员);\n'
    '1080p60: 116(大会员);\n'
    '720p60: 74;\n'
    '1080p: 80;\n'
    '720p: 64;\n'
    '480p: 32;\n'
    '360p: 16;\n'
    )
    Pv_s = 0
    pv = 1
    bv = input('请输入视频bv号:')
    psss = input('【A】下载指定P,【B】指定下载到多少P,【C】视频没有P:')
    if(psss == 'A'):
        pv = input('下载哪一P:')
        Pv_s = 1
    elif(psss == 'C'):
        p = 0
    else:
        p = input('下载到多少P:')

    hz = input(hzUI)
    shijian = input('每次下载结束等待时间(整数):')
    cmd()
    pyautogui.press('c')
    pyautogui.press('d')
    pyautogui.press('space')
    jr_cmd(ml)
    if (int(p) >= 1):
        ppp = 1
        for pp in range(int(p)):
            jr_cmd(mling)
            jr_cmd(bv)
            jr_cmd(str(ppp))
            jr_cmd(hz)
            if (hz == '80'):
                HEVC = 'Y'
            else:
                HEVC = 'Y'
            jr_cmd(HEVC)
            ppp += 1
            pyautogui.press('enter')
            sleep(int(shijian))
    elif(Pv_s == 1):
        jr_cmd(mling)
        jr_cmd(bv)
        jr_cmd(str(pv))
        jr_cmd(hz)
        if (hz == '80'):
            HEVC =  'Y'
        else:
            HEVC = "N"
        jr_cmd(HEVC)
        pyautogui.press('enter')
        sleep(int(shijian))
    else:
        jr_cmd(mling)
        jr_cmd(bv)
        jr_cmd(hz)
        if (hz == '80'):
            HEVC = 'Y' 
        else:
            HEVC = 'N'
        jr_cmd(HEVC)
    sleep(int(shijian))
    gb = 'exit'
    jr_cmd(gb)
elif(ssui == 'B'):
    print ('<【A】返回首页\n')
    print('设置未开放\n')
    sz = input('请输入:')
    if (sz == 'A'):
        cmd()
        gzml = sys.argv[0]
        print (gzml)
        jr_cmd('cd '+gzml) 
elif(ssui == 'C'):
    print('软件作者:星姮十织\n代码仓库:https://github.com/hengshizhi/bilibili-video-download\n使用其他项目:bilibili_own_tools')
elif(ssui == 'D'):
    print('注意事项:\n 1>视频下载时最好不要动,除非下载较大视频在走进度条 \n 2>本cmd操控器还有很多的bug,我会继续更新,敬请期待')

#pyautogui.typewrite('cd',' ',ml)

#pyautogui.typewrite('cd C:/cd C:/')

看完代码后感叹道:这不只是一个CMD操控器吗?

没错,这玩意就是使用程序操控另一个程序,没想到把,哈哈哈哈哈

所以我们要给它取个名,就叫做P2P视频下载器好啦!

就到测试环节了,下面是测试

测试

hengshizhi/bilibili-video-download: 用于下载bilibili的视频

需要的环境
requests
json
subprocess
aria2c和ffmpeg

在data.txt配置路径

C:\bi

打开cmd

C:\bi>python p2p.py
返回:
下载路径: C:\bi
【A】下载视频
【B】设置
【C】软件信息
【D】注意事项
请输入:

输入A,bv:BV1Ed4y1D7G3,没有P选C,1080P写80,等待时间8秒

下载路径: C:\bi
【A】下载视频
【B】设置
【C】软件信息
【D】注意事项
请输入:A
请输入视频bv号:BV1Ed4y1D7G3
【A】下载指定P,【B】指定下载到多少P,【C】视频没有P:C
画质选择:
4K:120(大会员);
1080p60: 116(大会员);
720p60: 74;
1080p: 80;
720p: 64;
480p: 32;
360p: 16;
80
每次下载结束等待时间(整数):8

新窗口返回

请输入BV号:BV1Ed4y1D7G3
This video has 1 page(s)
画质选择
4K:120
1080p60: 116
720p60: 74
1080p: 80
720p: 64
480p: 32
360p: 16
选择画质:80
80
Downloading BV1Ed4y1D7G3 【官方MV】 法老Pharaoh —《无名之辈》 Page 0
This page have HEVC codec.
是否下载HEVC格式?Y/NY

08/03 17:20:34 [NOTICE] Downloading 1 item(s)

08/03 17:20:34 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details.
[#9ac168 20MiB/22MiB(93%) CN:1 DL:12MiB]
08/03 17:20:36 [NOTICE] Download complete: C:/bi/Video.mp4

Download Results:
gid   |stat|avg speed  |path/URI
======+====+===========+=======================================================
9ac168|OK  |    12MiB/s|C:/bi/Video.mp4

Status Legend:
(OK):download completed.

08/03 17:20:36 [NOTICE] Downloading 1 item(s)

08/03 17:20:37 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details.
[#da476a 9.1MiB/12MiB(73%) CN:1 DL:12MiB]
08/03 17:20:38 [NOTICE] Download complete: C:/bi/Audio.aac

Download Results:
gid   |stat|avg speed  |path/URI
======+====+===========+=======================================================
da476a|OK  |    12MiB/s|C:/bi/Audio.aac

Status Legend:
(OK):download completed.
ffmpeg -i Video.mp4 -i Audio.aac -c:v copy -c:a copy -strict experimental "【官方MV】 法老Pharaoh —《无名之辈》_1.mp4"
ffmpeg version 4.4.1-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11.2.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Video.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 1
    compatible_brands: iso5dsmsmsixdash
    encoder         : Lavf58.29.100
    description     : Packed by Bilibili XCoder v2.0.2
  Duration: 00:05:27.04, start: 0.000000, bitrate: 573 kb/s
  Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 1 kb/s, 25 fps, 25 tbr, 16k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'Audio.aac':
  Metadata:
    major_brand     : iso5
    minor_version   : 1
    compatible_brands: avc1iso5dsmsmsixdash
    encoder         : Lavf58.29.100
    description     : Packed by Bilibili XCoder v2.0.2
  Duration: 00:05:27.10, start: 0.000000, bitrate: 319 kb/s
  Stream #1:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 4 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Output #0, mp4, to '【官方MV】 法老Pharaoh —《无名之辈》_1.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 1
    compatible_brands: iso5dsmsmsixdash
    description     : Packed by Bilibili XCoder v2.0.2
    encoder         : Lavf58.76.100
  Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1 kb/s, 25 fps, 25 tbr, 16k tbn, 16k tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 4 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 8176 fps=0.0 q=-1.0 Lsize=   35727kB time=00:05:27.08 bitrate= 894.8kbits/s speed=3.58e+03x
video:22810kB audio:12672kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.689378%

python新手写代码不太熟练,请多多指教!

轻松下载大量bilibili视频
当前页面https://www.df100.ltd/154.asp,文章作者星姮十织
维度前沿|Dimension Frontier © 2022. 版权所有
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇