aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2011-01-28 19:59:18 +0100
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>2011-01-28 19:59:18 +0100
commite30189021db82c98019a9c055b9d81e4a7417b81 (patch)
tree497e9785794c7358ffd5c86794c31e81ac42579c
parent09bd408c284771224db5665d937b62d6c36759fb (diff)
Make the file timestamp feature optional
-rwxr-xr-xyoutube-dl34
1 files changed, 26 insertions, 8 deletions
diff --git a/youtube-dl b/youtube-dl
index e28788e3c..05869004b 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -283,6 +283,7 @@ class FileDownloader(object):
logtostderr: Log messages to stderr instead of stdout.
consoletitle: Display progress in console window's titlebar.
nopart: Do not use temporary .part files.
+ updatetime: Use the Last-modified header to set output file timestamps.
"""
params = None
@@ -460,6 +461,23 @@ class FileDownloader(object):
os.rename(old_filename, new_filename)
except (IOError, OSError), err:
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):
"""Report destination filename."""
@@ -757,15 +775,11 @@ class FileDownloader(object):
if data_len is not None and byte_counter != data_len:
raise ContentTooShortError(byte_counter, long(data_len))
self.try_rename(tmpfilename, filename)
+
# Update file modification time
- timestr = data.info().get('last-modified', None)
- if timestr is not None:
- filetime = timeconvert(timestr)
- if filetime is not None:
- try:
- os.utime(filename,(time.time(), filetime))
- except:
- pass
+ if self.params.get('updatetime', True):
+ self.try_utime(filename, data.info().get('last-modified', None))
+
return True
class InfoExtractor(object):
@@ -2439,6 +2453,9 @@ if __name__ == '__main__':
dest='cookiefile', metavar='FILE', help='file to dump cookie jar to')
filesystem.add_option('--no-part',
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)
(opts, args) = parser.parse_args()
@@ -2563,6 +2580,7 @@ if __name__ == '__main__':
'logtostderr': opts.outtmpl == '-',
'consoletitle': opts.consoletitle,
'nopart': opts.nopart,
+ 'updatetime': opts.updatetime,
})
fd.add_info_extractor(youtube_search_ie)
fd.add_info_extractor(youtube_pl_ie)