def maxduration_filter(reader, max_duration):
    """
    Filter dialogs by maximum duration.
    """
    for dialog in reader:
        duration = dialog[-1].datetime - dialog[0].datetime
        if duration <= max_duration:
            yield dialog
