def download(self, data, movie, manual=False, filedata=None): if self.isDisabled(manual) or not self.isCorrectType(data.get('type')): return log.error('Sending "%s" (%s) to Synology.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False if data.get('type') == 'torrent': log.error('Can\'t add binary torrent file') return False try: # Send request to Transmission srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password')) remote_torrent = srpc.add_torrent_uri(data.get('url')) log.info('Response: %s', remote_torrent) return remote_torrent['success'] except Exception, err: log.error('Exception while adding torrent: %s', err) return False
def connect(self, reconnect=False): """ Connect to the delugeRPC, re-use connection when already available :param reconnect: force reconnect :return: DelugeRPC instance """ # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol=False).split(':') # Force host assignment if len(host) == 1: host.append(80) if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False if not self.drpc or reconnect: self.drpc = DelugeRPC(host[0], port=host[1], username=self.conf('username'), password=self.conf('password')) return self.drpc
def download(self, data = None, media = None, filedata = None): if not media: media = {} if not data: data = {} response = False log.error('Sending "%s" (%s) to Synology.', (data['name'], data['protocol'])) # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password')) if data['protocol'] == 'torrent_magnet': log.info('Adding torrent URL %s', data['url']) response = srpc.create_task(url = data['url']) elif data['protocol'] in ['nzb', 'torrent']: log.info('Adding %s' % data['protocol']) if not filedata: log.error('No %s data found', data['protocol']) else: filename = data['name'] + '.' + data['protocol'] response = srpc.create_task(filename = filename, filedata = filedata) except: log.error('Exception while adding torrent: %s', traceback.format_exc()) finally: return self.downloadReturnId('') if response else False
def download(self, data, movie, filedata = None): response = False log.error('Sending "%s" (%s) to Synology.', (data['name'], data['type'])) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password')) if data['type'] == 'torrent_magnet': log.info('Adding torrent URL %s', data['url']) response = srpc.create_task(url = data['url']) elif data['type'] in ['nzb', 'torrent']: log.info('Adding %s' % data['type']) if not filedata: log.error('No %s data found' % data['type']) else: filename = data['name'] + '.' + data['type'] response = srpc.create_task(filename = filename, filedata = filedata) except Exception, err: log.error('Exception while adding torrent: %s', err)
def download(self, data, movie, manual = False, filedata = None): if self.isDisabled(manual) or not self.isCorrectType(data.get('type')): return log.error('Sending "%s" (%s) to Synology.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False if data.get('type') == 'torrent': log.error('Can\'t add binary torrent file') return False try: # Send request to Transmission srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password')) remote_torrent = srpc.add_torrent_uri(data.get('url')) log.info('Response: %s', remote_torrent) return remote_torrent['success'] except Exception, err: log.error('Exception while adding torrent: %s', err) return False
def download(self, data = {}, movie = {}, manual = False, filedata = None): if self.isDisabled(manual) or not self.isCorrectType(data.get('type')): return log.info('Sending "%s" to Transmission.', data.get('name')) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False # Set parameters for Transmission params = { 'paused': self.conf('paused', default = 0), 'download_dir': self.conf('directory', default = None) } try: if not filedata: log.error('Failed sending torrent to transmission, no data') tc = transmissionrpc.Client(host[0], port = host[1], user = self.conf('username'), password = self.conf('password')) torrent = tc.add_torrent(b64encode(filedata), **params) # Change settings of added torrents try: torrent.seed_ratio_limit = self.conf('ratio') torrent.seed_ratio_mode = 'single' if self.conf('ratio') else 'global' except transmissionrpc.TransmissionError, e: log.error('Failed to change settings for transfer in transmission: %s', e) return True
def download(self, data, movie, filedata=None): response = False log.error('Sending "%s" (%s) to Synology.', (data['name'], data['type'])) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password')) if data['type'] == 'torrent_magnet': log.info('Adding torrent URL %s', data['url']) response = srpc.create_task(url=data['url']) elif data['type'] in ['nzb', 'torrent']: log.info('Adding %s' % data['type']) if not filedata: log.error('No %s data found' % data['type']) else: filename = data['name'] + '.' + data['type'] response = srpc.create_task(filename=filename, filedata=filedata) except Exception, err: log.error('Exception while adding torrent: %s', err)
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False # This is where v4 and v5 begin to differ if(self.conf('version') == 'v4'): if not self.conf('api_key'): log.error('Config properties are not filled in correctly, API key is missing.') return False url = 'http://' + str(host[0]) + ':' + str(host[1]) + '/jsonrpc' client = JsonRpcClient(url, 'Token ' + self.conf('api_key')) self.hadouken_api = HadoukenAPIv4(client) return True else: auth_type = self.conf('auth_type') header = None if auth_type == 'api_key': header = 'Token ' + self.conf('api_key') elif auth_type == 'user_pass': header = 'Basic ' + b64encode(self.conf('auth_user') + ':' + self.conf('auth_pass')) url = 'http://' + str(host[0]) + ':' + str(host[1]) + '/api' client = JsonRpcClient(url, header) self.hadouken_api = HadoukenAPIv5(client) return True return False
def download(self, data=None, media=None, filedata=None): if not media: media = {} if not data: data = {} response = False log.error('Sending "%s" (%s) to Synology.', (data["name"], data["protocol"])) # Load host from config and split out port. host = cleanHost(self.conf("host"), protocol=False).split(":") if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf("username"), self.conf("password")) if data["protocol"] == "torrent_magnet": log.info("Adding torrent URL %s", data["url"]) response = srpc.create_task(url=data["url"]) elif data["protocol"] in ["nzb", "torrent"]: log.info("Adding %s" % data["protocol"]) if not filedata: log.error("No %s data found", data["protocol"]) else: filename = data["name"] + "." + data["protocol"] response = srpc.create_task(filename=filename, filedata=filedata) except: log.error("Exception while adding torrent: %s", traceback.format_exc()) finally: return self.downloadReturnId("") if response else False
def cleanValue(self, value): if(isInt(value)): return int(value) if str(value).lower() in self.bool: return self.bool.get(str(value).lower()) return value.strip()
def cleanValue(self, value): if (isInt(value)): return int(value) if str(value).lower() in self.bool: return self.bool.get(str(value).lower()) return value.strip()
def download(self, data, movie, manual=False, filedata=None): if self.isDisabled(manual) or not self.isCorrectType(data.get('type')): return log.debug('Sending "%s" (%s) to Transmission.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False # Set parameters for Transmission folder_name = self.createFileName(data, filedata, movie)[:-len(data.get('type')) - 1] params = { 'paused': self.conf('paused', default=0), 'download-dir': os.path.join(self.conf('directory', default=''), folder_name).rstrip(os.path.sep) } torrent_params = { 'seedRatioLimit': self.conf('ratio'), 'seedRatioMode': (0 if self.conf('ratio') else 1) } if not filedata and data.get('type') == 'torrent': log.error('Failed sending torrent, no data') return False # Send request to Transmission try: trpc = TransmissionRPC(host[0], port=host[1], username=self.conf('username'), password=self.conf('password')) if data.get('type') == 'torrent_magnet': remote_torrent = trpc.add_torrent_uri(data.get('url'), arguments=params) torrent_params['trackerAdd'] = self.torrent_trackers else: remote_torrent = trpc.add_torrent_file(b64encode(filedata), arguments=params) # Change settings of added torrents trpc.set_torrent(remote_torrent['torrent-added']['hashString'], torrent_params) return True except Exception, err: log.error('Failed to change settings for transfer: %s', err) return False
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf('host')).rstrip('/').rsplit(':', 1) if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False self.trpc = TransmissionRPC(host[0], port = host[1], rpc_url = self.conf('rpc_url').strip('/ '), username = self.conf('username'), password = self.conf('password')) return self.trpc
def download(self, data, movie, filedata=None): log.debug('Sending "%s" (%s) to uTorrent.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False torrent_params = {} if self.conf('label'): torrent_params['label'] = self.conf('label') if not filedata and data.get('type') == 'torrent': log.error('Failed sending torrent, no data') return False if data.get('type') == 'torrent_magnet': torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper() torrent_params['trackers'] = '%0D%0A%0D%0A'.join( self.torrent_trackers) else: info = bdecode(filedata)["info"] torrent_hash = sha1(bencode(info)).hexdigest().upper() torrent_filename = self.createFileName(data, filedata, movie) # Convert base 32 to hex if len(torrent_hash) == 32: torrent_hash = b16encode(b32decode(torrent_hash)) # Send request to uTorrent try: if not self.utorrent_api: self.utorrent_api = uTorrentAPI(host[0], port=host[1], username=self.conf('username'), password=self.conf('password')) if data.get('type') == 'torrent_magnet': self.utorrent_api.add_torrent_uri(data.get('url')) else: self.utorrent_api.add_torrent_file(torrent_filename, filedata) # Change settings of added torrents self.utorrent_api.set_torrent(torrent_hash, torrent_params) if self.conf('paused', default=0): self.utorrent_api.pause_torrent(torrent_hash) return True except Exception, err: log.error('Failed to send torrent to uTorrent: %s', err) return False
def download(self, data, movie, filedata = None): log.info('Sending "%s" (%s) to Transmission.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False # Set parameters for Transmission params = { 'paused': self.conf('paused', default = 0), } if len(self.conf('directory', default = '')) > 0: folder_name = self.createFileName(data, filedata, movie)[:-len(data.get('type')) - 1] folder_path = os.path.join(self.conf('directory', default = ''), folder_name).rstrip(os.path.sep) # Create the empty folder to download too self.makeDir(folder_path) params['download-dir'] = folder_path torrent_params = {} if self.conf('ratio'): torrent_params = { 'seedRatioLimit': self.conf('ratio'), 'seedRatioMode': self.conf('ratiomode') } if not filedata and data.get('type') == 'torrent': log.error('Failed sending torrent, no data') return False # Send request to Transmission try: trpc = TransmissionRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) if data.get('type') == 'torrent_magnet': remote_torrent = trpc.add_torrent_uri(data.get('url'), arguments = params) torrent_params['trackerAdd'] = self.torrent_trackers else: remote_torrent = trpc.add_torrent_file(b64encode(filedata), arguments = params) if not remote_torrent: return False # Change settings of added torrents elif torrent_params: trpc.set_torrent(remote_torrent['torrent-added']['hashString'], torrent_params) log.info('Torrent sent to Transmission successfully.') return self.downloadReturnId(remote_torrent['torrent-added']['hashString']) except: log.error('Failed to change settings for transfer: %s', traceback.format_exc()) return False
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False self.utorrent_api = uTorrentAPI(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) return self.utorrent_api
def connect(self, reconnect = False): # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False if not self.drpc or reconnect: self.drpc = DelugeRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) return self.drpc
def download(self, data=None, media=None, filedata=None): """ Send a torrent/nzb file to the downloader :param data: dict returned from provider Contains the release information :param media: media dict with information Used for creating the filename when possible :param filedata: downloaded torrent/nzb filedata The file gets downloaded in the searcher and send to this function This is done to have failed checking before using the downloader, so the downloader doesn't need to worry about that :return: boolean One faile returns false, but the downloaded should log his own errors """ if not media: media = {} if not data: data = {} response = False log.error('Sending "%s" (%s) to Synology.', (data['name'], data['protocol'])) # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol=False).split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password'), self.conf('destination')) if data['protocol'] == 'torrent_magnet': log.info('Adding torrent URL %s', data['url']) response = srpc.create_task(url=data['url']) elif data['protocol'] in ['nzb', 'torrent']: log.info('Adding %s' % data['protocol']) if not filedata: log.error('No %s data found', data['protocol']) else: filename = data['name'] + '.' + data['protocol'] response = srpc.create_task(filename=filename, filedata=filedata) except: log.error('Exception while adding torrent: %s', traceback.format_exc()) finally: return self.downloadReturnId('') if response else False
def download(self, data, movie, filedata=None): log.debug('Sending "%s" (%s) to uTorrent.', (data.get("name"), data.get("type"))) # Load host from config and split out port. host = self.conf("host").split(":") if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False torrent_params = {} if self.conf("label"): torrent_params["label"] = self.conf("label") if not filedata and data.get("type") == "torrent": log.error("Failed sending torrent, no data") return False if data.get("type") == "torrent_magnet": torrent_hash = re.findall("urn:btih:([\w]{32,40})", data.get("url"))[0].upper() torrent_params["trackers"] = "%0D%0A%0D%0A".join(self.torrent_trackers) else: info = bdecode(filedata)["info"] torrent_hash = sha1(bencode(info)).hexdigest().upper() torrent_filename = self.createFileName(data, filedata, movie) # Convert base 32 to hex if len(torrent_hash) == 32: torrent_hash = b16encode(b32decode(torrent_hash)) # Send request to uTorrent try: if not self.utorrent_api: self.utorrent_api = uTorrentAPI( host[0], port=host[1], username=self.conf("username"), password=self.conf("password") ) if data.get("type") == "torrent_magnet": self.utorrent_api.add_torrent_uri(data.get("url")) else: self.utorrent_api.add_torrent_file(torrent_filename, filedata) # Change settings of added torrents self.utorrent_api.set_torrent(torrent_hash, torrent_params) if self.conf("paused", default=0): self.utorrent_api.pause_torrent(torrent_hash) return self.downloadReturnId(torrent_hash) except Exception, err: log.error("Failed to send torrent to uTorrent: %s", err) return False
def getAllDownloadStatus(self): log.debug('Checking uTorrent download status.') # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False try: self.utorrent_api = uTorrentAPI(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) except Exception, err: log.error('Failed to get uTorrent object: %s', err) return False
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False if not self.conf('apikey'): log.error('Config properties are not filled in correctly, API key is missing.') return False self.hadouken_api = HadoukenAPI(host[0], port = host[1], api_key = self.conf('api_key')) return True
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf("host")).rstrip("/").rsplit(":", 1) if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False self.trpc = TransmissionRPC( host[0], port=host[1], rpc_url=self.conf("rpc_url").strip("/ "), username=self.conf("username"), password=self.conf("password"), ) return self.trpc
def download(self, data, movie, filedata = None): log.debug('Sending "%s" (%s) to uTorrent.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False torrent_params = {} if self.conf('label'): torrent_params['label'] = self.conf('label') if not filedata and data.get('type') == 'torrent': log.error('Failed sending torrent, no data') return False if data.get('type') == 'torrent_magnet': torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper() torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers) else: info = bdecode(filedata)["info"] torrent_hash = sha1(bencode(info)).hexdigest().upper() torrent_filename = self.createFileName(data, filedata, movie) # Convert base 32 to hex if len(torrent_hash) == 32: torrent_hash = b16encode(b32decode(torrent_hash)) # Send request to uTorrent try: if not self.utorrent_api: self.utorrent_api = uTorrentAPI(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) if data.get('type') == 'torrent_magnet': self.utorrent_api.add_torrent_uri(data.get('url')) else: self.utorrent_api.add_torrent_file(torrent_filename, filedata) # Change settings of added torrents self.utorrent_api.set_torrent(torrent_hash, torrent_params) if self.conf('paused', default = 0): self.utorrent_api.pause_torrent(torrent_hash) return True except Exception, err: log.error('Failed to send torrent to uTorrent: %s', err) return False
def download(self, data, movie, manual=False, filedata=None): if self.isDisabled(manual) or not self.isCorrectType(data.get("type")): return log.debug('Sending "%s" (%s) to Transmission.', (data.get("name"), data.get("type"))) # Load host from config and split out port. host = self.conf("host").split(":") if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False # Set parameters for Transmission folder_name = self.createFileName(data, filedata, movie)[: -len(data.get("type")) - 1] folder_path = os.path.join(self.conf("directory", default=""), folder_name).rstrip(os.path.sep) # Create the empty folder to download too self.makeDir(folder_path) params = {"paused": self.conf("paused", default=0), "download-dir": folder_path} torrent_params = {"seedRatioLimit": self.conf("ratio"), "seedRatioMode": (0 if self.conf("ratio") else 1)} if not filedata and data.get("type") == "torrent": log.error("Failed sending torrent, no data") return False # Send request to Transmission try: trpc = TransmissionRPC( host[0], port=host[1], username=self.conf("username"), password=self.conf("password") ) if data.get("type") == "torrent_magnet": remote_torrent = trpc.add_torrent_uri(data.get("url"), arguments=params) torrent_params["trackerAdd"] = self.torrent_trackers else: remote_torrent = trpc.add_torrent_file(b64encode(filedata), arguments=params) # Change settings of added torrents trpc.set_torrent(remote_torrent["torrent-added"]["hashString"], torrent_params) return True except Exception, err: log.error("Failed to change settings for transfer: %s", err) return False
def getAllDownloadStatus(self): log.debug("Checking uTorrent download status.") # Load host from config and split out port. host = self.conf("host").split(":") if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False try: self.utorrent_api = uTorrentAPI( host[0], port=host[1], username=self.conf("username"), password=self.conf("password") ) except Exception, err: log.error("Failed to get uTorrent object: %s", err) return False
def download(self, data = None, media = None, filedata = None): """ Send a torrent/nzb file to the downloader :param data: dict returned from provider Contains the release information :param media: media dict with information Used for creating the filename when possible :param filedata: downloaded torrent/nzb filedata The file gets downloaded in the searcher and send to this function This is done to have fail checking before using the downloader, so the downloader doesn't need to worry about that :return: boolean One fail returns false, but the downloader should log his own errors """ if not media: media = {} if not data: data = {} response = False log.info('Sending "%s" (%s) to Synology.', (data['name'], data['protocol'])) # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password'), self.conf('destination')) if data['protocol'] == 'torrent_magnet': log.info('Adding torrent URL %s', data['url']) response = srpc.create_task(url = data['url']) elif data['protocol'] in ['nzb', 'torrent']: log.info('Adding %s' % data['protocol']) if not filedata: log.error('No %s data found', data['protocol']) else: filename = data['name'] + '.' + data['protocol'] response = srpc.create_task(filename = filename, filedata = filedata) except: log.error('Exception while adding torrent: %s', traceback.format_exc()) finally: return self.downloadReturnId('') if response else False
def download(self, data, movie, manual = False, filedata = None): if self.isDisabled(manual) or not self.isCorrectType(data.get('type')): return log.debug('Sending "%s" (%s) to Transmission.', (data.get('name'), data.get('type'))) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False # Set parameters for Transmission folder_name = self.createFileName(data, filedata, movie)[:-len(data.get('type')) - 1] params = { 'paused': self.conf('paused', default = 0), 'download-dir': os.path.join(self.conf('directory', default = ''), folder_name).rstrip(os.path.sep) } torrent_params = { 'seedRatioLimit': self.conf('ratio'), 'seedRatioMode': (0 if self.conf('ratio') else 1) } if not filedata and data.get('type') == 'torrent': log.error('Failed sending torrent, no data') return False # Send request to Transmission try: trpc = TransmissionRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) if data.get('type') == 'torrent_magnet': remote_torrent = trpc.add_torrent_uri(data.get('url'), arguments = params) torrent_params['trackerAdd'] = self.torrent_trackers else: remote_torrent = trpc.add_torrent_file(b64encode(filedata), arguments = params) # Change settings of added torrents trpc.set_torrent(remote_torrent['torrent-added']['hashString'], torrent_params) return True except Exception, err: log.error('Failed to change settings for transfer: %s', err) return False
def download(self, data={}, movie={}): if self.isDisabled() or not self.isCorrectType(data.get('type')): return log.info('Sending "%s" to Transmission.' % data.get('name')) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error( "Config properties are not filled in correctly, port is missing." ) return False # Set parameters for Transmission params = { 'paused': self.conf('paused', 0), 'download_dir': self.conf('directory', None) } change_params = { 'seedRatioLimit': self.conf('ratio'), 'seedRatioMode': 1 if self.conf('ratio') else 0 } try: tc = transmissionrpc.Client(host[0], port=host[1], user=self.conf('username'), password=self.conf('password')) tr_id = tc.add_uri(data.get('url'), **params) # Change settings of added torrents for item in tr_id: try: tc.change(item, timeout=None, **change_params) except transmissionrpc.TransmissionError, e: log.error( 'Failed to change settings for transfer in transmission: %s' % e) return True
def getAllDownloadStatus(self): log.debug('Checking Transmission download status.') # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False # Go through Queue try: trpc = TransmissionRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) return_params = { 'fields': ['id', 'name', 'hashString', 'percentDone', 'status', 'eta', 'isFinished', 'downloadDir', 'uploadRatio'] } queue = trpc.get_alltorrents(return_params) except Exception, err: log.error('Failed getting queue: %s', err) return False
def getAllDownloadStatus(self): log.debug('Checking uTorrent download status.') # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False try: self.utorrent_api = uTorrentAPI(host[0], port=host[1], username=self.conf('username'), password=self.conf('password')) except Exception, err: log.error('Failed to get uTorrent object: %s', err) return False
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol=False).split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False if not self.conf('api_key'): log.error( 'Config properties are not filled in correctly, API key is missing.' ) return False self.hadouken_api = HadoukenAPI(host[0], port=host[1], api_key=self.conf('api_key')) return True
def connect(self, reconnect = False): """ Connect to the delugeRPC, re-use connection when already available :param reconnect: force reconnect :return: DelugeRPC instance """ # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol = False).split(':') # Force host assignment if len(host) == 1: host.append(80) if not isInt(host[1]): log.error('Config properties are not filled in correctly, port is missing.') return False if not self.drpc or reconnect: self.drpc = DelugeRPC(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) return self.drpc
def connect(self): # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol=False).split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False # This is where v4 and v5 begin to differ if (self.conf('version') == 'v4'): if not self.conf('api_key'): log.error( 'Config properties are not filled in correctly, API key is missing.' ) return False url = 'http://' + str(host[0]) + ':' + str(host[1]) + '/jsonrpc' client = JsonRpcClient(url, 'Token ' + self.conf('api_key')) self.hadouken_api = HadoukenAPIv4(client) return True else: auth_type = self.conf('auth_type') header = None if auth_type == 'api_key': header = 'Token ' + self.conf('api_key') elif auth_type == 'user_pass': header = 'Basic ' + b64encode( self.conf('auth_user') + ':' + self.conf('auth_pass')) url = 'http://' + str(host[0]) + ':' + str(host[1]) + '/api' client = JsonRpcClient(url, header) self.hadouken_api = HadoukenAPIv5(client) return True return False
def download(self, data = {}, movie = {}): if self.isDisabled() or not self.isCorrectType(data.get('type')): return log.info('Sending "%s" to Transmission.' % data.get('name')) # Load host from config and split out port. host = self.conf('host').split(':') if not isInt(host[1]): log.error("Config properties are not filled in correctly, port is missing.") return False # Set parameters for Transmission params = { 'paused': self.conf('paused', 0), 'download_dir': self.conf('directory', None) } change_params = { 'seedRatioLimit': self.conf('ratio'), 'seedRatioMode': 1 if self.conf('ratio') else 0 } try: tc = transmissionrpc.Client(host[0], port = host[1], user = self.conf('username'), password = self.conf('password')) tr_id = tc.add_uri(data.get('url'), **params) # Change settings of added torrents for item in tr_id: try: tc.change(item, timeout = None, **change_params) except transmissionrpc.TransmissionError, e: log.error('Failed to change settings for transfer in transmission: %s' % e) return True
def download(self, data=None, media=None, filedata=None): if not media: media = {} if not data: data = {} response = False log.error('Sending "%s" (%s) to Synology.', (data['name'], data['protocol'])) # Load host from config and split out port. host = cleanHost(self.conf('host'), protocol=False).split(':') if not isInt(host[1]): log.error( 'Config properties are not filled in correctly, port is missing.' ) return False try: # Send request to Synology srpc = SynologyRPC(host[0], host[1], self.conf('username'), self.conf('password'), self.conf('destination')) if data['protocol'] == 'torrent_magnet': log.info('Adding torrent URL %s', data['url']) response = srpc.create_task(url=data['url']) elif data['protocol'] in ['nzb', 'torrent']: log.info('Adding %s' % data['protocol']) if not filedata: log.error('No %s data found', data['protocol']) else: filename = data['name'] + '.' + data['protocol'] response = srpc.create_task(filename=filename, filedata=filedata) except: log.error('Exception while adding torrent: %s', traceback.format_exc()) finally: return self.downloadReturnId('') if response else False