From 0eac041a26eed14f59215e09b8f563ab819a4ad5 Mon Sep 17 00:00:00 2001 From: mano3m Date: Sat, 19 Apr 2014 22:11:28 +0200 Subject: [PATCH 1/2] Add 'A' and 'An' to 'The' prefix This was bothering me for a long time now ;) We do put The at the end but not A nor An. Fixed now :) --- couchpotato/core/media/_base/media/index.py | 8 ++++---- couchpotato/core/media/movie/_base/static/movie.js | 4 ++++ couchpotato/core/plugins/renamer.py | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/media/_base/media/index.py b/couchpotato/core/media/_base/media/index.py index d0b52c38..fd1affca 100644 --- a/couchpotato/core/media/_base/media/index.py +++ b/couchpotato/core/media/_base/media/index.py @@ -99,7 +99,7 @@ from couchpotato.core.helpers.encoding import simplifyString""" class TitleIndex(TreeBasedIndex): - _version = 2 + _version = 3 custom_header = """from CodernityDB.tree_index import TreeBasedIndex from string import ascii_letters @@ -123,7 +123,7 @@ from couchpotato.core.helpers.encoding import toUnicode, simplifyString""" nr_prefix = '' if title and len(title) > 0 and title[0] in ascii_letters else '#' title = simplifyString(title) - for prefix in ['the ']: + for prefix in ['the ', 'an ', 'a ']: if prefix == title[:len(prefix)]: title = title[len(prefix):] break @@ -132,7 +132,7 @@ from couchpotato.core.helpers.encoding import toUnicode, simplifyString""" class StartsWithIndex(TreeBasedIndex): - _version = 2 + _version = 3 custom_header = """from CodernityDB.tree_index import TreeBasedIndex from string import ascii_letters @@ -153,7 +153,7 @@ from couchpotato.core.helpers.encoding import toUnicode, simplifyString""" title = toUnicode(title) title = simplifyString(title) - for prefix in ['the ']: + for prefix in ['the ', 'an ', 'a ']: if prefix == title[:len(prefix)]: title = title[len(prefix):] break diff --git a/couchpotato/core/media/movie/_base/static/movie.js b/couchpotato/core/media/movie/_base/static/movie.js index 25d5e08f..a251e79d 100644 --- a/couchpotato/core/media/movie/_base/static/movie.js +++ b/couchpotato/core/media/movie/_base/static/movie.js @@ -250,6 +250,10 @@ var Movie = new Class({ getUnprefixedTitle: function(t){ if(t.substr(0, 4).toLowerCase() == 'the ') t = t.substr(4) + ', The'; + if(t.substr(0, 3).toLowerCase() == 'an ') + t = t.substr(3) + ', An'; + if(t.substr(0, 2).toLowerCase() == 'a ') + t = t.substr(2) + ', A'; return t; }, diff --git a/couchpotato/core/plugins/renamer.py b/couchpotato/core/plugins/renamer.py index 3830b97d..1fd4fed6 100644 --- a/couchpotato/core/plugins/renamer.py +++ b/couchpotato/core/plugins/renamer.py @@ -290,8 +290,9 @@ class Renamer(Plugin): # Put 'The' at the end name_the = movie_name - if movie_name[:4].lower() == 'the ': - name_the = movie_name[4:] + ', The' + for prefix in ['the ', 'an ', 'a ']: + if prefix == movie_name[:len(prefix)].lower(): + name_the = movie_name[len(prefix):] + ', ' + prefix.strip().capitalize() replacements = { 'ext': 'mkv', From 72383592ba98dc77ff07d5436762137443cd1d5f Mon Sep 17 00:00:00 2001 From: mano3m Date: Sun, 20 Apr 2014 10:18:44 +0200 Subject: [PATCH 2/2] Clean-up --- couchpotato/core/media/movie/_base/static/movie.js | 4 ++-- couchpotato/core/plugins/renamer.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/media/movie/_base/static/movie.js b/couchpotato/core/media/movie/_base/static/movie.js index a251e79d..86205efc 100644 --- a/couchpotato/core/media/movie/_base/static/movie.js +++ b/couchpotato/core/media/movie/_base/static/movie.js @@ -250,9 +250,9 @@ var Movie = new Class({ getUnprefixedTitle: function(t){ if(t.substr(0, 4).toLowerCase() == 'the ') t = t.substr(4) + ', The'; - if(t.substr(0, 3).toLowerCase() == 'an ') + else if(t.substr(0, 3).toLowerCase() == 'an ') t = t.substr(3) + ', An'; - if(t.substr(0, 2).toLowerCase() == 'a ') + else if(t.substr(0, 2).toLowerCase() == 'a ') t = t.substr(2) + ', A'; return t; }, diff --git a/couchpotato/core/plugins/renamer.py b/couchpotato/core/plugins/renamer.py index 1fd4fed6..5f2d4024 100644 --- a/couchpotato/core/plugins/renamer.py +++ b/couchpotato/core/plugins/renamer.py @@ -292,7 +292,8 @@ class Renamer(Plugin): name_the = movie_name for prefix in ['the ', 'an ', 'a ']: if prefix == movie_name[:len(prefix)].lower(): - name_the = movie_name[len(prefix):] + ', ' + prefix.strip().capitalize() + name_the = movie_name[len(prefix):] + ', ' + prefix.strip().capitalize() + break replacements = { 'ext': 'mkv',