From 4bdd23e36a077b377439f84a1c0abcc5e4c5570d Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 11 May 2012 22:59:47 +0200 Subject: [PATCH] Do some title testing. fix #246 closes #238 --- couchpotato/core/helpers/variable.py | 15 +++++++++++++++ couchpotato/core/plugins/movie/main.py | 2 +- couchpotato/core/plugins/renamer/main.py | 10 ++++++---- couchpotato/core/plugins/score/main.py | 3 ++- couchpotato/core/plugins/searcher/main.py | 11 +++++++---- couchpotato/core/providers/metadata/xbmc/main.py | 3 ++- couchpotato/core/providers/nzb/moovee/main.py | 3 ++- couchpotato/core/providers/nzb/mysterbin/main.py | 4 ++-- couchpotato/core/providers/nzb/nzbclub/main.py | 4 ++-- couchpotato/core/providers/nzb/nzbindex/main.py | 4 ++-- couchpotato/core/providers/nzb/x264/main.py | 4 ++-- .../core/providers/torrent/kickasstorrents/main.py | 4 ++-- couchpotato/core/providers/trailer/hdtrailers/main.py | 6 +++--- 13 files changed, 48 insertions(+), 25 deletions(-) diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index b398d30..29e4bf4 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -1,8 +1,11 @@ +from couchpotato.core.logger import CPLog import hashlib import os.path import platform import re +log = CPLog(__name__) + def getDataDir(): # Windows @@ -102,3 +105,15 @@ def natsortKey(s): def natcmp(a, b): return cmp(natsortKey(a), natsortKey(b)) + +def getTitle(library_dict): + try: + try: + return library_dict['titles'][0]['title'] + except: + log.error('Could not get title for %s' % library_dict['identifier']) + return None + except: + log.error('Could not get title for library item: %s' % library_dict) + return None + diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index 52e6edc..17814a5 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -437,7 +437,7 @@ class MoviePlugin(Plugin): db = get_session() m = db.query(Movie).filter_by(id = movie_id).first() - if not m: + if not m or len(m.library.titles) == 0: log.debug('Can\'t restatus movie, doesn\'t seem to exist.') return False diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index c60d6cc..29d81a6 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -3,7 +3,7 @@ from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEvent, fireEventAsync from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.helpers.request import jsonified -from couchpotato.core.helpers.variable import getExt, mergeDicts +from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, File, Profile @@ -82,8 +82,10 @@ class Renamer(Plugin): remove_files = [] remove_releases = [] + movie_title = getTitle(group['library']) + # Add _UNKNOWN_ if no library item is connected - if not group['library']: + if not group['library'] or not movie_title: if group['dirname']: rename_files[group['parentdir']] = group['parentdir'].replace(group['dirname'], '_UNKNOWN_%s' % group['dirname']) else: # Add it to filename @@ -105,7 +107,7 @@ class Renamer(Plugin): fireEvent('renamer.before', group) # Remove weird chars from moviename - movie_name = re.sub(r"[\x00\/\\:\*\?\"<>\|]", '', group['library']['titles'][0]['title']) + movie_name = re.sub(r"[\x00\/\\:\*\?\"<>\|]", '', movie_title) # Put 'The' at the end name_the = movie_name @@ -369,7 +371,7 @@ class Renamer(Plugin): fireEventAsync('renamer.after', group) # Notify on download - download_message = 'Downloaded %s (%s)' % (group['library']['titles'][0]['title'], replacements['quality']) + download_message = 'Downloaded %s (%s)' % (movie_title, replacements['quality']) fireEventAsync('movie.downloaded', message = download_message, data = group) # Break if CP wants to shut down diff --git a/couchpotato/core/plugins/score/main.py b/couchpotato/core/plugins/score/main.py index 49dbba4..74fed1d 100644 --- a/couchpotato/core/plugins/score/main.py +++ b/couchpotato/core/plugins/score/main.py @@ -1,5 +1,6 @@ from couchpotato.core.event import addEvent from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.helpers.variable import getTitle from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.score.scores import nameScore, nameRatioScore, \ @@ -35,6 +36,6 @@ class Score(Plugin): score += providerScore(nzb['provider']) # Duplicates in name - score += duplicateScore(nzb['name'], movie['library']['titles'][0]['title']) + score += duplicateScore(nzb['name'], getTitle(movie['library'])) return score diff --git a/couchpotato/core/plugins/searcher/main.py b/couchpotato/core/plugins/searcher/main.py index 7dc7a12..1b274bb 100644 --- a/couchpotato/core/plugins/searcher/main.py +++ b/couchpotato/core/plugins/searcher/main.py @@ -1,7 +1,7 @@ from couchpotato import get_session from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.helpers.encoding import simplifyString, toUnicode -from couchpotato.core.helpers.variable import md5, getImdb +from couchpotato.core.helpers.variable import md5, getImdb, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Movie, Release, ReleaseInfo @@ -78,7 +78,10 @@ class Searcher(Plugin): release_dates = fireEvent('library.update_release_date', identifier = movie['library']['identifier'], merge = True) available_status = fireEvent('status.get', 'available', single = True) - default_title = movie['library']['titles'][0]['title'] + default_title = getTitle(movie['library']) + if not default_title: + return + for quality_type in movie['profile']['types']: if not self.couldBeReleased(quality_type['quality']['identifier'], release_dates, pre_releases): log.info('To early to search for %s, %s' % (quality_type['quality']['identifier'], default_title)) @@ -168,7 +171,7 @@ class Searcher(Plugin): rls.status_id = snatched_status.get('id') db.commit() - log_movie = '%s (%s) in %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], rls.quality.label) + log_movie = '%s (%s) in %s' % (getTitle(movie['library']), movie['library']['year'], rls.quality.label) snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie) log.info(snatch_message) fireEvent('movie.snatched', message = snatch_message, data = rls.to_dict()) @@ -274,7 +277,7 @@ class Searcher(Plugin): if self.checkNFO(nzb['name'], movie['library']['identifier']): return True - log.info("Wrong: %s, undetermined naming. Looking for '%s (%s)'" % (nzb['name'], movie['library']['titles'][0]['title'], movie['library']['year'])) + log.info("Wrong: %s, undetermined naming. Looking for '%s (%s)'" % (nzb['name'], getTitle(movie['library']), movie['library']['year'])) return False def containsOtherQuality(self, nzb, movie_year = None, preferred_quality = {}, single_category = False): diff --git a/couchpotato/core/providers/metadata/xbmc/main.py b/couchpotato/core/providers/metadata/xbmc/main.py index 9a09edd..d6c9bed 100644 --- a/couchpotato/core/providers/metadata/xbmc/main.py +++ b/couchpotato/core/providers/metadata/xbmc/main.py @@ -1,4 +1,5 @@ from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.helpers.variable import getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.metadata.base import MetaDataBase from xml.etree.ElementTree import Element, SubElement, tostring @@ -32,7 +33,7 @@ class XBMC(MetaDataBase): # Title try: el = SubElement(nfoxml, 'title') - el.text = toUnicode(data['library']['titles'][0]['title']) + el.text = toUnicode(getTitle(data['library'])) except: pass diff --git a/couchpotato/core/providers/nzb/moovee/main.py b/couchpotato/core/providers/nzb/moovee/main.py index a6aeb32..65f118d 100644 --- a/couchpotato/core/providers/nzb/moovee/main.py +++ b/couchpotato/core/providers/nzb/moovee/main.py @@ -1,5 +1,6 @@ from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import tryUrlencode +from couchpotato.core.helpers.variable import getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider from dateutil.parser import parse @@ -26,7 +27,7 @@ class Moovee(NZBProvider): if self.isDisabled() or not self.isAvailable(self.urls['search']) or quality.get('hd', False): return results - q = '%s %s' % (movie['library']['titles'][0]['title'], quality.get('identifier')) + q = '%s %s' % (getTitle(movie['library']), quality.get('identifier')) url = self.urls['search'] % tryUrlencode(q) cache_key = 'moovee.%s' % q diff --git a/couchpotato/core/providers/nzb/mysterbin/main.py b/couchpotato/core/providers/nzb/mysterbin/main.py index 0f7ffb3..7e19d1b 100644 --- a/couchpotato/core/providers/nzb/mysterbin/main.py +++ b/couchpotato/core/providers/nzb/mysterbin/main.py @@ -1,7 +1,7 @@ from BeautifulSoup import BeautifulSoup from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider from couchpotato.environment import Env @@ -25,7 +25,7 @@ class Mysterbin(NZBProvider): if self.isDisabled() or not self.isAvailable(self.urls['search']): return results - q = '"%s" %s %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], quality.get('identifier')) + q = '"%s" %s %s' % (getTitle(movie['library']), movie['library']['year'], quality.get('identifier')) for ignored in Env.setting('ignored_words', 'searcher').split(','): q = '%s -%s' % (q, ignored.strip()) diff --git a/couchpotato/core/providers/nzb/nzbclub/main.py b/couchpotato/core/providers/nzb/nzbclub/main.py index 2c672f8..40bc2d1 100644 --- a/couchpotato/core/providers/nzb/nzbclub/main.py +++ b/couchpotato/core/providers/nzb/nzbclub/main.py @@ -2,7 +2,7 @@ from BeautifulSoup import BeautifulSoup from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider from couchpotato.environment import Env @@ -27,7 +27,7 @@ class NZBClub(NZBProvider, RSS): if self.isDisabled() or not self.isAvailable(self.urls['search']): return results - q = '"%s" %s %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], quality.get('identifier')) + q = '"%s" %s %s' % (getTitle(movie['library']), movie['library']['year'], quality.get('identifier')) for ignored in Env.setting('ignored_words', 'searcher').split(','): q = '%s -%s' % (q, ignored.strip()) diff --git a/couchpotato/core/providers/nzb/nzbindex/main.py b/couchpotato/core/providers/nzb/nzbindex/main.py index 0b708b2..831ea9c 100644 --- a/couchpotato/core/providers/nzb/nzbindex/main.py +++ b/couchpotato/core/providers/nzb/nzbindex/main.py @@ -2,7 +2,7 @@ from BeautifulSoup import BeautifulSoup from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider from couchpotato.environment import Env @@ -29,7 +29,7 @@ class NzbIndex(NZBProvider, RSS): if self.isDisabled() or not self.isAvailable(self.urls['api']): return results - q = '%s %s %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], quality.get('identifier')) + q = '%s %s %s' % (getTitle(movie['library']), movie['library']['year'], quality.get('identifier')) arguments = tryUrlencode({ 'q': q, 'age': Env.setting('retention', 'nzb'), diff --git a/couchpotato/core/providers/nzb/x264/main.py b/couchpotato/core/providers/nzb/x264/main.py index d1b9f72..4292dee 100644 --- a/couchpotato/core/providers/nzb/x264/main.py +++ b/couchpotato/core/providers/nzb/x264/main.py @@ -1,6 +1,6 @@ from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import tryUrlencode -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider import re @@ -25,7 +25,7 @@ class X264(NZBProvider): if self.isDisabled() or not self.isAvailable(self.urls['search'].split('requests')[0]) or not quality.get('hd', False): return results - q = '%s %s %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], quality.get('identifier')) + q = '%s %s %s' % (getTitle(movie['library']), movie['library']['year'], quality.get('identifier')) url = self.urls['search'] % tryUrlencode(q) cache_key = 'x264.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) diff --git a/couchpotato/core/providers/torrent/kickasstorrents/main.py b/couchpotato/core/providers/torrent/kickasstorrents/main.py index 6a039c7..0f38604 100644 --- a/couchpotato/core/providers/torrent/kickasstorrents/main.py +++ b/couchpotato/core/providers/torrent/kickasstorrents/main.py @@ -1,6 +1,6 @@ from BeautifulSoup import BeautifulSoup from couchpotato.core.event import fireEvent -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.torrent.base import TorrentProvider import StringIO @@ -38,7 +38,7 @@ class KickAssTorrents(TorrentProvider): return results cache_key = 'kickasstorrents.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) - data = self.getCache(cache_key, self.urls['search'] % (movie['library']['titles'][0]['title'], movie['library']['identifier'].replace('tt', ''))) + data = self.getCache(cache_key, self.urls['search'] % (getTitle(movie['library']), movie['library']['identifier'].replace('tt', ''))) if data: cat_ids = self.getCatId(quality['identifier']) diff --git a/couchpotato/core/providers/trailer/hdtrailers/main.py b/couchpotato/core/providers/trailer/hdtrailers/main.py index 03fa910..b68f76f 100644 --- a/couchpotato/core/providers/trailer/hdtrailers/main.py +++ b/couchpotato/core/providers/trailer/hdtrailers/main.py @@ -1,6 +1,6 @@ from BeautifulSoup import SoupStrainer, BeautifulSoup from couchpotato.core.helpers.encoding import tryUrlencode -from couchpotato.core.helpers.variable import mergeDicts +from couchpotato.core.helpers.variable import mergeDicts, getTitle from couchpotato.core.logger import CPLog from couchpotato.core.providers.trailer.base import TrailerProvider from string import letters, digits @@ -19,7 +19,7 @@ class HDTrailers(TrailerProvider): def search(self, group): - movie_name = group['library']['titles'][0]['title'] + movie_name = getTitle(group['library']) url = self.urls['api'] % self.movieUrlName(movie_name) data = self.getCache('hdtrailers.%s' % group['library']['identifier'], url) @@ -44,7 +44,7 @@ class HDTrailers(TrailerProvider): def findViaAlternative(self, group): results = {'480p':[], '720p':[], '1080p':[]} - movie_name = group['library']['titles'][0]['title'] + movie_name = getTitle(group['library']) url = "%s?%s" % (self.url['backup'], tryUrlencode({'s':movie_name})) data = self.getCache('hdtrailers.alt.%s' % group['library']['identifier'], url)