Skip to content

Instantly share code, notes, and snippets.

@fholzer
Created September 14, 2024 17:58
Show Gist options
  • Save fholzer/f09856c18f6db26d3ab95d1144672c36 to your computer and use it in GitHub Desktop.
Save fholzer/f09856c18f6db26d3ab95d1144672c36 to your computer and use it in GitHub Desktop.
GoPro Media Sorter

Sorts GoPro media files into subdirectories. By default GoPro splits recording into multiple files due to FAT's file size limit of 4GB. This script creates one subdirectory per recording, and moves all files of a recording into the respective recording's subdirectory.

Run the script in a directory that contains your GoPro media files.

#!/bin/bash
set -eo pipefail
function findSeries() {
ls -1 GX01*.MP4 | sed -e 's/^\(GX\)01\([0-9]\+\).\(MP4\)$/\1 \2 \3/'
}
function processSeries() {
local prefix="$1"
local id="$2"
local suffix="$3"
mkdir -p $id
let x=1
printf -v xfmt %02d $x
local fn="${prefix}${xfmt}${id}.${suffix}"
while : ; do
mv $fn $id/
local lrv="GL${xfmt}${id}.LRV"
if [[ -e "$lrv" ]]; then
mv $lrv $id/
fi
local thm="${prefix}${xfmt}${id}.THM"
if [[ -e "$thm" ]]; then
mv $thm $id/
fi
let x++
printf -v xfmt %02d $x
local fn="${prefix}${xfmt}${id}.${suffix}"
[[ -e "$fn" ]] || break
done
}
findSeries | while read prefix id suffix; do
processSeries $prefix $id $suffix
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment