Skip to content

Commit

Permalink
update version
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDoobPG authored and MrDoobPG committed Nov 6, 2019
1 parent b21acf5 commit 3b5233e
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 316 deletions.
6 changes: 4 additions & 2 deletions menu/traktarr/helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def get_response_dict(response, key_field=None, key_value=None):
break

if not found_response:
log.error("Unable to find a result with key %s where the value is %s", key_field, key_value)
log.error(
"Unable to find a result with key %s where the value is %s", key_field, key_value)

elif isinstance(response, dict):
found_response = response
else:
log.error("Unexpected response instance type of %s for %s", type(response).__name__, response)
log.error("Unexpected response instance type of %s for %s",
type(response).__name__, response)

except Exception:
log.exception("Exception determining response for %s: ", response)
Expand Down
3 changes: 2 additions & 1 deletion menu/traktarr/helpers/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def remove_existing_movies(radarr_movies, trakt_movies, callback=None):
# loop list adding to movies that do not already exist
for tmp in trakt_movies:
if 'movie' not in tmp or 'ids' not in tmp['movie'] or 'tmdb' not in tmp['movie']['ids']:
log.debug("Skipping movie because it did not have required fields: %s", tmp)
log.debug(
"Skipping movie because it did not have required fields: %s", tmp)
if callback:
callback('movie', tmp)
continue
Expand Down
21 changes: 12 additions & 9 deletions menu/traktarr/helpers/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
import requests

log = logger.get_logger(__name__)
def get_rating(apikey,movie):
imdbID = movie['movie']['ids']['imdb']


def get_rating(apikey, movie):
imdbID = movie['movie']['ids']['imdb']
if(imdbID):
log.debug("Requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(),imdbID)
r = requests.get('http://www.omdbapi.com/?i=' + imdbID + '&apikey=' + apikey)
log.debug("Requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s", movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
r = requests.get('http://www.omdbapi.com/?i=' +
imdbID + '&apikey=' + apikey)
if(r.status_code == 200):
log.debug("Successfully requested ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
for source in json.loads(r.text)["Ratings"]:
if(source['Source'] == 'Rotten Tomatoes'):
log.debug("Rotten Tomatoes shows rating: %s for %s (%d) | Genres: %s | Country: %s | imdbID: %s ",source['Value'],movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(),imdbID)
log.debug("Rotten Tomatoes shows rating: %s for %s (%d) | Genres: %s | Country: %s | imdbID: %s ", source['Value'], movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
return int(source['Value'].split('%')[0])
else:
log.debug("Error encountered when requesting ratings from OMDB for %s (%d) | Genres: %s | Country: %s | imdbID: %s",
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper(), imdbID)
else:
log.debug("Skipping %s (%d) | Genres: %s | Country: %s as it does not have an imdbID",
movie['movie']['title'], movie['movie']['year'],
Expand Down
12 changes: 8 additions & 4 deletions menu/traktarr/helpers/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ def series_tag_id_from_network(profile_tags, network_tags, network):
for tag_name, tag_networks in network_tags.items():
for tag_network in tag_networks:
if tag_network.lower() in network.lower() and tag_name.lower() in profile_tags:
log.debug("Using %s tag for network: %s", tag_name, network)
log.debug("Using %s tag for network: %s",
tag_name, network)
tags.append(profile_tags[tag_name.lower()])
if tags:
return tags
except Exception:
log.exception("Exception determining tag to use for network %s: ", network)
log.exception(
"Exception determining tag to use for network %s: ", network)
return None


Expand All @@ -30,7 +32,8 @@ def readable_tag_from_ids(profile_tag_ids, chosen_tag_ids):
if tags:
return tags
except Exception:
log.exception("Exception building readable tag name list from ids %s: ", chosen_tag_ids)
log.exception(
"Exception building readable tag name list from ids %s: ", chosen_tag_ids)
return None


Expand Down Expand Up @@ -64,7 +67,8 @@ def remove_existing_series(sonarr_series, trakt_series, callback=None):
# loop list adding to series that do not already exist
for tmp in trakt_series:
if 'show' not in tmp or 'ids' not in tmp['show'] or 'tvdb' not in tmp['show']['ids']:
log.debug("Skipping show because it did not have required fields: %s", tmp)
log.debug(
"Skipping show because it did not have required fields: %s", tmp)
if callback:
callback('show', tmp)
continue
Expand Down
35 changes: 35 additions & 0 deletions menu/traktarr/helpers/str.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from misc.log import logger

log = logger.get_logger(__name__)


def get_year_from_timestamp(timestamp):
year = 0
try:
if not timestamp:
return 0

year = timestamp[:timestamp.index('-')]
except Exception:
log.exception("Exception parsing year from %s: ", timestamp)
return int(year) if str(year).isdigit() else 0


def is_ascii(string):
try:
string.encode('ascii')
except UnicodeEncodeError:
return False
except UnicodeDecodeError:
return False
except Exception:
log.exception(u"Exception checking if %r was ascii: ", string)
return False
return True


def ensure_endswith(data, endswith_key):
if not data.strip().endswith(endswith_key):
return "%s%s" % (data.strip(), endswith_key)
else:
return data
Loading

0 comments on commit 3b5233e

Please sign in to comment.