-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spock): added ids for each audio files
- Loading branch information
Showing
12 changed files
with
83 additions
and
32 deletions.
There are no files selected for viewing
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
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
package assets | ||
|
||
import ( | ||
"errors" | ||
"math/rand" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
const assertDir = "assets" | ||
|
||
func GetAudioPaths(filename string) ([]string, error) { | ||
func Audios() ([]string, error) { | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
basePath := path.Join(dir, assertDir, filename) | ||
dir = filepath.Dir(basePath) | ||
name := filepath.Base(basePath) | ||
|
||
ls, err := os.ReadDir(dir) | ||
files, err := os.ReadDir(path.Join(dir, assertDir)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var paths []string | ||
if len(files) <= 0 { | ||
return nil, errors.New("assert directory is empty") | ||
} | ||
|
||
for _, d := range ls { | ||
fName := d.Name() | ||
if !d.IsDir() && strings.Contains(fName, name) { | ||
paths = append(paths, filepath.Join(dir, fName)) | ||
} | ||
paths := make([]string, len(files)) | ||
for i, f := range files { | ||
paths[i] = filepath.Join(dir, assertDir, f.Name()) | ||
} | ||
|
||
return paths, nil | ||
} | ||
|
||
func RandomAudio() (string, error) { | ||
paths, err := Audios() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return paths[rand.Int()%len(paths)], nil | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
pkgs.mkShell { | ||
buildInputs = with pkgs; [ | ||
go | ||
ffmpeg | ||
rnix-lsp | ||
nixfmt | ||
nixpkgs-fmt | ||
]; | ||
{ pkgs ? import <nixpkgs> { } }: | ||
pkgs.mkShell { | ||
buildInputs = with pkgs; [ | ||
gopls | ||
ffmpeg | ||
rnix-lsp | ||
nixfmt | ||
nixpkgs-fmt | ||
]; | ||
} |