Beispiel #1
0
def dissect_comment(comment):
    """
    :param comment: comment string
    :raises exceptions.MovieNotFound
    :raises exceptions.EpisodeNotFound
    :raises exceptions.OffensiveWord
    """
    split_command = comment.split(" ")
    requests_command = split_command[0]
    if not any(commands in requests_command.lower() for commands in COMMANDS):
        return

    split_command.pop(0)
    final_comment = " ".join(split_command)

    try:
        title = final_comment.split("[")[0].rstrip()
        if is_episode(title):
            search_episode(EPISODE_LIST, title, raise_resting=False)
        else:
            search_movie(MOVIE_LIST, title, raise_resting=False)
    except IndexError:
        return

    content = REQUEST_RE.findall(final_comment)
    if content:
        [check_offensive_content(text) for text in content]
        return {
            "command": requests_command,
            "title": title,
            "comment": final_comment,
            "content": content,
        }
Beispiel #2
0
def dissect_comment(comment):
    """
    :param comment: comment string
    :raises exceptions.MovieNotFound
    :raises exceptions.EpisodeNotFound
    :raises exceptions.OffensiveWord
    :raises exceptions.IvalidRequest
    """
    split_command = comment.split(" ")
    requests_command = split_command[0]

    if requests_command.lower() not in COMMANDS:
        return

    split_command.pop(0)
    final_comment = " ".join(split_command)

    if requests_command == "!parallel":
        parallels = is_parallel(final_comment)

        try:
            contents = [REQUEST_RE.findall(parallel) for parallel in parallels]
            if any(len(content) > 1
                   for content in contents) or len(parallels) > 3:
                raise InvalidRequest(final_comment)
        except TypeError:
            return

        title, content = "Parallel", ["Parallel"]
    else:
        try:
            title = final_comment.split("[")[0].rstrip()
            if is_episode(title):
                search_episode(EPISODE_LIST, title, raise_resting=False)
            else:
                search_movie(MOVIE_LIST, title, raise_resting=False)
        except IndexError:
            return
        content = REQUEST_RE.findall(final_comment)

    if content:
        [check_offensive_content(text) for text in content]
        return {
            "command": requests_command,
            "title": title,
            "comment": final_comment,
            "content": content,
        }
Beispiel #3
0
async def search(ctx, *args):
    query = " ".join(args)
    try:
        if is_episode(query):
            result = search_episode(EPISODE_LIST, query, raise_resting=False)
            message = f"{BASE}/episode/{result['id']}"
        else:
            result = search_movie(MOVIE_LIST, query, raise_resting=False)
            message = f"{BASE}/movie/{result['tmdb']}"
    except (MovieNotFound, EpisodeNotFound):
        message = "apoco si pa"

    await ctx.send(message)
Beispiel #4
0
def search_item(query, return_dict=False):
    if is_episode(query):
        EPISODE_LIST = db.get_list_of_episode_dicts()
        result = search_episode(EPISODE_LIST, query, raise_resting=False)
        if not return_dict:
            return f"{BASE}/episode/{result['id']}"
    else:
        MOVIE_LIST = db.get_list_of_movie_dicts()
        result = search_movie(MOVIE_LIST, query, raise_resting=False)
        if not return_dict:
            return f"{BASE}/movie/{result['tmdb']}"

    return result
Beispiel #5
0
def discover_movie(query, db_key, keywords):
    """
    Find a movie quote from common info (country, year or director).

    :param query: query
    :param db_key: country, year or director
    :param keywords: space-separated keywords
    :raises exceptions.BadKeywords
    :raises exceptions.TooShortQuery
    :raises exceptions.MovieNotFound
    :raises exceptions.QuoteNotFound
    """
    if re.match("^[A-Z][^?!.,]*[?.!,]$", keywords):
        raise exceptions.BadKeywords
    if len(keywords) < 4:
        raise exceptions.TooShortQuery

    keywords = keywords.split(" ")
    results = search_items(db_key, query)

    if not results:
        raise exceptions.MovieNotFound

    final_list = []
    for result in results:
        found_movie = search_movie(MOVIES, result[0] + " " + str(result[1]))
        try:
            subtitles = get_subtitle(found_movie)
        except FileNotFoundError:
            continue
        quote = find_quote(subtitles, keywords)
        if quote:
            final_list.append({
                "title": found_movie["title"],
                "year": found_movie["year"],
                "quote": quote,
            })
    if final_list:
        final_result = random.choice(final_list)
        logger.info("Quote found:")
        logger.info(final_result)
        return final_result
    raise exceptions.QuoteNotFound
Beispiel #6
0
def handle_gif_request(dictionary, movie_list):
    """
    Handle a GIF request. Return movie dictionary and GIF file (inside a list
    to avoid problems with the API).

    :param dictionary: request dictionary
    :param movie_list: list of movie dictionaries
    """
    possible_range = get_range(dictionary["content"][0])
    movie = search_movie(movie_list, dictionary["movie"], raise_resting=False)
    subtitle_list = get_subtitle(movie)

    if isinstance(possible_range, tuple):
        image_list = list(get_image_list_from_range(movie["path"], possible_range))
    else:
        sub_list = get_quote_list(subtitle_list, dictionary)
        image_list = list(get_image_list_from_subtitles(movie["path"], sub_list))

    filename = os.path.join(FRAMES_DIR, f"{dictionary['id']}.gif")
    image_list_to_gif(image_list, filename)

    return movie, [filename]