Browse Source

Merge branch 'develop'

pull/4328/merge
Ruud 10 years ago
parent
commit
38ee0ebe7b
  1. 5
      couchpotato/core/downloaders/putio/__init__.py
  2. 22
      couchpotato/core/downloaders/putio/main.py
  3. 2
      couchpotato/core/media/_base/providers/base.py
  4. 33
      couchpotato/core/media/_base/providers/nzb/omgwtfnzbs.py
  5. 2
      couchpotato/core/media/_base/providers/torrent/torrentbytes.py
  6. 3
      couchpotato/core/media/movie/charts/static/charts.js
  7. 4
      couchpotato/core/media/movie/suggestion/static/suggest.js
  8. 9
      libs/pio/api.py

5
couchpotato/core/downloaders/putio/__init__.py

@ -29,6 +29,11 @@ config = [{
'advanced': True, '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', 'name': 'callback_host',
'description': 'External reachable url to CP so put.io can do it\'s thing', 'description': 'External reachable url to CP so put.io can do it\'s thing',
}, },

22
couchpotato/core/downloaders/putio/main.py

@ -28,20 +28,32 @@ class PutIO(DownloaderBase):
return super(PutIO, self).__init__() 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): def download(self, data = None, media = None, filedata = None):
if not media: media = {} if not media: media = {}
if not data: data = {} if not data: data = {}
log.info('Sending "%s" to put.io', data.get('name')) log.info('Sending "%s" to put.io', data.get('name'))
url = data.get('url') url = data.get('url')
client = pio.Client(self.conf('oauth_token')) 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. # 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 # Note callback_host is NOT our address, it's the internet host that putio can call too
callbackurl = None callbackurl = None
if self.conf('download'): if self.conf('download'):
callbackurl = 'http://' + self.conf('callback_host') + '/' + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/')) callbackurl = 'http://' + self.conf('callback_host') + '%sdownloader.putio.getfrom/' %Env.get('api_base'.strip('/'))
resp = client.Transfer.add_url(url, callback_url = callbackurl) resp = client.Transfer.add_url(url, callback_url = callbackurl, parent_id = putioFolder)
log.debug('resp is %s', resp.id); log.debug('resp is %s', resp.id);
return self.downloadReturnId(resp.id) return self.downloadReturnId(resp.id)
@ -124,7 +136,9 @@ class PutIO(DownloaderBase):
client = pio.Client(self.conf('oauth_token')) client = pio.Client(self.conf('oauth_token'))
log.debug('About to get file List') 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') downloaddir = self.conf('download_dir')
for f in files: for f in files:

2
couchpotato/core/media/_base/providers/base.py

@ -94,6 +94,8 @@ class Provider(Plugin):
try: try:
data = XMLTree.fromstring(ss(data)) data = XMLTree.fromstring(ss(data))
return self.getElements(data, item_path) return self.getElements(data, item_path)
except XMLTree.ParseError:
log.error('Invalid XML returned, check "%s" manually for issues', url)
except: except:
log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc()))

33
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.event import fireEvent
from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode
from couchpotato.core.helpers.rss import RSS from couchpotato.core.helpers.rss import RSS
from couchpotato.core.helpers.variable import tryInt from couchpotato.core.helpers.variable import tryInt
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.media._base.providers.nzb.base import NZBProvider from couchpotato.core.media._base.providers.nzb.base import NZBProvider
from dateutil.parser import parse
log = CPLog(__name__) log = CPLog(__name__)
@ -16,8 +12,7 @@ log = CPLog(__name__)
class Base(NZBProvider, RSS): class Base(NZBProvider, RSS):
urls = { urls = {
'search': 'https://rss.omgwtfnzbs.org/rss-search.php?%s', 'search': 'https://api.omgwtfnzbs.org/json/?%s',
'detail_url': 'https://omgwtfnzbs.org/details.php?id=%s',
} }
http_time_between_calls = 1 # Seconds http_time_between_calls = 1 # Seconds
@ -47,22 +42,20 @@ class Base(NZBProvider, RSS):
'api': self.conf('api_key', default = ''), '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 if isinstance(nzbs, list):
nzb_id = parse_qs(urlparse(self.getTextElement(nzb, 'link')).query).get('id')[0] for nzb in nzbs:
results.append({ results.append({
'id': nzb_id, 'id': nzb.get('nzbid'),
'name': toUnicode(self.getTextElement(nzb, 'title')), 'name': toUnicode(nzb.get('release')),
'age': self.calculateAge(int(time.mktime(parse(self.getTextElement(nzb, 'pubDate')).timetuple()))), 'age': self.calculateAge(tryInt(nzb.get('usenetage'))),
'size': tryInt(enclosure['length']) / 1024 / 1024, 'size': tryInt(nzb.get('sizebytes')) / 1024 / 1024,
'url': enclosure['url'], 'url': nzb.get('getnzb'),
'detail_url': self.urls['detail_url'] % nzb_id, 'detail_url': nzb.get('details'),
'description': self.getTextElement(nzb, 'description') 'description': nzb.get('weblink')
}) })
config = [{ config = [{

2
couchpotato/core/media/_base/providers/torrent/torrentbytes.py

@ -56,7 +56,7 @@ class Base(TorrentProvider):
full_id = link['href'].replace('details.php?id=', '') full_id = link['href'].replace('details.php?id=', '')
torrent_id = full_id[:6] torrent_id = full_id[:6]
name = toUnicode(link.contents[0]) name = toUnicode(link.contents[0].encode('ISO-8859-1')).strip()
results.append({ results.append({
'id': torrent_id, 'id': torrent_id,

3
couchpotato/core/media/movie/charts/static/charts.js

@ -44,11 +44,12 @@ var Charts = new Class({
if( Cookie.read('suggestions_charts_menu_selected') === 'charts'){ if( Cookie.read('suggestions_charts_menu_selected') === 'charts'){
self.show(); self.show();
self.fireEvent.delay(0, self, 'created');
} }
else else
self.el.hide(); self.el.hide();
self.fireEvent.delay(0, self, 'created');
}, },
fill: function(json){ fill: function(json){

4
couchpotato/core/media/movie/suggestion/static/suggest.js

@ -51,8 +51,8 @@ var SuggestList = new Class({
self.show(); self.show();
else else
self.hide(); self.hide();
self.fireEvent('created'); self.fireEvent.delay(0, self, 'created');
}, },

9
libs/pio/api.py

@ -154,13 +154,14 @@ class _File(_BaseResource):
return [cls(f) for f in files] return [cls(f) for f in files]
@classmethod @classmethod
def upload(cls, path, name=None): def upload(cls, path, name=None, parent_id=0):
with open(path) as f: with open(path) as f:
if name: if name:
files = {'file': (name, f)} files = {'file': (name, f)}
else: else:
files = {'file': f} 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'] f = d['file']
return cls(f) return cls(f)
@ -239,7 +240,7 @@ class _Transfer(_BaseResource):
@classmethod @classmethod
def add_url(cls, url, parent_id=0, extract=False, callback_url=None): def add_url(cls, url, parent_id=0, extract=False, callback_url=None):
d = cls.client.request('/transfers/add', method='POST', data=dict( 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)) callback_url=callback_url))
t = d['transfer'] t = d['transfer']
return cls(t) return cls(t)
@ -249,7 +250,7 @@ class _Transfer(_BaseResource):
with open(path) as f: with open(path) as f:
files = {'file': f} files = {'file': f}
d = cls.client.request('/files/upload', method='POST', files=files, 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, extract=extract,
callback_url=callback_url)) callback_url=callback_url))
t = d['transfer'] t = d['transfer']

Loading…
Cancel
Save