Exemplo n.º 1
0
def get_image_list_from_subtitles(path, subs=[], dar=None):
    """
    :param path: video path
    :param subs: list of subtitle dictionaries
    :param dar: display aspect ratio from video
    """
    sanity_checks(subs)

    logger.info(f"Subtitles found: {len(subs)}")

    capture = cv2.VideoCapture(path)
    if not dar:
        dar = get_dar(path)

    fps = capture.get(cv2.CAP_PROP_FPS)
    for subtitle in subs:
        start, end = start_end_gif(fps, sub_dict=subtitle)
        end += 10

        logger.info(f"Start: {start} - end: {end}; diff: {start - end}")
        for i in range(start, end, 3):
            capture.set(1, i)
            pil = scale_to_gif(
                cv2_to_pil(fix_dar(path,
                                   capture.read()[1], dar)))
            yield draw_quote(center_crop_image(pil), subtitle["message"])
Exemplo n.º 2
0
def get_images(comment_dict, is_multiple, published=False):
    """
    :param comment_dict: request dictionary
    :param is_multiple: ignore palette generator
    :param published: published
    """
    frames = list(handle_commands(comment_dict, is_multiple))
    alt_title = None

    if comment_dict["parallel"]:
        final_frames = []
        homogenized = homogenize_images([frame[0].pill[0] for frame in frames])

        for index, frame in enumerate(frames):
            if frame[0].quote:
                final_frames.append(
                    draw_quote(homogenized[index], frame[0].quote))
            else:
                final_frames.append(homogenized[index])

        single_image_list = [get_collage(final_frames, False)]
        alt_title = get_alt_title(frames, comment_dict["is_episode"])
        frames = frames[0]

    else:
        frames = frames[0]

        if comment_dict["type"] == "!palette":
            single_image_list = [get_palette_legacy(frames[0].pill[0])]
        else:
            final_image_list = [im.pill for im in frames]
            single_image_list = reduce(lambda x, y: x + y, final_image_list)

        check_image_list_integrity(single_image_list)

        if 1 < len(single_image_list) < 4:
            single_image_list = [get_collage(single_image_list, False)]

    saved_images = save_images(single_image_list, frames[0].movie,
                               comment_dict)

    if not comment_dict["verified"] and published:
        try:
            check_nsfw(saved_images)
        except exceptions.NSFWContent:
            notify_discord(frames[0].movie, saved_images, comment_dict, True)
            raise

    notify_discord(frames[0].movie, saved_images, comment_dict)

    return saved_images, frames, alt_title