Skip to content

Commit

Permalink
Merge pull request #9800 from pymedusa/release/release-0.5.17
Browse files Browse the repository at this point in the history
Release/release 0.5.17
  • Loading branch information
medariox authored Aug 16, 2021
2 parents 25e7b60 + 06160b6 commit fbd43ad
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 112 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.5.17 (16-08-2021)

#### Fixes
- Fix history page (compact layout) fails to load. ([9794](https://github.com/pymedusa/Medusa/pull/9794))
- Prevent recommended shows (imdb) to cache empty responses to the api. ([9797](https://github.com/pymedusa/Medusa/pull/9797))
- Fix download handler throwing errors connecting to NZBget. ([9801](https://github.com/pymedusa/Medusa/pull/9801))

## 0.5.16 (13-08-2021)

#### New Features
Expand Down
39 changes: 24 additions & 15 deletions medusa/clients/nzb/nzbget.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,39 @@ def nzb_connection(url):
nzb_get_rpc = ServerProxy(url)
try:
if nzb_get_rpc.writelog('INFO', 'Medusa connected to test connection.'):
log.debug('Successfully connected to NZBget')
msg = 'Successfully connected to NZBget'
log.debug(msg)
else:
log.warning('Successfully connected to NZBget but unable to'
' send a message')
return True
msg = 'Successfully connected to NZBget but unable to send a message'
log.warning(msg)

return True, msg

except ProtocolError as error:
if error.errmsg == 'Unauthorized':
log.warning('NZBget username or password is incorrect.')
msg = 'NZBget username or password is incorrect.'
log.warning(msg)
else:
log.error('Protocol Error: {msg}', {'msg': error.errmsg})
return False
msg = f'Protocol Error: {error.errmsg}'
log.error(msg)

return False, msg

except Error as error:
log.warning('Please check your NZBget host and port (if it is running).'
' NZBget is not responding to this combination.'
' Error: {msg}', {'msg': error.errmsg})
return False
msg = ('Please check your NZBget host and port (if it is running).'
' NZBget is not responding to this combination.'
f' Error: {error}')
log.warning(msg)

return False, msg

except socket.error as error:
log.warning('Please check your NZBget host and port (if it is running).'
' NZBget is not responding to this combination.'
' Socket Error: {msg}', {'msg': error})
return False
msg = ('Please check your NZBget host and port (if it is running).'
' NZBget is not responding to this combination.'
f' Socket Error: {error}')
log.warning(msg)

return False, msg


def test_authentication(host=None, username=None, password=None, use_https=False):
Expand Down
6 changes: 4 additions & 2 deletions medusa/clients/nzb/sab.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ def test_authentication(host=None, username=None, password=None, apikey=None):
data = session.get_json(url, verify=False)

if not data:
log.info('Error connecting to sab, no data returned')
msg = 'Error connecting to SABnzbd, no data returned'
log.warning(msg)
return False, msg
else:
# check the result and determine if it's good or not
result, text = _check_sab_response(data)
return result, 'success' if result else text
return result, 'Successfully connected to SABnzbd' if result else text


@ttl_cache(60.0)
Expand Down
2 changes: 1 addition & 1 deletion medusa/clients/torrent/deluged.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_authentication(self):
if self.connect(True) and self.drpc.test():
return True, 'Success: Connected and Authenticated'
else:
return False, 'Error: Unable to Authenticate! Please check your config!'
return False, 'Error: Unable to Authenticate! Please check your config!'

def remove_ratio_reached(self):
"""Remove all Medusa torrents that ratio was reached.
Expand Down
2 changes: 1 addition & 1 deletion medusa/clients/torrent/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_authentication(self):
"""
r_code = self._get_auth()
if self.message:
return r_code, self.message
return bool(r_code), self.message
elif not self._check_path():
return False, self.message
if r_code:
Expand Down
6 changes: 3 additions & 3 deletions medusa/clients/torrent/rtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def test_authentication(self):
try:
self.auth = None
self._get_auth()
except Exception: # pylint: disable=broad-except
return False, 'Error: Unable to connect to {name}'.format(name=self.name)
except Exception:
return False, f'Error: Unable to connect to {self.name}'
else:
if self.auth is None:
return False, 'Error: Unable to get {name} Authentication, check your config!'.format(name=self.name)
return False, f'Error: Unable to get {self.name} Authentication, check your config!'
else:
return True, 'Success: Connected and Authenticated'

Expand Down
2 changes: 1 addition & 1 deletion medusa/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
log.logger.addHandler(logging.NullHandler())

INSTANCE_ID = text_type(uuid.uuid1())
VERSION = '0.5.16'
VERSION = '0.5.17'
USER_AGENT = 'Medusa/{version} ({system}; {release}; {instance})'.format(
version=VERSION, system=platform.system(), release=platform.release(),
instance=INSTANCE_ID)
Expand Down
12 changes: 1 addition & 11 deletions medusa/helpers/anidb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from medusa.cache import anidb_cache
from medusa.helper.exceptions import AnidbAdbaConnectionException
from medusa.logger.adapters.style import BraceAdapter

import six
from medusa.show.recommendations.recommended import create_key

log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())
Expand Down Expand Up @@ -48,15 +47,6 @@ def set_up_anidb_connection():
return app.ADBA_CONNECTION.authed()


def create_key(namespace, fn, **kw):
def generate_key(*args, **kw):
show_key = namespace + '|' + args[0]
if six.PY2:
return show_key.encode('utf-8')
return show_key
return generate_key


@anidb_cache.cache_on_arguments(namespace='anidb', function_key_generator=create_key)
def get_release_groups_for_anime(series_name):
"""Get release groups for an anidb anime."""
Expand Down
2 changes: 1 addition & 1 deletion medusa/name_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _parse_string(self, name):
elif result.series.is_anime or result.is_anime:
new_episode_numbers, new_season_numbers, new_absolute_numbers = self._parse_anime(result)

elif result.season_number and result.episode_numbers:
elif result.season_number:
new_episode_numbers, new_season_numbers, new_absolute_numbers = self._parse_series(result)

else:
Expand Down
17 changes: 0 additions & 17 deletions medusa/schedulers/download_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,27 +347,10 @@ def _postprocess(self, path, info_hash, resource_name, failed=False):
queue_item = PostProcessQueueItem(path, info_hash, resource_name=resource_name, failed=failed, episodes=episodes)
app.post_processor_queue_scheduler.action.add_item(queue_item)

@staticmethod
def _test_connection(client, client_type):
"""Need to structure, because of some subtle differences between clients."""
if client_type == 'torrent':
return client.test_authentication()

result = client.test_authentication()
if not result:
return False
return result[0]

def _clean(self, client):
"""Update status in the history table for torrents/nzb's that can't be located anymore."""
client_type = 'torrent' if isinstance(client, GenericClient) else 'nzb'

# Make sure the client can be reached. As we don't want to change the state for downloads
# because the client is temporary unavailable.
if not self._test_connection(client, client_type):
log.warning('The client cannot be reached or authentication is failing. Abandon cleanup.')
return

for history_result in self._get_history_results_from_db(client_type):
try:
if not client.get_status(history_result['info_hash']):
Expand Down
6 changes: 3 additions & 3 deletions medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def testSABnzbd(host=None, username=None, password=None, apikey=None):
return 'Error while testing connection. Check warning logs.'

if connection:
authed, auth_msg = sab.test_authentication(host, username, password, apikey) # @UnusedVariable
authed, auth_msg = sab.test_authentication(host, username, password, apikey)
if authed:
return 'Success. Connected and authenticated'
else:
Expand All @@ -210,7 +210,7 @@ def testSABnzbd(host=None, username=None, password=None, apikey=None):
@staticmethod
def testNZBget(host=None, username=None, password=None, use_https=False):
try:
connected_status = nzbget.test_authentication(
connected_status, error_msg = nzbget.test_authentication(
host, username, password, config.checkbox_to_value(use_https)
)
except Exception as error:
Expand All @@ -219,7 +219,7 @@ def testNZBget(host=None, username=None, password=None, use_https=False):
if connected_status:
return 'Success. Connected and authenticated'
else:
return 'Unable to connect to host'
return 'Unable to connect to host. Error: {msg}'.format(msg=error_msg)

@staticmethod
def testTorrent(torrent_method=None, host=None, username=None, password=None):
Expand Down
86 changes: 48 additions & 38 deletions medusa/show/recommendations/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
BasePopular,
RecommendedShow,
cached_get_imdb_series_details,
cached_get_imdb_series_genres,
create_key_from_series,
)

Expand Down Expand Up @@ -77,44 +78,53 @@ def fetch_popular_shows(self):
show_details = None
imdb_id = series['imdb_tt'] = imdb_show['id'].strip('/').split('/')[-1]

if imdb_id:
try:
show_details = cached_get_imdb_series_details(imdb_id)
except RequestException as error:
log.warning('Could not get show details for {imdb_id} with error: {error!r}',
{'imdb_id': imdb_id, 'error': error})

if show_details:
try:
series['year'] = imdb_show.get('year')
series['name'] = imdb_show['title']
series['image_url_large'] = imdb_show['image']['url']
series['image_path'] = posixpath.join('images', 'imdb_popular',
os.path.basename(series['image_url_large']))
series['image_url'] = '{0}{1}'.format(imdb_show['image']['url'].split('V1')[0], '_SY600_AL_.jpg')
series['imdb_url'] = 'http://www.imdb.com{imdb_id}'.format(imdb_id=imdb_show['id'])
series['votes'] = show_details['ratings'].get('ratingCount', 0)
series['outline'] = show_details['plot'].get('outline', {}).get('text')
series['rating'] = show_details['ratings'].get('rating', 0)
series['genres'] = show_details['genres'].get('genres')
except Exception as error:
log.warning('Could not parse show {imdb_id} with error: {error!r}',
{'imdb_id': imdb_id, 'error': error})
else:
continue

if all([series['year'], series['name'], series['imdb_tt']]):
try:
recommended_show = self._create_recommended_show(series)
if recommended_show:
recommended_show.save_to_db()
result.append(recommended_show)
except RequestException:
log.warning(
u'Could not connect to indexers to check if you already have'
u' this show in your library: {show} ({year})',
{'show': series['name'], 'year': series['name']}
)
if not imdb_id:
continue

series['year'] = imdb_show.get('year')
series['name'] = imdb_show['title']
series['image_url_large'] = imdb_show['image']['url']
series['image_path'] = posixpath.join(
'images', 'imdb_popular', os.path.basename(series['image_url_large'])
)
series['image_url'] = '{0}{1}'.format(imdb_show['image']['url'].split('V1')[0], '_SY600_AL_.jpg')
series['imdb_url'] = 'http://www.imdb.com{imdb_id}'.format(imdb_id=imdb_show['id'])

show_details = {}
show_genres = {}
try:
show_details = cached_get_imdb_series_details(imdb_id)
show_genres = cached_get_imdb_series_genres(imdb_id)
except Exception as error:
log.warning('Could not get show details for {imdb_id} with error: {error}',
{'imdb_id': imdb_id, 'error': error})

if not show_details:
continue

# Get details.
try:
series['votes'] = show_details.get('ratings', {}).get('ratingCount', 0)
series['outline'] = show_details.get('plot', {}).get('outline', {}).get('text')
series['rating'] = show_details.get('ratings', {}).get('rating', 0)
except Exception as error:
log.warning('Could not parse show {imdb_id} with error: {error!r}',
{'imdb_id': imdb_id, 'error': error})

series['genres'] = show_genres.get('genres', [])

if all([series['year'], series['name'], series['imdb_tt']]):
try:
recommended_show = self._create_recommended_show(series)
if recommended_show:
recommended_show.save_to_db()
result.append(recommended_show)
except RequestException:
log.warning(
u'Could not connect to indexers to check if you already have'
u' this show in your library: {show} ({year})',
{'show': series['name'], 'year': series['name']}
)

return result

Expand Down
35 changes: 29 additions & 6 deletions medusa/show/recommendations/recommended.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,16 @@ def get_categories():
return categories


def create_key(namespace, fn, **kw):
"""Create key out of namespace + firs arg."""
def generate_key(*args, **kw):
show_key = f'{namespace}|{args[0]}'
return show_key
return generate_key


@LazyApi.load_anidb_api
@recommended_series_cache.cache_on_arguments()
@recommended_series_cache.cache_on_arguments(namespace='tvdb_to_anidb', function_key_generator=create_key)
def cached_tvdb_to_aid(tvdb_id):
"""
Try to match an anidb id with a tvdb id.
Expand All @@ -359,7 +367,7 @@ def cached_tvdb_to_aid(tvdb_id):


@LazyApi.load_anidb_api
@recommended_series_cache.cache_on_arguments()
@recommended_series_cache.cache_on_arguments(namespace='anidb_to_tvdb', function_key_generator=create_key)
def cached_aid_to_tvdb(aid):
"""
Try to match a tvdb id with an anidb id.
Expand All @@ -370,16 +378,31 @@ def cached_aid_to_tvdb(aid):


@LazyApi.load_imdb_api
@recommended_series_cache.cache_on_arguments()
@recommended_series_cache.cache_on_arguments(namespace='series_details', function_key_generator=create_key)
def cached_get_imdb_series_details(imdb_id):
"""
Request the series details from the imdbpie api.
Use dogpile cache to return a cached id if available.
"""
title_detailed = LazyApi.imdb_api.get_title(imdb_id)
title_detailed['genres'] = LazyApi.imdb_api.get_title_genres(imdb_id)
return title_detailed
details = LazyApi.imdb_api.get_title(imdb_id)
if not details:
raise Exception(f'Could not get imdb details from {imdb_id}')
return details


@LazyApi.load_imdb_api
@recommended_series_cache.cache_on_arguments(namespace='series_genres', function_key_generator=create_key)
def cached_get_imdb_series_genres(imdb_id):
"""
Request the series genres from the imdbpie api.
Use dogpile cache to return a cached id if available.
"""
genres = LazyApi.imdb_api.get_title_genres(imdb_id)
if not genres:
raise Exception(f'Could not get imdb genres from {imdb_id}')
return genres


def create_key_from_series(namespace, fn, **kw):
Expand Down
Loading

0 comments on commit fbd43ad

Please sign in to comment.