Skip to content

Instantly share code, notes, and snippets.

@oct2pus
Created February 7, 2021 08:23
Show Gist options
  • Save oct2pus/ebd145b3ad2f2816cbba243411668bd9 to your computer and use it in GitHub Desktop.
Save oct2pus/ebd145b3ad2f2816cbba243411668bd9 to your computer and use it in GitHub Desktop.
Simple script I wrote to convert my .flac files into .opus files for mobile
#!/bin/env fish
# Requires opus-tools, golf (included in gist)
set SOURCE_DIR $argv[1]
set OUTPUT_DIR $argv[2]
set SOURCE_TREE (tree $SOURCE_DIR -d -i -L 1)
# incase I want to make any changes to the encoding.
function _encode
opusenc $argv[1] $argv[2]
end
# Create source tree structure
for folder in $SOURCE_TREE
mkdir -p $OUTPUT_DIR/$folder
set list (golf $SOURCE_DIR/$folder)
for i in $list
if test (string match -r "\.flac" $i)
set o (string replace ".flac" ".opus" $i)
if test ! -e $OUTPUT_DIR/$folder/$o
_encode $SOURCE_DIR/$folder/$i $OUTPUT_DIR/$folder/$o
end
else
if test ! -e $OUTPUT_DIR/$folder/$i
cp $SOURCE_DIR/$folder/$i $OUTPUT_DIR/$folder/$i
end
end
end
end
module github.com/oct2pus/golf
go 1.15
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
files, err := ioutil.ReadDir(os.Args[1])
if err != nil {
log.Println(err)
}
for _, file := range files {
if !file.IsDir() {
fmt.Println(file.Name())
}
}
}
@oct2pus
Copy link
Author

oct2pus commented May 16, 2021

bugs:
script doesn't handle directories nested any deeper than $???_DIR/$folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment