Example #1
0
    def process(self, filename, filecontent, sizemin, sizemax):
        """Final processing for a remote fetch

            Steps involved in processing:
            1.  Verifies that 'filecontent' is a valid bencoded file
            2.  Checks that the size is correct
            3.  Check that the path 'torrents/<filename>' doesn't exist
            4.  Write file to path
            5.  Tells rtorrent to load the file

            Errors / Resolution:
            1.  exit
            2.  renames file by prepending a random string ==> continue
        """
        try:
            bencoded = bencode.bdecode(filecontent)
        except bencode.BTL.BTFailure:
            self._log.error("Error in remote handler '%s': not a valid bencoded string", self.settings.name)
            logging.error("Error in remote handler '%s'\n%s", self.settings.name, traceback.format_exc())
            open("test.torrent", "w").write(filecontent)
            return

        length = self._getTorrentSize(bencoded)
        if sizemax and length > sizemax:
            return
        elif sizemin and length < sizemin:
            return

        target_p = os.path.join("torrents", filename)
        if os.path.exists(target_p):
            # rename
            prepend = "".join([random.choice(string.letters) for x in range(10)])
            filename = "%s-%s" % (prepend, filename)
        open("torrents/%s" % (filename), "wb").write(filecontent)
        self._ajax.load_from_remote(filename, self.settings.name, start=True)
Example #2
0
    def process(self, filename, filecontent, sizemin, sizemax):
        """Final processing for a remote fetch

            Steps involved in processing:
            1.  Verifies that 'filecontent' is a valid bencoded file
            2.  Checks that the size is correct
            3.  Check that the path 'torrents/<filename>' doesn't exist
            4.  Write file to path
            5.  Tells rtorrent to load the file

            Errors / Resolution:
            1.  exit
            2.  renames file by prepending a random string ==> continue
        """
        try:
            bencoded = bencode.bdecode(filecontent)
        except bencode.BTL.BTFailure:
            self._log.error("Error in remote handler '%s': not a valid bencoded string", self.settings.name)
            logging.error("Error in remote handler '%s'\n%s", self.settings.name, traceback.format_exc())
            open("test.torrent", "w").write(filecontent)
            return

        length = self._getTorrentSize(bencoded)
        if sizemax and length > sizemax:
            return
        elif sizemin and length < sizemin:
            return

        target_p = os.path.join("torrents", filename)
        if os.path.exists(target_p):
            # rename
            prepend = "".join([random.choice(string.letters) for x in range(10)])
            filename = "%s-%s" % (prepend, filename)
        open("torrents/%s" % (filename), "wb").write(filecontent)
        self._ajax.load_from_remote(filename, self.settings.name, start=True)
Example #3
0
    def fetch_torrent_rss(self, ID, alias, link, sizelim):
        lnk = urllib2.urlopen(link)
        # get filename if offered, else generate random filename
        try:
            filename = lnk.info()['Content-Disposition'].split(
                "filename=\"")[1][:-1]
        except:
            filename = "".join(
                [random.choice(string.letters)
                 for x in range(20)]) + ".torrent"

        linkcontent = lnk.read()
        # check valid torrent file
        try:
            bencoded = bencode.bdecode(linkcontent)
        except bencode.BTL.BTFailure:
            self.log(
                "error",
                "Error downloading from RSS feed (id: %s, alias: %s) - not a valid bencoded string",
                ID, alias)
            open("rss.test.torrent", "w").write(linkcontent)
            return

        # check size limits
        if sizelim[0] and sizelim[0] == 0:
            sizelim[0] = None
        if sizelim[1] and sizelim[1] == 0:
            sizelim[1] = None

        size_lower, size_upper = sizelim

        length = self._getTorrentSize(bencoded)
        if size_upper and length > size_upper:
            return
        elif size_lower and length < size_lower:
            return

        target_p = os.path.join("torrents", filename)
        if os.path.exists(target_p):
            prepend = "".join(
                [random.choice(string.letters) for x in range(5)])
            filename = "%s-%s" % (prepend, filename)
        open("torrents/%s" % (filename), "wb").write(linkcontent)
        self.ajax.load_from_rss(filename, alias, ID, start=True)
Example #4
0
 def fetch_torrent_rss(self, ID, alias, link, sizelim):
     lnk = urllib2.urlopen(link)
     #get filename if offered, else generate random filename
     try:
         filename = lnk.info()['Content-Disposition'].split("filename=\"")[1][:-1]
     except:
         filename = "".join([random.choice(string.letters) for x in range(20)]) + ".torrent"
         
     linkcontent = lnk.read()
     #check valid torrent file
     try:
         bencoded = bencode.bdecode(linkcontent)
     except bencode.BTL.BTFailure:
         self.log("error", "Error downloading from RSS feed (id: %s, alias: %s) - not a valid bencoded string", ID, alias)
         open("rss.test.torrent","w").write(linkcontent)
         return
     
     #check size limits
     if sizelim[0] and sizelim[0] == 0:
         sizelim[0] = None
     if sizelim[1] and sizelim[1] == 0:
         sizelim[1] = None
         
     size_upper, size_lower = sizelim
         
     length = self._getTorrentSize(bencoded)
     if size_upper and length > size_upper:
         return
     elif size_lower and length < size_lower:
         return
     
     target_p = os.path.join("torrents", filename)
     if os.path.exists(target_p):
         prepend = "".join([random.choice(string.letters) for x in range(5)])
         filename = "%s-%s" % (prepend, filename)
     open("torrents/%s" % (filename), "wb").write(linkcontent)
     self.ajax.load_from_rss(filename, alias, ID, start=True)