mirror of
https://github.com/l1ving/youtube-dl
synced 2025-01-24 22:43:08 +08:00
added option to write downloaded data to STDOUT instead of a file
This commit is contained in:
parent
053419cd24
commit
a59c25bc63
21
youtube-dl
21
youtube-dl
@ -444,8 +444,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
|
||||||
@ -870,7 +871,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
|
||||||
|
|
||||||
@ -887,7 +888,7 @@ class FileDownloader(object):
|
|||||||
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
|
||||||
@ -969,6 +970,9 @@ class FileDownloader(object):
|
|||||||
|
|
||||||
# Open file just in time
|
# Open file just in time
|
||||||
if stream is None:
|
if stream is None:
|
||||||
|
if self.params.get('writetostdout', True):
|
||||||
|
stream = sys.stdout
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
(stream, tmpfilename) = sanitize_open(tmpfilename, open_mode)
|
(stream, tmpfilename) = sanitize_open(tmpfilename, open_mode)
|
||||||
assert stream is not None
|
assert stream is not None
|
||||||
@ -999,7 +1003,8 @@ 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):
|
||||||
|
stream.close() # if we're using stdout, it was already open
|
||||||
self.report_finish()
|
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))
|
||||||
@ -3825,6 +3830,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,
|
||||||
@ -3974,7 +3982,7 @@ def 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,
|
||||||
@ -4012,6 +4020,7 @@ def 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user