NZBVortex, create unique ID

This commit is contained in:
Ruud
2014-09-23 17:40:21 +02:00
parent faefd7a5b5
commit f6d4ddbe80
+16 -11
View File
@@ -1,4 +1,5 @@
from base64 import b64encode from base64 import b64encode
import re
from urllib2 import URLError from urllib2 import URLError
from uuid import uuid4 from uuid import uuid4
import hashlib import hashlib
@@ -14,7 +15,7 @@ import urllib2
from couchpotato.core._base.downloader.main import DownloaderBase, ReleaseDownloadList from couchpotato.core._base.downloader.main import DownloaderBase, ReleaseDownloadList
from couchpotato.core.helpers.encoding import tryUrlencode, sp from couchpotato.core.helpers.encoding import tryUrlencode, sp
from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.helpers.variable import cleanHost, randomString
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
@@ -35,13 +36,17 @@ class NZBVortex(DownloaderBase):
# Send the nzb # Send the nzb
try: try:
nzb_id = '%s-%s' % (self.cpTag(media), randomString())
nzb_filename = self.createFileName(data, filedata, media) nzb_filename = self.createFileName(data, filedata, media)
self.call('nzb/add', files = {'file': (nzb_filename, filedata)}) nzb_filename = re.sub('(.cp\(tt[0-9{7}]+\))', '', nzb_filename)
nzb_filename = '%s%s.nzb' % (nzb_filename[0:-4], nzb_id)
response = self.call('nzb/add', files = {'file': (nzb_filename, filedata, 'application/octet-stream')})
time.sleep(10) if response and response.get('result', '').lower() == 'ok':
raw_statuses = self.call('nzb') return self.downloadReturnId(nzb_id)
nzb_id = [nzb['id'] for nzb in raw_statuses.get('nzbs', []) if os.path.basename(nzb['nzbFileName']) == nzb_filename][0]
return self.downloadReturnId(nzb_id) log.error('Something went wrong sending the NZB file. Response: %s', response)
return False
except: except:
log.error('Something went wrong sending the NZB file: %s', traceback.format_exc()) log.error('Something went wrong sending the NZB file: %s', traceback.format_exc())
return False return False
@@ -114,7 +119,7 @@ class NZBVortex(DownloaderBase):
log.error('Login failed, please check you api-key') log.error('Login failed, please check you api-key')
return False return False
def call(self, call, parameters = None, repeat = False, auth = True, *args, **kwargs): def call(self, call, parameters = None, is_repeat = False, auth = True, *args, **kwargs):
# Login first # Login first
if not parameters: parameters = {} if not parameters: parameters = {}
@@ -130,16 +135,16 @@ class NZBVortex(DownloaderBase):
url = cleanHost(self.conf('host'), ssl = self.conf('ssl')) + 'api/' + call url = cleanHost(self.conf('host'), ssl = self.conf('ssl')) + 'api/' + call
try: try:
data = self.urlopen('%s?%s' % (url, params), *args, **kwargs) data = self.getJsonData('%s?%s' % (url, params), *args, **kwargs)
if data: if data:
return json.loads(data) return data
except URLError as e: except URLError as e:
if hasattr(e, 'code') and e.code == 403: if hasattr(e, 'code') and e.code == 403:
# Try login and do again # Try login and do again
if not repeat: if not is_repeat:
self.login() self.login()
return self.call(call, parameters = parameters, repeat = True, **kwargs) return self.call(call, parameters = parameters, is_repeat = True, **kwargs)
log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc()))
except: except: