Commit 7678be44 authored by echel0n's avatar echel0n

Refactored external API to version 2 which uses series_id instead of...

Refactored external API to version 2 which uses series_id instead of indexer_id, part of larger code refactor.
parent 365a16db
......@@ -15,7 +15,7 @@ from sickrage.core.api.exceptions import ApiUnauthorized, ApiError
class API(object):
def __init__(self):
self.name = 'SR-API'
self.api_url = 'https://www.sickrage.ca/api/v1/'
self.api_url = 'https://www.sickrage.ca/api/v2/'
self.client_id = sickrage.app.oidc_client_id
self.client_secret = sickrage.app.oidc_client_secret
self.token_url = sickrage.app.oidc_client.well_known['token_endpoint']
......
......@@ -2,18 +2,18 @@ from sickrage.core.api import API
class ProviderCacheAPI(API):
def get(self, provider, indexer_id, season, episode):
query = 'cache/providers/{}/indexer_ids/{}/seasons/{}/episodes/{}'.format(provider, indexer_id, season, episode)
def get(self, provider, series_id, season, episode):
query = 'cache/provider/{}/series_id/{}/season/{}/episode/{}'.format(provider, series_id, season, episode)
return self._request('GET', query)
def add(self, data):
return self._request('POST', 'cache/providers', json=data)
return self._request('POST', 'cache/provider', json=data)
class TorrentCacheAPI(API):
def get(self, hash):
query = 'cache/torrents/{}'.format(hash)
query = 'cache/torrent/{}'.format(hash)
return self._request('GET', query)
def add(self, url):
return self._request('POST', 'cache/torrents', data=dict({'url': url}))
return self._request('POST', 'cache/torrent', data=dict({'url': url}))
......@@ -223,7 +223,7 @@ class TVCache(object):
'name': name,
'season': season,
'episodes': episodeText,
'indexer_id': parse_result.indexer_id,
'series_id': parse_result.indexer_id,
'url': url,
'time': int(time.mktime(datetime.datetime.today().timetuple())),
'quality': quality,
......@@ -267,13 +267,13 @@ class TVCache(object):
# get data from internal database
with sickrage.app.cache_db.session() as session:
dbData += [
x.as_dict() for x in session.query(CacheDB.Provider).filter_by(provider=self.providerID, indexer_id=show_id, season=season).filter(
x.as_dict() for x in session.query(CacheDB.Provider).filter_by(provider=self.providerID, series_id=show_id, season=season).filter(
CacheDB.Provider.episodes.contains("|{}|".format(episode)))
]
with sickrage.app.main_db.session() as session:
for curResult in dbData:
show_object = find_show(int(curResult["indexer_id"]), session=session)
show_object = find_show(int(curResult["series_id"]), session=session)
if not show_object:
continue
......@@ -291,7 +291,7 @@ class TVCache(object):
continue
# get the show object, or if it's not one of our shows then ignore it
result.show_id = int(curResult["indexer_id"])
result.show_id = int(curResult["series_id"])
# skip if provider is anime only and show is not anime
if self.provider.anime_only and not show_object.is_anime:
......
......@@ -129,7 +129,7 @@ class CacheDB(SRDatabase):
name = Column(Text)
season = Column(Integer)
episodes = Column(Text)
indexer_id = Column(Integer)
series_id = Column(Integer)
url = Column(String(256), index=True, unique=True)
time = Column(Integer)
quality = Column(Integer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment