import cookielib
import ctypes
import datetime
+import email.utils
import gzip
import htmlentitydefs
import httplib
stream = open(filename, open_mode)
return (stream, filename)
+def timeconvert(timestr):
+ """Convert RFC 2822 defined time string into system timestamp"""
+ timestamp = None
+ timetuple = email.utils.parsedate_tz(timestr)
+ if timetuple is not None:
+ timestamp = email.utils.mktime_tz(timetuple)
+ return timestamp
+
class DownloadError(Exception):
"""Download Error exception.
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
return True
class InfoExtractor(object):