Example #1
0
def get_movie(root, path):
    def get_movie_files(movie_path):
        return [movie_file for movie_file in os.listdir(movie_path)
                if os.path.isfile(os.path.join(movie_path, movie_file))
                and (os.path.splitext(movie_file)[1] in utils.get_movie_extensions())]

    if not os.path.exists(os.path.join(root, path)):
        raise OSError('Path do not exist')

    movie = Movie()
    movie.path = path

    rx = regex.get_movie(movie.path)
    movie.search_year = rx['year']
    movie.imdb = rx['imdbID']
    movie.search_title = rx['title']
    movie.search_alternative_title = utils.replace(rx['title'])
    movie.path = os.path.join(root, movie.path)

    files = get_movie_files(movie.path)
    if len(files) < 1:
        return movie

    # todo: this *should* not longer be needed,
    if 'new.mkv' in files and len(files) > 1:
        os.remove(os.path.join(movie.path, 'new.mkv'))
        files = get_movie_files(movie.path)

    # todo: implement multi cd support
    if len(files) == 1:
        movie.files = [files[0]]

    if len(files) > 1:
        # get only files that are tagged as CD
        for _file in [f for f in files if regex.get_cd(f) == '']:
            files.remove(_file)

        movie.files = files

    return movie