Beispiel #1
0
def draw_quote(pil_image, quote):
    """
    :param pil_image: PIL.Image object
    :param quote: quote
    :param sd_source: reduce stroke_width for low-res sources
    :raises exceptions.OffensiveWord
    """
    logger.info("Drawing subtitle")

    check_offensive_content(quote)
    quote = prettify_quote(clean_sub(quote))

    draw = ImageDraw.Draw(pil_image)

    width, height = pil_image.size
    font_size = int((width * 0.019) + (height * 0.019))
    font = ImageFont.truetype(FONT, font_size)
    # 0.067
    off = width * 0.08
    txt_w, txt_h = draw.textsize(quote, font)

    stroke = int(width * 0.0025)

    draw.text(
        ((width - txt_w) / 2, height - txt_h - off),
        quote,
        "white",
        font=font,
        align="center",
        stroke_width=stroke,
        stroke_fill="black",
    )

    return pil_image
Beispiel #2
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 #3
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,
        }