我正在尝试编写一个 bash 脚本,该脚本将从播放列表中下载所有 YouTube 视频,并根据 YouTube 视频本身的标题将它们保存到特定的文件名。到目前为止,我有两段独立的代码可以执行我想要的操作,但我不知道如何将它们组合在一起以作为一个单元运行。
这段代码查找给定页面上所有 YouTube 视频的标题:
curl -s "$1" | grep '<span class="title video-title "' | cut -d\> -f2 | cut -d\< -f1
这段代码将文件下载到由 youtube 视频 id 指定的文件名(例如 youtube.com/watch?v=< strong>CsBVaJelurE&feature=relmfu 将是 CsBVaJelurE.flv)
curl -s "$1" | grep "watch?" | cut -d\" -f4| while read video;
do youtube-dl "http://www.youtube.com$video";
done
我想要一个脚本,将 youtube .flv 文件输出到标题给出的文件名视频的名称(在本例中为 BASH 课程 2.flv),而不是简单的视频 ID 名称。预先感谢您的所有帮助。
I'm trying to write a bash script that will download all of the youtube videos from a playlist and save them to a specific file name based on the title of the youtube video itself. So far I have two separate pieces of code that do what I want but I don't know how to combine them together to function as a unit.
This piece of code finds the titles of all of the youtube videos on a given page:
curl -s "$1" | grep '<span class="title video-title "' | cut -d\> -f2 | cut -d\< -f1
And this piece of code downloads the files to a filename given by the youtube video id (e.g. the filename given by youtube.com/watch?v=CsBVaJelurE&feature=relmfu would be CsBVaJelurE.flv)
curl -s "$1" | grep "watch?" | cut -d\" -f4| while read video;
do youtube-dl "http://www.youtube.com$video";
done
I want a script that will output the youtube .flv file to a filename given by the title of the video (in this case BASH lesson 2.flv) rather than simply the video id name. Thanks in advance for all the help.
发布评论
评论(5)
好吧,经过进一步研究和更新我的 youtube-dl 版本,结果发现这个功能现在直接内置到程序中,不需要 shell 脚本来解决 youtube 上的播放列表下载问题。完整的文档可以在这里找到:(http://rg3.github.com/youtube -dl/documentation.html),但我原来问题的简单解决方案如下:
1)youtube-dl将自动处理播放列表链接,无需单独向其提供视频的URL其中包含的(这样就不需要使用 grep 搜索“watch?”来查找唯一的视频 id
2)现在有一个选项可以使用各种选项来格式化文件名,包括:
flv 或 mp4)。
文件。
将随着每次下载而增加,从零开始。
此输出选项的语法如下(其中 NAME 是上面显示的任何选项):
作为示例,要回答我原来的问题,语法如下:
再次感谢那些回答我的问题的人,您的帮助是非常感谢。
OK so after further research and updating my version of youtube-dl, it turns out that this functionality is now built directly into the program, negating the need for a shell script to solve the playlist download issue on youtube. The full documentation can be found here: (http://rg3.github.com/youtube-dl/documentation.html) but the simple solution to my original question is as follows:
1) youtube-dl will process a playlist link automatically, there is no need to individually feed it the URLs of the videos that are contained therein (this negates the need to use grep to search for "watch?" to find the unique video id
2) there is now an option included to format the filename with a variety of options including:
flv or mp4).
the file.
will be increased with each download, starting at zero.
the syntax for this output option is as follows (where NAME is any of the options shown above):
As an example, to answer my original question, the syntax is as follows:
Thanks again to those who responded to my question, your help is greatly appreciated.
如果您想使用 youtube 页面的标题作为文件名,您可以使用
youtube-dl
的-t
选项。如果您想使用“视频列表”页面中的标题,并且确定每个都有一个
watch?
URL code> title,那么你可以使用这样的东西:我没有测试它,因为我没有“视频列表”页面示例。
If you want to use the title from youtube page as a filename, you could use
-t
option ofyoutube-dl
. If you want to use the title from your "video list" page and you sure that there is exactly onewatch?
URL for every<span class="title video-title"
title, then you can use something like this:I did not tested it because I have no "video list" page example.
下面的方法可以工作并从 youtube
youtube-downloader.sh 播放泰坦尼克号
youtube-video-url.sh
bash youtube-player.sh saalGKY7ifU
它使用您可能已经安装的解码和bash。
this following method work and play you titanic from youtube
youtube-downloader.sh
youtube-video-url.sh
bash youtube-player.sh saalGKY7ifU
It uses decode and bash, that you may have installed.
我使用此 bash 脚本从给定的 YouTube 播放列表中下载给定的一组歌曲
注意:“关键字 i”是该播放列表中给定视频的标题(全部或部分;如果是部分,则对于该播放列表应该是唯一的) 。
编辑:您可以通过 pip install youtube-dl 安装 youtube-dl
I use this bash script to download a given set of songs from a given youtube's playlist
Note: "keyword i" is the title (in whole or part; if part, it should be unique to that playlist) of a given video in that playlist.
Edit: You can install youtube-dl by pip install youtube-dl