mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-25 11:41:52 +00:00
Make the file timestamp feature optional
This commit is contained in:
parent
09bd408c28
commit
e30189021d
1 changed files with 26 additions and 8 deletions
34
youtube-dl
34
youtube-dl
|
@ -283,6 +283,7 @@ class FileDownloader(object):
|
||||||
logtostderr: Log messages to stderr instead of stdout.
|
logtostderr: Log messages to stderr instead of stdout.
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
params = None
|
params = None
|
||||||
|
@ -461,6 +462,23 @@ class FileDownloader(object):
|
||||||
except (IOError, OSError), err:
|
except (IOError, OSError), err:
|
||||||
self.trouble(u'ERROR: unable to rename file')
|
self.trouble(u'ERROR: unable to rename file')
|
||||||
|
|
||||||
|
def try_utime(self, filename, last_modified_hdr):
|
||||||
|
"""Try to set the last-modified time of the given file."""
|
||||||
|
if last_modified_hdr is None:
|
||||||
|
return
|
||||||
|
if not os.path.isfile(filename):
|
||||||
|
return
|
||||||
|
timestr = last_modified_hdr
|
||||||
|
if timestr is None:
|
||||||
|
return
|
||||||
|
filetime = timeconvert(timestr)
|
||||||
|
if filetime is None:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
os.utime(filename,(time.time(), filetime))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
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)
|
||||||
|
@ -757,15 +775,11 @@ class FileDownloader(object):
|
||||||
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)
|
||||||
|
|
||||||
# Update file modification time
|
# Update file modification time
|
||||||
timestr = data.info().get('last-modified', None)
|
if self.params.get('updatetime', True):
|
||||||
if timestr is not None:
|
self.try_utime(filename, data.info().get('last-modified', None))
|
||||||
filetime = timeconvert(timestr)
|
|
||||||
if filetime is not None:
|
|
||||||
try:
|
|
||||||
os.utime(filename,(time.time(), filetime))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class InfoExtractor(object):
|
class InfoExtractor(object):
|
||||||
|
@ -2439,6 +2453,9 @@ if __name__ == '__main__':
|
||||||
dest='cookiefile', metavar='FILE', help='file to dump cookie jar to')
|
dest='cookiefile', metavar='FILE', help='file to dump cookie jar to')
|
||||||
filesystem.add_option('--no-part',
|
filesystem.add_option('--no-part',
|
||||||
action='store_true', dest='nopart', help='do not use .part files', default=False)
|
action='store_true', dest='nopart', help='do not use .part files', default=False)
|
||||||
|
filesystem.add_option('--no-mtime',
|
||||||
|
action='store_false', dest='updatetime',
|
||||||
|
help='do not use the Last-modified header to set the file modification time', default=True)
|
||||||
parser.add_option_group(filesystem)
|
parser.add_option_group(filesystem)
|
||||||
|
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
@ -2563,6 +2580,7 @@ if __name__ == '__main__':
|
||||||
'logtostderr': opts.outtmpl == '-',
|
'logtostderr': opts.outtmpl == '-',
|
||||||
'consoletitle': opts.consoletitle,
|
'consoletitle': opts.consoletitle,
|
||||||
'nopart': opts.nopart,
|
'nopart': opts.nopart,
|
||||||
|
'updatetime': opts.updatetime,
|
||||||
})
|
})
|
||||||
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 a new issue