Downloads the content at url to download folder :param url: :param get: :param post: :param ref: :param cookies: :param disposition: if True and server provides content-disposition header\ the filename will be changed if needed :return
(self, url, get={}, post={}, ref=True, cookies=True, disposition=False)
| 457 | return res |
| 458 | |
| 459 | def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=False): |
| 460 | """Downloads the content at url to download folder |
| 461 | |
| 462 | :param url: |
| 463 | :param get: |
| 464 | :param post: |
| 465 | :param ref: |
| 466 | :param cookies: |
| 467 | :param disposition: if True and server provides content-disposition header\ |
| 468 | the filename will be changed if needed |
| 469 | :return: The location where the file was saved |
| 470 | """ |
| 471 | |
| 472 | self.checkForSameFiles() |
| 473 | |
| 474 | self.pyfile.setStatus("downloading") |
| 475 | |
| 476 | download_folder = self.config['general']['download_folder'] |
| 477 | |
| 478 | location = save_join(download_folder, self.pyfile.package().folder) |
| 479 | |
| 480 | if not exists(location): |
| 481 | makedirs(location, int(self.core.config["permission"]["folder"], 8)) |
| 482 | |
| 483 | if self.core.config["permission"]["change_dl"] and os.name != "nt": |
| 484 | try: |
| 485 | uid = getpwnam(self.config["permission"]["user"])[2] |
| 486 | gid = getgrnam(self.config["permission"]["group"])[2] |
| 487 | |
| 488 | chown(location, uid, gid) |
| 489 | except Exception, e: |
| 490 | self.log.warning(_("Setting User and Group failed: %s") % str(e)) |
| 491 | |
| 492 | # convert back to unicode |
| 493 | location = fs_decode(location) |
| 494 | name = save_path(self.pyfile.name) |
| 495 | |
| 496 | filename = join(location, name) |
| 497 | |
| 498 | self.core.hookManager.dispatchEvent("downloadStarts", self.pyfile, url, filename) |
| 499 | |
| 500 | try: |
| 501 | newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies, |
| 502 | chunks=self.getChunkCount(), resume=self.resumeDownload, |
| 503 | progressNotify=self.pyfile.setProgress, disposition=disposition) |
| 504 | finally: |
| 505 | self.pyfile.size = self.req.size |
| 506 | |
| 507 | if disposition and newname and newname != name: #triple check, just to be sure |
| 508 | self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname}) |
| 509 | self.pyfile.name = newname |
| 510 | filename = join(location, newname) |
| 511 | |
| 512 | fs_filename = fs_encode(filename) |
| 513 | |
| 514 | if self.core.config["permission"]["change_file"]: |
| 515 | chmod(fs_filename, int(self.core.config["permission"]["file"], 8)) |
| 516 |
nothing calls this directly
no test coverage detected