Created
February 7, 2021 08:23
-
-
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
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/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 |
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
module github.com/oct2pus/golf | |
go 1.15 |
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
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()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bugs:
script doesn't handle directories nested any deeper than $???_DIR/$folder