#!/bin/bash -e if [ -z "$1" -o -z "$2" ]; then echo "Usage: $0 --bluray-device|--dvd-device SOMEDIRECTORY" exit 1 fi device_param="$1" device_path="$2" if [ "$device_param" = "--bluray-device" ]; then device_scheme="bd" elif [ "$device_param" = "--dvd-device" ]; then device_scheme="dvd" else echo "Unknown device type: $device_param" exit 1 fi function mpv_wrap { mpv 2> /dev/null \ --quiet \ --ao=null \ --vo=null \ --frames 1 \ --no-cache \ --no-config \ "$@" } function get_highest_title { mpv_wrap \ "$device_param" "$device_path" "${device_scheme}://" \ --term-playing-msg='${disc-title-list}TITLE_LIST_END' \ | grep -B2 'TITLE_LIST_END' \ | head -n1 \ | cut -d':' -f1 } function get_length { mpv_wrap \ "$device_param" "$device_path" "${device_scheme}://${1}" \ --term-playing-msg='TITLE_LENGTH=${duration}' \ | grep 'TITLE_LENGTH' \ | head -n1 \ | cut -d'=' -f2 } highest_title="$(get_highest_title)" for title in $(seq 0 "$highest_title"); do echo -n "$title " get_length "$title" done