refactor: use std lib trimsuffix

This commit is contained in:
Jan Bader 2025-01-28 15:08:08 +01:00
parent 224a6bc9af
commit 8e86f9eb9a
3 changed files with 4 additions and 16 deletions

View File

@ -76,8 +76,8 @@ func removeSuffix(suffix string) filepath.WalkFunc {
dir := filepath.Dir(p)
ext := filepath.Ext(filename)
filenameNoExt := trimSuffix(filename, ext)
filenameNoSuff := trimSuffix(filenameNoExt, suffix)
filenameNoExt := strings.TrimSuffix(filename, ext)
filenameNoSuff := strings.TrimSuffix(filenameNoExt, suffix)
if filenameNoSuff != filenameNoExt {
newFilename := filenameNoSuff + ext
@ -132,7 +132,7 @@ func unpack(p string, f os.FileInfo, err error) error {
}
cmd := exec.Command(execCmd, p)
filename = trimSuffix(filename, ext)
filename = strings.TrimSuffix(filename, ext)
ext = filepath.Ext(filename)
if ext == "" {
fmt.Println(p)

View File

@ -21,7 +21,7 @@ func newMediaElement(p string) *mediaElement {
dir := filepath.Dir(p)
name := filepath.Base(p)
ext := filepath.Ext(name)
name = trimSuffix(name, ext)
name = strings.TrimSuffix(name, ext)
name = strings.ReplaceAll(name, ".", " ")
dash := strings.Index(name, "-")

12
util.go
View File

@ -1,12 +0,0 @@
package main
import (
"strings"
)
func trimSuffix(s, suffix string) string {
if strings.HasSuffix(s, suffix) {
s = s[:len(s)-len(suffix)]
}
return s
}