本文介绍了Shell脚本从播放列表下载youtube文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个bash脚本,该脚本将从播放列表中下载所有youtube视频,并将其保存为基于youtube视频本身标题的特定文件名。到目前为止,我有两个单独的代码段可以满足我的要求,但是我不知道如何将它们组合在一起作为一个单元来工作。

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.

这段代码查找给定页面上所有youtube视频的标题:

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

这段代码将文件下载到youtube视频ID给出的文件名(例如youtube.com/watch?v=CsBVaJelurE&feature=relmfu给出的文件名将是CsBVaJelurE.flv)

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

我想要一个脚本,该脚本将youtube .flv文件输出为视频标题给定的文件名(在本例中为BASH课程2.flv ),而不是简单地使用视频ID名称。

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.

推荐答案

好的,所以在进一步研究和更新我的版本youtube-dl,事实证明,此功能现已直接内置到程序中,无需使用shell脚本即可解决youtube上的播放列表下载问题。完整的文档可在此处找到:(),但简单我原来的问题的解决方案如下:

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将自动处理播放列表链接,无需单独为其提供视频网址其中包含的操作系统(这消除了使用grep搜索观看?以找到唯一的视频ID

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的需要),现在包含了一个选项

2) there is now an option included to format the filename with a variety of options including:


  • id:将序列替换为视频标识符。

  • url:该序列将替换为视频URL。

  • 上载器:该序列将替换为上传视频的人的昵称。

  • upload_date:该序列将替换为YYYYMMDD格式的上传日期。

  • 标题:该序列将由文字视频标题替代。

  • ext:序列将被适当的扩展名(例如
    flv或mp4)替换。

  • epoch:序列将被Unix替换创建文件
    的时期。

  • 自动编号:该序列将由一个五位数字代替,每次下载
    都会增加一次,starti ng为零。

  • id: The sequence will be replaced by the video identifier.
  • url: The sequence will be replaced by the video URL.
  • uploader: The sequence will be replaced by the nickname of the person who uploaded the video.
  • upload_date: The sequence will be replaced by the upload date in YYYYMMDD format.
  • title: The sequence will be replaced by the literal video title.
  • ext: The sequence will be replaced by the appropriate extension (likeflv or mp4).
  • epoch: The sequence will be replaced by the Unix epoch when creatingthe file.
  • autonumber: The sequence will be replaced by a five-digit number thatwill be increased with each download, starting at zero.

此输出选项的语法如下(其中NAME是上面显示的任何选项):

the syntax for this output option is as follows (where NAME is any of the options shown above):

youtube-dl -o '%(NAME)s' http://www.youtube.com/your_video_or_playlist_url

例如,要回答我的原始问题,语法如下:

As an example, to answer my original question, the syntax is as follows:

youtube-dl -o '%(title)s.%(ext)s' http://www.youtube.com/playlist?list=PL2284887FAE36E6D8&feature=plcp

再次感谢那些回答我的问题的人,非常感谢您的帮助。

Thanks again to those who responded to my question, your help is greatly appreciated.

这篇关于Shell脚本从播放列表下载youtube文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:15