Skip to content

Instantly share code, notes, and snippets.

@parkerlreed
Last active September 29, 2024 07:43
Show Gist options
  • Save parkerlreed/fd6dccfcdd6b3202b478cfe383ef5eb2 to your computer and use it in GitHub Desktop.
Save parkerlreed/fd6dccfcdd6b3202b478cfe383ef5eb2 to your computer and use it in GitHub Desktop.
Script to read tracks from corrupted/unfinalized DVD media
#!/bin/bash
# Device to read from
device="/dev/sr0"
# Get the current date and time
current_date_time=$(date +"%Y%m%d_%H%M%S")
# Function to parse the track information
parse_tracks() {
local track_number=""
local start_addr=""
local track_size=""
while read -r line; do
if [[ $line =~ ^READ\ TRACK\ INFORMATION\[\#([0-9]+)\]:$ ]]; then
track_number=${BASH_REMATCH[1]}
elif [[ $line =~ Track\ Start\ Address:\ +([0-9]+)\*2KB ]]; then
start_addr=${BASH_REMATCH[1]}
elif [[ $line =~ Track\ Size:\ +([0-9]+)\*2KB ]]; then
track_size=${BASH_REMATCH[1]}
tracks+=("$track_number $start_addr $track_size")
fi
done < <(dvd+rw-mediainfo "$device")
}
# Parse the tracks
tracks=()
parse_tracks
if [[ -z "$tracks" ]]; then
exit
fi
# Display tracks to the user
echo "Available tracks:"
for i in "${!tracks[@]}"; do
track_number=$(echo "${tracks[$i]}" | awk '{print $1}')
track_size=$(echo "${tracks[$i]}" | awk '{print $3}')
echo "Track $track_number: Size = $((track_size * 2)) KB"
done
# Ask the user to select a track
read -p "Enter the track number to extract: " selected_track
# Find the selected track's start address and size
for track in "${tracks[@]}"; do
track_number=$(echo "$track" | awk '{print $1}')
if [[ $track_number -eq $selected_track ]]; then
start_addr=$(echo "$track" | awk '{print $2}')
track_size=$(echo "$track" | awk '{print $3}')
break
fi
done
# Generate the output filename using the current date and time plus track number
output_file="$HOME/Videos/${current_date_time}_track${selected_track}.vob"
# Final command to save track to file
dd bs=2048 skip="$start_addr" count="$track_size" if="$device" of="$output_file" status=progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment