-
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.
Merge pull request #4 from DeliverBle/fix/webm-to-mp3
Fix/webm to mp3
- Loading branch information
Showing
14 changed files
with
435 additions
and
19 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package client | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"regexp" | ||
) | ||
|
||
func ChangeFileNameMp3ToWebm(inputFileName string) (*string, error) { | ||
// Check if the input file exists | ||
if _, err := os.Stat(inputFileName); os.IsNotExist(err) { | ||
return nil, fmt.Errorf("file %s does not exist", inputFileName) | ||
} | ||
|
||
// Use a regular expression to remove all instances of ".mp3" from the file name | ||
r := regexp.MustCompile("\\.mp3") | ||
outputFileName := r.ReplaceAllString(inputFileName, "") | ||
|
||
// Append the new extension to the file name | ||
outputFileNameWithWebm := outputFileName + ".webm" | ||
|
||
// Rename the input file to the output file | ||
err := os.Rename(inputFileName, outputFileNameWithWebm) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to rename file %s to %s: %v", inputFileName, outputFileNameWithWebm, err) | ||
} | ||
|
||
return &outputFileName, nil | ||
} | ||
|
||
func ConvertWebmBlobToMp3File(input string) error { | ||
cmd := exec.Command("ffmpeg", "-i", input+".webm", input+".mp3") | ||
var out bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd.Stdout = &out | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
if err != nil { | ||
fmt.Println(fmt.Sprint(err) + ": " + stderr.String()) | ||
return fmt.Errorf("ffmpeg command failed") | ||
} | ||
fmt.Println("Result: " + out.String()) | ||
|
||
return nil | ||
} |
Oops, something went wrong.