title: Shell Script to download youtube files from playlist
body: <p>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.</p>
  
  <p>This piece of code finds the titles of all of the youtube videos on a given page:</p>
  
  <pre><code>curl -s "$1" | grep '&lt;span class="title video-title "' | cut -d\&gt; -f2 | cut -d\&lt; -f1
  </code></pre>
  
  <p>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=<strong>CsBVaJelurE</strong>&amp;feature=relmfu would be CsBVaJelurE.flv)</p>
  
  <pre><code>curl -s "$1" | grep "watch?" | cut -d\" -f4| while read video; 
  do youtube-dl "http://www.youtube.com$video";
  done
  </code></pre>
  
  <p>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.</p>