Last active
April 4, 2024 15:35
-
-
Save danielm/6c012e3b9a74636b4a2be0a56b19cf57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script rename to a more userfriendy file name, so we can easly view/sort it etc. | |
# Specially in multi-part files, Given the Nameing convention: | |
# https://community.gopro.com/s/article/GoPro-Camera-File-Naming-Convention?language=en_US | |
# | |
# Eample: | |
# - GH010051.MP4 ==> GH0051-01.mp4 | |
# - GH020051.MP4 ==> GH0051-02.mp4 | |
# | |
# Testing: add the --dry-run parameter so visualize what would the comand do | |
# | |
# Folders: For now files are kept in the same folder where we are running the script | |
# | |
# Set the directory containing the GoPro files | |
input_dir=$(pwd) | |
# Check if the input directory exists | |
if [ ! -d "$input_dir" ]; then | |
echo "Input directory does not exist!" | |
exit 1 | |
fi | |
dry_run=false | |
# Check for command line arguments | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
--dry-run) | |
dry_run=true | |
shift | |
;; | |
*) | |
echo "Unknown option: $key" | |
exit 1 | |
;; | |
esac | |
done | |
# Iterate through each file in the input directory | |
for file in "$input_dir"/*; do | |
# Check if the file is an MP4 file | |
if [[ -f "$file" && "$file" == *.MP4 ]]; then | |
# Extracting chapter number and file number | |
chapter_number=$(basename "$file" | cut -c 3-4) | |
file_number=$(basename "$file" | cut -c 5-8) | |
# Extracting encoding type | |
encoding_type=$(basename "$file" | cut -c 2) | |
# Constructing the new filename | |
new_filename="$input_dir/GH$file_number-$chapter_number.mp4" | |
# Move the file | |
if [ "$dry_run" = true ]; then | |
echo "Dry run: Would convert $file to $new_filename" | |
else | |
mv "$file" "$new_filename" | |
echo "Converted $file to $new_filename" | |
fi | |
fi | |
## TODO: Clear LRV and THM | |
done | |
echo "Conversion complete!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment