Commit 07005ed3 authored by echel0n's avatar echel0n
Browse files

Refactored API url

parent 451aa807
# Changelog
- * f41616c - 2017-12-15: Refactored API url
- * 4faba09 - 2017-12-16: Refactored API url
- * 451aa80 - 2017-12-15: Refactored API url
- * a915b3c - 2017-12-15: Added new code for converting magnet links to torrent files via SR API
- * bb8a5b8 - 2017-12-15: Fix unicode issues for Newpct torrent provider
- * c0f1698 - 2017-12-15: Added custom url setting to torrent9 provider
......
......@@ -68,14 +68,20 @@ class API(object):
def user_profile(self):
return self._request('GET', 'users/me')
def add_cache_result(self, data):
def add_provider_cache_result(self, data):
self._request('POST', 'v1/providers/cache/results', json=data)
def get_cache_results(self, provider, indexerid=None):
def get_provider_cache_results(self, provider, indexerid=None):
query = ('v1/providers/cache/results/{}'.format(provider),
'v1/providers/cache/results/{}/indexerids/{}'.format(provider, indexerid))[indexerid is not None]
return self._request('GET', query)
def magnet2torrent(self, magnet):
return self._request('POST', 'v1/torrents/mag2tor', data=dict({'magnet':magnet}))
def get_torrent_cache_results(self, hash=None):
query = ('v1/torrents/cache/results',
'v1/torrents/cache/results/{}'.format(hash))[hash is not None]
return self._request('GET', query)
def add_torrent_cache_result(self, url):
self._request('POST', 'v1/torrents/cache/results', data=dict({'url': url}))
\ No newline at end of file
......@@ -227,7 +227,7 @@ class TVCache(object):
# add to external database
if sickrage.app.config.enable_api_providers_cache and not self.provider.private:
try:
sickrage.app.api.add_cache_result(dbData)
sickrage.app.api.add_provider_cache_result(dbData)
except Exception:
pass
......@@ -242,7 +242,7 @@ class TVCache(object):
# get data from external database
if sickrage.app.config.enable_api_providers_cache and not self.provider.private:
try:
dbData += sickrage.app.api.get_cache_results(self.providerID, ep_obj.show.indexerid)
dbData += sickrage.app.api.get_provider_cache_results(self.providerID, ep_obj.show.indexerid)
except Exception:
pass
......
......@@ -18,7 +18,6 @@
from __future__ import unicode_literals
import base64
import datetime
import importlib
import io
......@@ -26,7 +25,7 @@ import itertools
import os
import random
import re
from base64 import b16encode, b32decode
from base64 import b16encode, b32decode, b64decode
from collections import OrderedDict, defaultdict
from time import sleep
from urlparse import urljoin
......@@ -652,12 +651,13 @@ class TorrentProvider(GenericProvider):
torrent_url = "https://itorrents.org/torrent/{info_hash}.torrent".format(info_hash=info_hash)
result = verify_torrent(super(TorrentProvider, self).get_content(torrent_url))
# try api
if not result:
try:
result = verify_torrent(base64.b64decode(sickrage.app.api.magnet2torrent(url)['message']).strip())
except Exception:
pass
# try api
if not result:
try:
result = verify_torrent(
b64decode(sickrage.app.api.get_torrent_cache_results(info_hash)['message']).strip())
except Exception:
pass
if not result:
result = verify_torrent(super(TorrentProvider, self).get_content(url))
......
Supports Markdown
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