本文整理汇总了Python中libtrakt.TraktAPI类的典型用法代码示例。如果您正苦于以下问题:Python TraktAPI类的具体用法?Python TraktAPI怎么用?Python TraktAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TraktAPI类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_notify
def test_notify(self, username, blacklist_name=None):
"""
Sends a test notification to trakt with the given authentication info and returns a boolean
representing success.
api: The api string to use
username: The username to use
blacklist_name: slug of trakt list used to hide not interested show
Returns: True if the request succeeded, False otherwise
"""
try:
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
trakt_api.validateAccount()
if blacklist_name and blacklist_name is not None:
trakt_lists = trakt_api.traktRequest("users/" + username + "/lists")
found = False
for trakt_list in trakt_lists:
if trakt_list['ids']['slug'] == blacklist_name:
return "Test notice sent successfully to Trakt"
if not found:
return "Trakt blacklist doesn't exists"
else:
return "Test notice sent successfully to Trakt"
except (traktException, traktAuthException, traktServerBusy) as e:
logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
return "Test notice failed to Trakt: %s" % ex(e)
示例2: addShowToBlacklist
def addShowToBlacklist(self, indexer_id):
# URL parameters
data = {'shows': [{'ids': {'tvdb': indexer_id}}]}
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
trakt_api.traktRequest('users/{user}/lists/{blacklist}/items'.format
(user=sickbeard.TRAKT_USERNAME, blacklist=sickbeard.TRAKT_BLACKLIST_NAME),
data, method='POST')
return self.redirect('/addShows/trendingShows/')
示例3: __init__
def __init__(self):
self.trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
self.todoWanted = []
self.show_watchlist = {}
self.episode_watchlist = {}
self.collection_list = {}
self.amActive = False
示例4: __init__
def __init__(self):
self.trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
self.todoBacklog = []
self.todoWanted = []
self.ShowWatchlist = {}
self.EpisodeWatchlist = {}
self.Collectionlist = {}
self.amActive = False
示例5: update_library
def update_library(self, ep_obj):
"""
Sends a request to trakt indicating that the given episode is part of our library.
ep_obj: The TVEpisode object to add to trakt
"""
trakt_id = sickbeard.indexerApi(ep_obj.show.indexer).config['trakt_id']
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
if sickbeard.USE_TRAKT:
try:
# URL parameters
data = {
'shows': [
{
'title': ep_obj.show.name,
'year': ep_obj.show.startyear,
'ids': {},
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = ep_obj.show.indexerid
else:
data['shows'][0]['ids']['tvrage'] = ep_obj.show.indexerid
if sickbeard.TRAKT_SYNC_WATCHLIST:
if sickbeard.TRAKT_REMOVE_SERIESLIST:
trakt_api.traktRequest("sync/watchlist/remove", data, method='POST')
# Add Season and Episode + Related Episodes
data['shows'][0]['seasons'] = [{'number': ep_obj.season, 'episodes': []}]
for relEp_Obj in [ep_obj] + ep_obj.relatedEps:
data['shows'][0]['seasons'][0]['episodes'].append({'number': relEp_Obj.episode})
if sickbeard.TRAKT_SYNC_WATCHLIST:
if sickbeard.TRAKT_REMOVE_WATCHLIST:
trakt_api.traktRequest("sync/watchlist/remove", data, method='POST')
# update library
trakt_api.traktRequest("sync/collection", data, method='POST')
except (traktException, traktAuthException, traktServerBusy) as e:
logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
示例6: run
def run(self): # pylint: disable=too-many-branches, too-many-statements, too-many-return-statements
super(QueueItemAdd, self).run()
if self.showDir:
try:
assert isinstance(self.showDir, six.text_type)
except AssertionError:
logger.log(traceback.format_exc(), logger.WARNING)
self._finish_early()
return
logger.log('Starting to add show {0}'.format('by ShowDir: {0}'.format(self.showDir) if self.showDir else 'by Indexer Id: {0}'.format(self.indexer_id)))
# make sure the Indexer IDs are valid
try:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
lINDEXER_API_PARMS['language'] = self.lang or sickbeard.INDEXER_DEFAULT_LANGUAGE
logger.log('{0}: {1!r}'.format(sickbeard.indexerApi(self.indexer).name, lINDEXER_API_PARMS))
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
s = t[self.indexer_id]
# Let's try to create the show Dir if it's not provided. This way we force the show dir to build build using the
# Indexers provided series name
if self.root_dir and not self.showDir:
show_name = get_showname_from_indexer(self.indexer, self.indexer_id, self.lang)
if not show_name:
logger.log('Unable to get a show {0}, can\'t add the show'.format(self.showDir))
self._finish_early()
return
self.showDir = ek(os.path.join, self.root_dir, sanitize_filename(show_name))
dir_exists = makeDir(self.showDir)
if not dir_exists:
logger.log('Unable to create the folder {0}, can\'t add the show'.format(self.showDir))
self._finish_early()
return
chmodAsParent(self.showDir)
# this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no proper english version of the show
if getattr(s, 'seriesname', None) is None:
# noinspection PyPep8
error_string = 'Show in {0} has no name on {1}, probably searched with the wrong language. Delete .nfo and add manually in the correct language.'.format(
self.showDir, sickbeard.indexerApi(self.indexer).name)
logger.log(error_string, logger.WARNING)
ui.notifications.error('Unable to add show', error_string)
self._finish_early()
return
# if the show has no episodes/seasons
if not s:
error_string = 'Show {0} is on {1} but contains no season/episode data.'.format(
s[b'seriesname'], sickbeard.indexerApi(self.indexer).name)
logger.log(error_string)
ui.notifications.error('Unable to add show', error_string)
self._finish_early()
return
except Exception as error:
error_string = 'Unable to look up the show in {0} on {1} using ID {2}, not using the NFO. Delete .nfo and try adding manually again.'.format(
self.showDir, sickbeard.indexerApi(self.indexer).name, self.indexer_id)
logger.log('{0}: {1}'.format(error_string, error), logger.ERROR)
ui.notifications.error(
'Unable to add show', error_string)
if sickbeard.USE_TRAKT:
trakt_id = sickbeard.indexerApi(self.indexer).config[b'trakt_id']
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
title = self.showDir.split('/')[-1]
data = {
'shows': [
{
'title': title,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = self.indexer_id
else:
data['shows'][0]['ids']['tvrage'] = self.indexer_id
trakt_api.traktRequest('sync/watchlist/remove', data, method='POST')
self._finish_early()
return
try:
try:
newShow = TVShow(self.indexer, self.indexer_id, self.lang)
except MultipleShowObjectsException as error:
#.........这里部分代码省略.........
示例7: TraktChecker
class TraktChecker(object):
def __init__(self):
self.trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
self.todoBacklog = []
self.todoWanted = []
self.ShowWatchlist = {}
self.EpisodeWatchlist = {}
self.Collectionlist = {}
self.amActive = False
def run(self, force=False):
self.amActive = True
# add shows from trakt.tv watchlist
if sickbeard.TRAKT_SYNC_WATCHLIST:
self.todoWanted = [] # its about to all get re-added
if len(sickbeard.ROOT_DIRS.split('|')) < 2:
logger.log(u"No default root directory", logger.WARNING)
return
try:
self.syncWatchlist()
except Exception:
logger.log(traceback.format_exc(), logger.DEBUG)
try:
# sync trakt.tv library with sickrage library
self.syncLibrary()
except Exception:
logger.log(traceback.format_exc(), logger.DEBUG)
self.amActive = False
def findShow(self, indexer, indexerid):
traktShow = None
try:
library = self.trakt_api.traktRequest("sync/collection/shows") or []
if not library:
logger.log(u"Could not connect to trakt service, aborting library check", logger.WARNING)
return
if not len(library):
logger.log(u"No shows found in your library, aborting library update", logger.DEBUG)
return
traktShow = [x for x in library if int(indexerid) in [int(x['show']['ids']['tvdb'] or 0), int(x['show']['ids']['tvrage'] or 0)]]
except traktException as e:
logger.log(u"Could not connect to Trakt service. Aborting library check. Error: %s" % repr(e), logger.WARNING)
return traktShow
def removeShowFromTraktLibrary(self, show_obj):
if self.findShow(show_obj.indexer, show_obj.indexerid):
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
# URL parameters
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = show_obj.indexerid
else:
data['shows'][0]['ids']['tvrage'] = show_obj.indexerid
logger.log(u"Removing %s from trakt.tv library" % show_obj.name, logger.DEBUG)
try:
self.trakt_api.traktRequest("sync/collection/remove", data, method='POST')
except traktException as e:
logger.log(u"Could not connect to Trakt service. Aborting removing show %s from Trakt library. Error: %s" % (show_obj.name, repr(e)), logger.WARNING)
def addShowToTraktLibrary(self, show_obj):
"""
Sends a request to trakt indicating that the given show and all its episodes is part of our library.
show_obj: The TVShow object to add to trakt
"""
data = {}
if not self.findShow(show_obj.indexer, show_obj.indexerid):
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
# URL parameters
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {}
}
]
}
#.........这里部分代码省略.........
示例8: run
def run(self):
ShowQueueItem.run(self)
logger.log(u"Starting to add show {0}".format("by ShowDir: {0}".format(self.showDir) if self.showDir else "by Indexer Id: {0}".format(self.indexer_id)))
# make sure the Indexer IDs are valid
try:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
if self.lang:
lINDEXER_API_PARMS['language'] = self.lang
logger.log(u"" + str(sickbeard.indexerApi(self.indexer).name) + ": " + repr(lINDEXER_API_PARMS))
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
s = t[self.indexer_id]
# Let's try to create the show Dir if it's not provided. This way we force the show dir to build build using the
# Indexers provided series name
if not self.showDir and self.root_dir:
show_name = get_showname_from_indexer(self.indexer, self.indexer_id, self.lang)
if show_name:
self.showDir = ek(os.path.join, self.root_dir, sanitize_filename(show_name))
dir_exists = makeDir(self.showDir)
if not dir_exists:
logger.log(u"Unable to create the folder {0}, can't add the show".format(self.showDir))
return
chmodAsParent(self.showDir)
else:
logger.log(u"Unable to get a show {0}, can't add the show".format(self.showDir))
return
# this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no proper english version of the show
if getattr(s, 'seriesname', None) is None:
logger.log(u"Show in {} has no name on {}, probably searched with the wrong language.".format
(self.showDir, sickbeard.indexerApi(self.indexer).name), logger.ERROR)
ui.notifications.error("Unable to add show",
"Show in " + self.showDir + " has no name on " + str(sickbeard.indexerApi(
self.indexer).name) + ", probably the wrong language. Delete .nfo and add manually in the correct language.")
self._finishEarly()
return
# if the show has no episodes/seasons
if not s:
logger.log(u"Show " + str(s['seriesname']) + " is on " + str(
sickbeard.indexerApi(self.indexer).name) + " but contains no season/episode data.")
ui.notifications.error("Unable to add show",
"Show " + str(s['seriesname']) + " is on " + str(sickbeard.indexerApi(
self.indexer).name) + " but contains no season/episode data.")
self._finishEarly()
return
except Exception as e:
logger.log(u"%s Error while loading information from indexer %s. Error: %r" % (self.indexer_id, sickbeard.indexerApi(self.indexer).name, ex(e)), logger.ERROR)
# logger.log(u"Show name with ID %s doesn't exist on %s anymore. If you are using trakt, it will be removed from your TRAKT watchlist. If you are adding manually, try removing the nfo and adding again" %
# (self.indexer_id, sickbeard.indexerApi(self.indexer).name), logger.WARNING)
ui.notifications.error(
"Unable to add show",
"Unable to look up the show in %s on %s using ID %s, not using the NFO. Delete .nfo and try adding manually again." %
(self.showDir, sickbeard.indexerApi(self.indexer).name, self.indexer_id)
)
if sickbeard.USE_TRAKT:
trakt_id = sickbeard.indexerApi(self.indexer).config['trakt_id']
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
title = self.showDir.split("/")[-1]
data = {
'shows': [
{
'title': title,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = self.indexer_id
else:
data['shows'][0]['ids']['tvrage'] = self.indexer_id
trakt_api.traktRequest("sync/watchlist/remove", data, method='POST')
self._finishEarly()
return
try:
newShow = TVShow(self.indexer, self.indexer_id, self.lang)
newShow.load_from_indexer()
self.show = newShow
# set up initial values
self.show.location = self.showDir
self.show.subtitles = self.subtitles if self.subtitles is not None else sickbeard.SUBTITLES_DEFAULT
self.show.quality = self.quality if self.quality else sickbeard.QUALITY_DEFAULT
self.show.flatten_folders = self.flatten_folders if self.flatten_folders is not None else sickbeard.FLATTEN_FOLDERS_DEFAULT
self.show.anime = self.anime if self.anime is not None else sickbeard.ANIME_DEFAULT
self.show.scene = self.scene if self.scene is not None else sickbeard.SCENE_DEFAULT
#.........这里部分代码省略.........
示例9: run
def run(self):
ShowQueueItem.run(self)
logger.log(u"Starting to add show " + self.showDir)
# make sure the Indexer IDs are valid
try:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
if self.lang:
lINDEXER_API_PARMS['language'] = self.lang
logger.log(u"" + str(sickbeard.indexerApi(self.indexer).name) + ": " + repr(lINDEXER_API_PARMS))
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
s = t[self.indexer_id]
# this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no proper english version of the show
if getattr(s, 'seriesname', None) is None:
logger.log(u"Show in " + self.showDir + " has no name on " + str(
sickbeard.indexerApi(self.indexer).name) + ", probably the wrong language used to search with.",
logger.ERROR)
ui.notifications.error("Unable to add show",
"Show in " + self.showDir + " has no name on " + str(sickbeard.indexerApi(
self.indexer).name) + ", probably the wrong language. Delete .nfo and add manually in the correct language.")
self._finishEarly()
return
# if the show has no episodes/seasons
if not s:
logger.log(u"Show " + str(s['seriesname']) + " is on " + str(
sickbeard.indexerApi(self.indexer).name) + " but contains no season/episode data.", logger.ERROR)
ui.notifications.error("Unable to add show",
"Show " + str(s['seriesname']) + " is on " + str(sickbeard.indexerApi(
self.indexer).name) + " but contains no season/episode data.")
self._finishEarly()
return
except Exception, e:
logger.log(u"Error while loading information from indexer %s. Error: %r" % (self.indexer_id,sickbeard.indexerApi(self.indexer).name, ex(e)),logger.ERROR)
#logger.log(u"Show name with ID %s doesn't exist on %s anymore. If you are using trakt, it will be removed from your TRAKT watchlist. If you are adding manually, try removing the nfo and adding again" %
# (self.indexer_id,sickbeard.indexerApi(self.indexer).name) , logger.WARNING)
ui.notifications.error("Unable to add show",
"Unable to look up the show in " + self.showDir + " on " + str(sickbeard.indexerApi(
self.indexer).name) + " using ID " + str(
self.indexer_id) + ", not using the NFO. Delete .nfo and try adding manually again.")
if sickbeard.USE_TRAKT:
trakt_id = sickbeard.indexerApi(self.indexer).config['trakt_id']
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
title = self.showDir.split("/")[-1]
data = {
'shows': [
{
'title': title,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = self.indexer_id
else:
data['shows'][0]['ids']['tvrage'] = self.indexer_id
trakt_api.traktRequest("sync/watchlist/remove", data, method='POST')
self._finishEarly()
return
示例10: update_watchlist
def update_watchlist(self, show_obj=None, s=None, e=None, data_show=None, data_episode=None, update="add"):
"""
Sends a request to trakt indicating that the given episode is part of our library.
show_obj: The TVShow object to add to trakt
s: season number
e: episode number
data_show: structured object of shows trakt type
data_episode: structured object of episodes trakt type
update: type o action add or remove
"""
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
if sickbeard.USE_TRAKT:
data = {}
try:
# URL parameters
if show_obj is not None:
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {},
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = show_obj.indexerid
else:
data['shows'][0]['ids']['tvrage'] = show_obj.indexerid
elif data_show is not None:
data.update(data_show)
else:
logger.log(u"there's a coding problem contact developer. It's needed to be provided at lest one of the two: data_show or show_obj", logger.WARNING)
return False
if data_episode is not None:
data['shows'][0].update(data_episode)
elif s is not None:
# trakt URL parameters
season = {
'season': [
{
'number': s,
}
]
}
if e is not None:
# trakt URL parameters
episode = {
'episodes': [
{
'number': e
}
]
}
season['season'][0].update(episode)
data['shows'][0].update(season)
trakt_url = "sync/watchlist"
if update == "remove":
trakt_url += "/remove"
trakt_api.traktRequest(trakt_url, data, method='POST')
except (traktException, traktAuthException, traktServerBusy) as e:
logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING)
return False
return True
示例11: TraktChecker
class TraktChecker(object):
def __init__(self):
self.trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
self.todoBacklog = []
self.todoWanted = []
self.ShowWatchlist = {}
self.EpisodeWatchlist = {}
self.Collectionlist = {}
self.amActive = False
def run(self, force=False):
self.amActive = True
# add shows from trakt.tv watchlist
if sickbeard.TRAKT_SYNC_WATCHLIST:
self.todoWanted = [] # its about to all get re-added
if len(sickbeard.ROOT_DIRS.split('|')) < 2:
logger.log("No default root directory", logger.WARNING)
return
try:
self.syncWatchlist()
except Exception:
logger.log(traceback.format_exc(), logger.DEBUG)
try:
# sync trakt.tv library with sickrage library
self.syncLibrary()
except Exception:
logger.log(traceback.format_exc(), logger.DEBUG)
# check if the user has watched any episode
if sickbeard.TRAKT_SYNC_WATCHED:
self.updateWatchedData()
self.amActive = False
def findShow(self, indexer, indexerid):
traktShow = None
try:
library = self.trakt_api.traktRequest("sync/collection/shows") or []
if not library:
logger.log("No shows found in your library, aborting library update", logger.DEBUG)
return
traktShow = [x for x in library if int(indexerid) in [int(x['show']['ids']['tvdb'] or 0), int(x['show']['ids']['tvrage'] or 0)]]
except traktException as e:
logger.log("Could not connect to Trakt service. Aborting library check. Error: {0}".format(repr(e)), logger.WARNING)
return traktShow
def removeShowFromTraktLibrary(self, show_obj):
if self.findShow(show_obj.indexer, show_obj.indexerid):
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
# URL parameters
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = show_obj.indexerid
else:
data['shows'][0]['ids']['tvrage'] = show_obj.indexerid
logger.log("Removing {0} from trakt.tv library".format(show_obj.name), logger.DEBUG)
try:
self.trakt_api.traktRequest("sync/collection/remove", data, method='POST')
except traktException as e:
logger.log("Could not connect to Trakt service. Aborting removing show {0} from Trakt library. Error: {1}".format(show_obj.name, repr(e)), logger.WARNING)
def addShowToTraktLibrary(self, show_obj):
"""
Sends a request to trakt indicating that the given show and all its episodes is part of our library.
show_obj: The TVShow object to add to trakt
"""
data = {}
if not self.findShow(show_obj.indexer, show_obj.indexerid):
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
# URL parameters
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {}
}
]
}
#.........这里部分代码省略.........
示例12: TraktChecker
class TraktChecker(object):
def __init__(self):
self.trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
self.todoWanted = []
self.show_watchlist = {}
self.episode_watchlist = {}
self.collection_list = {}
self.amActive = False
def run(self, force=False): # pylint: disable=unused-argument
self.amActive = True
# add shows from Trakt watchlist
if sickbeard.TRAKT_SYNC_WATCHLIST:
self.todoWanted = [] # its about to all get re-added
if len(sickbeard.ROOT_DIRS.split('|')) < 2:
logger.log(u"No default root directory", logger.WARNING)
return
try:
self.sync_watchlist()
except Exception:
logger.log(traceback.format_exc(), logger.DEBUG)
try:
# sync Trakt library with medusa library
self.sync_library()
except Exception:
logger.log(traceback.format_exc(), logger.DEBUG)
self.amActive = False
def find_show(self, indexerid):
try:
trakt_library = self.trakt_api.traktRequest("sync/collection/shows") or []
if not trakt_library:
logger.log(u"No shows found in your library, aborting library update", logger.DEBUG)
return
trakt_show = [x for x in trakt_library if int(indexerid) in [int(x['show']['ids']['tvdb'] or 0), int(x['show']['ids']['tvrage'] or 0)]]
except traktException as e:
logger.log(u"Could not connect to Trakt. Aborting library check. Error: {}".format(repr(e)), logger.WARNING)
return trakt_show if trakt_show else None
def remove_show_trakt_library(self, show_obj):
if self.find_show(show_obj.indexerid):
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
# URL parameters
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = show_obj.indexerid
else:
data['shows'][0]['ids']['tvrage'] = show_obj.indexerid
logger.log(u"Removing '{}' from Trakt library".format(show_obj.name), logger.DEBUG)
try:
self.trakt_api.traktRequest("sync/collection/remove", data, method='POST')
except traktException as e:
logger.log(u"Could not connect to Trakt. Aborting removing show '{}' from Trakt library. Error: {}".format(show_obj.name, repr(e)), logger.WARNING)
def add_show_trakt_library(self, show_obj):
"""
Sends a request to trakt indicating that the given show and all its episodes is part of our library.
show_obj: The TVShow object to add to trakt
"""
data = {}
if not self.find_show(show_obj.indexerid):
trakt_id = sickbeard.indexerApi(show_obj.indexer).config['trakt_id']
# URL parameters
data = {
'shows': [
{
'title': show_obj.name,
'year': show_obj.startyear,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data['shows'][0]['ids']['tvdb'] = show_obj.indexerid
else:
data['shows'][0]['ids']['tvrage'] = show_obj.indexerid
if data:
#.........这里部分代码省略.........
示例13: getTrendingShows
def getTrendingShows(self, traktList=None):
"""
Display the new show page which collects a tvdb id, folder, and extra options and
posts them to addNewShow
"""
t = PageTemplate(rh=self, filename='trendingShows.mako')
trakt_list = traktList if traktList else ''
trakt_list = trakt_list.lower()
if trakt_list == 'trending':
page_url = 'shows/trending'
elif trakt_list == 'popular':
page_url = 'shows/popular'
elif trakt_list == 'anticipated':
page_url = 'shows/anticipated'
elif trakt_list == 'collected':
page_url = 'shows/collected'
elif trakt_list == 'watched':
page_url = 'shows/watched'
elif trakt_list == 'played':
page_url = 'shows/played'
elif trakt_list == 'recommended':
page_url = 'recommendations/shows'
elif trakt_list == 'newshow':
page_url = 'calendars/all/shows/new/%s/30' % datetime.date.today().strftime('%Y-%m-%d')
elif trakt_list == 'newseason':
page_url = 'calendars/all/shows/premieres/%s/30' % datetime.date.today().strftime('%Y-%m-%d')
else:
page_url = 'shows/anticipated'
trending_shows = []
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
try:
not_liked_show = ''
if sickbeard.TRAKT_ACCESS_TOKEN != '':
library_shows = trakt_api.traktRequest('sync/collection/shows?extended=full') or []
if sickbeard.TRAKT_BLACKLIST_NAME is not None and sickbeard.TRAKT_BLACKLIST_NAME:
not_liked_show = trakt_api.traktRequest('users/{user}/lists/{blacklist}/items'.format(
user=sickbeard.TRAKT_USERNAME, blacklist=sickbeard.TRAKT_BLACKLIST_NAME)) or []
else:
logger.log(u'Trakt blacklist name is empty', logger.DEBUG)
limit_show = ''
if trakt_list not in ['recommended', 'newshow', 'newseason']:
limit_show = 'limit={number}&'.format(number=100 + len(not_liked_show))
shows = trakt_api.traktRequest('{url}?{limit}extended=full,images'.format(url=page_url, limit=limit_show)) or []
if sickbeard.TRAKT_ACCESS_TOKEN != '':
library_shows = trakt_api.traktRequest('sync/collection/shows?extended=full') or []
for show in shows:
try:
if 'show' not in show:
show['show'] = show
if not Show.find(sickbeard.showList, [int(show['show']['ids']['tvdb'])]):
if sickbeard.TRAKT_ACCESS_TOKEN != '':
if show['show']['ids']['tvdb'] not in (lshow['show']['ids']['tvdb'] for lshow in library_shows):
if not_liked_show:
if show['show']['ids']['tvdb'] not in (show['show']['ids']['tvdb'] for show in not_liked_show if show['type'] == 'show'):
trending_shows += [show]
else:
trending_shows += [show]
else:
if not_liked_show:
if show['show']['ids']['tvdb'] not in (show['show']['ids']['tvdb'] for show in not_liked_show if show['type'] == 'show'):
trending_shows += [show]
else:
trending_shows += [show]
except MultipleShowObjectsException:
continue
if sickbeard.TRAKT_BLACKLIST_NAME != '':
blacklist = True
else:
blacklist = False
except traktException as e:
logger.log(u'Could not connect to Trakt service: %s' % ex(e), logger.WARNING)
return t.render(blacklist=blacklist, trending_shows=trending_shows)
示例14: run
def run(self):
ShowQueueItem.run(self)
logging.info("Starting to add show " + self.showDir)
# make sure the Indexer IDs are valid
try:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
if self.lang:
lINDEXER_API_PARMS[b'language'] = self.lang
logging.info("" + str(sickbeard.indexerApi(self.indexer).name) + ": " + repr(lINDEXER_API_PARMS))
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
s = t[self.indexer_id]
# this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no proper english version of the show
if getattr(s, 'seriesname', None) is None:
logging.error("Show in " + self.showDir + " has no name on " + str(
sickbeard.indexerApi(self.indexer).name) + ", probably the wrong language used to search with.")
ui.notifications.error("Unable to add show",
"Show in " + self.showDir + " has no name on " + str(sickbeard.indexerApi(
self.indexer).name) + ", probably the wrong language. Delete .nfo and add manually in the correct language.")
self._finishEarly()
return
# if the show has no episodes/seasons
if not s:
logging.error("Show " + str(s[b'seriesname']) + " is on " + str(
sickbeard.indexerApi(self.indexer).name) + " but contains no season/episode data.")
ui.notifications.error("Unable to add show",
"Show " + str(s[b'seriesname']) + " is on " + str(sickbeard.indexerApi(
self.indexer).name) + " but contains no season/episode data.")
self._finishEarly()
return
except Exception as e:
logging.error("%s Error while loading information from indexer %s. Error: %r" % (
self.indexer_id, sickbeard.indexerApi(self.indexer).name, ex(e)))
ui.notifications.error(
"Unable to add show",
"Unable to look up the show in %s on %s using ID %s, not using the NFO. Delete .nfo and try adding manually again." %
(self.showDir, sickbeard.indexerApi(self.indexer).name, self.indexer_id)
)
if sickbeard.USE_TRAKT:
trakt_id = sickbeard.indexerApi(self.indexer).config[b'trakt_id']
trakt_api = TraktAPI(sickbeard.SSL_VERIFY, sickbeard.TRAKT_TIMEOUT)
title = self.showDir.split("/")[-1]
data = {
'shows': [
{
'title': title,
'ids': {}
}
]
}
if trakt_id == 'tvdb_id':
data[b'shows'][0][b'ids'][b'tvdb'] = self.indexer_id
else:
data[b'shows'][0][b'ids'][b'tvrage'] = self.indexer_id
trakt_api.traktRequest("sync/watchlist/remove", data, method='POST')
self._finishEarly()
return
try:
newShow = TVShow(self.indexer, self.indexer_id, self.lang)
newShow.loadFromIndexer()
self.show = newShow
# set up initial values
self.show.location = self.showDir
self.show.subtitles = self.subtitles if self.subtitles != None else sickbeard.SUBTITLES_DEFAULT
self.show.quality = self.quality if self.quality else sickbeard.QUALITY_DEFAULT
self.show.flatten_folders = self.flatten_folders if self.flatten_folders != None else sickbeard.FLATTEN_FOLDERS_DEFAULT
self.show.anime = self.anime if self.anime != None else sickbeard.ANIME_DEFAULT
self.show.scene = self.scene if self.scene != None else sickbeard.SCENE_DEFAULT
self.show.archive_firstmatch = self.archive if self.archive != None else sickbeard.ARCHIVE_DEFAULT
self.show.paused = self.paused if self.paused != None else False
# set up default new/missing episode status
logging.info("Setting all episodes to the specified default status: " + str(self.show.default_ep_status))
self.show.default_ep_status = self.default_status
if self.show.anime:
self.show.release_groups = BlackAndWhiteList(self.show.indexerid)
if self.blacklist:
self.show.release_groups.set_black_keywords(self.blacklist)
if self.whitelist:
self.show.release_groups.set_white_keywords(self.whitelist)
# # be smartish about this
# if self.show.genre and "talk show" in self.show.genre.lower():
# self.show.air_by_date = 1
# if self.show.genre and "documentary" in self.show.genre.lower():
#.........这里部分代码省略.........