Commit 40fe5667 authored by echel0n's avatar echel0n
Browse files

Merge branch 'release/9.2.65'

parents 398d9d82 3c60c67e
# Changelog
- * 49c2bfe - 2017-12-15: Release v9.2.64
- * 7bc398a - 2017-12-16: Release v9.2.65
- * d53ccb0 - 2017-12-16: Fixed url issue
- * 1c5d901 - 2017-12-16: refactored torrent cache api calls
- * e5ee3a3 - 2017-12-16: refactored torrent cache api calls
- * 07005ed - 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
- * 032e9ed - 2017-12-15: Release v9.2.64
- * 92337a7 - 2017-12-15: Added code to cleanup cached provider results with UNKNOWN quality Added code to prevent parsed search results with UNKNOWN quality from being cached
- * 9d35ea1 - 2017-12-14: Release v9.2.63
- * 22c5664 - 2017-12-14: Fixed issue "Unable to contact theTVDB: [0]: Series result returned zero"
......
......@@ -68,11 +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 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
......@@ -224,10 +224,10 @@ class TVCache(object):
# add to internal database
sickrage.app.cache_db.insert(dbData)
# add to external database
# add to external provider cache 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
......
......@@ -6,9 +6,9 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: sickrage 9.2.64\n"
"Project-Id-Version: sickrage 9.2.65\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2017-12-15 00:24-0500\n"
"POT-Creation-Date: 2017-12-16 18:16-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
......
......@@ -25,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
......@@ -632,36 +632,39 @@ class TorrentProvider(GenericProvider):
return result
def get_content(self, url):
urls = [url]
bt_cache_urls = [
'https://itorrents.org/torrent/{info_hash}.torrent',
'http://reflektor.karmorra.info/torrent/{info_hash}.torrent',
'https://torrent.cd/torrents/download/{info_hash}.torrent',
'https://asnet.pw/download/{info_hash}/',
'http://p2pdl.com/download/{info_hash}',
]
result = None
def verify_torrent(content):
try:
if bencode.bdecode(content).get('info'):
return content
except Exception:
pass
if url.startswith('magnet'):
# try iTorrents
info_hash = str(re.findall(r'urn:btih:([\w]{32,40})', url)[0]).upper()
if len(info_hash) == 32:
info_hash = b16encode(b32decode(info_hash)).upper()
if not info_hash:
sickrage.app.log.error("Unable to extract torrent hash from magnet: " + url)
return urls
if info_hash:
torrent_url = "https://itorrents.org/torrent/{info_hash}.torrent".format(info_hash=info_hash)
result = verify_torrent(super(TorrentProvider, self).get_content(torrent_url))
urls = [x.format(info_hash=info_hash) for x in bt_cache_urls]
# try api
if not result and sickrage.app.config.enable_api:
try:
# add to external database
sickrage.app.api.add_torrent_cache_result(url)
result = verify_torrent(
b64decode(sickrage.app.api.get_torrent_cache_results(info_hash)).strip())
except Exception:
pass
random.shuffle(urls)
if not result:
result = verify_torrent(super(TorrentProvider, self).get_content(url))
for u in urls:
try:
content = super(TorrentProvider, self).get_content(u)
if bencode.bdecode(content).get('info'):
return content
except Exception:
pass
return result
def _get_title_and_url(self, item):
title, download_url = '', ''
......
......@@ -166,7 +166,10 @@ class NewpctProvider(TorrentProvider):
def _process_title(self, title, url):
# Convert to unicode and strip unwanted characters
title = title.encode('latin-1').decode('utf8').strip()
try:
title = title.encode('latin-1').decode('utf8').strip()
except Exception:
title = title.strip()
# Check if subtitled
subtitles = re.search(r'\[V.O.[^\[]*]', title, flags=re.I)
......
......@@ -25,7 +25,7 @@ from urlparse import urljoin
import sickrage
from sickrage.core.caches.tv_cache import TVCache
from sickrage.core.helpers import bs4_parser, try_int, convert_size
from sickrage.core.helpers import bs4_parser, try_int, convert_size, validate_url
from sickrage.providers import TorrentProvider
......@@ -41,6 +41,8 @@ class Torrent9Provider(TorrentProvider):
self.minseed = None
self.minleech = None
self.custom_url = ""
self.proper_strings = ['PROPER', 'REPACK']
self.cache = TVCache(self)
......@@ -65,6 +67,12 @@ class Torrent9Provider(TorrentProvider):
else:
search_url = self.urls['rss']
if self.custom_url:
if not validate_url(self.custom_url):
sickrage.app.log.warning("Invalid custom url: {0}".format(self.custom_url))
return results
search_url = urljoin(self.custom_url, search_url.split(self.urls['base_url'])[1])
try:
data = self.session.get(search_url).text
results += self.parse(data, mode)
......@@ -90,7 +98,8 @@ class Torrent9Provider(TorrentProvider):
title = result.find('a').get_text(strip=False).replace("HDTV", "HDTV x264-Torrent9")
title = re.sub(r' Saison', ' Season', title, flags=re.I)
tmp = result.find("a")['href'].split('/')[-1].replace('.html', '.torrent').strip()
download_url = (self.urls['base_url'] + '/get_torrent/{0}'.format(tmp) + ".torrent")
download_url = urljoin(self.custom_url or self.urls['base_url'],
'/get_torrent/{0}'.format(tmp) + ".torrent")
if not all([title, download_url]):
continue
......
9.2.64
\ No newline at end of file
9.2.65
\ No newline at end of file
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