Exemple #1
0
def canonicalTitle(title, lang=None, imdbIndex=None):
    """Return the title in the canonic format 'Movie Title, The';
    beware that it doesn't handle long imdb titles.
    The 'lang' argument can be used to specify the language of the title.
    """
    isUnicode = True
    articlesDicts = linguistics.articlesDictsForLang(lang)
    try:
        if title.split(", ")[-1].lower() in articlesDicts[isUnicode]:
            return title
    except IndexError:
        pass

    _format = u"%s%s, %s"
    ltitle = title.lower()
    if imdbIndex:
        imdbIndex = " (%s)" % imdbIndex
    else:
        imdbIndex = ""
    spArticles = linguistics.spArticlesForLang(lang)
    for article in spArticles[isUnicode]:
        if ltitle.startswith(article):
            lart = len(article)
            title = _format % (title[lart:], imdbIndex, title[:lart])
            if article[-1] == " ":
                title = title[:-1]
            break
    return title
Exemple #2
0
    if canonical is not None:
        if canonical:
            name = canonicalName(name)
        else:
            name = normalizeName(name)
    imdbIndex = name_dict.get("imdbIndex")
    if imdbIndex:
        name += " (%s)" % imdbIndex
    return name


# XXX: here only for backward compatibility.  Find and remove any dependency.
_articles = linguistics.GENERIC_ARTICLES
_unicodeArticles = linguistics.toUnicode(_articles)
articlesDicts = linguistics.articlesDictsForLang(None)
spArticles = linguistics.spArticlesForLang(None)


def canonicalTitle(title, lang=None, imdbIndex=None):
    """Return the title in the canonic format 'Movie Title, The';
    beware that it doesn't handle long imdb titles.
    The 'lang' argument can be used to specify the language of the title.
    """
    isUnicode = True
    articlesDicts = linguistics.articlesDictsForLang(lang)
    try:
        if title.split(", ")[-1].lower() in articlesDicts[isUnicode]:
            return title
    except IndexError:
        pass