Urlopen try,except fixes
This commit is contained in:
@@ -3,6 +3,7 @@ from couchpotato.core.downloaders.base import Downloader
|
||||
from couchpotato.core.logger import CPLog
|
||||
from inspect import isfunction
|
||||
import socket
|
||||
import traceback
|
||||
import xmlrpclib
|
||||
|
||||
log = CPLog(__name__)
|
||||
@@ -48,8 +49,8 @@ class NZBGet(Downloader):
|
||||
else:
|
||||
log.info('Downloading: %s' % data.get('url'))
|
||||
file = self.urlopen(data.get('url'))
|
||||
except Exception, e:
|
||||
log.error('Unable to get NZB file: %s' % e)
|
||||
except:
|
||||
log.error('Unable to get NZB file: %s' % traceback.format_exc())
|
||||
return False
|
||||
|
||||
if rpc.append(nzb_name, self.conf('category'), False, standard_b64encode(file.strip())):
|
||||
|
||||
@@ -79,9 +79,9 @@ class NMJ(Notification):
|
||||
|
||||
if self.mount:
|
||||
log.debug('Try to mount network drive via url: %s' % (mount))
|
||||
data = self.urlopen(mount)
|
||||
if not data:
|
||||
log.error('Warning: Couldn\'t contact popcorn hour on host %s' % host)
|
||||
try:
|
||||
data = self.urlopen(mount)
|
||||
except:
|
||||
return False
|
||||
|
||||
params = {
|
||||
@@ -94,9 +94,9 @@ class NMJ(Notification):
|
||||
UPDATE_URL = 'http://%(host)s:8008/metadata_database?%(params)s'
|
||||
updateUrl = UPDATE_URL % {'host': host, 'params': params}
|
||||
|
||||
response = self.urlopen(updateUrl)
|
||||
if not response:
|
||||
log.error('Warning: Couldn\'t contact Popcorn Hour on host %s' % host)
|
||||
try:
|
||||
response = self.urlopen(updateUrl)
|
||||
except:
|
||||
return False
|
||||
|
||||
try:
|
||||
|
||||
@@ -3,6 +3,7 @@ from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
from flask.helpers import json
|
||||
import base64
|
||||
import traceback
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -30,8 +31,8 @@ class Notifo(Notification):
|
||||
if result['status'] != 'success' or result['response_message'] != 'OK':
|
||||
raise Exception
|
||||
|
||||
except Exception, e:
|
||||
log.error('Notification failed: %s' % e)
|
||||
except:
|
||||
log.error('Notification failed: %s' % traceback.format_exc())
|
||||
return False
|
||||
|
||||
log.info('Notifo notification successful.')
|
||||
|
||||
@@ -29,7 +29,9 @@ class XBMC(Notification):
|
||||
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('password')))[:-1]
|
||||
}
|
||||
|
||||
if not self.urlopen(url, headers = headers):
|
||||
try:
|
||||
self.urlopen(url, headers = headers)
|
||||
except:
|
||||
log.error("Couldn't sent command to XBMC")
|
||||
return False
|
||||
|
||||
|
||||
@@ -160,12 +160,20 @@ class Plugin(object):
|
||||
log.error("Something went wrong when finishing the plugin function. Could not find the 'is_running' key")
|
||||
|
||||
|
||||
def getCache(self, cache_key):
|
||||
def getCache(self, cache_key, url = None):
|
||||
cache = Env.get('cache').get(cache_key)
|
||||
if cache:
|
||||
log.debug('Getting cache %s' % cache_key)
|
||||
return cache
|
||||
|
||||
if url:
|
||||
try:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
return data
|
||||
except:
|
||||
pass
|
||||
|
||||
def setCache(self, cache_key, value, timeout = 300):
|
||||
log.debug('Setting cache %s' % cache_key)
|
||||
Env.get('cache').set(cache_key, value, timeout)
|
||||
|
||||
@@ -34,9 +34,9 @@ class FileManager(Plugin):
|
||||
|
||||
def download(self, url = '', dest = None, overwrite = False):
|
||||
|
||||
file = self.urlopen(url)
|
||||
if not file:
|
||||
log.error('File is empty, don\'t download')
|
||||
try:
|
||||
file = self.urlopen(url)
|
||||
except:
|
||||
return False
|
||||
|
||||
if not dest: # to Cache
|
||||
|
||||
@@ -261,7 +261,10 @@ class Searcher(Plugin):
|
||||
|
||||
nfo = self.getCache(cache_key)
|
||||
if not nfo:
|
||||
nfo = self.urlopen('http://www.srrdb.com/showfile.php?release=%s' % check_name)
|
||||
self.setCache(cache_key, nfo)
|
||||
try:
|
||||
nfo = self.urlopen('http://www.srrdb.com/showfile.php?release=%s' % check_name)
|
||||
self.setCache(cache_key, nfo)
|
||||
except:
|
||||
pass
|
||||
|
||||
return getImdb(nfo) == imdb_id
|
||||
|
||||
@@ -20,9 +20,8 @@ class CouchPotatoApi(MovieProvider):
|
||||
|
||||
def releaseDate(self, imdb_id):
|
||||
|
||||
data = self.urlopen((self.apiUrl % ('eta')) + (id + '/'))
|
||||
|
||||
try:
|
||||
data = self.urlopen((self.apiUrl % ('eta')) + (id + '/'))
|
||||
dates = json.loads(data)
|
||||
log.info('Found ETA for %s: %s' % (imdb_id, dates))
|
||||
except Exception, e:
|
||||
@@ -31,10 +30,8 @@ class CouchPotatoApi(MovieProvider):
|
||||
return dates
|
||||
|
||||
def suggest(self, movies = [], ignore = []):
|
||||
|
||||
data = self.urlopen((self.apiUrl % ('suggest')) + ','.join(movies) + '/' + ','.join(ignore) + '/')
|
||||
|
||||
try:
|
||||
data = self.urlopen((self.apiUrl % ('suggest')) + ','.join(movies) + '/' + ','.join(ignore) + '/')
|
||||
suggestions = json.loads(data)
|
||||
log.info('Found Suggestions for %s' % (suggestions))
|
||||
except Exception, e:
|
||||
|
||||
@@ -28,39 +28,32 @@ class Moovee(NZBProvider):
|
||||
url = self.urls['search'] % quote_plus(q)
|
||||
|
||||
cache_key = 'moovee.%s' % q
|
||||
data = self.getCache(cache_key)
|
||||
if not data:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
data = self.getCache(cache_key, url)
|
||||
if data:
|
||||
match = re.compile(self.regex, re.DOTALL).finditer(data)
|
||||
|
||||
if not data:
|
||||
log.error('Failed to get data from %s.' % url)
|
||||
return results
|
||||
for nzb in match:
|
||||
new = {
|
||||
'id': nzb.group('reqid'),
|
||||
'name': nzb.group('title'),
|
||||
'type': 'nzb',
|
||||
'provider': self.getName(),
|
||||
'age': self.calculateAge(time.mktime(parse(nzb.group('age')).timetuple())),
|
||||
'size': None,
|
||||
'url': self.urls['download'] % (nzb.group('reqid')),
|
||||
'download': self.download,
|
||||
'detail_url': '',
|
||||
'description': '',
|
||||
'check_nzb': False,
|
||||
}
|
||||
|
||||
match = re.compile(self.regex, re.DOTALL).finditer(data)
|
||||
|
||||
for nzb in match:
|
||||
new = {
|
||||
'id': nzb.group('reqid'),
|
||||
'name': nzb.group('title'),
|
||||
'type': 'nzb',
|
||||
'provider': self.getName(),
|
||||
'age': self.calculateAge(time.mktime(parse(nzb.group('age')).timetuple())),
|
||||
'size': None,
|
||||
'url': self.urls['download'] % (nzb.group('reqid')),
|
||||
'download': self.download,
|
||||
'detail_url': '',
|
||||
'description': '',
|
||||
'check_nzb': False,
|
||||
}
|
||||
|
||||
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||
nzb = new, movie = movie, quality = quality,
|
||||
imdb_results = False, single_category = False, single = True)
|
||||
if is_correct_movie:
|
||||
results.append(new)
|
||||
self.found(new)
|
||||
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||
nzb = new, movie = movie, quality = quality,
|
||||
imdb_results = False, single_category = False, single = True)
|
||||
if is_correct_movie:
|
||||
results.append(new)
|
||||
self.found(new)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
@@ -66,9 +66,11 @@ class Newzbin(NZBProvider, RSS):
|
||||
headers = {
|
||||
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('password')))[:-1]
|
||||
}
|
||||
|
||||
data = self.urlopen(url, headers = headers)
|
||||
self.setCache(cache_key, data)
|
||||
try:
|
||||
data = self.urlopen(url, headers = headers)
|
||||
self.setCache(cache_key, data)
|
||||
except:
|
||||
return results
|
||||
|
||||
if data:
|
||||
try:
|
||||
|
||||
@@ -100,15 +100,7 @@ class Newznab(NZBProvider, RSS):
|
||||
def createItems(self, url, cache_key, host, single_cat = False, movie = None, quality = None, for_feed = False):
|
||||
results = []
|
||||
|
||||
data = self.getCache(cache_key)
|
||||
if not data:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
|
||||
if not data:
|
||||
log.error('Failed to get data from %s.' % url)
|
||||
return results
|
||||
|
||||
data = self.getCache(cache_key, url)
|
||||
if data:
|
||||
try:
|
||||
try:
|
||||
|
||||
@@ -37,15 +37,7 @@ class NzbIndex(NZBProvider, RSS):
|
||||
|
||||
cache_key = 'nzbindex.%s.%s' % (movie['library'].get('identifier'), quality.get('identifier'))
|
||||
|
||||
data = self.getCache(cache_key)
|
||||
if not data:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
|
||||
if not data:
|
||||
log.error('Failed to get data from %s.' % url)
|
||||
return results
|
||||
|
||||
data = self.getCache(cache_key, url)
|
||||
if data:
|
||||
try:
|
||||
try:
|
||||
|
||||
@@ -50,15 +50,7 @@ class NZBMatrix(NZBProvider, RSS):
|
||||
cache_key = 'nzbmatrix.%s.%s' % (movie['library'].get('identifier'), cat_ids)
|
||||
single_cat = True
|
||||
|
||||
data = self.getCache(cache_key)
|
||||
if not data:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
|
||||
if not data:
|
||||
log.error('Failed to get data from %s.' % url)
|
||||
return results
|
||||
|
||||
data = self.getCache(cache_key, url)
|
||||
if data:
|
||||
try:
|
||||
try:
|
||||
|
||||
@@ -47,15 +47,7 @@ class Nzbs(NZBProvider, RSS):
|
||||
|
||||
cache_key = 'nzbs.%s.%s' % (movie['library'].get('identifier'), str(cat_id))
|
||||
|
||||
data = self.getCache(cache_key)
|
||||
if not data:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
|
||||
if not data:
|
||||
log.error('Failed to get data from %s.' % url)
|
||||
return results
|
||||
|
||||
data = self.getCache(cache_key, url)
|
||||
if data:
|
||||
try:
|
||||
try:
|
||||
|
||||
@@ -27,45 +27,38 @@ class X264(NZBProvider):
|
||||
url = self.urls['search'] % quote_plus(q)
|
||||
|
||||
cache_key = 'x264.%s' % q
|
||||
data = self.getCache(cache_key)
|
||||
if not data:
|
||||
data = self.urlopen(url)
|
||||
self.setCache(cache_key, data)
|
||||
data = self.getCache(cache_key, url)
|
||||
if data:
|
||||
match = re.compile(self.regex, re.DOTALL).finditer(data)
|
||||
|
||||
if not data:
|
||||
log.error('Failed to get data from %s.' % url)
|
||||
return results
|
||||
for nzb in match:
|
||||
try:
|
||||
age_match = re.match('((?P<day>\d+)d)', nzb.group('age'))
|
||||
age = age_match.group('day')
|
||||
except:
|
||||
age = 1
|
||||
|
||||
match = re.compile(self.regex, re.DOTALL).finditer(data)
|
||||
new = {
|
||||
'id': nzb.group('id'),
|
||||
'name': nzb.group('title'),
|
||||
'type': 'nzb',
|
||||
'provider': self.getName(),
|
||||
'age': tryInt(age),
|
||||
'size': None,
|
||||
'url': self.urls['download'] % (nzb.group('id')),
|
||||
'download': self.download,
|
||||
'detail_url': '',
|
||||
'description': '',
|
||||
'check_nzb': False,
|
||||
}
|
||||
|
||||
for nzb in match:
|
||||
try:
|
||||
age_match = re.match('((?P<day>\d+)d)', nzb.group('age'))
|
||||
age = age_match.group('day')
|
||||
except:
|
||||
age = 1
|
||||
|
||||
new = {
|
||||
'id': nzb.group('id'),
|
||||
'name': nzb.group('title'),
|
||||
'type': 'nzb',
|
||||
'provider': self.getName(),
|
||||
'age': tryInt(age),
|
||||
'size': None,
|
||||
'url': self.urls['download'] % (nzb.group('id')),
|
||||
'download': self.download,
|
||||
'detail_url': '',
|
||||
'description': '',
|
||||
'check_nzb': False,
|
||||
}
|
||||
|
||||
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||
nzb = new, movie = movie, quality = quality,
|
||||
imdb_results = False, single_category = False, single = True)
|
||||
if is_correct_movie:
|
||||
results.append(new)
|
||||
self.found(new)
|
||||
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||
nzb = new, movie = movie, quality = quality,
|
||||
imdb_results = False, single_category = False, single = True)
|
||||
if is_correct_movie:
|
||||
results.append(new)
|
||||
self.found(new)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@ class HDTrailers(TrailerProvider):
|
||||
movie_name = movie['library']['titles'][0]['title']
|
||||
|
||||
url = self.url['api'] % self.movieUrlName(movie_name)
|
||||
data = self.urlopen(url)
|
||||
try:
|
||||
data = self.urlopen(url)
|
||||
except:
|
||||
return {}
|
||||
|
||||
p480 = []
|
||||
p720 = []
|
||||
@@ -45,7 +48,10 @@ class HDTrailers(TrailerProvider):
|
||||
results = {'480p':[], '720p':[], '1080p':[]}
|
||||
|
||||
url = "%s?%s" % (self.url['backup'], urlencode({'s':movie}))
|
||||
data = self.urlopen(url)
|
||||
try:
|
||||
data = self.urlopen(url)
|
||||
except:
|
||||
return results
|
||||
|
||||
try:
|
||||
tables = SoupStrainer('div')
|
||||
|
||||
@@ -10,7 +10,10 @@ class AlloCine(UserscriptBase):
|
||||
if not 'fichefilm_gen_cfilm' in url:
|
||||
return 'Url isn\'t from a movie'
|
||||
|
||||
data = self.urlopen(url)
|
||||
try:
|
||||
data = self.urlopen(url)
|
||||
except:
|
||||
return
|
||||
|
||||
html = BeautifulSoup(data)
|
||||
title = html.find('title').contents[0].strip()
|
||||
|
||||
@@ -8,7 +8,10 @@ class AppleTrailers(UserscriptBase):
|
||||
|
||||
def getMovie(self, url):
|
||||
|
||||
data = self.urlopen(url)
|
||||
try:
|
||||
data = self.urlopen(url)
|
||||
except:
|
||||
return
|
||||
|
||||
name = re.search("trailerTitle.*=.*\'(?P<name>.*)\';", data)
|
||||
name = name.group('name').decode('string_escape')
|
||||
|
||||
@@ -42,7 +42,10 @@ class UserscriptBase(Plugin):
|
||||
return
|
||||
|
||||
def getMovie(self, url):
|
||||
data = self.urlopen(url)
|
||||
try:
|
||||
data = self.urlopen(url)
|
||||
except:
|
||||
data = ''
|
||||
return self.getInfo(getImdb(data))
|
||||
|
||||
def getInfo(self, identifier):
|
||||
|
||||
Reference in New Issue
Block a user