2014-03-10 05:18:05 +00:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-05-26 10:42:34 +00:00
|
|
|
# GNU General Public License for more details.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-05-11 12:49:07 +00:00
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard import logger
|
2014-07-31 04:31:54 +00:00
|
|
|
from sickbeard.common import Quality
|
2014-07-31 04:47:17 +00:00
|
|
|
|
|
|
|
from sickbeard import helpers, show_name_helpers
|
2016-09-04 20:00:44 +00:00
|
|
|
from sickbeard.exceptions import MultipleShowObjectsException, AuthException, ex
|
2014-07-31 04:31:54 +00:00
|
|
|
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
|
2015-06-15 19:09:01 +00:00
|
|
|
from sickbeard.rssfeeds import RSSFeeds
|
2014-09-20 12:03:48 +00:00
|
|
|
import itertools
|
2014-03-10 05:18:05 +00:00
|
|
|
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
class CacheDBConnection(db.DBConnection):
|
|
|
|
def __init__(self, providerName):
|
2014-12-13 05:04:21 +00:00
|
|
|
db.DBConnection.__init__(self, 'cache.db')
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-06-07 23:16:01 +00:00
|
|
|
# Create the table if it's not already there
|
|
|
|
try:
|
|
|
|
if not self.hasTable('lastUpdate'):
|
2014-12-13 05:04:21 +00:00
|
|
|
self.action('CREATE TABLE lastUpdate (provider TEXT, time NUMERIC)')
|
2015-06-08 12:47:01 +00:00
|
|
|
except Exception as e:
|
2014-12-13 05:04:21 +00:00
|
|
|
if str(e) != 'table lastUpdate already exists':
|
2014-06-07 23:16:01 +00:00
|
|
|
raise
|
2014-03-10 05:18:05 +00:00
|
|
|
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
|
2015-06-15 19:09:01 +00:00
|
|
|
class TVCache:
|
2014-03-10 05:18:05 +00:00
|
|
|
def __init__(self, provider):
|
|
|
|
|
|
|
|
self.provider = provider
|
2015-07-13 09:39:20 +00:00
|
|
|
self.providerID = self.provider.get_id()
|
2014-07-19 21:16:05 +00:00
|
|
|
self.providerDB = None
|
2015-09-18 00:06:34 +00:00
|
|
|
self.update_freq = 10
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
def get_db(self):
|
2014-12-23 22:28:06 +00:00
|
|
|
return CacheDBConnection(self.providerID)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def _clearCache(self):
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
if self.should_clear_cache():
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2015-03-29 15:46:46 +00:00
|
|
|
myDB.action('DELETE FROM provider_cache WHERE provider = ?', [self.providerID])
|
2014-05-18 12:59:42 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _title_and_url(self, item):
|
2014-12-22 18:30:53 +00:00
|
|
|
# override this in the provider if recent search has a different data layout to backlog searches
|
2015-09-18 00:06:34 +00:00
|
|
|
return self.provider._title_and_url(item)
|
2014-08-15 03:43:11 +00:00
|
|
|
|
2017-08-02 21:13:02 +00:00
|
|
|
def _cache_data(self, **kwargs):
|
2014-03-10 05:18:05 +00:00
|
|
|
data = None
|
|
|
|
return data
|
|
|
|
|
2014-08-12 10:09:11 +00:00
|
|
|
def _checkAuth(self):
|
2015-07-13 09:39:20 +00:00
|
|
|
return self.provider._check_auth()
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def _checkItemAuth(self, title, url):
|
|
|
|
return True
|
|
|
|
|
2016-09-04 20:00:44 +00:00
|
|
|
def updateCache(self, **kwargs):
|
2015-06-19 23:34:56 +00:00
|
|
|
try:
|
|
|
|
self._checkAuth()
|
|
|
|
except AuthException as e:
|
|
|
|
logger.log(u'Authentication error: ' + ex(e), logger.ERROR)
|
|
|
|
return []
|
|
|
|
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
if self.should_update():
|
2017-08-02 21:13:02 +00:00
|
|
|
data = self._cache_data(**kwargs)
|
2014-05-11 12:49:07 +00:00
|
|
|
|
2014-07-27 10:59:21 +00:00
|
|
|
# clear cache
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
if data:
|
|
|
|
self._clearCache()
|
2014-07-27 10:59:21 +00:00
|
|
|
|
|
|
|
# parse data
|
2014-08-12 10:09:11 +00:00
|
|
|
cl = []
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
for item in data or []:
|
2015-09-18 00:06:34 +00:00
|
|
|
title, url = self._title_and_url(item)
|
2014-08-12 10:09:11 +00:00
|
|
|
ci = self._parseItem(title, url)
|
|
|
|
if ci is not None:
|
|
|
|
cl.append(ci)
|
|
|
|
|
|
|
|
if len(cl) > 0:
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2014-08-12 10:09:11 +00:00
|
|
|
myDB.mass_action(cl)
|
2014-05-11 12:49:07 +00:00
|
|
|
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
# set updated as time the attempt to fetch data is
|
|
|
|
self.setLastUpdate()
|
|
|
|
|
2014-05-11 12:49:07 +00:00
|
|
|
return []
|
|
|
|
|
2016-02-26 01:07:39 +00:00
|
|
|
def getRSSFeed(self, url, **kwargs):
|
|
|
|
return RSSFeeds(self.provider).get_feed(url, **kwargs)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def _translateTitle(self, title):
|
2014-07-21 13:29:07 +00:00
|
|
|
return u'' + title.replace(' ', '.')
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def _translateLinkURL(self, url):
|
|
|
|
return url.replace('&', '&')
|
|
|
|
|
2014-08-05 16:19:54 +00:00
|
|
|
def _parseItem(self, title, url):
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
self._checkItemAuth(title, url)
|
|
|
|
|
|
|
|
if title and url:
|
|
|
|
title = self._translateTitle(title)
|
|
|
|
url = self._translateLinkURL(url)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-12-13 05:04:21 +00:00
|
|
|
logger.log(u'Attempting to add item to cache: ' + title, logger.DEBUG)
|
2015-07-13 09:39:20 +00:00
|
|
|
return self.add_cache_entry(title, url)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
2014-03-25 05:57:24 +00:00
|
|
|
logger.log(
|
2014-12-13 05:04:21 +00:00
|
|
|
u'The data returned from the ' + self.provider.name + ' feed is incomplete, this result is unusable',
|
2014-03-25 05:57:24 +00:00
|
|
|
logger.DEBUG)
|
|
|
|
return None
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def _getLastUpdate(self):
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2014-12-13 05:04:21 +00:00
|
|
|
sqlResults = myDB.select('SELECT time FROM lastUpdate WHERE provider = ?', [self.providerID])
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
if sqlResults:
|
2014-12-13 05:04:21 +00:00
|
|
|
lastTime = int(sqlResults[0]['time'])
|
2014-03-11 20:22:00 +00:00
|
|
|
if lastTime > int(time.mktime(datetime.datetime.today().timetuple())):
|
|
|
|
lastTime = 0
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
|
|
|
lastTime = 0
|
|
|
|
|
|
|
|
return datetime.datetime.fromtimestamp(lastTime)
|
|
|
|
|
2014-05-15 07:20:00 +00:00
|
|
|
def _getLastSearch(self):
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2014-12-13 05:04:21 +00:00
|
|
|
sqlResults = myDB.select('SELECT time FROM lastSearch WHERE provider = ?', [self.providerID])
|
2014-05-15 07:20:00 +00:00
|
|
|
|
|
|
|
if sqlResults:
|
2014-12-13 05:04:21 +00:00
|
|
|
lastTime = int(sqlResults[0]['time'])
|
2014-05-15 07:20:00 +00:00
|
|
|
if lastTime > int(time.mktime(datetime.datetime.today().timetuple())):
|
|
|
|
lastTime = 0
|
|
|
|
else:
|
|
|
|
lastTime = 0
|
|
|
|
|
|
|
|
return datetime.datetime.fromtimestamp(lastTime)
|
|
|
|
|
2014-05-11 12:49:07 +00:00
|
|
|
def setLastUpdate(self, toDate=None):
|
2014-03-10 05:18:05 +00:00
|
|
|
if not toDate:
|
|
|
|
toDate = datetime.datetime.today()
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2014-12-13 05:04:21 +00:00
|
|
|
myDB.upsert('lastUpdate',
|
2014-06-21 22:46:59 +00:00
|
|
|
{'time': int(time.mktime(toDate.timetuple()))},
|
|
|
|
{'provider': self.providerID})
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-05-15 07:20:00 +00:00
|
|
|
def setLastSearch(self, toDate=None):
|
|
|
|
if not toDate:
|
|
|
|
toDate = datetime.datetime.today()
|
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2014-12-13 05:04:21 +00:00
|
|
|
myDB.upsert('lastSearch',
|
2014-06-21 22:46:59 +00:00
|
|
|
{'time': int(time.mktime(toDate.timetuple()))},
|
|
|
|
{'provider': self.providerID})
|
2014-05-11 12:49:07 +00:00
|
|
|
|
2014-05-15 07:20:00 +00:00
|
|
|
lastUpdate = property(_getLastUpdate)
|
|
|
|
lastSearch = property(_getLastSearch)
|
2014-05-11 12:49:07 +00:00
|
|
|
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
def should_update(self):
|
2014-03-10 05:18:05 +00:00
|
|
|
# if we've updated recently then skip the update
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
return datetime.datetime.today() - self.lastUpdate >= datetime.timedelta(minutes=self.update_freq)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
def should_clear_cache(self):
|
2014-12-22 18:30:53 +00:00
|
|
|
# if recent search hasn't used our previous results yet then don't clear the cache
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
return self.lastSearch >= self.lastUpdate
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2016-09-04 20:00:44 +00:00
|
|
|
def add_cache_entry(self, name, url, parse_result=None, indexer_id=0, id_dict=None):
|
2014-07-15 02:00:53 +00:00
|
|
|
|
2014-07-22 06:00:58 +00:00
|
|
|
# check if we passed in a parsed result or should we try and create one
|
|
|
|
if not parse_result:
|
2014-05-26 20:16:07 +00:00
|
|
|
|
2014-07-22 06:00:58 +00:00
|
|
|
# create showObj from indexer_id if available
|
|
|
|
showObj=None
|
|
|
|
if indexer_id:
|
2016-09-04 20:00:44 +00:00
|
|
|
try:
|
|
|
|
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
|
|
|
|
except MultipleShowObjectsException:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if id_dict:
|
|
|
|
try:
|
|
|
|
showObj = helpers.find_show_by_id(sickbeard.showList, id_dict=id_dict, no_mapped_ids=False)
|
|
|
|
except MultipleShowObjectsException:
|
|
|
|
return None
|
2014-04-30 22:07:18 +00:00
|
|
|
|
2014-07-22 06:00:58 +00:00
|
|
|
try:
|
2017-07-21 21:34:23 +00:00
|
|
|
np = NameParser(showObj=showObj, convert=True, indexer_lookup=False)
|
2015-09-25 14:33:25 +00:00
|
|
|
parse_result = np.parse(name)
|
2014-07-22 06:00:58 +00:00
|
|
|
except InvalidNameException:
|
2014-12-13 05:04:21 +00:00
|
|
|
logger.log(u'Unable to parse the filename ' + name + ' into a valid episode', logger.DEBUG)
|
2014-07-22 06:00:58 +00:00
|
|
|
return None
|
|
|
|
except InvalidShowException:
|
2015-09-25 14:33:25 +00:00
|
|
|
logger.log(u'No show in the db matches filename ' + name + ' not cached', logger.DEBUG)
|
2014-07-22 06:00:58 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
if not parse_result or not parse_result.series_name:
|
|
|
|
return None
|
2014-04-28 23:03:49 +00:00
|
|
|
|
2014-07-22 06:00:58 +00:00
|
|
|
# if we made it this far then lets add the parsed result to cache for usager later on
|
2014-07-24 18:16:59 +00:00
|
|
|
season = parse_result.season_number if parse_result.season_number else 1
|
|
|
|
episodes = parse_result.episode_numbers
|
2014-04-26 05:42:40 +00:00
|
|
|
|
2014-05-03 09:23:26 +00:00
|
|
|
if season and episodes:
|
|
|
|
# store episodes as a seperated string
|
2014-12-13 05:04:21 +00:00
|
|
|
episodeText = '|' + '|'.join(map(str, episodes)) + '|'
|
2014-04-29 13:14:19 +00:00
|
|
|
|
2014-05-03 09:23:26 +00:00
|
|
|
# get the current timestamp
|
|
|
|
curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
|
2014-04-30 22:07:18 +00:00
|
|
|
|
2014-05-03 09:23:26 +00:00
|
|
|
# get quality of release
|
2014-07-22 06:00:58 +00:00
|
|
|
quality = parse_result.quality
|
2014-04-30 22:07:18 +00:00
|
|
|
|
2014-05-03 09:23:26 +00:00
|
|
|
if not isinstance(name, unicode):
|
2014-07-15 02:00:53 +00:00
|
|
|
name = unicode(name, 'utf-8', 'replace')
|
2014-05-03 09:23:26 +00:00
|
|
|
|
2014-07-06 11:10:25 +00:00
|
|
|
# get release group
|
|
|
|
release_group = parse_result.release_group
|
|
|
|
|
2014-07-22 04:53:32 +00:00
|
|
|
# get version
|
|
|
|
version = parse_result.version
|
|
|
|
|
2014-12-13 05:04:21 +00:00
|
|
|
logger.log(u'Added RSS item: [' + name + '] to cache: [' + self.providerID + ']', logger.DEBUG)
|
2014-05-11 12:49:07 +00:00
|
|
|
|
2014-05-04 12:05:27 +00:00
|
|
|
return [
|
2015-03-29 15:46:46 +00:00
|
|
|
'INSERT OR IGNORE INTO provider_cache (provider, name, season, episodes, indexerid, url, time, quality, release_group, version) VALUES (?,?,?,?,?,?,?,?,?,?)',
|
|
|
|
[self.providerID, name, season, episodeText, parse_result.show.indexerid, url, curTimestamp, quality, release_group, version]]
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-08-30 08:47:00 +00:00
|
|
|
def searchCache(self, episode, manualSearch=False):
|
|
|
|
neededEps = self.findNeededEpisodes(episode, manualSearch)
|
2014-09-20 12:03:48 +00:00
|
|
|
if len(neededEps) > 0:
|
|
|
|
return neededEps[episode]
|
|
|
|
else:
|
|
|
|
return []
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def listPropers(self, date=None):
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2015-03-29 15:46:46 +00:00
|
|
|
sql = "SELECT * FROM provider_cache WHERE name LIKE '%.PROPER.%' OR name LIKE '%.REPACK.%' AND provider = ?"
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
if date:
|
2014-12-13 05:04:21 +00:00
|
|
|
sql += ' AND time >= ' + str(int(time.mktime(date.timetuple())))
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-03-29 15:46:46 +00:00
|
|
|
return filter(lambda x: x['indexerid'] != 0, myDB.select(sql, [self.providerID]))
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-09-20 12:03:48 +00:00
|
|
|
def findNeededEpisodes(self, episode, manualSearch=False):
|
2014-03-10 05:18:05 +00:00
|
|
|
neededEps = {}
|
2014-09-20 12:03:48 +00:00
|
|
|
cl = []
|
2014-08-30 08:47:00 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
myDB = self.get_db()
|
2014-09-20 12:03:48 +00:00
|
|
|
if type(episode) != list:
|
2014-06-21 22:46:59 +00:00
|
|
|
sqlResults = myDB.select(
|
2015-03-29 15:46:46 +00:00
|
|
|
'SELECT * FROM provider_cache WHERE provider = ? AND indexerid = ? AND season = ? AND episodes LIKE ?',
|
|
|
|
[self.providerID, episode.show.indexerid, episode.season, '%|' + str(episode.episode) + '|%'])
|
2014-09-20 12:03:48 +00:00
|
|
|
else:
|
|
|
|
for epObj in episode:
|
|
|
|
cl.append([
|
2015-06-15 19:09:01 +00:00
|
|
|
'SELECT * FROM provider_cache WHERE provider = ? AND indexerid = ? AND season = ?'
|
|
|
|
+ ' AND episodes LIKE ? AND quality IN (' + ','.join([str(x) for x in epObj.wantedQuality]) + ')',
|
2015-03-29 15:46:46 +00:00
|
|
|
[self.providerID, epObj.show.indexerid, epObj.season, '%|' + str(epObj.episode) + '|%']])
|
2014-12-23 22:28:06 +00:00
|
|
|
sqlResults = myDB.mass_action(cl)
|
|
|
|
if sqlResults:
|
|
|
|
sqlResults = list(itertools.chain(*sqlResults))
|
2014-09-20 12:03:48 +00:00
|
|
|
|
2014-12-23 22:28:06 +00:00
|
|
|
if not sqlResults:
|
2015-04-23 10:02:21 +00:00
|
|
|
self.setLastSearch()
|
2014-12-23 22:28:06 +00:00
|
|
|
return neededEps
|
2014-08-30 08:47:00 +00:00
|
|
|
|
|
|
|
# for each cache entry
|
|
|
|
for curResult in sqlResults:
|
|
|
|
|
|
|
|
# skip non-tv crap
|
2017-07-21 21:34:23 +00:00
|
|
|
if not show_name_helpers.pass_wordlist_checks(curResult['name'], parse=False, indexer_lookup=False):
|
2014-08-30 08:47:00 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
# get the show object, or if it's not one of our shows then ignore it
|
2014-12-13 05:04:21 +00:00
|
|
|
showObj = helpers.findCertainShow(sickbeard.showList, int(curResult['indexerid']))
|
2014-08-30 08:47:00 +00:00
|
|
|
if not showObj:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# skip if provider is anime only and show is not anime
|
|
|
|
if self.provider.anime_only and not showObj.is_anime:
|
2015-06-04 22:09:36 +00:00
|
|
|
logger.log(u'' + str(showObj.name) + ' is not an anime, skipping', logger.DEBUG)
|
2014-08-30 08:47:00 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
# get season and ep data (ignoring multi-eps for now)
|
2014-12-13 05:04:21 +00:00
|
|
|
curSeason = int(curResult['season'])
|
2014-08-30 08:47:00 +00:00
|
|
|
if curSeason == -1:
|
|
|
|
continue
|
2014-12-13 05:04:21 +00:00
|
|
|
curEp = curResult['episodes'].split('|')[1]
|
2014-08-30 08:47:00 +00:00
|
|
|
if not curEp:
|
|
|
|
continue
|
|
|
|
curEp = int(curEp)
|
|
|
|
|
2014-12-13 05:04:21 +00:00
|
|
|
curQuality = int(curResult['quality'])
|
|
|
|
curReleaseGroup = curResult['release_group']
|
|
|
|
curVersion = curResult['version']
|
2014-08-30 08:47:00 +00:00
|
|
|
|
|
|
|
# if the show says we want that episode then add it to the list
|
|
|
|
if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch):
|
2014-12-13 05:04:21 +00:00
|
|
|
logger.log(u'Skipping ' + curResult['name'] + ' because we don\'t want an episode that\'s ' +
|
2014-08-30 08:47:00 +00:00
|
|
|
Quality.qualityStrings[curQuality], logger.DEBUG)
|
|
|
|
continue
|
|
|
|
|
2014-09-20 12:03:48 +00:00
|
|
|
epObj = showObj.getEpisode(curSeason, curEp)
|
2014-08-30 08:47:00 +00:00
|
|
|
|
|
|
|
# build a result object
|
2014-12-13 05:04:21 +00:00
|
|
|
title = curResult['name']
|
|
|
|
url = curResult['url']
|
2014-08-30 08:47:00 +00:00
|
|
|
|
2014-12-13 05:04:21 +00:00
|
|
|
logger.log(u'Found result ' + title + ' at ' + url)
|
2014-08-30 08:47:00 +00:00
|
|
|
|
2015-07-13 09:39:20 +00:00
|
|
|
result = self.provider.get_result([epObj], url)
|
|
|
|
if None is result:
|
|
|
|
continue
|
2014-08-30 08:47:00 +00:00
|
|
|
result.show = showObj
|
|
|
|
result.name = title
|
|
|
|
result.quality = curQuality
|
|
|
|
result.release_group = curReleaseGroup
|
|
|
|
result.version = curVersion
|
|
|
|
result.content = None
|
|
|
|
|
|
|
|
# add it to the list
|
|
|
|
if epObj not in neededEps:
|
|
|
|
neededEps[epObj] = [result]
|
|
|
|
else:
|
|
|
|
neededEps[epObj].append(result)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-05-15 07:20:00 +00:00
|
|
|
# datetime stamp this search so cache gets cleared
|
|
|
|
self.setLastSearch()
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
return neededEps
|