diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-05-01 14:04:33 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-05-01 14:04:33 +0200 |
commit | 11d9224e3b472621e56d0862e600cd5133bd3fd1 (patch) | |
tree | bc4b3ef95b84c5780bfe9292c08b3a8b653273b5 /youtube_dl/FileDownloader.py | |
parent | 6cd657f9f213faf9dc21d55f581f86a453b6e2c2 (diff) |
add --write-thumbnail option to download thumbnail (Suggested by `)
Diffstat (limited to 'youtube_dl/FileDownloader.py')
-rw-r--r-- | youtube_dl/FileDownloader.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index a67d3c902..574863e7c 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -7,6 +7,7 @@ import math import io import os import re +import shutil import socket import subprocess import sys @@ -79,6 +80,7 @@ class FileDownloader(object): updatetime: Use the Last-modified header to set output file timestamps. writedescription: Write the video description to a .description file writeinfojson: Write the video description to a .info.json file + writethumbnail: Write the thumbnail image to a file writesubtitles: Write the video subtitles to a file onlysubtitles: Downloads only the subtitles of the video allsubtitles: Downloads all the subtitles of the video @@ -658,6 +660,20 @@ class FileDownloader(object): self.report_error(u'Cannot write metadata to JSON file ' + infofn) return + if self.params.get('writethumbnail', False): + if 'thumbnail' in info_dict: + thumb_format = info_dict['thumbnail'].rpartition(u'/')[2].rpartition(u'.')[2] + if not thumb_format: + thumb_format = 'jpg' + thumb_filename = filename.rpartition('.')[0] + u'.' + thumb_format + self.to_screen(u'[%s] %s: Downloading thumbnail ...' % + (info_dict['extractor'], info_dict['id'])) + uf = compat_urllib_request.urlopen(info_dict['thumbnail']) + with open(thumb_filename, 'wb') as thumbf: + shutil.copyfileobj(uf, thumbf) + self.to_screen(u'[%s] %s: Writing thumbnail to: %s' % + (info_dict['extractor'], info_dict['id'], thumb_filename)) + if not self.params.get('skip_download', False): if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(filename)): success = True |