Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_trakt_refresh(cls, username, authorization):
log.debug('[Trakt.tv] Token has been refreshed for %r', username)
# Retrieve trakt account matching this `authorization`
with Trakt.configuration.http(retry=True).oauth(token=authorization.get('access_token')):
settings = Trakt['users/settings'].get(validate_token=False)
if not settings:
log.warn('[Trakt.tv] Unable to retrieve account details for token')
return False
# Retrieve trakt account username from `settings`
s_username = settings.get('user', {}).get('username')
if not s_username:
log.warn('[Trakt.tv] Unable to retrieve username for token')
return False
if s_username != username:
log.warn('[Trakt.tv] Token mismatch (%r != %r)', s_username, username)
return False
def getTextQuery(self, query, type, year):
with Trakt.configuration.http(retry=True, timeout=90):
result = Trakt['search'].query(query, type, year)
if result and not isinstance(result, list):
result = [result]
return result
def getMovieSummary(self, movieId):
with Trakt.configuration.http(retry=True):
return Trakt['movies'].get(movieId)
def getShowRatingForUser(self, showId, idType='tvdb'):
ratings = {}
with Trakt.configuration.oauth.from_response(self.authorization):
with Trakt.configuration.http(retry=True):
Trakt['sync/ratings'].shows(ratings)
return findShowMatchInList(showId, ratings, idType)
def getUser(self):
with Trakt.configuration.oauth.from_response(self.authorization):
with Trakt.configuration.http(retry=True):
result = Trakt['users/settings'].get()
return result
def getEpisodeSummary(self, showId, season, episode):
with Trakt.configuration.http(retry=True):
return Trakt['shows'].episode(showId, season, episode)
def getShowsWatched(self, shows):
with Trakt.configuration.oauth.from_response(self.authorization):
with Trakt.configuration.http(retry=True, timeout=90):
Trakt['sync/watched'].shows(shows, exceptions=True)
return shows
def getShowRatingForUser(self, showId, idType='tvdb'):
ratings = {}
with Trakt.configuration.oauth.from_response(self.authorization):
with Trakt.configuration.http(retry=True):
Trakt['sync/ratings'].shows(ratings)
return findShowMatchInList(showId, ratings, idType)
def removeRating(self, mediaObject):
with Trakt.configuration.oauth.from_response(self.authorization):
with Trakt.configuration.http(retry=True):
result = Trakt['sync/ratings'].remove(mediaObject)
return result
def scrobbleMovie(self, movie, percent, status):
result = None
with Trakt.configuration.oauth.from_response(self.authorization):
if status == 'start':
with Trakt.configuration.http(retry=True):
result = Trakt['scrobble'].start(
movie=movie,
progress=percent)
elif status == 'pause':
with Trakt.configuration.http(retry=True):
result = Trakt['scrobble'].pause(
movie=movie,
progress=percent)
elif status == 'stop':
# don't retry on stop, this will cause multiple scrobbles
result = Trakt['scrobble'].stop(
movie=movie,
progress=percent)
else:
logger.debug("scrobble() Bad scrobble status")
return result