Exemple #1
0
    def torrents_file_priority(self,
                               hash=None,
                               file_ids=None,
                               priority=None,
                               **kwargs):
        """
        Set priority for one or more files. (alias: torrents_filePrio)

        Exceptions:
            InvalidRequest400 if priority is invalid or at least one file ID is not an integer
            NotFound404
            Conflict409 if torrent metadata has not finished downloading or at least one file was not found
        :param hash: hash for torrent
        :param file_ids: single file ID or a list. See
        :param priority: priority for file(s)
            Properties: https://github.com/qbittorrent/qBittorrent/wiki/Web-API-Documentation#set-file-priority
        :return:
        """
        data = {
            'hash': hash,
            'id': list2string(file_ids, "|"),
            'priority': priority
        }
        self._post(_name=APINames.Torrents,
                   _method='filePrio',
                   data=data,
                   **kwargs)
Exemple #2
0
    def search_start(self,
                     pattern=None,
                     plugins=None,
                     category=None,
                     **kwargs):
        """
        Start a search. Python must be installed. Host may limit nuber of concurrent searches.

        Exceptions:
            Conflict409Error

        :param pattern: term to search for
        :param plugins: list of plugins to use for searching (supports 'all' and 'enabled')
        :param category: categories to limit search; dependent on plugins. (supports 'all')
        :return: ID of search job
        """
        data = {
            'pattern': pattern,
            'plugins': list2string(plugins, '|'),
            'category': category
        }
        return self._post(_name=APINames.Search,
                          _method='start',
                          data=data,
                          **kwargs)
Exemple #3
0
    def torrents_download_limit(self, hashes=None, **kwargs):
        """
        Retrieve the download limit for one or more torrents. (alias: torrents_downloadLimit)

        :return: dictioanry {hash: limit} (-1 represents no limit)
        """
        data = {'hashes': list2string(hashes, "|")}
        return self._post(_name=APINames.Torrents,
                          _method='downloadLimit',
                          data=data,
                          **kwargs)
Exemple #4
0
 def torrents_toggle_first_last_piece_priority(self, hashes=None, **kwargs):
     """
     Toggle priority of first/last piece downloading. (alias: torrents_toggleFirstLastPiecePrio)
     :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
     :return: None
     """
     data = {'hashes': list2string(hashes, '|')}
     self._post(_name=APINames.Torrents,
                _method='toggleFirstLastPiecePrio',
                data=data,
                **kwargs)
Exemple #5
0
    def torrents_toggle_sequential_download(self, hashes=None, **kwargs):
        """
        Toggle sequential download for one or more torrents. (alias: torrents_toggleSequentialDownload)

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :return: None
        """
        data = {'hashes': list2string(hashes)}
        self._post(_name=APINames.Torrents,
                   _method='toggleSequentialDownload',
                   data=data,
                   **kwargs)
Exemple #6
0
    def torrents_remove_categories(self, categories=None, **kwargs):
        """
        Delete one or more categories. (alias: torrents_removeCategories)

        :param categories: categories to delete
        :return: None
        """
        data = {'categories': list2string(categories, '\n')}
        self._post(_name=APINames.Torrents,
                   _method='removeCategories',
                   data=data,
                   **kwargs)
Exemple #7
0
    def torrents_recheck(self, hashes=None, **kwargs):
        """
        Recheck a torrent in qBittorrent.

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :return: None
        """
        data = {'hashes': list2string(hashes, '|')}
        self._post(_name=APINames.Torrents,
                   _method='recheck',
                   data=data,
                   **kwargs)
    def transfer_ban_peers(self, peers=None, **kwargs):
        """
        Ban one or more peers. (alias: transfer_banPeers)

        :param peers: one or more peers to ban. each peer should take the form 'host:port'
        :return: None
        """
        data = {'peers': list2string(peers, '|')}
        self._post(_name=APINames.Transfer,
                   _method='banPeers',
                   data=data,
                   **kwargs)
Exemple #9
0
    def torrents_pause(self, hashes=None, **kwargs):
        """
        Pause one or more torrents in qBitorrent.

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :return: None
        """
        data = {'hashes': list2string(hashes, "|")}
        self._post(_name=APINames.Torrents,
                   _method='pause',
                   data=data,
                   **kwargs)
Exemple #10
0
    def search_install_plugin(self, sources=None, **kwargs):
        """
        Install search plugins from either URL or file. (alias: search_installPlugin)

        :param sources: list of URLs or filepaths
        :return: None
        """
        data = {'sources': list2string(sources, '|')}
        self._post(_name=APINames.Search,
                   _method='installPlugin',
                   data=data,
                   **kwargs)
Exemple #11
0
    def search_uninstall_plugin(self, sources=None, **kwargs):
        """
        Uninstall search plugins. (alias: search_uninstallPlugin)

        :param sources:
        :return: None
        """
        data = {'sources': list2string(sources, '|')}
        self._post(_name=APINames.Search,
                   _method='uninstallPlugin',
                   data=data,
                   **kwargs)
Exemple #12
0
    def torrents_upload_limit(self, hashes=None, **kwargs):
        """
        Retrieve the upload limit for onee or more torrents. (alias: torrents_uploadLimit)

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :return: dictionary of limits
        """
        data = {'hashes': list2string(hashes, '|')}
        return self._post(_name=APINames.Torrents,
                          _method='uploadLimit',
                          data=data,
                          **kwargs)
Exemple #13
0
    def torrents_set_upload_limit(self, limit=None, hashes=None, **kwargs):
        """
        Set the upload limit for one or more torrents. (alias: torrents_setUploadLimit)

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param limit: bytes/second (-1 sets the limit to infinity)
        :return: None
        """
        data = {'hashes': list2string(hashes, '|'), 'limit': limit}
        self._post(_name=APINames.Torrents,
                   _method='setUploadLimit',
                   data=data,
                   **kwargs)
Exemple #14
0
    def torrents_set_super_seeding(self, enable=None, hashes=None, **kwargs):
        """
        Set one or more torrents as super seeding. (alias: torrents_setSuperSeeding)

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param enable: True or False
        :return:
        """
        data = {'hashes': list2string(hashes, '|'), 'value': enable}
        self._post(_name=APINames.Torrents,
                   _method='setSuperSeeding',
                   data=data,
                   **kwargs)
Exemple #15
0
    def torrents_set_auto_management(self, enable=None, hashes=None, **kwargs):
        """
        Enable or disable automatic torrent management for one or more torrents. (alias: torrents_setAutoManagement)

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param enable: True or False
        :return: None
        """
        data = {'hashes': list2string(hashes, '|'), 'enable': enable}
        self._post(_name=APINames.Torrents,
                   _method='setAutoManagement',
                   data=data,
                   **kwargs)
Exemple #16
0
    def torrents_set_force_start(self, enable=None, hashes=None, **kwargs):
        """
        Force start one or more torrents. (alias: torrents_setForceStart)

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param enable: True or False (False makes this equivalent to torrents_resume())
        :return: None
        """
        data = {'hashes': list2string(hashes, '|'), 'value': enable}
        self._post(_name=APINames.Torrents,
                   _method='setForceStart',
                   data=data,
                   **kwargs)
Exemple #17
0
    def torrents_reannounce(self, hashes=None, **kwargs):
        """
        Reannounce a torrent.

        Note: torrents/reannounce not available web API version 2.0.2

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :return: None
        """
        data = {'hashes': list2string(hashes, '|')}
        self._post(_name=APINames.Torrents,
                   _method='reannounce',
                   data=data,
                   **kwargs)
Exemple #18
0
    def torrents_bottom_priority(self, hashes=None, **kwargs):
        """
        Set torrent as highest priority. Torrent Queuing must be enabled. (alias: torrents_bottomPrio)

        Exceptions:
            Conflict409

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :return: None
        """
        data = {'hashes': list2string(hashes, '|')}
        self._post(_name=APINames.Torrents,
                   _method='bottomPrio',
                   data=data,
                   **kwargs)
Exemple #19
0
    def torrents_add_trackers(self, hash=None, urls=None, **kwargs):
        """
        Add trackers to a torrent. (alias: torrents_addTrackers)

        Exceptions:
            NotFound404Error

        :param hash: hash for torrent
        :param urls: tracker urls to add to torrent
        :return: None
        """
        data = {'hash': hash, 'urls': list2string(urls, '\n')}
        self._post(_name=APINames.Torrents,
                   _method='addTrackers',
                   data=data,
                   **kwargs)
Exemple #20
0
    def torrents_delete(self, delete_files=None, hashes=None, **kwargs):
        """
        Remove a torrent from qBittorrent and optionally delete its files.

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param delete_files: Truw to delete the torrent's files
        :return: None
        """
        data = {
            'hashes': list2string(hashes, '|'),
            'deleteFiles': delete_files
        }
        self._post(_name=APINames.Torrents,
                   _method='delete',
                   data=data,
                   **kwargs)
Exemple #21
0
    def torrents_set_category(self, category=None, hashes=None, **kwargs):
        """
        Set a category for one or more torrents. (alias: torrents_setCategory)

        Exceptions:
            Conflict409 for bad category

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param category: category to assign to torrent
        :return: None
        """
        data = {'hashes': list2string(hashes, '|'), 'category': category}
        self._post(_name=APINames.Torrents,
                   _method='setCategory',
                   data=data,
                   **kwargs)
Exemple #22
0
    def torrents_set_location(self, location=None, hashes=None, **kwargs):
        """
        Set location for torrents's files. (alias: torrents_setLocation)

        Exceptions:
            Unauthorized403 if the user doesn't have permissions to write to the location
            Conflict409 if the directory cannot be created at the location

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param location: disk location to move torrent's files
        :return: None
        """
        data = {'hashes': list2string(hashes, '|'), 'location': location}
        self._post(_name=APINames.Torrents,
                   _method='setLocation',
                   data=data,
                   **kwargs)
Exemple #23
0
    def torrents_remove_trackers(self, hash=None, urls=None, **kwargs):
        """
        Remove trackers from a torrent. (alias: torrents_removeTrackers)

        Exceptions:
            NotFound404Error
            Conflict409Error

        :param hash: hash for torrent
        :param urls: tracker urls to removed from torrent
        :return: None
        """
        data = {'hash': hash, 'urls': list2string(urls, '|')}
        self._post(_name=APINames.Torrents,
                   _method='removeTrackers',
                   data=data,
                   **kwargs)
Exemple #24
0
    def torrents_set_share_limits(self,
                                  ratio_limit=None,
                                  seeding_time_limit=None,
                                  hashes=None,
                                  **kwargs):
        """
        Set share limits for one or more torrents.

        :param hashes: single torrent hash or list of torrent hashes. Or 'all' for all torrents.
        :param ratio_limit: max ratio to seed a torrent. (-2 means use the global value and -1 is no limit)
        :param seeding_time_limit: minutes (-2 means use the global value and -1 is no limit_
        :return: None
        """
        data = {
            'hashes': list2string(hashes, "|"),
            'ratioLimit': ratio_limit,
            'seedingTimeLimit': seeding_time_limit
        }
        self._post(_name=APINames.Torrents,
                   _method='setShareLimits',
                   data=data,
                   **kwargs)
Exemple #25
0
    def torrents_info(self,
                      status_filter=None,
                      category=None,
                      sort=None,
                      reverse=None,
                      limit=None,
                      offset=None,
                      hashes=None,
                      **kwargs):
        """
        Retrieves list of info for torrents.

        Note: hashes is available starting web API version 2.0.1

        :param status_filter: Filter list by all, downloading, completed, paused, active, inactive, resumed
        :param category: Filter list by category
        :param sort: Sort list by any property returned
        :param reverse: Reverse sorting
        :param limit: Limit length of list
        :param offset: Start of list (if <0, offset from end of list)
        :param hashes: Filter list by hash (seperate multiple hashes with a '|')
        :return: List of torrents
            Properties: https://github.com/qbittorrent/qBittorrent/wiki/Web-API-Documentation#get-torrent-list
        """
        parameters = {
            'filter': status_filter,
            'category': category,
            'sort': sort,
            'reverse': reverse,
            'limit': limit,
            'offset': offset,
            'hashes': list2string(hashes, '|')
        }
        return self._get(_name=APINames.Torrents,
                         _method='info',
                         params=parameters,
                         **kwargs)
Exemple #26
0
    def torrents_add(self,
                     urls=None,
                     torrent_files=None,
                     save_path=None,
                     cookie=None,
                     category=None,
                     is_skip_checking=None,
                     is_paused=None,
                     is_root_folder=None,
                     rename=None,
                     upload_limit=None,
                     download_limit=None,
                     use_auto_torrent_management=None,
                     is_sequential_download=None,
                     is_first_last_piece_priority=None,
                     **kwargs):
        """
        Add one or more torrents by URLs and/or torrent files.

        Exceptions:
            UnsupportedMediaType415Error if file is not a valid torrent file
            FileNotFoundError if a torrent file doesn't exist
            PermissionError if read permission is denied to torrent file

        :param urls: List of URLs (http://, https://, magnet: and bc://bt/)
        :param torrent_files: list of torrent files
        :param save_path: location to save the torrent data
        :param cookie: cookie to retrieve torrents by URL
        :param category: category to assign to torrent(s)
        :param is_skip_checking: skip hash checking
        :param is_paused: True to start torrent(s) paused
        :param is_root_folder: True or False to create root folder
        :param rename: new name for torrent(s)
        :param upload_limit: upload limit in bytes/second
        :param download_limit: donwnload limit in bytes/second
        :param use_auto_torrent_management: True or False to use automatic torrent management
        :param is_sequential_download: True or False for sequential download
        :param is_first_last_piece_priority: True or False for first and last piece download priority
        :return: "Ok." for success and ""Fails." for failure
        """

        data = {
            'urls': (None, list2string(urls, '\n')),
            'savepath': (None, save_path),
            'cookie': (None, cookie),
            'category': (None, category),
            'skip_checking': (None, is_skip_checking),
            'paused': (None, is_paused),
            'root_folder': (None, is_root_folder),
            'rename': (None, rename),
            'upLimit': (None, upload_limit),
            'dlLimit': (None, download_limit),
            'useAutoTMM': (None, use_auto_torrent_management),
            'sequentialDownload': (None, is_sequential_download),
            'firstLastPiecePrio': (None, is_first_last_piece_priority)
        }

        if torrent_files:
            if isinstance(torrent_files, str):
                torrent_files = [torrent_files]
            torrent_files = [
                (path.basename(torrent_file), open(torrent_file, 'rb'))
                for torrent_file in [
                    path.abspath(path.realpath(path.expanduser(torrent_file)))
                    for torrent_file in torrent_files
                ]
            ]

        return self._post(_name=APINames.Torrents,
                          _method='add',
                          data=data,
                          files=torrent_files,
                          **kwargs)