miglioria title_unify per ricerca
This commit is contained in:
@@ -748,24 +748,20 @@ def title_unify(title):
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
u_title = ''
|
u_title = ''
|
||||||
sep_count = 0
|
for c in unicodedata.normalize('NFD', title):
|
||||||
for c in unicodedata.normalize('NFD', title if PY3 else title.decode('utf-8', 'ignore')):
|
|
||||||
cat = unicodedata.category(c)
|
cat = unicodedata.category(c)
|
||||||
if cat != 'Mn':
|
if cat != 'Mn':
|
||||||
if cat == 'Pd':
|
if cat == 'Pd':
|
||||||
c_new = '-'
|
c_new = '-'
|
||||||
elif cat in ['Ll', 'Lu'] or c in [':']:
|
elif cat in ['Ll', 'Lu'] or c == ':':
|
||||||
c_new = c
|
c_new = c
|
||||||
else:
|
else:
|
||||||
c_new = ' '
|
c_new = ' '
|
||||||
if c_new in ['-', ':']:
|
|
||||||
sep_count += 1
|
|
||||||
|
|
||||||
u_title += c_new
|
u_title += c_new
|
||||||
if sep_count == 1: # subtitle, split but only if there's one, it might be part of title
|
|
||||||
|
if (u_title.count(':') + u_title.count('-')) == 1:
|
||||||
|
# subtitle, split but only if there's one, it might be part of title
|
||||||
spl = u_title.replace(':', '-').split('-')
|
spl = u_title.replace(':', '-').split('-')
|
||||||
if len(spl[0]) > 5:
|
u_title = spl[0] if len(spl[0]) > 5 else spl[1]
|
||||||
u_title = spl[0]
|
|
||||||
else:
|
|
||||||
u_title = spl[1]
|
|
||||||
return u_title.strip()
|
return u_title.strip()
|
||||||
Reference in New Issue
Block a user