mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-07 09:57:16 +08:00
Set downloaded file's time stamp from last-modified header
This file stamp setting is very relaxed. If there's any problem along the way (no last-modified header, bad time string format, no time set privileges,...) or if nothing is downloaded (e.g. using resumed download but the file was already complete) then nothing is done.
This commit is contained in:
parent
9f7963468b
commit
40682e77d1
22
youtube-dl
22
youtube-dl
@ -6,6 +6,7 @@
|
||||
# Author: Vasyl' Vavrychuk
|
||||
# Author: Witold Baryluk
|
||||
# License: Public domain code
|
||||
import calendar
|
||||
import cookielib
|
||||
import ctypes
|
||||
import datetime
|
||||
@ -18,6 +19,7 @@ import netrc
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import rfc822
|
||||
import socket
|
||||
import string
|
||||
import StringIO
|
||||
@ -117,6 +119,17 @@ def sanitize_open(filename, open_mode):
|
||||
stream = open(filename, open_mode)
|
||||
return (stream, filename)
|
||||
|
||||
def timeconvert(timestr):
|
||||
"""Convert RFC 2822-defined time string into system timestamp"""
|
||||
timestamp = None
|
||||
timetuple = rfc822.parsedate_tz(timestr)
|
||||
if timetuple is not None:
|
||||
timestamp = calendar.timegm(timetuple)
|
||||
# adjust time if there's a time zone
|
||||
if timetuple[9] is not None:
|
||||
timestamp -= timetuple[9]
|
||||
return timestamp
|
||||
|
||||
class DownloadError(Exception):
|
||||
"""Download Error exception.
|
||||
|
||||
@ -748,6 +761,15 @@ 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
|
||||
return True
|
||||
|
||||
class InfoExtractor(object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user