--- /dev/null
+#!/bin/bash
+
+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_param="-bluray-device"
+ device_scheme="bluray"
+elif [ "$device_param" = "--dvd-device" ]; then
+ device_param="-dvd-device"
+ device_scheme="dvd"
+else
+ echo "Unknown device type: $device_param"
+ exit 1
+fi
+
+mplayer 2> /dev/null \
+ -quiet \
+ -ao null \
+ -vo null \
+ -frames 0 \
+ -identify \
+ "$device_param" "$device_path" \
+ "${device_scheme}://" | \
+ sed -e 's/ID_\(DVD\|BLURAY\)_TITLE_\([0-9]*\)*_LENGTH=\(.*\)$/\2 \3/;tx;d;:x' | \
+ sort -n
+
--- /dev/null
+#!/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=${length}' \
+ | 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
+
+++ /dev/null
-#!/bin/bash
-
-if [ -z "$1" ]; then
- echo "Usage: $0 dvd-device"
- exit 1
-fi
-
-mplayer 2> /dev/null \
- -quiet -ao null -vo null -frames 0 -identify -dvd-device "$1" dvd:// | \
- grep 'ID_DVD_TITLE_[0-9]*_LENGTH' | \
- sed -e 's/ID_DVD_TITLE_//' -e 's/_LENGTH=/ /' | \
- sort -n
-