Exemplo n.º 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
Exemplo n.º 2
0
def normalizeTitle(title, lang=None):
    """Return the title in the normal "The Title" format;
    beware that it doesn't handle long imdb titles, but only the
    title portion, without year[/imdbIndex] or special markup.
    The 'lang' argument can be used to specify the language of the title.
    """
    isUnicode = True
    stitle = title.split(", ")
    articlesDicts = linguistics.articlesDictsForLang(lang)
    if len(stitle) > 1 and stitle[-1].lower() in articlesDicts[isUnicode]:
        sep = " "
        if stitle[-1][-1] in ("'", "-"):
            sep = ""

        _format = u"%s%s%s"
        _joiner = u", "
        title = _format % (stitle[-1], sep, _joiner.join(stitle[:-1]))
    return title
Exemplo n.º 3
0
        return ""
    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