mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-23 10:37:18 -05:00
--writedescription option
This commit is contained in:
parent
c6b55a8d48
commit
8b95c38707
30
youtube-dl
30
youtube-dl
@ -8,6 +8,10 @@
|
|||||||
# Author: Paweł Paprota
|
# Author: Paweł Paprota
|
||||||
# Author: Gergely Imreh
|
# Author: Gergely Imreh
|
||||||
# License: Public domain code
|
# License: Public domain code
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import cookielib
|
import cookielib
|
||||||
import ctypes
|
import ctypes
|
||||||
import datetime
|
import datetime
|
||||||
@ -301,6 +305,7 @@ class FileDownloader(object):
|
|||||||
consoletitle: Display progress in console window's titlebar.
|
consoletitle: Display progress in console window's titlebar.
|
||||||
nopart: Do not use temporary .part files.
|
nopart: Do not use temporary .part files.
|
||||||
updatetime: Use the Last-modified header to set output file timestamps.
|
updatetime: Use the Last-modified header to set output file timestamps.
|
||||||
|
writedescription: Write the video description to a .description file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
params = None
|
params = None
|
||||||
@ -496,6 +501,10 @@ class FileDownloader(object):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def report_writedescription(self, descfn):
|
||||||
|
""" Report that the description file has been written """
|
||||||
|
self.to_screen(u'[info] Video description written to: %s' % descfn, ignore_encoding_errors=True)
|
||||||
|
|
||||||
def report_destination(self, filename):
|
def report_destination(self, filename):
|
||||||
"""Report destination filename."""
|
"""Report destination filename."""
|
||||||
self.to_screen(u'[download] Destination: %s' % filename, ignore_encoding_errors=True)
|
self.to_screen(u'[download] Destination: %s' % filename, ignore_encoding_errors=True)
|
||||||
@ -582,6 +591,16 @@ class FileDownloader(object):
|
|||||||
self.trouble(u'ERROR: unable to create directories: %s' % str(err))
|
self.trouble(u'ERROR: unable to create directories: %s' % str(err))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.params.get('writedescription', False):
|
||||||
|
try:
|
||||||
|
descfn = filename + '.description'
|
||||||
|
with contextlib.closing(open(descfn, 'wb')) as descfile:
|
||||||
|
descfile.write(info_dict['description'].encode('utf-8'))
|
||||||
|
self.report_writedescription(descfn)
|
||||||
|
except (OSError, IOError):
|
||||||
|
self.trouble(u'ERROR: Cannot write description file: %s' % str(descfn))
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
success = self._do_download(filename, info_dict['url'].encode('utf-8'), info_dict.get('player_url', None))
|
success = self._do_download(filename, info_dict['url'].encode('utf-8'), info_dict.get('player_url', None))
|
||||||
except (OSError, IOError), err:
|
except (OSError, IOError), err:
|
||||||
@ -1086,7 +1105,7 @@ class YoutubeIE(InfoExtractor):
|
|||||||
lxml.etree
|
lxml.etree
|
||||||
except NameError:
|
except NameError:
|
||||||
video_description = u'No description available.'
|
video_description = u'No description available.'
|
||||||
if self._downloader.params.get('forcedescription', False):
|
if self._downloader.params.get('forcedescription', False) or self._downloader.params.get('writedescription', False):
|
||||||
warnings.warn(u'You are using an old Python version, install Python 2.6+ or lxml. Falling back to old video description extractor.')
|
warnings.warn(u'You are using an old Python version, install Python 2.6+ or lxml. Falling back to old video description extractor.')
|
||||||
mobj = re.search(r'<meta name="description" content="(.*)"(?:\s*/)?>', video_webpage)
|
mobj = re.search(r'<meta name="description" content="(.*)"(?:\s*/)?>', video_webpage)
|
||||||
if mobj is not None:
|
if mobj is not None:
|
||||||
@ -2529,10 +2548,7 @@ class FacebookIE(InfoExtractor):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# description
|
# description
|
||||||
video_description = 'No description available.'
|
video_description = video_info.get('description', 'No description available.')
|
||||||
if (self._downloader.params.get('forcedescription', False) and
|
|
||||||
'description' in video_info):
|
|
||||||
video_description = video_info['description']
|
|
||||||
|
|
||||||
url_map = video_info['video_urls']
|
url_map = video_info['video_urls']
|
||||||
if len(url_map.keys()) > 0:
|
if len(url_map.keys()) > 0:
|
||||||
@ -2903,6 +2919,9 @@ if __name__ == '__main__':
|
|||||||
filesystem.add_option('--no-mtime',
|
filesystem.add_option('--no-mtime',
|
||||||
action='store_false', dest='updatetime',
|
action='store_false', dest='updatetime',
|
||||||
help='do not use the Last-modified header to set the file modification time', default=True)
|
help='do not use the Last-modified header to set the file modification time', default=True)
|
||||||
|
filesystem.add_option('--write-description',
|
||||||
|
action='store_true', dest='writedescription',
|
||||||
|
help='write video description to a .description file', default=False)
|
||||||
parser.add_option_group(filesystem)
|
parser.add_option_group(filesystem)
|
||||||
|
|
||||||
postproc = optparse.OptionGroup(parser, 'Post-processing Options')
|
postproc = optparse.OptionGroup(parser, 'Post-processing Options')
|
||||||
@ -3040,6 +3059,7 @@ if __name__ == '__main__':
|
|||||||
'consoletitle': opts.consoletitle,
|
'consoletitle': opts.consoletitle,
|
||||||
'nopart': opts.nopart,
|
'nopart': opts.nopart,
|
||||||
'updatetime': opts.updatetime,
|
'updatetime': opts.updatetime,
|
||||||
|
'writedescription': opts.writedescription,
|
||||||
})
|
})
|
||||||
fd.add_info_extractor(youtube_search_ie)
|
fd.add_info_extractor(youtube_search_ie)
|
||||||
fd.add_info_extractor(youtube_pl_ie)
|
fd.add_info_extractor(youtube_pl_ie)
|
||||||
|
Loading…
Reference in New Issue
Block a user