示例#1
0
    def rename(self):
        request = UTorrentConn("127.0.0.1:2219", "Boyshouse", "nickc")
        torr = request.getbyhash(self.dl_hash)
        if torr == None:
            print "no hash " + self.name
            return

        filename = request.getfilename(self.dl_hash)
        dir = os.path.abspath(torr.dir)
        (root, ext) = os.path.splitext(filename)

        try:
            os.rename(dir + "\\" + filename, self.getDir() + "/" + self.getFileName() + ext)
        except Exception as e:
            print dir + "\\" + filename
            print self.getDir() + "/" + self.getFileName() + ext
            print e
            return
        request.remove(self.dl_hash)
        self.path = self.getDir() + "/" + self.getFileName() + ext

        # If in dir (e.g. dir exists in "Season" folder), remove dir
        for file in os.listdir(self.getDir()):
            if os.path.isdir(self.getDir() + "/" + file):
                try:
                    shutil.rmtree(self.getDir() + "/" + file)
                except:
                    pass

        self.dl_hash = ""
        self.save()
示例#2
0
    def download(self, link, name):
        if not os.path.exists(self.getDir()):
            os.mkdir(self.getDir())

        if os.path.isfile(self.path):
            os.remove(self.path)

        dl = UTorrentDL()
        dl.get(link, self.getDir())

        request = UTorrentConn("127.0.0.1:2219", "Boyshouse", "nickc")
        torrents = request.gettorrs()
        for torrent in torrents:
            # print torrent.name
            # print name
            if torrent.name == name:
                # Check if it is a .rar
                error = True
                while error:
                    try:
                        filename = request.getfilename(torrent.hash)
                    except:
                        continue
                    error = False
                # print filename
                # print 'hi'
                ext = os.path.splitext(filename)[1]
                # print ext
                if ext == ".rar" or fnmatch.fnmatch(ext, ".r[0-9][0-9]"):
                    request.removedata(torrent.hash)
                    request.remove(torrent.hash)
                    return False

                error = True
                while error:
                    try:
                        request.setprop("label", str(self.id), torrent.hash)
                    except:
                        continue
                    error = False

                self.dl_hash = torrent.hash
                self.downloading = True
                self.save()
                return True
        print "Did not find torrent"