Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dsebastien/49166bb36157f9100e19e2a020c70cb2 to your computer and use it in GitHub Desktop.
Save dsebastien/49166bb36157f9100e19e2a020c70cb2 to your computer and use it in GitHub Desktop.
# Convert Adobe Premiere Pro chapter markers (CSV) to YouTube timestamps
c2yt() {
# Check if input file is provided
if [ -z "$1" ]; then
echo "Error: Please provide the path to the CSV file"
echo "Usage: process_premiere_markers <path-to-csv>"
return 1
fi
# Check if input file exists
if [ ! -f "$1" ]; then
echo "Error: File not found: $1"
return 1
fi
# Define input and output paths
input_file="$1"
filename=$(basename "$input_file")
filename_no_ext="${filename%.*}"
dir_path=$(dirname "$input_file")
output_file="${dir_path}/${filename_no_ext} - YouTube.txt"
# Process the file using awk
# This handles:
# 1. Skipping the header line
# 2. Extracting the marker name (column 1)
# 3. Extracting just the hh:mm:ss part of the timestamp
# 4. Combining with a single space
# First handle the encoding - Adobe Premiere often exports as UTF-16LE
if command -v iconv >/dev/null 2>&1; then
# Try to convert from UTF-16LE to UTF-8
iconv -f UTF-16LE -t UTF-8 "$input_file" > /tmp/premiere_markers_temp.csv 2>/dev/null
# If conversion failed, try processing the original file
if [ $? -ne 0 ]; then
temp_file="$input_file"
else
temp_file="/tmp/premiere_markers_temp.csv"
fi
else
# If iconv is not available, try with the original file
temp_file="$input_file"
fi
# Use awk to process the file
awk -F'\t' 'NR>1 {
# Extract the marker name
marker_name = $1
# Extract the timestamp from column 3 (IN column)
in_time = $3
# Extract just the hh:mm:ss part using regex
if (match(in_time, /[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/)) {
timestamp = substr(in_time, RSTART, RLENGTH)
} else {
timestamp = in_time
}
# Print the marker name and timestamp with a single space
if (marker_name != "" && timestamp != "") {
print marker_name " " timestamp
}
}' "$temp_file" > "$output_file"
# Clean up temp file if created
if [ "$temp_file" = "/tmp/premiere_markers_temp.csv" ]; then
rm "$temp_file"
fi
# Report success
echo "Processing complete!"
echo "Original file: $input_file"
echo "Generated text file: $output_file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment