Changeset 6f7770


Ignore:
Timestamp:
02/23/2012 12:49:54 AM (13 years ago)
Author:
Calum Lind <calumlind+deluge@gmail.com>
Branches:
2.0.x, develop, master
Children:
8452b63
Parents:
2b01ba
git-author:
Thomas Hipp <thomashipp@googlemail.com> (02/22/2012 05:44:00 PM)
git-committer:
Calum Lind <calumlind+deluge@gmail.com> (02/23/2012 12:49:54 AM)
Message:

Magnet link support in autoadd plugin

Check the watch folders for .magnet files which contain valid magnet links
and add them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py

    r2b01ba r6f7770  
    162162        component.get("EventManager").emit(AutoaddOptionsChangedEvent())
    163163
    164     def load_torrent(self, filename):
     164    def load_torrent(self, filename, magnet):
    165165        try:
    166166            log.debug("Attempting to open %s for add.", filename)
    167             _file = open(filename, "rb")
     167            if magnet == False:
     168                _file = open(filename, "rb")
     169            elif magnet == True:
     170                _file = open(filename, "r")
    168171            filedump = _file.read()
    169172            if not filedump:
     
    175178
    176179        # Get the info to see if any exceptions are raised
    177         lt.torrent_info(lt.bdecode(filedump))
     180        if magnet == False:
     181            lt.torrent_info(lt.bdecode(filedump))
    178182
    179183        return filedump
     
    216220                # Skip directories
    217221                continue
    218             elif os.path.splitext(filename)[1] == ".torrent":
     222            else:
     223                ext = os.path.splitext(filename)[1]
     224                if ext == ".torrent":
     225                    magnet = False
     226                elif ext == ".magnet":
     227                    magnet = True
     228                else:
     229                    continue
    219230                try:
    220                     filedump = self.load_torrent(filepath)
     231                    filedump = self.load_torrent(filepath, magnet)
    221232                except (RuntimeError, Exception), e:
    222233                    # If the torrent is invalid, we keep track of it so that we
     
    238249
    239250                # The torrent looks good, so lets add it to the session.
    240                 torrent_id = component.get("TorrentManager").add(
    241                     filedump=filedump, filename=filename, options=opts,
    242                     owner=watchdir.get("owner", "localclient")
    243                 )
     251                if magnet == False:
     252                    torrent_id = component.get("TorrentManager").add(
     253                        filedump=filedump, filename=filename, options=opts,
     254                        owner=watchdir.get("owner", "localclient")
     255                    )
     256                elif magnet == True:
     257                    torrent_id = component.get("TorrentManager").add(
     258                        magnet=filedump, options=opts,
     259                        owner=watchdir.get("owner", "localclient")
     260                    )
    244261                # If the torrent added successfully, set the extra options.
    245262                if torrent_id:
     
    255272                        else:
    256273                            component.get("TorrentManager").queue_bottom(torrent_id)
     274                else:
     275                    # torrent handle is invalid and so is the magnet link
     276                    if magnet == True:
     277                        log.debug("invalid magnet link")
     278                        os.rename(filepath, filepath + ".invalid")
     279                        continue
    257280
    258281                # Rename, copy or delete the torrent once added to deluge.
Note: See TracChangeset for help on using the changeset viewer.