'Do a lookup from TMDb for the movie matching the passed arguments.
Any combination of criteria can be passed, the most specific criteria specified will be used.
:param int tmdb_id: tmdb_id of desired movie
:param unicode imdb_id: imdb_id of desired movie
:param unicode title: title of desired movie
:param int year: release year of desired movie
:param unicode smart_match: attempt to clean and parse title and year from a string
:param bool only_cached: if this is specified, an online lookup will not occur if the movie is not in the cache
session: optionally specify a session to use, if specified, returned Movie will be live in that session
:param session: sqlalchemy Session in which to do cache lookups/storage. commit may be called on a passed in
session. If not supplied, a session will be created automatically.
:return: The :class:`TMDBMovie` object populated with data from tmdb
:raises: :class:`LookupError` if a match cannot be found or there are other problems with the lookup'

@staticmethod
@with_session
def lookup(title=None, year=None, tmdb_id=None, imdb_id=None, smart_match=None, only_cached=False, session=None):

    get_tmdb_config()
    if (smart_match and (not (title or tmdb_id or imdb_id))):
        title_parser = get_plugin_by_name(u'parsing').instance.parse_movie(smart_match)
        title = title_parser.name
        year = title_parser.year
    if (not (title or tmdb_id or imdb_id)):
        raise LookupError(u'No    criteria    specified    for    TMDb    lookup')
    id_str = u'<title={},    year={},    tmdb_id={},    imdb_id={}>'.format(title, year, tmdb_id, imdb_id)
    log.debug(u'Looking    up    TMDb    information    for    %s', id_str)
    movie = None
    if (imdb_id or tmdb_id):
        ors = []
        if tmdb_id:
            ors.append((TMDBMovie.id == tmdb_id))
        if imdb_id:
            ors.append((TMDBMovie.imdb_id == imdb_id))
        movie = session.query(TMDBMovie).filter(or_(*ors)).first()
    elif title:
        movie_filter = session.query(TMDBMovie).filter((func.lower(TMDBMovie.name) == title.lower()))
        if year:
            movie_filter = movie_filter.filter((TMDBMovie.year == year))
        movie = movie_filter.first()
        if (not movie):
            search_string = ((title + u'    ({})'.format(year)) if year else title)
            found = session.query(TMDBSearchResult).filter((TMDBSearchResult.search == search_string.lower())).first()
            if (found and found.movie):
                movie = found.movie
    if movie:
        refresh_time = timedelta(days=2)
        if movie.released:
            if (movie.released > (datetime.now().date() - timedelta(days=7))):
                refresh_time = timedelta(days=1)
            else:
                age_in_years = ((datetime.now().date() - movie.released).days / 365)
                refresh_time += timedelta(days=(age_in_years * 5))
        if ((movie.updated < (datetime.now() - refresh_time)) and (not only_cached)):
            log.debug(u'Cache    has    expired    for    %s,    attempting    to    refresh    from    TMDb.', movie.name)
            try:
                updated_movie = TMDBMovie(id=movie.id)
            except LookupError:
                log.error(u'Error    refreshing    movie    details    from    TMDb,    cached    info    being    used.')
            else:
                movie = session.merge(updated_movie)
        else:
            log.debug(u'Movie    %s    information    restored    from    cache.', movie.name)
    else:
        if only_cached:
            raise LookupError((u'Movie    %s    not    found    from    cache' % id_str))
        log.verbose(u'Searching    from    TMDb    %s', id_str)
        if (imdb_id and (not tmdb_id)):
            try:
                result = tmdb_request(u'find/{}'.format(imdb_id), external_source=u'imdb_id')
            except requests.RequestException as e:
                raise LookupError(u'Error    searching    imdb    id    on    tmdb:    {}'.format(e))
            if result[u'movie_results']:
                tmdb_id = result[u'movie_results'][0][u'id']
        if (not tmdb_id):
            search_string = ((title + u'    ({})'.format(year)) if year else title)
            searchparams = {u'query': title}
            if year:
                searchparams[u'year'] = year
            try:
                results = tmdb_request(u'search/movie', **searchparams)
            except requests.RequestException as e:
                raise LookupError(u'Error    searching    for    tmdb    item    {}:    {}'.format(search_string, e))
            if (not results[u'results']):
                raise LookupError(u'No    results    for    {}    from    tmdb'.format(search_string))
            tmdb_id = results[u'results'][0][u'id']
            session.add(TMDBSearchResult(search=search_string, movie_id=tmdb_id))
        if tmdb_id:
            movie = TMDBMovie(id=tmdb_id)
            movie = session.merge(movie)
        else:
            raise LookupError(u'Unable    to    find    movie    on    tmdb:    {}'.format(id_str))
    return movie
