下载视频/音频的python脚本,使用youtube dl构建

vidl的Python项目详细描述


视界

vidl是一个脚本,旨在使用youtube dl从任何人轻松下载视频/音频。它自动将缩略图嵌入到mp3/mp4/m4a文件中。

如果找到mp3文件,vidl将向其添加元数据。--no-md选项关闭此选项。 titleartistyear元数据被添加,但是如果url是播放列表,它也会添加albumalbum artisttrack numbertrack count。 如果标题包含“-”,vidl通常将其前后的内容分别用作艺术家和标题。--dont-extract-md选项关闭此行为。

安装

  1. 安装python(建议3.7)
  2. 安装ffmpeg and ffprobe
  3. 运行pip install vidl。如果不起作用,请尝试pip3而不是pip
  4. 如果您不在macos或windows上,则需要指定vidl将文件下载到vidl配置文件中的位置。运行vidl --config-path查看配置文件的位置。 如果你在macos上,我建议setting up shortcuts for vidl

更新

通过运行pip install vidl --upgrade --upgrade-strategy eager更新vidl。如果不起作用,请尝试pip3而不是pip。 如果vidl无法下载url,可能是因为youtube dl已经过时了。--upgrade-strategy eager部分更新youtube dl。

卸载

运行pip uninstall vidl。如果不起作用,请尝试pip3而不是pip

要完全卸载vidl,请转到vidl的配置文件(运行vidl --config-path查看它的位置)并删除它所在的文件夹。

用法

示例: vidl https://www.youtube.com/watch?v=ta_ZVS7HkwI

  • 以MP3格式下载视频,并添加它检测到的元数据。

vidl mp3 https://www.youtube.com/watch?v=ta_ZVS7HkwI --no-md

  • 以MP3格式下载视频,无需添加元数据。

vidl

  • 打印Vidl的帮助菜单,如下所示:
    Download Usage:
        vidl [format] [options] <URL>
    
    Download Options:
        format             mp3, mp4, wav or m4a. Default mp3.
        --no-md            Don't add metadata to downloaded files.
        --no-smart-md      Don't extract artist and song name from title.
        --no-dl            Don't download anything. Usually used with -v
        -v, --verbose      Display all logs.
    
    Global Options:
        --version          Display vidl version. "vidl -v" also works.
        -h, --help         Display this help message.
        --config-path      Display the location of vidl's configuration file.
    

配置

vidl有一个配置文件,您可以通过运行vidl --config-path找到其位置。在其中,您可以设置下载文件夹和文件名模板。

如果你搞砸了,可以删除文件,下次运行vidl时将重新创建默认文件。

自定义元数据分析

vidl有一个user_md_parser.py文件。默认情况下,它什么也不做,但是您可以配置它来操作您下载的歌曲的元数据。在我的例子中,如果标题以“[ncs release]结尾,我将“comment”元数据设置为“ncs”。

相关文档可以在文件中找到。该文件与vidl的配置文件位于同一文件夹中,可以通过运行vidl --config-path找到该文件。如果你搞砸了,可以删除文件,下次运行vidl时将重新创建默认文件。

Set up shortcuts for vidl (macOS)

You'll be able to select any piece of text, press your chosen shortcut and the link(s) in your selected text will be downloaded! A little tedious to set up, but well worth it.

First, we need to create a macOS Service:

  1. Open the Automator app.

  2. Choose File > New, and select Service.

  3. (TLDR; Add ^{}) In the window that just popped up, there are two columns on the left (if not, click the ^{} button in the status bar). Select ^{} in the first column, and in the second column, drag ^{} into the main part of the window.

  4. Make your settings match these:

    Service receives selected [URLs] in [any application]. Input is [only URLs]. In your Run Shell Script box; Shell: [/bin/bash]. Pass input: [as arguments]

    If you want the shortcut to only work in one app, select that app instead of ^{}.

  5. In the text box in the "Run Shell Script" box, paste in the following script:

    ^{pr 2}$

    Replace ^{} with the path you get from running ^{} in the terminal. Replace ^{} with the path you get from running ^{} in the terminal. Replace ^{} with the path you get from running ^{} in the terminal.

  6. Choose File > Save. Type in vidl.

Almost done, you just need to tie a shortcut to the macOS Service you just created:

  1. Open the System Preferences app.
  2. Go to Keyboard and select the Shortcuts tab.
  3. Select Services from the left column, and locate vidl (should be under Internet). Add your preferred shortcut.

Dev Instructions

Installation

  1. Install Python. You may want to install it using pyenv为了管理python版本(如果poetry没有检测到正确的版本,可以使用pyenv修复它)。
  2. 安装ffmpeg and ffprobe
  3. 安装Poetry
  4. 运行poetry install以安装python包依赖项。
  5. 如果您不在macos或windows上,则需要指定vidl将文件下载到vidl配置文件中的位置。运行vidl --config-path查看配置文件的位置。

我建议运行poetry config settings.virtualenvs.in-project true。此命令使poetry在项目文件夹中创建python虚拟环境,因此您可以轻松地删除它。此外,如果您在工作区(或全局)设置中将python.pythonPath设置设置设置为${workspaceFolder}/.venv/bin/python,它还允许vscode的python扩展检测虚拟环境。

运行

poetry run vidl

替代poetry run <command>的方法是运行poetry shell以进入虚拟环境的bash cli,然后自己运行命令(例如vidl)。

待办事项

  • 可选通知。告诉您下载何时开始、何时完成以及应用的元数据
  • 对于将来的配置可能性,将--no-md替换为--md--!md。也许叫它defaults而不是config
    • 将所有配置添加为选项,例如添加下载文件夹选项。
    • 将所有选项添加为configs,例如add md option。
    • 为个人ME添加配置/选项塔达
  • 允许直接传递youtube dl参数

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java GWT对话框从不显示帮助   java在简单的MapReduce作业中带来了极大的开销   javacom。mysql。jdbc。例外情况。jdbc4。MySQLIntegrityConstraintViolationException:列不能为null/onetoone映射   如何通过TCP/IP与Java和Labview进行通信,并发送浮点数据缓冲区?   java Apache camel与spring事件基本示例   java如何使我的秒表应用程序在完全关闭后仍能运行?   java Nutch爬网错误输入路径不存在   java是Mapreduce中按值传递还是按引用传递的键?   正则表达式替换java中的特定字符   Java DOM XML解析   java Eclipse未显示服务器的项目   使用Arraylist进行快速排序的排序Java实现疑难解答   java Split text包含字符串列表中的数字   检查Java中的两个lambda是否执行相同的代码?   java为什么dispatchTouchEvent避免在屏幕上单击?