commit 1041495f6a371fad2aaee33abb962a5a3c4c0d13 Author: oct2pus Date: Sun Apr 7 01:04:55 2024 -0500 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..01bd03b --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2024 Octopus "Oct2pus" Octopus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/convert.fish b/convert.fish new file mode 100644 index 0000000..fa6bfa7 --- /dev/null +++ b/convert.fish @@ -0,0 +1,29 @@ +#!/bin/env fish + +# Requires opus-tools, golf (included in gist) +set SOURCE_DIR $argv[1] +set OUTPUT_DIR $argv[2] +set SOURCE_TREE (gold $SOURCE_DIR) + +# 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 diff --git a/gold/go.mod b/gold/go.mod new file mode 100644 index 0000000..262aac5 --- /dev/null +++ b/gold/go.mod @@ -0,0 +1,3 @@ +module git.jade.moe/oct2pus/flac2opus/gold + +go 1.19 diff --git a/gold/main.go b/gold/main.go new file mode 100644 index 0000000..756c00a --- /dev/null +++ b/gold/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "io/fs" + "log" + "os" + "strings" +) + +func main() { + var files []fs.DirEntry + var err error + if len(os.Args) > 1 { + files, err = os.ReadDir(os.Args[1]) + } else { + files, err = os.ReadDir(".") + } + if err != nil { + log.Fatalln(err) + } + for _, file := range files { + if file.IsDir() && !strings.HasPrefix(file.Name(), ".") { + fmt.Println(file.Name()) + } + } +} diff --git a/golf/go.mod b/golf/go.mod new file mode 100644 index 0000000..606c1b8 --- /dev/null +++ b/golf/go.mod @@ -0,0 +1,3 @@ +module git.jade.moe/oct2pus/flac2opus/golf + +go 1.19 diff --git a/golf/main.go b/golf/main.go new file mode 100644 index 0000000..8d53b08 --- /dev/null +++ b/golf/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "io/fs" + "log" + "os" + "strings" +) + +func main() { + var files []fs.DirEntry + var err error + if len(os.Args) > 1 { + files, err = os.ReadDir(os.Args[1]) + } else { + files, err = os.ReadDir(".") + } + if err != nil { + log.Fatalln(err) + } + for _, file := range files { + if !file.IsDir() && !strings.HasPrefix(file.Name(), ".") { + fmt.Println(file.Name()) + } + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..bcfa0b0 --- /dev/null +++ b/readme.md @@ -0,0 +1,17 @@ +# Flac2Opus + +script to batch convert .flac files to .opus files + +## Usage + +`./convert.fish sourcedir destdir` + +## Requirements + +You need golang & opus-tools (for opusenc). you can likely substitute it with ffmpeg if you would like to modify the script, though. + +golf (*GO* *L*ist *F*iles) and gold (*GO* *L*ist *D*irectories) are expected to be in your $PATH. + +## LICENSE + +MIT \ No newline at end of file