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()
def download_any(request): link = request.GET.get('link') name = request.GET.get('name') dl = UTorrentDL() dl.get(link, dump_dir) request = UTorrentConn("127.0.0.1:2219", "Boyshouse", "nickc") torrents = request.gettorrs() for torrent in torrents: if torrent.name == name: request.setprop("label", "Dump-" + torrent.hash, torrent.hash) return HttpResponse()
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"
def update(request): utorr = UTorrentConn("127.0.0.1:2219", "Boyshouse", "nickc") torrs = utorr.gettorrs() return render_to_response('dashboard/update.html', {'torrs' : torrs[:4]})
def utorrent(request): utorr = UTorrentConn(settings.utorrent_host, settings.utorrent_user, settings.utorrent_password) torrs = utorr.gettorrs() return render_to_response('dashboard/utorrent.html', {'torrs' : torrs})
def cleanup(self): request = UTorrentConn("127.0.0.1:2219", "Boyshouse", "nickc") request.stop(self.dl_hash) self.downloading = False self.path = "pending" self.save()