Ejemplo n.º 1
0
def shots_parse(ctx, threshold, extraction_type, frames_path, from_file,
                local_sequence, color, keyframes, keyframe_thumbnails,
                keyframe_montage, label, limit, slices):
    """Shot detection and feature extraction."""

    project = ctx.obj[PROJECT_KEY]

    if from_file:
        shots = Shot.from_dicts(project.read(Project.File.shots))
    else:
        if extraction_type == ExtractionType.edge.value or extraction_type == ExtractionType.edgeim.value:
            threshold = threshold if threshold is not None else 1000
            shots = edge_detection.edge_detect(
                project, threshold, limit,
                extraction_type == ExtractionType.edgeim.value, local_sequence)
        else:
            threshold = threshold if threshold is not None else 0.4
            shots = shot_detection.detect(project, threshold, limit,
                                          local_sequence, extraction_type)

        ctx.obj[VERBOSE_KEY] and pprint(shots)

    if label:
        shots = label_detection.run(project, shots)
        pprint([shot.keyframe.labels for shot in shots])

    if keyframes:
        path = project.folder_path(project.Folder.keyframes)
        path_utils.delete_files_in_folder(path)
        path_utils.create_directory(path)

        shot_detection.copy_keyframes(project, shots)

    if keyframe_thumbnails:
        path = project.folder_path(project.Folder.keyframe_thumbnails)
        path_utils.delete_files_in_folder(path)

        shot_detection.keyframe_thumbnails(project)
        size = shot_detection.montage_keyframe_size(project)

    if slices:
        shot_detection.write_spatio_temporal_slices(project, shots)

    if color:
        shots = image_colors.run(project, shots, cluster_count=color)
        ctx.obj[VERBOSE_KEY] and pprint([s.keyframe.colors for s in shots])

    if keyframe_montage:
        shot_detection.keyframe_montage(project)
        size = shot_detection.montage_keyframe_size(project)

    if shots and len(shots):
        data = objects_as_dict(shots)
        data and project.write(data, Project.File.shots)

    ctx.obj[SHOTS_KEY] = shots
Ejemplo n.º 2
0
def subtitles_parse(ctx, path):
    """Parses subtitles."""
    project = ctx.obj[PROJECT_KEY]
    path = path if path else project.file_path(Project.File.original_subtitles)

    parsed_subtitles = subtitles_parser.parse_file(path)
    data = objects_as_dict(parsed_subtitles)
    data and project.write(data, Project.File.subtitles)

    ctx.obj[VERBOSE_KEY] and pprint(parsed_subtitles)
    ctx.obj[SUBTITLES_KEY] = parsed_subtitles
Ejemplo n.º 3
0
def parse_chapters(ctx, title):
    """Download the chapters for a movie."""

    project = ctx.obj[PROJECT_KEY]
    title = title if title else project.name
    chapters = chapters_parser.run(project, title)

    data = objects_as_dict(chapters)
    data and project.write(data, Project.File.chapters)

    ctx.obj[CHAPTERS_KEY] = chapters
    pprint(chapters)
Ejemplo n.º 4
0
def screenplay(ctx, url):
    """Parses movie scripts."""
    project = ctx.obj[PROJECT_KEY]

    if url:
        entities = script_parser.run(url)
        data = objects_as_dict(entities)
        data and project.write(data, Project.File.script)
    else:
        result = project.read(Project.File.script)
        entities = ScriptEntity.from_dicts(result)

    ctx.obj[VERBOSE_KEY] and pprint(entities)
    ctx.obj[SCRIPT_KEY] = entities
Ejemplo n.º 5
0
def characters(ctx, subtitles_path, movie_script, algorithm, partial):
    """Merges movie scripts and subtitles."""
    project = ctx.obj[PROJECT_KEY]
    logger = ctx.obj[LOGGER_KEY]

    partial = 1 if partial is None else partial

    if subtitles_path:
        subtitles = Subtitle.from_dicts(path_utils.load_json(subtitles_path))
    elif SUBTITLES_KEY in ctx.obj:
        subtitles = ctx.obj[SUBTITLES_KEY]
    else:
        data = project.read(Project.File.subtitles)
        subtitles = Subtitle.from_dicts(data)

    if movie_script is not None:
        obj = path_utils.load_json(movie_script)
        speeches = ScriptEntity.from_dicts(obj)
    elif SCRIPT_KEY in ctx.obj:
        speeches = ctx.obj[SCRIPT_KEY]
    else:
        data = project.read(Project.File.script)
        data = script_parser.clean_script(
            data)  # remove when no longer required
        speeches = ScriptEntity.from_dicts(data)

    speeches = [speech for speech in speeches if speech.type == "speech"]

    if algorithm == CharactersAlgorithm.dtw.value:
        alignment = dtw_merger.run(speeches, subtitles, partial, logger,
                                   ctx.obj[VERBOSE_KEY])
    elif algorithm == CharactersAlgorithm.nw.value:
        alignment = needleman_wunsch.run(speeches, subtitles, partial, logger,
                                         ctx.obj[VERBOSE_KEY])
    else:
        alignment = dtw_merger.run(speeches, subtitles, partial, logger,
                                   ctx.obj[VERBOSE_KEY])

    merged_subtitles = alignment.subtitles
    ctx.obj[SUBTITLES_KEY] = merged_subtitles

    data = objects_as_dict(merged_subtitles)
    data and project.write(data, Project.File.merged_subtitles)

    logger.write()