1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2025-05-05 21:27:31 +00:00

Merge 96cf6898facb1f91945fe83b9172531d5e7d210a into 849edab8ec4fed42f131285b66235b26c78a2d1a

This commit is contained in:
GitHub Merge Button 2011-11-24 09:06:23 -08:00
commit 3b2660d34c

View File

@ -447,8 +447,9 @@ 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 writedescription: Write the video description to a .description file.
writeinfojson: Write the video description to a .info.json file writeinfojson: Write the video description to a .info.json file.
writetostdout: Write downloaded video to stdout.
""" """
params = None params = None
@ -873,7 +874,7 @@ class FileDownloader(object):
player_url = info_dict.get('player_url', None) player_url = info_dict.get('player_url', None)
# Check file already present # Check file already present
if self.params.get('continuedl', False) and os.path.isfile(filename) and not self.params.get('nopart', False): if self.params.get('writetostdout', False) and self.params.get('continuedl', False) and os.path.isfile(filename) and not self.params.get('nopart', False):
self.report_file_already_downloaded(filename) self.report_file_already_downloaded(filename)
return True return True
@ -888,9 +889,9 @@ class FileDownloader(object):
headers = {'Youtubedl-no-compression': 'True'} headers = {'Youtubedl-no-compression': 'True'}
basic_request = urllib2.Request(url, None, headers) basic_request = urllib2.Request(url, None, headers)
request = urllib2.Request(url, None, headers) request = urllib2.Request(url, None, headers)
# Establish possible resume length # Establish possible resume length
if os.path.isfile(tmpfilename): if self.params.get('writetostdout', False) and os.path.isfile(tmpfilename):
resume_len = os.path.getsize(tmpfilename) resume_len = os.path.getsize(tmpfilename)
else: else:
resume_len = 0 resume_len = 0
@ -972,14 +973,17 @@ class FileDownloader(object):
# Open file just in time # Open file just in time
if stream is None: if stream is None:
try: if self.params.get('writetostdout', True):
(stream, tmpfilename) = sanitize_open(tmpfilename, open_mode) stream = sys.stdout
assert stream is not None else:
filename = self.undo_temp_name(tmpfilename) try:
self.report_destination(filename) (stream, tmpfilename) = sanitize_open(tmpfilename, open_mode)
except (OSError, IOError), err: assert stream is not None
self.trouble(u'ERROR: unable to open for writing: %s' % str(err)) filename = self.undo_temp_name(tmpfilename)
return False self.report_destination(filename)
except (OSError, IOError), err:
self.trouble(u'ERROR: unable to open for writing: %s' % str(err))
return False
try: try:
stream.write(data_block) stream.write(data_block)
except (IOError, OSError), err: except (IOError, OSError), err:
@ -1002,8 +1006,9 @@ class FileDownloader(object):
if stream is None: if stream is None:
self.trouble(u'\nERROR: Did not get any data blocks') self.trouble(u'\nERROR: Did not get any data blocks')
return False return False
stream.close() if self.params.get('writetostdout', False):
self.report_finish() stream.close() # if we're using stdout, it was already open
self.report_finish()
if data_len is not None and byte_counter != data_len: if data_len is not None and byte_counter != data_len:
raise ContentTooShortError(byte_counter, long(data_len)) raise ContentTooShortError(byte_counter, long(data_len))
self.try_rename(tmpfilename, filename) self.try_rename(tmpfilename, filename)
@ -4075,6 +4080,9 @@ def parseOpts():
filesystem.add_option('--write-info-json', filesystem.add_option('--write-info-json',
action='store_true', dest='writeinfojson', action='store_true', dest='writeinfojson',
help='write video metadata to a .info.json file', default=False) help='write video metadata to a .info.json file', default=False)
filesystem.add_option('--stdout',
action='store_true', dest='writetostdout',
help='write video to STDOUT', default=False)
postproc.add_option('--extract-audio', action='store_true', dest='extractaudio', default=False, postproc.add_option('--extract-audio', action='store_true', dest='extractaudio', default=False,
@ -4227,7 +4235,7 @@ def _real_main():
'usenetrc': opts.usenetrc, 'usenetrc': opts.usenetrc,
'username': opts.username, 'username': opts.username,
'password': opts.password, 'password': opts.password,
'quiet': (opts.quiet or opts.geturl or opts.gettitle or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat), 'quiet': (opts.quiet or opts.geturl or opts.gettitle or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.writetostdout),
'forceurl': opts.geturl, 'forceurl': opts.geturl,
'forcetitle': opts.gettitle, 'forcetitle': opts.gettitle,
'forcethumbnail': opts.getthumbnail, 'forcethumbnail': opts.getthumbnail,
@ -4265,6 +4273,7 @@ def _real_main():
'writeinfojson': opts.writeinfojson, 'writeinfojson': opts.writeinfojson,
'matchtitle': opts.matchtitle, 'matchtitle': opts.matchtitle,
'rejecttitle': opts.rejecttitle, 'rejecttitle': opts.rejecttitle,
'writetostdout': opts.writetostdout
}) })
for extractor in extractors: for extractor in extractors:
fd.add_info_extractor(extractor) fd.add_info_extractor(extractor)