コード例 #1
0
    def set_utime(self, last_modified: str = None):
        """Sets the last modified and last activated time of a downloaded file

        Args:
            last_modified (str, optional): The last_modified header from the Webpage. Defaults to None.
        """

        try:
            if last_modified is not None:
                filetime = timeconvert(last_modified)
                if filetime is not None and filetime > 0:
                    os.utime(self.file.saved_to, (time.time(), filetime))
                    return

            if self.file.content_timemodified is not None and self.file.content_timemodified > 0:
                os.utime(self.file.saved_to,
                         (time.time(), self.file.content_timemodified))

        except Exception:
            logging.debug('T%s - Could not change utime', self.thread_id)
コード例 #2
0
 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(encodeFilename(filename)):
         return
     timestr = last_modified_hdr
     if timestr is None:
         return
     filetime = timeconvert(timestr)
     if filetime is None:
         return filetime
     # Ignore obviously invalid dates
     if filetime == 0:
         return
     try:
         os.utime(filename, (time.time(), filetime))
     except:
         pass
     return filetime
コード例 #3
0
ファイル: test_utils.py プロジェクト: Kyad/youtube-dl
 def test_timeconvert(self):
     self.assertTrue(timeconvert('') is None)
     self.assertTrue(timeconvert('bougrg') is None)
コード例 #4
0
 def test_timeconvert(self):
     self.assertTrue(timeconvert('') is None)
     self.assertTrue(timeconvert('bougrg') is None)
コード例 #5
0
ファイル: test_utils.py プロジェクト: egerlach/youtube-dl
 def test_timeconvert(self):
     self.assertTrue(timeconvert("") is None)
     self.assertTrue(timeconvert("bougrg") is None)