From ed6a46e9c082954830d0e551f8a390bf3bc84f66 Mon Sep 17 00:00:00 2001 From: dumaresq Date: Sun, 17 Aug 2014 16:28:47 -0400 Subject: [PATCH 01/13] Added putioDownloader --- couchpotato/core/downloaders/putioDownload.py | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 couchpotato/core/downloaders/putioDownload.py diff --git a/couchpotato/core/downloaders/putioDownload.py b/couchpotato/core/downloaders/putioDownload.py new file mode 100644 index 00000000..4202e7bc --- /dev/null +++ b/couchpotato/core/downloaders/putioDownload.py @@ -0,0 +1,124 @@ +from __future__ import with_statement +import os +import traceback +import putio + +from couchpotato.api import addApiView +from couchpotato.core.event import addEvent +from couchpotato.core._base.downloader.main import DownloaderBase +from couchpotato.core.helpers.encoding import sp +from couchpotato.core.helpers.variable import getDownloadDir +from couchpotato.core.logger import CPLog +from couchpotato.environment import Env + +log = CPLog(__name__) + +autoload = 'Putiodownload' + + +class Putiodownload(DownloaderBase): + + protocol = ['torrent', 'torrent_magnet'] + status_support = False + + def __init__(self): + addApiView('putiodownload.getfrom', self.getFromPutio, docs = { + 'desc': 'Allows you to download file from prom Put.io', + }) + return super(Putiodownload,self).__init__() + + + def download(self, data = None, media = None, filedata = None): + if not media: media = {} + if not data: data = {} + log.info ('Sending "%s" to put.io', data.get('name')) + url = data.get('url') + OAUTH_TOKEN = self.conf('oauth_token') + client = putio.Client(OAUTH_TOKEN) + # Need to constuct a the API url a better way. + callbackurl = None + if self.conf('download'): + callbackurl = 'http://'+self.conf('callback_host')+'/'+self.conf('url_base', section='core')+'/api/'+self.conf('api_key', section='core')+'/putiodownload.getfrom/' + client.Transfer.add_url(url,callback_url=callbackurl) + return True + + def test(self): + OAUTH_TOKEN = self.conf('oauth_token') + try: + client = putio.Client(OAUTH_TOKEN) + if client.File.list(): + return True + except: + log.info('Failed to get file listing, check OAUTH_TOKEN') + return False + + def getFromPutio(self, **kwargs): + log.info('Put.io Download has been called') + OAUTH_TOKEN = self.conf('oauth_token') + client = putio.Client(OAUTH_TOKEN) + files = client.File.list() + delete = self.conf('detele_file') + downloaddir = self.conf('download_dir') + tempdownloaddir = '/export/nas/Downloads/incomplete' + for f in files: + if str(f.id) == str(kwargs.get('file_id')): + # Need to read this in from somewhere + client.File.download(f, dest=tempdownloaddir, delete_after_download=delete) + shutil.move(tempdownloaddir+"/"+str(f.name),downloaddir) + return True + +config = [{ + 'name': 'putiodownload', + 'groups': [ + { + 'tab': 'downloaders', + 'list': 'download_providers', + 'name': 'putiodownload', + 'label': 'put.io Download', + 'description': 'This will start a torrent download on Put.io.
Note: you must have a putio account and API', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + 'radio_group': 'torrent', + }, + { + 'name': 'oauth_token', + 'label': 'oauth_token', + 'description': 'This is the OAUTH_TOKEN from your putio API', + }, + { + 'name': 'callback_host', + 'description': 'This is used to generate the callback url', + }, + { + 'name': 'download', + 'description': 'Set this to have CouchPotato download the file from Put.io', + 'type': 'bool', + 'default': 0, + }, + { + 'name': 'detele_file', + 'description': 'Set this to remove the file from putio after sucessful download Note: does nothing if you don\'t select download', + 'type': 'bool', + 'default': 0, + }, + { + 'name': 'download_dir', + 'label': 'Download Directory', + 'description': 'The Directory to download files to, does nothing if you don\'t select download', + 'default': '/', + }, + { + 'name': 'manual', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Disable this downloader for automated searches, but use it when I manually send a release.', + }, + ], + } + ], +}] From 5acab980254a16145d05adab48af5c934c4c7427 Mon Sep 17 00:00:00 2001 From: dumaresq Date: Tue, 19 Aug 2014 19:32:00 -0400 Subject: [PATCH 02/13] fixed hardcoded directory --- couchpotato/core/downloaders/putioDownload.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/downloaders/putioDownload.py b/couchpotato/core/downloaders/putioDownload.py index 4202e7bc..4eaa24f8 100644 --- a/couchpotato/core/downloaders/putioDownload.py +++ b/couchpotato/core/downloaders/putioDownload.py @@ -59,7 +59,7 @@ class Putiodownload(DownloaderBase): files = client.File.list() delete = self.conf('detele_file') downloaddir = self.conf('download_dir') - tempdownloaddir = '/export/nas/Downloads/incomplete' + tempdownloaddir = self.conf('tempdownload_dir') for f in files: if str(f.id) == str(kwargs.get('file_id')): # Need to read this in from somewhere @@ -111,6 +111,12 @@ config = [{ 'description': 'The Directory to download files to, does nothing if you don\'t select download', 'default': '/', }, + { + 'name': 'tempdownload_dir', + 'label': 'Temporary Download Directory', + 'description': 'The Temporary Directory to download files to, does nothing if you don\'t select download', + 'default': '/', + }, { 'name': 'manual', 'default': 0, From bb73cb8eecbd9d020c43ca5d30c12b7dab7cfacc Mon Sep 17 00:00:00 2001 From: dumaresq Date: Sun, 24 Aug 2014 18:19:01 -0400 Subject: [PATCH 03/13] Fixed missing library --- couchpotato/core/downloaders/putioDownload.py | 1 + 1 file changed, 1 insertion(+) diff --git a/couchpotato/core/downloaders/putioDownload.py b/couchpotato/core/downloaders/putioDownload.py index 4eaa24f8..bc27a665 100644 --- a/couchpotato/core/downloaders/putioDownload.py +++ b/couchpotato/core/downloaders/putioDownload.py @@ -2,6 +2,7 @@ from __future__ import with_statement import os import traceback import putio +import shutil from couchpotato.api import addApiView from couchpotato.core.event import addEvent From 53e7e383a313e7f57de03605dc1e46832adf037d Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 29 Aug 2014 11:38:28 +0200 Subject: [PATCH 04/13] put.io rename --- couchpotato/core/downloaders/{putioDownload.py => putio.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename couchpotato/core/downloaders/{putioDownload.py => putio.py} (100%) diff --git a/couchpotato/core/downloaders/putioDownload.py b/couchpotato/core/downloaders/putio.py similarity index 100% rename from couchpotato/core/downloaders/putioDownload.py rename to couchpotato/core/downloaders/putio.py From d0f1e7c6a36006815ae17786504452c86d582c41 Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 29 Aug 2014 12:30:31 +0200 Subject: [PATCH 05/13] Update put.io code --- couchpotato/core/downloaders/putio.py | 131 --------- .../core/downloaders/putio/__init__.py | 69 +++++ couchpotato/core/downloaders/putio/api.py | 271 ++++++++++++++++++ couchpotato/core/downloaders/putio/main.py | 87 ++++++ .../core/downloaders/putio/static/putio.js | 68 +++++ 5 files changed, 495 insertions(+), 131 deletions(-) delete mode 100644 couchpotato/core/downloaders/putio.py create mode 100644 couchpotato/core/downloaders/putio/__init__.py create mode 100644 couchpotato/core/downloaders/putio/api.py create mode 100644 couchpotato/core/downloaders/putio/main.py create mode 100644 couchpotato/core/downloaders/putio/static/putio.js diff --git a/couchpotato/core/downloaders/putio.py b/couchpotato/core/downloaders/putio.py deleted file mode 100644 index bc27a665..00000000 --- a/couchpotato/core/downloaders/putio.py +++ /dev/null @@ -1,131 +0,0 @@ -from __future__ import with_statement -import os -import traceback -import putio -import shutil - -from couchpotato.api import addApiView -from couchpotato.core.event import addEvent -from couchpotato.core._base.downloader.main import DownloaderBase -from couchpotato.core.helpers.encoding import sp -from couchpotato.core.helpers.variable import getDownloadDir -from couchpotato.core.logger import CPLog -from couchpotato.environment import Env - -log = CPLog(__name__) - -autoload = 'Putiodownload' - - -class Putiodownload(DownloaderBase): - - protocol = ['torrent', 'torrent_magnet'] - status_support = False - - def __init__(self): - addApiView('putiodownload.getfrom', self.getFromPutio, docs = { - 'desc': 'Allows you to download file from prom Put.io', - }) - return super(Putiodownload,self).__init__() - - - def download(self, data = None, media = None, filedata = None): - if not media: media = {} - if not data: data = {} - log.info ('Sending "%s" to put.io', data.get('name')) - url = data.get('url') - OAUTH_TOKEN = self.conf('oauth_token') - client = putio.Client(OAUTH_TOKEN) - # Need to constuct a the API url a better way. - callbackurl = None - if self.conf('download'): - callbackurl = 'http://'+self.conf('callback_host')+'/'+self.conf('url_base', section='core')+'/api/'+self.conf('api_key', section='core')+'/putiodownload.getfrom/' - client.Transfer.add_url(url,callback_url=callbackurl) - return True - - def test(self): - OAUTH_TOKEN = self.conf('oauth_token') - try: - client = putio.Client(OAUTH_TOKEN) - if client.File.list(): - return True - except: - log.info('Failed to get file listing, check OAUTH_TOKEN') - return False - - def getFromPutio(self, **kwargs): - log.info('Put.io Download has been called') - OAUTH_TOKEN = self.conf('oauth_token') - client = putio.Client(OAUTH_TOKEN) - files = client.File.list() - delete = self.conf('detele_file') - downloaddir = self.conf('download_dir') - tempdownloaddir = self.conf('tempdownload_dir') - for f in files: - if str(f.id) == str(kwargs.get('file_id')): - # Need to read this in from somewhere - client.File.download(f, dest=tempdownloaddir, delete_after_download=delete) - shutil.move(tempdownloaddir+"/"+str(f.name),downloaddir) - return True - -config = [{ - 'name': 'putiodownload', - 'groups': [ - { - 'tab': 'downloaders', - 'list': 'download_providers', - 'name': 'putiodownload', - 'label': 'put.io Download', - 'description': 'This will start a torrent download on Put.io.
Note: you must have a putio account and API', - 'wizard': True, - 'options': [ - { - 'name': 'enabled', - 'default': 0, - 'type': 'enabler', - 'radio_group': 'torrent', - }, - { - 'name': 'oauth_token', - 'label': 'oauth_token', - 'description': 'This is the OAUTH_TOKEN from your putio API', - }, - { - 'name': 'callback_host', - 'description': 'This is used to generate the callback url', - }, - { - 'name': 'download', - 'description': 'Set this to have CouchPotato download the file from Put.io', - 'type': 'bool', - 'default': 0, - }, - { - 'name': 'detele_file', - 'description': 'Set this to remove the file from putio after sucessful download Note: does nothing if you don\'t select download', - 'type': 'bool', - 'default': 0, - }, - { - 'name': 'download_dir', - 'label': 'Download Directory', - 'description': 'The Directory to download files to, does nothing if you don\'t select download', - 'default': '/', - }, - { - 'name': 'tempdownload_dir', - 'label': 'Temporary Download Directory', - 'description': 'The Temporary Directory to download files to, does nothing if you don\'t select download', - 'default': '/', - }, - { - 'name': 'manual', - 'default': 0, - 'type': 'bool', - 'advanced': True, - 'description': 'Disable this downloader for automated searches, but use it when I manually send a release.', - }, - ], - } - ], -}] diff --git a/couchpotato/core/downloaders/putio/__init__.py b/couchpotato/core/downloaders/putio/__init__.py new file mode 100644 index 00000000..1f4865ec --- /dev/null +++ b/couchpotato/core/downloaders/putio/__init__.py @@ -0,0 +1,69 @@ +from .main import PutIO + + +def autoload(): + return PutIO() + + +config = [{ + 'name': 'putio', + 'groups': [ + { + 'tab': 'downloaders', + 'list': 'download_providers', + 'name': 'putio', + 'label': 'put.io', + 'description': 'This will start a torrent download on Put.io.', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + 'radio_group': 'torrent', + }, + { + 'name': 'oauth_token', + 'label': 'oauth_token', + 'description': 'This is the OAUTH_TOKEN from your putio API', + 'advanced': True, + }, + { + 'name': 'callback_host', + 'description': 'This is used to generate the callback url', + }, + { + 'name': 'download', + 'description': 'Set this to have CouchPotato download the file from Put.io', + 'type': 'bool', + 'default': 0, + }, + { + 'name': 'delete_file', + 'description': 'Set this to remove the file from putio after sucessful download Note: does nothing if you don\'t select download', + 'type': 'bool', + 'default': 0, + }, + { + 'name': 'download_dir', + 'type': 'directory', + 'label': 'Download Directory', + 'description': 'The Directory to download files to, does nothing if you don\'t select download', + }, + { + 'name': 'tempdownload_dir', + 'type': 'directory', + 'label': 'Temporary Download Directory', + 'description': 'The Temporary Directory to download files to, does nothing if you don\'t select download', + }, + { + 'name': 'manual', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Disable this downloader for automated searches, but use it when I manually send a release.', + }, + ], + } + ], +}] diff --git a/couchpotato/core/downloaders/putio/api.py b/couchpotato/core/downloaders/putio/api.py new file mode 100644 index 00000000..0f2a2c66 --- /dev/null +++ b/couchpotato/core/downloaders/putio/api.py @@ -0,0 +1,271 @@ +# -*- coding: utf-8 -*- + +# Changed +# Removed iso8601 library requirement +# Added CP logging + +import os +import re +import json +import webbrowser +from urllib import urlencode +from couchpotato import CPLog +from dateutil.parser import parse + +import requests + +BASE_URL = 'https://api.put.io/v2' +ACCESS_TOKEN_URL = 'https://api.put.io/v2/oauth2/access_token' +AUTHENTICATION_URL = 'https://api.put.io/v2/oauth2/authenticate' + +log = CPLog(__name__) + + +class AuthHelper(object): + + def __init__(self, client_id, client_secret, redirect_uri, type='code'): + self.client_id = client_id + self.client_secret = client_secret + self.callback_url = redirect_uri + self.type = type + + @property + def authentication_url(self): + """Redirect your users to here to authenticate them.""" + params = { + 'client_id': self.client_id, + 'response_type': self.type, + 'redirect_uri': self.callback_url + } + return AUTHENTICATION_URL + "?" + urlencode(params) + + def open_authentication_url(self): + webbrowser.open(self.authentication_url) + + def get_access_token(self, code): + params = { + 'client_id': self.client_id, + 'client_secret': self.client_secret, + 'grant_type': 'authorization_code', + 'redirect_uri': self.callback_url, + 'code': code + } + response = requests.get(ACCESS_TOKEN_URL, params=params) + log.debug(response) + assert response.status_code == 200 + return response.json()['access_token'] + + +class Client(object): + + def __init__(self, access_token): + self.access_token = access_token + self.session = requests.session() + + # Keep resource classes as attributes of client. + # Pass client to resource classes so resource object + # can use the client. + attributes = {'client': self} + self.File = type('File', (_File,), attributes) + self.Transfer = type('Transfer', (_Transfer,), attributes) + self.Account = type('Account', (_Account,), attributes) + + def request(self, path, method='GET', params=None, data=None, files=None, + headers=None, raw=False, stream=False): + """ + Wrapper around requests.request() + + Prepends BASE_URL to path. + Inserts oauth_token to query params. + Parses response as JSON and returns it. + + """ + if not params: + params = {} + + if not headers: + headers = {} + + # All requests must include oauth_token + params['oauth_token'] = self.access_token + + headers['Accept'] = 'application/json' + + url = BASE_URL + path + log.debug('url: %s', url) + + response = self.session.request( + method, url, params=params, data=data, files=files, + headers=headers, allow_redirects=True, stream=stream) + log.debug('response: %s', response) + if raw: + return response + + log.debug('content: %s', response.content) + try: + response = json.loads(response.content) + except ValueError: + raise Exception('Server didn\'t send valid JSON:\n%s\n%s' % ( + response, response.content)) + + if response['status'] == 'ERROR': + raise Exception(response['error_type']) + + return response + + +class _BaseResource(object): + + client = None + + def __init__(self, resource_dict): + """Constructs the object from a dict.""" + # All resources must have id and name attributes + self.id = None + self.name = None + self.__dict__.update(resource_dict) + try: + self.created_at = parse(self.created_at) + except AttributeError: + self.created_at = None + + def __str__(self): + return self.name.encode('utf-8') + + def __repr__(self): + # shorten name for display + name = self.name[:17] + '...' if len(self.name) > 20 else self.name + return '<%s id=%r, name="%r">' % ( + self.__class__.__name__, self.id, name) + + +class _File(_BaseResource): + + @classmethod + def get(cls, id): + d = cls.client.request('/files/%i' % id, method='GET') + t = d['file'] + return cls(t) + + @classmethod + def list(cls, parent_id=0): + d = cls.client.request('/files/list', params={'parent_id': parent_id}) + files = d['files'] + return [cls(f) for f in files] + + @classmethod + def upload(cls, path, name=None): + with open(path) as f: + if name: + files = {'file': (name, f)} + else: + files = {'file': f} + d = cls.client.request('/files/upload', method='POST', files=files) + + f = d['file'] + return cls(f) + + def dir(self): + """List the files under directory.""" + return self.list(parent_id=self.id) + + def download(self, dest='.', delete_after_download=False): + if self.content_type == 'application/x-directory': + self._download_directory(dest, delete_after_download) + else: + self._download_file(dest, delete_after_download) + + def _download_directory(self, dest='.', delete_after_download=False): + name = self.name + if isinstance(name, unicode): + name = name.encode('utf-8', 'replace') + + dest = os.path.join(dest, name) + if not os.path.exists(dest): + os.mkdir(dest) + + for sub_file in self.dir(): + sub_file.download(dest, delete_after_download) + + if delete_after_download: + self.delete() + + def _download_file(self, dest='.', delete_after_download=False): + response = self.client.request( + '/files/%s/download' % self.id, raw=True, stream=True) + + filename = re.match( + 'attachment; filename=(.*)', + response.headers['content-disposition']).groups()[0] + # If file name has spaces, it must have quotes around. + filename = filename.strip('"') + + with open(os.path.join(dest, filename), 'wb') as f: + for chunk in response.iter_content(chunk_size=1024): + if chunk: # filter out keep-alive new chunks + f.write(chunk) + f.flush() + + if delete_after_download: + self.delete() + + def delete(self): + return self.client.request('/files/delete', method='POST', + data={'file_ids': str(self.id)}) + + def move(self, parent_id): + return self.client.request('/files/move', method='POST', + data={'file_ids': str(self.id), 'parent_id': str(parent_id)}) + + def rename(self, name): + return self.client.request('/files/rename', method='POST', + data={'file_id': str(self.id), 'name': str(name)}) + + +class _Transfer(_BaseResource): + + @classmethod + def list(cls): + d = cls.client.request('/transfers/list') + transfers = d['transfers'] + return [cls(t) for t in transfers] + + @classmethod + def get(cls, id): + d = cls.client.request('/transfers/%i' % id, method='GET') + t = d['transfer'] + return cls(t) + + @classmethod + def add_url(cls, url, parent_id=0, extract=False, callback_url=None): + d = cls.client.request('/transfers/add', method='POST', data=dict( + url=url, parent_id=parent_id, extract=extract, + callback_url=callback_url)) + t = d['transfer'] + return cls(t) + + @classmethod + def add_torrent(cls, path, parent_id=0, extract=False, callback_url=None): + with open(path) as f: + files = {'file': f} + d = cls.client.request('/files/upload', method='POST', files=files, + data=dict(parent_id=parent_id, + extract=extract, + callback_url=callback_url)) + t = d['transfer'] + return cls(t) + + @classmethod + def clean(cls): + return cls.client.request('/transfers/clean', method='POST') + + +class _Account(_BaseResource): + + @classmethod + def info(cls): + return cls.client.request('/account/info', method='GET') + + @classmethod + def settings(cls): + return cls.client.request('/account/settings', method='GET') diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py new file mode 100644 index 00000000..10e6aa11 --- /dev/null +++ b/couchpotato/core/downloaders/putio/main.py @@ -0,0 +1,87 @@ +import shutil + +from couchpotato.api import addApiView +from couchpotato.core._base.downloader.main import DownloaderBase +from couchpotato.core.logger import CPLog +import api as pio + +log = CPLog(__name__) + +autoload = 'Putiodownload' + + +class PutIO(DownloaderBase): + protocol = ['torrent', 'torrent_magnet'] + status_support = False + + def __init__(self): + addApiView('downloader.putio.getfrom', self.getFromPutio, docs = { + 'desc': 'Allows you to download file from prom Put.io', + }) + + addApiView('downloader.putio.auth_url', self.getAuthorizationUrl) + + return super(PutIO, self).__init__() + + def download(self, data = None, media = None, filedata = None): + if not media: media = {} + if not data: data = {} + + log.info('Sending "%s" to put.io', data.get('name')) + url = data.get('url') + + client = pio.Client(self.conf('oauth_token')) + + # Need to constuct a the API url a better way. + callbackurl = None + if self.conf('download'): + callbackurl = 'http://' + self.conf('callback_host') + '/' + self.conf('url_base', + section = 'core') + '/api/' + self.conf( + 'api_key', section = 'core') + '/downloader.putiodownload.getfrom/' + client.Transfer.add_url(url, callback_url = callbackurl) + + return True + + def test(self): + try: + client = pio.Client(self.conf('oauth_token')) + if client.File.list(): + return True + except: + log.info('Failed to get file listing, check OAUTH_TOKEN') + return False + + def getAuthorizationUrl(self): + # See notification/twitter + pass + + def getCredentials(self): + # Save oauth_token here to settings + pass + + def getAllDownloadStatus(self, ids): + # See other downloaders for examples + + # Check putio for status + + # Check "getFromPutio" progress + pass + + def getFromPutio(self, **kwargs): + + log.info('Put.io Download has been called') + client = pio.Client(self.conf('oauth_token')) + files = client.File.list() + + tempdownloaddir = self.conf('tempdownload_dir') + downloaddir = self.conf('download_dir') + + for f in files: + if str(f.id) == str(kwargs.get('file_id')): + # Need to read this in from somewhere + client.File.download(f, dest = tempdownloaddir, delete_after_download = self.conf('delete_file')) + shutil.move(tempdownloaddir + "/" + str(f.name), downloaddir) + + # Mark status of file_id as "done" here for getAllDownloadStatus + + return True diff --git a/couchpotato/core/downloaders/putio/static/putio.js b/couchpotato/core/downloaders/putio/static/putio.js new file mode 100644 index 00000000..1b71c263 --- /dev/null +++ b/couchpotato/core/downloaders/putio/static/putio.js @@ -0,0 +1,68 @@ +var PutIODownloader = new Class({ + + initialize: function(){ + var self = this; + + App.addEvent('loadSettings', self.addRegisterButton.bind(self)); + }, + + addRegisterButton: function(){ + var self = this; + + var setting_page = App.getPage('Settings'); + setting_page.addEvent('create', function(){ + + var fieldset = setting_page.tabs.downloaders.groups.putio, + l = window.location; + + var putio_set = 0; + fieldset.getElements('input[type=text]').each(function(el){ + putio_set += +(el.get('value') != ''); + }); + + new Element('.ctrlHolder').adopt( + + // Unregister button + (putio_set > 0) ? + [ + self.unregister = new Element('a.button.red', { + 'text': 'Unregister "'+fieldset.getElement('input[name*=screen_name]').get('value')+'"', + 'events': { + 'click': function(){ + fieldset.getElements('input[type=text]').set('value', '').fireEvent('change'); + + self.unregister.destroy(); + self.unregister_or.destroy(); + } + } + }), + self.unregister_or = new Element('span[text=or]') + ] + : null, + + // Register button + new Element('a.button', { + 'text': putio_set > 0 ? 'Register a different account' : 'Register your put.io account', + 'events': { + 'click': function(){ + Api.request('downloader.putio.auth_url', { + 'data': { + 'host': l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + }, + 'onComplete': function(json){ + window.location = json.url; + } + }); + } + } + }) + ).inject(fieldset.getElement('.test_button'), 'before'); + }) + + } + +}); + +window.addEvent('domready', function(){ + new PutIODownloader(); +}); From 872a4f4650d40bb8189723f1fd785d2fa8c57c78 Mon Sep 17 00:00:00 2001 From: dumaresq Date: Sun, 7 Sep 2014 17:59:16 -0400 Subject: [PATCH 06/13] Worked on geting Oauth and adding download status --- couchpotato/core/downloaders/putio/main.py | 73 ++++++++++++++++------ 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 10e6aa11..5e56b103 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -1,8 +1,10 @@ import shutil from couchpotato.api import addApiView -from couchpotato.core._base.downloader.main import DownloaderBase +from couchpotato.core._base.downloader.main import DownloaderBase, ReleaseDownloadList +from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog +from couchpotato.environment import Env import api as pio log = CPLog(__name__) @@ -12,7 +14,9 @@ autoload = 'Putiodownload' class PutIO(DownloaderBase): protocol = ['torrent', 'torrent_magnet'] - status_support = False + status_support = True + client_id = '1575' + client_secret = '132qbpseq1ymwn83wus4' def __init__(self): addApiView('downloader.putio.getfrom', self.getFromPutio, docs = { @@ -20,6 +24,7 @@ class PutIO(DownloaderBase): }) addApiView('downloader.putio.auth_url', self.getAuthorizationUrl) + addApiView('downloader.putio.credentials', self.getCredentials) return super(PutIO, self).__init__() @@ -35,12 +40,10 @@ class PutIO(DownloaderBase): # Need to constuct a the API url a better way. callbackurl = None if self.conf('download'): - callbackurl = 'http://' + self.conf('callback_host') + '/' + self.conf('url_base', - section = 'core') + '/api/' + self.conf( - 'api_key', section = 'core') + '/downloader.putiodownload.getfrom/' - client.Transfer.add_url(url, callback_url = callbackurl) - - return True + callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/')) + resp = client.Transfer.add_url(url, callback_url = callbackurl) + log.debug('resp is %s', resp.id); + return self.downloadReturnId(resp.id) def test(self): try: @@ -51,21 +54,53 @@ class PutIO(DownloaderBase): log.info('Failed to get file listing, check OAUTH_TOKEN') return False - def getAuthorizationUrl(self): - # See notification/twitter - pass + def getAuthorizationUrl(self, host = None, **kwargs): + callback_url = cleanHost(host) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) + log.info('callback_url is %s', callback_url) + #I can't figure out how to pass this into getCredentials so I'm saving it here + self.apicallhost = host; + oauth = pio.AuthHelper(client_id=self.client_id,client_secret=self.client_secret,redirect_uri=callback_url) + resp = oauth.authentication_url + log.info ('reps is %s,', resp) + return { + 'success': True, + 'url': resp, + } - def getCredentials(self): - # Save oauth_token here to settings - pass + + def getCredentials(self, **kwargs): + code = kwargs.get('code') + log.info('getCredentials Called with code: %s', code) + callback_url = cleanHost(self.apicallhost) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) + log.info('callback is %s',callback_url) + oauth = pio.AuthHelper(client_id=self.client_id,client_secret=self.client_secret,redirect_uri=callback_url) + oauth_token = oauth.get_access_token(code) + log.info('oauth_token is: %s', oauth_token) + self.conf('oauth_token', value = oauth_token); + return 'redirect', Env.get('web_base') + 'settings/downloaders/' def getAllDownloadStatus(self, ids): - # See other downloaders for examples - - # Check putio for status - + log.debug('Checking putio download status.') + client = pio.Client(self.conf('oauth_token')) + transfers = client.Transfer.list() + log.debug(transfers); + release_downloads = ReleaseDownloadList(self) + for t in transfers: + if t.status == "COMPLETED" and self.conf('download') == False : + status = 'completed' + else: + #status = t.status.lower() + status = 'busy' + release_downloads.append({ + 'id' : t.id, + 'name': t.name, + 'status': status, + 'timeleft': t.estimated_time, + }) + + log.info(release_downloads) # Check "getFromPutio" progress - pass + return release_downloads def getFromPutio(self, **kwargs): From c77b270fa80da360747dcd2e1ba720f121334b3b Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Thu, 18 Sep 2014 06:00:09 -0400 Subject: [PATCH 07/13] Cleaned up OAUTH and made the download asyc --- couchpotato/core/downloaders/putio/main.py | 45 +++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 5e56b103..764d5c1d 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -1,6 +1,7 @@ import shutil from couchpotato.api import addApiView +from couchpotato.core.event import addEvent, fireEventAsync from couchpotato.core._base.downloader.main import DownloaderBase, ReleaseDownloadList from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog @@ -25,6 +26,7 @@ class PutIO(DownloaderBase): addApiView('downloader.putio.auth_url', self.getAuthorizationUrl) addApiView('downloader.putio.credentials', self.getCredentials) + addEvent('putio.download', self.putioDownloader) return super(PutIO, self).__init__() @@ -57,24 +59,18 @@ class PutIO(DownloaderBase): def getAuthorizationUrl(self, host = None, **kwargs): callback_url = cleanHost(host) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) log.info('callback_url is %s', callback_url) - #I can't figure out how to pass this into getCredentials so I'm saving it here - self.apicallhost = host; - oauth = pio.AuthHelper(client_id=self.client_id,client_secret=self.client_secret,redirect_uri=callback_url) - resp = oauth.authentication_url - log.info ('reps is %s,', resp) + target_url = "http://sabnzbd.dumaresq.ca/index.cgi?target=" + callback_url + log.info('target_url is %s', target_url) return { 'success': True, - 'url': resp, + 'url': target_url, } def getCredentials(self, **kwargs): - code = kwargs.get('code') - log.info('getCredentials Called with code: %s', code) - callback_url = cleanHost(self.apicallhost) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) - log.info('callback is %s',callback_url) - oauth = pio.AuthHelper(client_id=self.client_id,client_secret=self.client_secret,redirect_uri=callback_url) - oauth_token = oauth.get_access_token(code) + oauth_token = kwargs.get('oauth') + if not oauth_token: + return 'redirect', Env.get('web_base') + 'settigs/downloaders/' log.info('oauth_token is: %s', oauth_token) self.conf('oauth_token', value = oauth_token); return 'redirect', Env.get('web_base') + 'settings/downloaders/' @@ -102,17 +98,16 @@ class PutIO(DownloaderBase): # Check "getFromPutio" progress return release_downloads - def getFromPutio(self, **kwargs): - - log.info('Put.io Download has been called') + def putioDownloader(self, fid): + log.info('Put.io Real downloader called with file_id: %s',fid) client = pio.Client(self.conf('oauth_token')) + log.debug('About to get file List') files = client.File.list() - + log.debug('File list is %s',files) tempdownloaddir = self.conf('tempdownload_dir') downloaddir = self.conf('download_dir') - for f in files: - if str(f.id) == str(kwargs.get('file_id')): + if str(f.id) == str(fid): # Need to read this in from somewhere client.File.download(f, dest = tempdownloaddir, delete_after_download = self.conf('delete_file')) shutil.move(tempdownloaddir + "/" + str(f.name), downloaddir) @@ -120,3 +115,17 @@ class PutIO(DownloaderBase): # Mark status of file_id as "done" here for getAllDownloadStatus return True + + def getFromPutio(self, **kwargs): + # This needs some checking so that we don't download the same file multiple times. + # This needs to have a way to query if the download is still going + # would be nice to be albe to check how much is downloaded and report that. + file_id = str(kwargs.get('file_id')) + log.info('Put.io Download has been called file_id is %s', file_id) + fireEventAsync('putio.download',fid = file_id) + # Mark status of file_id as "done" here for getAllDownloadStatus + + return { + 'success': True, + } + From ef2b8e88b4b05307bbc65a0d58e36c513e93694c Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Fri, 19 Sep 2014 07:07:23 -0400 Subject: [PATCH 08/13] better download checking --- couchpotato/core/downloaders/putio/main.py | 68 +++++++++++++--------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 764d5c1d..6ddea4e2 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -1,4 +1,4 @@ -import shutil +import datetime from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEventAsync @@ -18,6 +18,7 @@ class PutIO(DownloaderBase): status_support = True client_id = '1575' client_secret = '132qbpseq1ymwn83wus4' + downloadingList = [] def __init__(self): addApiView('downloader.putio.getfrom', self.getFromPutio, docs = { @@ -27,7 +28,6 @@ class PutIO(DownloaderBase): addApiView('downloader.putio.auth_url', self.getAuthorizationUrl) addApiView('downloader.putio.credentials', self.getCredentials) addEvent('putio.download', self.putioDownloader) - return super(PutIO, self).__init__() def download(self, data = None, media = None, filedata = None): @@ -82,19 +82,34 @@ class PutIO(DownloaderBase): log.debug(transfers); release_downloads = ReleaseDownloadList(self) for t in transfers: - if t.status == "COMPLETED" and self.conf('download') == False : - status = 'completed' - else: - #status = t.status.lower() - status = 'busy' - release_downloads.append({ - 'id' : t.id, - 'name': t.name, - 'status': status, - 'timeleft': t.estimated_time, - }) + if t.id in ids: + log.debug('id is %s', t.id) + log.debug('P.Status is %s',t.id) + log.debug('downloading list is %s', self.downloadingList) + if t.status == "COMPLETED" and self.conf('download') == False : + status = 'completed' + # This is Ugly but if we are set to download, and the thing is complete, we need to check the dowlading status + # Becuase putio changed the IDs the only thing we can check is the name. + elif t.status == "COMPLETED" and self.conf('download') == True: + status = 'busy' + # This is not ideal, right now if we are downloading anything we can't mark anything as completed + # The name and ID don't match currently so I can't use those... + if not self.downloadingList: + now = datetime.datetime.now() + log.debug ('now is %s', now) + log.debug ('t.finished_at is %s',t.finished_at) + if (now - t.finished_at) > datetime.timedelta(5,0): + status = 'completed' + else: + status = 'busy' + release_downloads.append({ + 'id' : t.id, + 'name': t.name, + 'status': status, + 'timeleft': t.estimated_time, + }) - log.info(release_downloads) + log.debug(release_downloads) # Check "getFromPutio" progress return release_downloads @@ -104,28 +119,25 @@ class PutIO(DownloaderBase): log.debug('About to get file List') files = client.File.list() log.debug('File list is %s',files) - tempdownloaddir = self.conf('tempdownload_dir') downloaddir = self.conf('download_dir') for f in files: if str(f.id) == str(fid): - # Need to read this in from somewhere - client.File.download(f, dest = tempdownloaddir, delete_after_download = self.conf('delete_file')) - shutil.move(tempdownloaddir + "/" + str(f.name), downloaddir) - - # Mark status of file_id as "done" here for getAllDownloadStatus + client.File.download(f, dest = downloaddir, delete_after_download = self.conf('delete_file')) + # Once the download is complete we need to remove it from the running list. + self.downloadingList.remove(fid) return True def getFromPutio(self, **kwargs): - # This needs some checking so that we don't download the same file multiple times. - # This needs to have a way to query if the download is still going - # would be nice to be albe to check how much is downloaded and report that. file_id = str(kwargs.get('file_id')) log.info('Put.io Download has been called file_id is %s', file_id) - fireEventAsync('putio.download',fid = file_id) - # Mark status of file_id as "done" here for getAllDownloadStatus - + if file_id not in self.downloadingList: + self.downloadingList.append(file_id) + fireEventAsync('putio.download',fid = file_id) + return { + 'success': True, + } return { - 'success': True, - } + 'success': False, + } From fba228fd9de9bb924016202f2e4b372826fe5f04 Mon Sep 17 00:00:00 2001 From: dumaresq Date: Fri, 19 Sep 2014 20:26:54 -0400 Subject: [PATCH 09/13] fixing check function --- couchpotato/core/downloaders/putio/main.py | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 6ddea4e2..ad206ccf 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -16,20 +16,21 @@ autoload = 'Putiodownload' class PutIO(DownloaderBase): protocol = ['torrent', 'torrent_magnet'] status_support = True - client_id = '1575' - client_secret = '132qbpseq1ymwn83wus4' downloadingList = [] + # This is the location on the Internet of the Oauth helper server + oauthServerURL = "http://sabnzb.dumaresq.ca/index.cgi" + def __init__(self): addApiView('downloader.putio.getfrom', self.getFromPutio, docs = { 'desc': 'Allows you to download file from prom Put.io', }) - addApiView('downloader.putio.auth_url', self.getAuthorizationUrl) addApiView('downloader.putio.credentials', self.getCredentials) addEvent('putio.download', self.putioDownloader) return super(PutIO, self).__init__() + def download(self, data = None, media = None, filedata = None): if not media: media = {} if not data: data = {} @@ -40,6 +41,7 @@ class PutIO(DownloaderBase): client = pio.Client(self.conf('oauth_token')) # Need to constuct a the API url a better way. + # Note callback_host is NOT our address, it's the internet host that putio can call too callbackurl = None if self.conf('download'): callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/')) @@ -47,6 +49,7 @@ class PutIO(DownloaderBase): log.debug('resp is %s', resp.id); return self.downloadReturnId(resp.id) + def test(self): try: client = pio.Client(self.conf('oauth_token')) @@ -59,7 +62,7 @@ class PutIO(DownloaderBase): def getAuthorizationUrl(self, host = None, **kwargs): callback_url = cleanHost(host) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) log.info('callback_url is %s', callback_url) - target_url = "http://sabnzbd.dumaresq.ca/index.cgi?target=" + callback_url + target_url = oauthServerURL + "?target=" + callback_url log.info('target_url is %s', target_url) return { 'success': True, @@ -75,6 +78,7 @@ class PutIO(DownloaderBase): self.conf('oauth_token', value = oauth_token); return 'redirect', Env.get('web_base') + 'settings/downloaders/' + def getAllDownloadStatus(self, ids): log.debug('Checking putio download status.') client = pio.Client(self.conf('oauth_token')) @@ -83,22 +87,19 @@ class PutIO(DownloaderBase): release_downloads = ReleaseDownloadList(self) for t in transfers: if t.id in ids: - log.debug('id is %s', t.id) - log.debug('P.Status is %s',t.id) log.debug('downloading list is %s', self.downloadingList) if t.status == "COMPLETED" and self.conf('download') == False : status = 'completed' - # This is Ugly but if we are set to download, and the thing is complete, we need to check the dowlading status - # Becuase putio changed the IDs the only thing we can check is the name. + # So check if we are trying to download something elif t.status == "COMPLETED" and self.conf('download') == True: status = 'busy' # This is not ideal, right now if we are downloading anything we can't mark anything as completed # The name and ID don't match currently so I can't use those... if not self.downloadingList: - now = datetime.datetime.now() - log.debug ('now is %s', now) - log.debug ('t.finished_at is %s',t.finished_at) - if (now - t.finished_at) > datetime.timedelta(5,0): + now = datetime.datetime.utcnow() + date_time = datetime.datetime.strptime(t.finished_at,"%Y-%m-%dT%H:%M:%S") + # We need to make sure a race condition didn't happen + if (now - date_time) > datetime.timedelta(minutes=5): status = 'completed' else: status = 'busy' @@ -110,9 +111,9 @@ class PutIO(DownloaderBase): }) log.debug(release_downloads) - # Check "getFromPutio" progress return release_downloads + def putioDownloader(self, fid): log.info('Put.io Real downloader called with file_id: %s',fid) client = pio.Client(self.conf('oauth_token')) @@ -128,6 +129,7 @@ class PutIO(DownloaderBase): return True + def getFromPutio(self, **kwargs): file_id = str(kwargs.get('file_id')) log.info('Put.io Download has been called file_id is %s', file_id) From 2c40db307433210324a011873c67ab6d62ad26a2 Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Fri, 19 Sep 2014 20:28:03 -0400 Subject: [PATCH 10/13] removed un-needed variable --- couchpotato/core/downloaders/putio/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/couchpotato/core/downloaders/putio/__init__.py b/couchpotato/core/downloaders/putio/__init__.py index 1f4865ec..af05e360 100644 --- a/couchpotato/core/downloaders/putio/__init__.py +++ b/couchpotato/core/downloaders/putio/__init__.py @@ -50,12 +50,6 @@ config = [{ 'label': 'Download Directory', 'description': 'The Directory to download files to, does nothing if you don\'t select download', }, - { - 'name': 'tempdownload_dir', - 'type': 'directory', - 'label': 'Temporary Download Directory', - 'description': 'The Temporary Directory to download files to, does nothing if you don\'t select download', - }, { 'name': 'manual', 'default': 0, From 3e58378490a57bf0bc1e40166521cce4d24db788 Mon Sep 17 00:00:00 2001 From: dumaresq Date: Fri, 19 Sep 2014 21:41:58 -0400 Subject: [PATCH 11/13] figured out how to make the check work better --- couchpotato/core/downloaders/putio/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index ad206ccf..3d55504c 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -92,15 +92,21 @@ class PutIO(DownloaderBase): status = 'completed' # So check if we are trying to download something elif t.status == "COMPLETED" and self.conf('download') == True: - status = 'busy' + # Assume we are done + status = 'completed' # This is not ideal, right now if we are downloading anything we can't mark anything as completed # The name and ID don't match currently so I can't use those... if not self.downloadingList: now = datetime.datetime.utcnow() date_time = datetime.datetime.strptime(t.finished_at,"%Y-%m-%dT%H:%M:%S") # We need to make sure a race condition didn't happen - if (now - date_time) > datetime.timedelta(minutes=5): - status = 'completed' + if (now - date_time) < datetime.timedelta(minutes=5): + #5 minutes haven't passed so we wait + status = 'busy' + else: + # If we have the file_id in the downloadingList mark it as busy + if str(t.file_id) in self.downloadingList: + status = 'busy' else: status = 'busy' release_downloads.append({ @@ -119,7 +125,6 @@ class PutIO(DownloaderBase): client = pio.Client(self.conf('oauth_token')) log.debug('About to get file List') files = client.File.list() - log.debug('File list is %s',files) downloaddir = self.conf('download_dir') for f in files: if str(f.id) == str(fid): From 4aa9801be41713a15001a61a9287020b4627c044 Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Sat, 20 Sep 2014 19:39:12 -0400 Subject: [PATCH 12/13] general code cleanup --- couchpotato/core/downloaders/putio/main.py | 87 +++++++++++----------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 3d55504c..8184b27d 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -1,5 +1,3 @@ -import datetime - from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEventAsync from couchpotato.core._base.downloader.main import DownloaderBase, ReleaseDownloadList @@ -7,6 +5,7 @@ from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog from couchpotato.environment import Env import api as pio +import datetime log = CPLog(__name__) @@ -18,7 +17,7 @@ class PutIO(DownloaderBase): status_support = True downloadingList = [] # This is the location on the Internet of the Oauth helper server - oauthServerURL = "http://sabnzb.dumaresq.ca/index.cgi" + oauthServerURL = "http://sabnzbd.dumaresq.ca/index.cgi" def __init__(self): @@ -39,8 +38,7 @@ class PutIO(DownloaderBase): url = data.get('url') client = pio.Client(self.conf('oauth_token')) - - # Need to constuct a the API url a better way. + # It might be possible to call getFromPutio from the renamer if we can then we don't need to do this. # Note callback_host is NOT our address, it's the internet host that putio can call too callbackurl = None if self.conf('download'): @@ -59,11 +57,12 @@ class PutIO(DownloaderBase): log.info('Failed to get file listing, check OAUTH_TOKEN') return False + def getAuthorizationUrl(self, host = None, **kwargs): callback_url = cleanHost(host) + '%sdownloader.putio.credentials/' % (Env.get('api_base').lstrip('/')) - log.info('callback_url is %s', callback_url) - target_url = oauthServerURL + "?target=" + callback_url - log.info('target_url is %s', target_url) + log.debug('callback_url is %s', callback_url) + target_url = self.oauthServerURL + "?target=" + callback_url + log.debug('target_url is %s', target_url) return { 'success': True, 'url': target_url, @@ -71,10 +70,11 @@ class PutIO(DownloaderBase): def getCredentials(self, **kwargs): - oauth_token = kwargs.get('oauth') - if not oauth_token: - return 'redirect', Env.get('web_base') + 'settigs/downloaders/' - log.info('oauth_token is: %s', oauth_token) + try: + oauth_token = kwargs.get('oauth') + except: + return 'redirect', Env.get('web_base') + 'settigs/downloaders/' + log.debug('oauth_token is: %s', oauth_token) self.conf('oauth_token', value = oauth_token); return 'redirect', Env.get('web_base') + 'settings/downloaders/' @@ -86,37 +86,33 @@ class PutIO(DownloaderBase): log.debug(transfers); release_downloads = ReleaseDownloadList(self) for t in transfers: - if t.id in ids: - log.debug('downloading list is %s', self.downloadingList) - if t.status == "COMPLETED" and self.conf('download') == False : - status = 'completed' - # So check if we are trying to download something - elif t.status == "COMPLETED" and self.conf('download') == True: - # Assume we are done - status = 'completed' - # This is not ideal, right now if we are downloading anything we can't mark anything as completed - # The name and ID don't match currently so I can't use those... - if not self.downloadingList: - now = datetime.datetime.utcnow() - date_time = datetime.datetime.strptime(t.finished_at,"%Y-%m-%dT%H:%M:%S") - # We need to make sure a race condition didn't happen - if (now - date_time) < datetime.timedelta(minutes=5): - #5 minutes haven't passed so we wait - status = 'busy' + if t.id in ids: + log.debug('downloading list is %s', self.downloadingList) + if t.status == "COMPLETED" and self.conf('download') == False : + status = 'completed' + # So check if we are trying to download something + elif t.status == "COMPLETED" and self.conf('download') == True: + # Assume we are done + status = 'completed' + if not self.downloadingList: + now = datetime.datetime.utcnow() + date_time = datetime.datetime.strptime(t.finished_at,"%Y-%m-%dT%H:%M:%S") + # We need to make sure a race condition didn't happen + if (now - date_time) < datetime.timedelta(minutes=5): + # 5 minutes haven't passed so we wait + status = 'busy' + else: + # If we have the file_id in the downloadingList mark it as busy + if str(t.file_id) in self.downloadingList: + status = 'busy' else: - # If we have the file_id in the downloadingList mark it as busy - if str(t.file_id) in self.downloadingList: - status = 'busy' - else: - status = 'busy' - release_downloads.append({ + status = 'busy' + release_downloads.append({ 'id' : t.id, 'name': t.name, 'status': status, 'timeleft': t.estimated_time, - }) - - log.debug(release_downloads) + }) return release_downloads @@ -136,14 +132,19 @@ class PutIO(DownloaderBase): def getFromPutio(self, **kwargs): - file_id = str(kwargs.get('file_id')) + try: + file_id = str(kwargs.get('file_id')) + except: + return { + 'success' : False, + } log.info('Put.io Download has been called file_id is %s', file_id) if file_id not in self.downloadingList: - self.downloadingList.append(file_id) - fireEventAsync('putio.download',fid = file_id) - return { + self.downloadingList.append(file_id) + fireEventAsync('putio.download',fid = file_id) + return { 'success': True, - } + } return { 'success': False, } From 8de5fcdac657ee52108f07ef45ca22f18bb26a33 Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Sat, 20 Sep 2014 19:39:35 -0400 Subject: [PATCH 13/13] fixed button name --- couchpotato/core/downloaders/putio/static/putio.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/downloaders/putio/static/putio.js b/couchpotato/core/downloaders/putio/static/putio.js index 1b71c263..f58292ae 100644 --- a/couchpotato/core/downloaders/putio/static/putio.js +++ b/couchpotato/core/downloaders/putio/static/putio.js @@ -26,10 +26,10 @@ var PutIODownloader = new Class({ (putio_set > 0) ? [ self.unregister = new Element('a.button.red', { - 'text': 'Unregister "'+fieldset.getElement('input[name*=screen_name]').get('value')+'"', + 'text': 'Unregister "'+fieldset.getElement('input[name*=oauth_token]').get('value')+'"', 'events': { 'click': function(){ - fieldset.getElements('input[type=text]').set('value', '').fireEvent('change'); + fieldset.getElements('input[name*=oauth_token]').set('value', '').fireEvent('change'); self.unregister.destroy(); self.unregister_or.destroy();