Private GIT

Skip to content
Snippets Groups Projects
Commit bc4a4ce8 authored by Nic Wolfe's avatar Nic Wolfe
Browse files

Fixed merge conflicts for online scene exceptions

parents c20de0a4 c6e36dd1
Branches
Tags
No related merge requests found
#!/usr/bin/python
#!/usr/bin/env python
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
#
......
#!/usr/bin/python
#!/usr/bin/env python
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
......
#!/usr/bin/python
#!/usr/bin/env python
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
......
......@@ -38,7 +38,7 @@ from sickbeard import logger
from sickbeard.common import *
from sickbeard.databases import mainDB
from sickbeard.databases import mainDB, cache_db
from lib.configobj import ConfigObj
......@@ -51,7 +51,7 @@ PID = None
CFG = None
CONFIG_FILE = None
PROG_DIR = None
PROG_DIR = '.'
MY_FULLNAME = None
MY_NAME = None
MY_ARGS = []
......@@ -641,6 +641,9 @@ def initialize(consoleLogging=True):
# initialize the main SB database
db.upgradeDatabase(db.DBConnection(), mainDB.InitialSchema)
# initialize the cache database
db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema)
# fix up any db problems
db.sanityCheckDatabase(db.DBConnection(), mainDB.MainSanityCheck)
......
......@@ -297,3 +297,4 @@ countryList = {'Australia': 'AU',
'Canada': 'CA',
'USA': 'US'
}
......@@ -16,4 +16,4 @@
# You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
__all__ = ["mainDB"]
\ No newline at end of file
__all__ = ["mainDB", "cache"]
\ No newline at end of file
......@@ -384,4 +384,3 @@ class SetNzbTorrentSettings(PopulateRootDirs):
sickbeard.save_config()
self.incDBVersion()
\ No newline at end of file
......@@ -340,13 +340,11 @@ class PostProcessor(object):
# for each possible interpretation of that scene name
for cur_name in name_list:
self._log(u"Checking scene exceptions for a match on "+cur_name, logger.DEBUG)
for exceptionID in common.sceneExceptions:
# for each exception name
for curException in common.sceneExceptions[exceptionID]:
if cur_name.lower() in (curException.lower(), sceneHelpers.sanitizeSceneName(curException).lower().replace('.',' ')):
self._log(u"Scene exception lookup got tvdb id "+str(exceptionID)+u", using that", logger.DEBUG)
scene_id = sceneHelpers.get_scene_exception_by_name(cur_name)
if scene_id:
self._log(u"Scene exception lookup got tvdb id "+str(scene_id)+u", using that", logger.DEBUG)
_finalize(parse_result)
return (exceptionID, season, episodes)
return (scene_id, season, episodes)
# see if we can find the name directly in the DB, if so use it
for cur_name in name_list:
......
......@@ -16,12 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
from sickbeard import common
from sickbeard.common import countryList
from sickbeard import logger
from sickbeard import db
import re
import datetime
import urllib
from name_parser.parser import NameParser, InvalidNameException
......@@ -86,7 +87,7 @@ def sceneToNormalShowNames(name):
results.append(re.sub('(\D)(\d{4})$', '\\1(\\2)', cur_name))
# add brackets around the country
country_match_str = '|'.join(common.countryList.values())
country_match_str = '|'.join(countryList.values())
results.append(re.sub('(?i)([. _-])('+country_match_str+')$', '\\1(\\2)', cur_name))
results += name_list
......@@ -187,9 +188,7 @@ def makeSceneSearchString (episode):
def allPossibleShowNames(show):
showNames = [show.name]
if int(show.tvdbid) in common.sceneExceptions:
showNames += common.sceneExceptions[int(show.tvdbid)]
showNames += [name for name in get_scene_exceptions(show.tvdbid)]
# if we have a tvrage name then use it
if show.tvrname != "" and show.tvrname != None:
......@@ -197,8 +196,8 @@ def allPossibleShowNames(show):
newShowNames = []
country_list = common.countryList
country_list.update(dict(zip(common.countryList.values(), common.countryList.keys())))
country_list = countryList
country_list.update(dict(zip(countryList.values(), countryList.keys())))
# if we have "Show Name Australia" or "Show Name (Australia)" this will add "Show Name (AU)" for
# any countries defined in common.countryList
......@@ -239,3 +238,66 @@ def isGoodResult(name, show, log=True):
if log:
logger.log(u"Provider gave result "+name+" but that doesn't seem like a valid result for "+show.name+" so I'm ignoring it")
return False
def get_scene_exceptions(tvdb_id):
"""
Given a tvdb_id, return a list of all the scene exceptions.
"""
myDB = db.DBConnection("cache.db")
exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE tvdb_id = ?", [tvdb_id])
return [cur_exception["show_name"] for cur_exception in exceptions]
def get_scene_exception_by_name(show_name):
"""
Given a show name, return the tvdbid of the exception, None if no exception
is present.
"""
myDB = db.DBConnection("cache.db")
# try the obvious case first
exception_result = myDB.select("SELECT tvdb_id FROM scene_exceptions WHERE LOWER(show_name) = ?", [show_name.lower()])
if exception_result:
return int(exception_result[0]["tvdb_id"])
all_exception_results = myDB.select("SELECT show_name, tvdb_id FROM scene_exceptions")
for cur_exception in all_exception_results:
cur_exception_name = cur_exception["show_name"]
cur_tvdb_id = int(cur_exception["tvdb_id"])
if show_name.lower() in (cur_exception_name.lower(), sanitizeSceneName(cur_exception_name).lower().replace('.',' ')):
logger.log(u"Scene exception lookup got tvdb id "+str(cur_tvdb_id)+u", using that", logger.DEBUG)
return cur_tvdb_id
return None
def retrieve_exceptions():
exception_dict = {}
url = 'http://midgetspy.github.com/sb_tvdb_scene_exceptions/exceptions.txt'
open_url = urllib.urlopen(url)
# each exception is on one line with the format tvdb_id: 'show name 1', 'show name 2', etc
for cur_line in open_url.readlines():
tvdb_id, sep, aliases = cur_line.partition(':')
if not aliases:
continue
tvdb_id = int(tvdb_id)
# regex out the list of shows, taking \' into account
alias_list = re.findall(r"'(.*?)(?<!\\)',?", aliases)
exception_dict[tvdb_id] = alias_list
myDB = db.DBConnection("cache.db")
myDB.action("DELETE FROM scene_exceptions WHERE 1=1")
for cur_tvdb_id in exception_dict:
for cur_exception in exception_dict[cur_tvdb_id]:
myDB.action("INSERT INTO scene_exceptions (tvdb_id, show_name) VALUES (?,?)", [cur_tvdb_id, cur_exception])
......@@ -19,6 +19,7 @@
import sickbeard
from sickbeard import helpers, version, ui
from sickbeard import logger
from sickbeard import sceneHelpers
import os, os.path, platform, shutil, time
import subprocess, re
......@@ -48,6 +49,9 @@ class CheckVersion():
def run(self):
self.check_for_new_version()
# refresh scene exceptions too
sceneHelpers.retrieve_exceptions()
def find_install_type(self):
"""
Determines how this copy of SB was installed.
......
......@@ -5,6 +5,10 @@ sys.path.append(os.path.abspath('..'))
from sickbeard import sceneHelpers, common
import sickbeard
from sickbeard import db
from sickbeard.databases import cache_db
class Show:
def __init__(self, name, tvdbid, tvrname):
self.name = name
......@@ -58,7 +62,9 @@ class SceneTests(unittest.TestCase):
self._test_sceneToNormalShowNames('Show Name YA', ['Show Name YA'])
def test_allPossibleShowNames(self):
common.sceneExceptions[-1] = ['Exception Test']
#common.sceneExceptions[-1] = ['Exception Test']
myDB = db.DBConnection("cache.db")
myDB.action("INSERT INTO scene_exceptions (tvdb_id, show_name) VALUES (?,?)", [-1, 'Exception Test'])
common.countryList['Full Country Name'] = 'FCN'
self._test_allPossibleShowNames('Show Name', expected=['Show Name'])
......@@ -77,9 +83,38 @@ class SceneTests(unittest.TestCase):
self._test_filterBadReleases('German.Show.S02.Some.Stuff-Grp', True)
self._test_filterBadReleases('Show.S02.This.Is.German', False)
print 'Loading exceptions...',
db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema)
sceneHelpers.retrieve_exceptions()
print 'done.'
class SceneExceptionTestCase(unittest.TestCase):
def test_sceneExceptionsEmpty(self):
self.assertEqual(sceneHelpers.get_scene_exceptions(0), [])
def test_sceneExceptionsBabylon5(self):
self.assertEqual(sorted(sceneHelpers.get_scene_exceptions(70726)), ['Babylon 5', 'Babylon5'])
def test_sceneExceptionByName(self):
self.assertEqual(sceneHelpers.get_scene_exception_by_name('Babylon5'), 70726)
self.assertEqual(sceneHelpers.get_scene_exception_by_name('babylon 5'), 70726)
self.assertEqual(sceneHelpers.get_scene_exception_by_name('Carlos 2010'), 164451)
def test_sceneExceptionByNameEmpty(self):
self.assertEqual(sceneHelpers.get_scene_exception_by_name('nothing useful'), None)
if __name__ == '__main__':
if len(sys.argv) > 1:
suite = unittest.TestLoader().loadTestsFromName('scene_helpers_tests.SceneTests.test_'+sys.argv[1])
suite = unittest.TestLoader().loadTestsFromName('scene_helpers_tests.SceneExceptionTestCase.test_'+sys.argv[1])
unittest.TextTestRunner(verbosity=2).run(suite)
else:
suite = unittest.TestLoader().loadTestsFromTestCase(SceneTests)
unittest.TextTestRunner(verbosity=2).run(suite)
suite = unittest.TestLoader().loadTestsFromTestCase(SceneExceptionTestCase)
unittest.TextTestRunner(verbosity=2).run(suite)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment