'Given a long imdb canonical title, returns a movieID or
None if not found.'

def _getTitleID(self, title):

    td = analyze_title(title)
    condition = None
    if (td['kind'] == 'episode'):
        epof = td['episode    of']
        seriesID = [s.id for s in Title.select(AND((Title.q.title == self.toUTF8(epof['title'])), self._buildNULLCondition(Title.q.imdbIndex, epof.get('imdbIndex')), (Title.q.kindID == self._kindRev[epof['kind']]), self._buildNULLCondition(Title.q.productionYear, epof.get('year'))))]
        if seriesID:
            condition = AND(IN(Title.q.episodeOfID, seriesID), (Title.q.title == self.toUTF8(td['title'])), self._buildNULLCondition(Title.q.imdbIndex, td.get('imdbIndex')), (Title.q.kindID == self._kindRev[td['kind']]), self._buildNULLCondition(Title.q.productionYear, td.get('year')))
    if (condition is None):
        condition = AND((Title.q.title == self.toUTF8(td['title'])), self._buildNULLCondition(Title.q.imdbIndex, td.get('imdbIndex')), (Title.q.kindID == self._kindRev[td['kind']]), self._buildNULLCondition(Title.q.productionYear, td.get('year')))
    res = Title.select(condition)
    try:
        if (res.count() != 1):
            return None
    except (UnicodeDecodeError, TypeError):
        return None
    return res[0].id
