From 038b4c63eee7b12a0ac6de62bc8305122a4ed3af Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Sun, 4 Jan 2015 17:09:36 -0500 Subject: [PATCH 1/8] Updated to follow putio API changes --- libs/pio/api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/pio/api.py b/libs/pio/api.py index 0f2a2c66..ecfc1776 100644 --- a/libs/pio/api.py +++ b/libs/pio/api.py @@ -154,13 +154,14 @@ class _File(_BaseResource): return [cls(f) for f in files] @classmethod - def upload(cls, path, name=None): + def upload(cls, path, name=None, parent_id=0): 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) + d = cls.client.request('/files/upload', method='POST', + data={'parent_id': parent_id}, files=files) f = d['file'] return cls(f) @@ -239,7 +240,7 @@ class _Transfer(_BaseResource): @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, + url=url, save_parent_id=parent_id, extract=extract, callback_url=callback_url)) t = d['transfer'] return cls(t) @@ -249,7 +250,7 @@ class _Transfer(_BaseResource): with open(path) as f: files = {'file': f} d = cls.client.request('/files/upload', method='POST', files=files, - data=dict(parent_id=parent_id, + data=dict(save_parent_id=parent_id, extract=extract, callback_url=callback_url)) t = d['transfer'] From d012dc5c85aa88538990da01b41f1a664366e3d7 Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Sun, 4 Jan 2015 17:10:16 -0500 Subject: [PATCH 2/8] Added new folder option --- couchpotato/core/downloaders/putio/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/couchpotato/core/downloaders/putio/__init__.py b/couchpotato/core/downloaders/putio/__init__.py index 114ad6d8..60ccad58 100644 --- a/couchpotato/core/downloaders/putio/__init__.py +++ b/couchpotato/core/downloaders/putio/__init__.py @@ -28,6 +28,11 @@ config = [{ 'description': 'This is the OAUTH_TOKEN from your putio API', 'advanced': True, }, + { + 'name': 'folder', + 'description': ('The folder on putio where you want the upload to go','Must be a folder in the root directory'), + 'default': 0, + }, { 'name': 'callback_host', 'description': 'External reachable url to CP so put.io can do it\'s thing', From 2c72cd7d9f1a38fcf77695655ce1875de40cbd32 Mon Sep 17 00:00:00 2001 From: Andrew Dumaresq Date: Sun, 4 Jan 2015 17:10:40 -0500 Subject: [PATCH 3/8] Added new folder option and fixed but in callback url --- couchpotato/core/downloaders/putio/main.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/downloaders/putio/main.py b/couchpotato/core/downloaders/putio/main.py index 76ac2033..ce58ff7c 100644 --- a/couchpotato/core/downloaders/putio/main.py +++ b/couchpotato/core/downloaders/putio/main.py @@ -28,20 +28,32 @@ class PutIO(DownloaderBase): return super(PutIO, self).__init__() + def convertFolder(self, client, folder): + if folder == 0: + return 0 + else: + files = client.File.list() + for f in files: + if f.name == folder and f.content_type == "application/x-directory": + return f.id + #If we get through the whole list and don't get a match we will use the root + return 0 + 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')) + putioFolder = self.convertFolder(client, self.conf('folder')) + log.debug('putioFolder ID is %s', putioFolder) # 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'): - callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/')) - resp = client.Transfer.add_url(url, callback_url = callbackurl) + callbackurl = 'http://' + self.conf('callback_host') + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/')) + resp = client.Transfer.add_url(url, callback_url = callbackurl, parent_id = putioFolder) log.debug('resp is %s', resp.id); return self.downloadReturnId(resp.id) @@ -124,7 +136,9 @@ class PutIO(DownloaderBase): client = pio.Client(self.conf('oauth_token')) log.debug('About to get file List') - files = client.File.list() + putioFolder = self.convertFolder(client, self.conf('folder')) + log.debug('PutioFolderID is %s', putioFolder) + files = client.File.list(parent_id=putioFolder) downloaddir = self.conf('download_dir') for f in files: From 4c68566c7767e30c920a8a617410c9783eda4855 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 8 Jan 2015 14:59:53 +0100 Subject: [PATCH 4/8] Use new OMGWTFNZB api fix #4471 --- .../media/_base/providers/nzb/omgwtfnzbs.py | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py b/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py index bac0614d..21799787 100644 --- a/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py +++ b/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py @@ -1,13 +1,9 @@ -from urlparse import urlparse, parse_qs -import time - from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode from couchpotato.core.helpers.rss import RSS from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.media._base.providers.nzb.base import NZBProvider -from dateutil.parser import parse log = CPLog(__name__) @@ -16,8 +12,7 @@ log = CPLog(__name__) class Base(NZBProvider, RSS): urls = { - 'search': 'https://rss.omgwtfnzbs.org/rss-search.php?%s', - 'detail_url': 'https://omgwtfnzbs.org/details.php?id=%s', + 'search': 'https://api.omgwtfnzbs.org/json/?%s', } http_time_between_calls = 1 # Seconds @@ -47,21 +42,18 @@ class Base(NZBProvider, RSS): 'api': self.conf('api_key', default = ''), }) - nzbs = self.getRSSData(self.urls['search'] % params) + nzbs = self.getJsonData(self.urls['search'] % params) for nzb in nzbs: - enclosure = self.getElement(nzb, 'enclosure').attrib - nzb_id = parse_qs(urlparse(self.getTextElement(nzb, 'link')).query).get('id')[0] - results.append({ - 'id': nzb_id, - 'name': toUnicode(self.getTextElement(nzb, 'title')), - 'age': self.calculateAge(int(time.mktime(parse(self.getTextElement(nzb, 'pubDate')).timetuple()))), - 'size': tryInt(enclosure['length']) / 1024 / 1024, - 'url': enclosure['url'], - 'detail_url': self.urls['detail_url'] % nzb_id, - 'description': self.getTextElement(nzb, 'description') + 'id': nzb.get('nzbid'), + 'name': toUnicode(nzb.get('release')), + 'age': self.calculateAge(tryInt(nzb.get('usenetage'))), + 'size': tryInt(nzb.get('sizebytes')) / 1024 / 1024, + 'url': nzb.get('getnzb'), + 'detail_url': nzb.get('details'), + 'description': nzb.get('weblink') }) From 2c080fec3d3a2fdcf63de5b641ad92dd088ae1e3 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 8 Jan 2015 16:56:38 +0100 Subject: [PATCH 5/8] TorrentBytes nbsp issue fix #4026 --- couchpotato/core/media/_base/providers/torrent/torrentbytes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/media/_base/providers/torrent/torrentbytes.py b/couchpotato/core/media/_base/providers/torrent/torrentbytes.py index 8e2becb2..fadd2ea0 100644 --- a/couchpotato/core/media/_base/providers/torrent/torrentbytes.py +++ b/couchpotato/core/media/_base/providers/torrent/torrentbytes.py @@ -56,7 +56,7 @@ class Base(TorrentProvider): full_id = link['href'].replace('details.php?id=', '') torrent_id = full_id[:6] - name = toUnicode(link.contents[0]) + name = toUnicode(link.contents[0].encode('ISO-8859-1')).strip() results.append({ 'id': torrent_id, From e7b089edf596294e8a3bf8b14981517f8171e038 Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 9 Jan 2015 20:13:17 +0100 Subject: [PATCH 6/8] Give better XML issues --- couchpotato/core/media/_base/providers/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/couchpotato/core/media/_base/providers/base.py b/couchpotato/core/media/_base/providers/base.py index 587545c8..1062a1a8 100644 --- a/couchpotato/core/media/_base/providers/base.py +++ b/couchpotato/core/media/_base/providers/base.py @@ -94,6 +94,8 @@ class Provider(Plugin): try: data = XMLTree.fromstring(ss(data)) return self.getElements(data, item_path) + except XMLTree.ParseError: + log.error('Invalid XML returned, check "%s" manually for issues', url) except: log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) From 1827c2e4cd43de2f5e74d6076ab6a8d2520e2af7 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 10 Jan 2015 12:17:30 +0100 Subject: [PATCH 7/8] Don't parse omgwtfnzb if no results are returned --- .../media/_base/providers/nzb/omgwtfnzbs.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py b/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py index 21799787..ea5f90f7 100644 --- a/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py +++ b/couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py @@ -44,17 +44,18 @@ class Base(NZBProvider, RSS): nzbs = self.getJsonData(self.urls['search'] % params) - for nzb in nzbs: + if isinstance(nzbs, list): + for nzb in nzbs: - results.append({ - 'id': nzb.get('nzbid'), - 'name': toUnicode(nzb.get('release')), - 'age': self.calculateAge(tryInt(nzb.get('usenetage'))), - 'size': tryInt(nzb.get('sizebytes')) / 1024 / 1024, - 'url': nzb.get('getnzb'), - 'detail_url': nzb.get('details'), - 'description': nzb.get('weblink') - }) + results.append({ + 'id': nzb.get('nzbid'), + 'name': toUnicode(nzb.get('release')), + 'age': self.calculateAge(tryInt(nzb.get('usenetage'))), + 'size': tryInt(nzb.get('sizebytes')) / 1024 / 1024, + 'url': nzb.get('getnzb'), + 'detail_url': nzb.get('details'), + 'description': nzb.get('weblink') + }) config = [{ From 132fa12ef4d5f12493e2c60ae1d2afbd2e67ed1d Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 10 Jan 2015 12:17:47 +0100 Subject: [PATCH 8/8] Late list not loaded on home --- couchpotato/core/media/movie/charts/static/charts.js | 3 ++- couchpotato/core/media/movie/suggestion/static/suggest.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/media/movie/charts/static/charts.js b/couchpotato/core/media/movie/charts/static/charts.js index 3d70f7f8..d70a1c64 100644 --- a/couchpotato/core/media/movie/charts/static/charts.js +++ b/couchpotato/core/media/movie/charts/static/charts.js @@ -44,11 +44,12 @@ var Charts = new Class({ if( Cookie.read('suggestions_charts_menu_selected') === 'charts'){ self.show(); - self.fireEvent.delay(0, self, 'created'); } else self.el.hide(); + self.fireEvent.delay(0, self, 'created'); + }, fill: function(json){ diff --git a/couchpotato/core/media/movie/suggestion/static/suggest.js b/couchpotato/core/media/movie/suggestion/static/suggest.js index ca4b07c2..ace7f387 100644 --- a/couchpotato/core/media/movie/suggestion/static/suggest.js +++ b/couchpotato/core/media/movie/suggestion/static/suggest.js @@ -51,8 +51,8 @@ var SuggestList = new Class({ self.show(); else self.hide(); - - self.fireEvent('created'); + + self.fireEvent.delay(0, self, 'created'); },