Пример #1
0
    def pick_initial_filename(self, suffix=".part", torrent=False):
        """Pick a path to download to based on self.shortFilename.

        This method sets self.filename, as well as creates any leading
        paths needed to start downloading there.

        If the torrent flag is true, then the filename we're working
        with is utf-8 and shouldn't be transformed in any way.

        If the torrent flag is false, then the filename we're working
        with is ascii and needs to be transformed into something sane.
        (default)
        """
        download_dir = os.path.join(app.config.get(prefs.MOVIES_DIRECTORY),
                                    'Incomplete Downloads')
        # Create the download directory if it doesn't already exist.
        if not os.path.exists(download_dir):
            fileutil.makedirs(download_dir)
        filename = self.shortFilename + suffix
        if not torrent:
            # this is an ascii filename and needs to be fixed
            filename = clean_filename(filename)
        self.filename, fp = next_free_filename(
                                os.path.join(download_dir, filename))
        # We can close this object now the file's been created, I guess.
        # This will linger in the filesystem namespace, caller is responsible
        # for cleaning this up (which I think it does).
        fp.close()
Пример #2
0
 def calc_filename(self, redirected_url):
     try:
         disposition = self.headers['content-disposition']
     except KeyError:
         pass
     else:
         filename = self.find_value_from_header(disposition, 'filename')
         if filename is not None:
             return download_utils.clean_filename(filename)
     return download_utils.filename_from_url(util.unicodify(redirected_url),
                                             clean=True)
Пример #3
0
 def calc_filename(self, redirected_url):
     try:
         disposition = self.headers['content-disposition']
     except KeyError:
         pass
     else:
         filename = self.find_value_from_header(disposition, 'filename')
         if filename is not None:
             return download_utils.clean_filename(filename)
     return download_utils.filename_from_url(util.unicodify(redirected_url), 
             clean=True)
Пример #4
0
 def on_headers(self, info):
     if 'total-size' in info:
         self.totalSize = info['total-size']
     if not self.accept_download_size(self.totalSize):
         self.handle_error(_("Not enough disk space"),
             _("%(amount)s MB required to store this video") %
               {"amount": self.totalSize / (2 ** 20)})
         return
     # We should successfully download the file.  Reset retryCount
     # and accept defeat if we see an error.
     self.restartOnError = False
     # update shortFilename based on the headers.  This will affect
     # how we move the file once the download is finished
     self.shortFilename = clean_filename(info['filename'])
     if self.expectedContentType is not None:
         ext_content_type = self.expectedContentType
     else:
         ext_content_type = info.get('content-type')
     self.shortFilename = check_filename_extension(self.shortFilename,
             ext_content_type)
Пример #5
0
 def check_clean_filename(self, filename, test_against):
     self.assertEquals(download_utils.clean_filename(filename),
                       test_against)
Пример #6
0
 def check_clean_filename(self, filename, test_against):
     self.assertEquals(download_utils.clean_filename(filename),
                       test_against)