Example #1
0
    def add_task_bt(self, filename, select=False):
        """
        Added a new BT task

        :param str filename: path to torrent file to upload
        :param bool select: whether to select files in the torrent.

            * If True, it returns the opened torrent (:class:`.Torrent`) and
                can then iterate files in :attr:`.Torrent.files` and
                select/unselect them before calling :func:`Torrent.submit`
            * If False, it will submit the torrent with default selected files

        """
        filename = eval_path(filename)
        u = self.upload(filename, self.torrents_directory)
        t = self._load_torrent(u)
        if select:
            return t
        return t.submit()
Example #2
0
    def upload(self, filename, directory=None):
        """
        Upload a file ``filename`` to ``directory``

        :param str filename: path to the file to upload
        :param directory: destionation :class:`.Directory`, defaults to
            :class:`.API.downloads_directory` if None
        :return: the uploaded file
        :rtype: :class:`.File`
        """
        filename = eval_path(filename)
        if directory is None:
            directory = self.downloads_directory

        # First request
        res1 = self._req_upload(filename, directory)
        data1 = res1['data']
        file_id = data1['file_id']

        # Second request
        res2 = self._req_file(file_id)
        data2 = res2['data'][0]
        data2.update(**data1)
        return _instantiate_uploaded_file(self, data2)
Example #3
0
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import

try:
    import configparser
except ImportError:
    import ConfigParser as configparser
import os
import logging
from u115.utils import pjoin, eval_path

_d = os.path.dirname(__file__)
user_dir = eval_path('~')
PROJECT_PATH = os.path.abspath(pjoin(_d, os.pardir))
PROJECT_CREDENTIALS = pjoin(PROJECT_PATH, '.credentials')
USER_CREDENTIALS = pjoin(user_dir, '.115')
CREDENTIALS = None
COOKIES_FILENAME = pjoin(user_dir, '.115cookies')

LOGGING_API_LOGGER = 'API'
LOGGING_FORMAT = "%(levelname)s:%(name)s:%(funcName)s: %(message)s"
LOGGING_LEVEL = logging.ERROR
DEBUG_REQ_FMT = """
  TYPE: Request
  FUNC: %s
   URL: %s
METHOD: %s
PARAMS: %s
  DATA: %s
"""