How can I download just thumbnails using youtube-dl?
<p>I've been trying to download the thumbnails of a list of URL's (youtube videos) I have.</p>

<p>I've been using youtube-dl and I've worked it out to this so far:</p>

<pre><code>     import os

     with open('results.txt') as f:
          for line in f:
              os.system("youtube-dl " + "--write-thumbnail " + line)
</code></pre>

<p>Like this I'm able to download the thumbnails but I'm forced to downloading the youtube videos as well.</p>

<p>How can I just download the thumbnail?</p>

<p>It looks like passing --list-thumbnails will return the url to the thumbnail images, but it will just output to the screen when calling os.system().</p>

<p>The following isn't the prettiest, but it's a quick working example of getting the output of youtube-dl into a string using subprocess, parsing it to get the url, and downloading with requests:</p>

<pre><code>import re
import requests
import subprocess

with open('results.txt') as f:
    for line in f:
        proc = subprocess.Popen(['youtube-dl', '--list-thumbnails', line], stdout=subprocess.PIPE)
        youtubedl_output, err = proc.communicate()
        imgurl = re.search("(?P&lt;url&gt;https?://[^\s]+)", youtubedl_output).group('url')
        r = requests.get(imgurl)
        if r.status_code == 200:
            with open(imgurl.split('/')[4] + '.jpg', 'wb') as file:
                for chunk in r.iter_content(1024):
                    file.write(chunk)
</code></pre>

<p>Hope this helped!</p>

python youtube youtube-dl