-
Notifications
You must be signed in to change notification settings - Fork 15
/
utils_test.go
158 lines (119 loc) · 3.44 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"fmt"
"os"
"testing"
"time"
"github.com/issadarkthing/gomu/lyric"
"github.com/stretchr/testify/assert"
"github.com/tramhao/id3v2"
)
func TestFmtDuration(t *testing.T) {
samples := map[time.Duration]string{
time.Second * 5: "00:05",
time.Hour * 2: "02:00:00",
time.Minute*4 + time.Second*15: "04:15",
time.Minute * 0: "00:00",
time.Millisecond * 5: "00:00",
}
for k, v := range samples {
got := fmtDuration(k)
if got != v {
t.Errorf("fmtDuration(%s); Expected %s got %s", k, v, got)
}
}
}
func TestGetName(t *testing.T) {
samples := map[string]string{
"hello.mp3": "hello",
"~/music/fl.mp3": "fl",
"/home/terra/Music/pop/hola na.mp3": "hola na",
"~/macklemary - (ft jello) extreme!! .mp3": "macklemary - (ft jello) extreme!! ",
}
for k, v := range samples {
got := getName(k)
if got != v {
t.Errorf("GetName(%s); Expected %s got %s", k, v, got)
}
}
}
func TestDownloadedFilePath(t *testing.T) {
sample := `[youtube] jJPMnTXl63E: Downloading webpage
[download] Destination: /tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.webm
[download] 100%% of 2.54MiB in 00:0213MiB/s ETA 00:002
[ffmpeg] Destination: /tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.mp3
Deleting original file /tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.webm (pass -k to keep)`
result := "/tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.mp3"
got := extractFilePath([]byte(sample), "/tmp")
if got != result {
t.Errorf("downloadedFilePath(%s); expected %s got %s", sample, result, got)
}
}
func TestEscapeBackSlash(t *testing.T) {
sample := map[string]string{
"/home/terra": "\\/home\\/terra",
"~/Documents/memes": "~\\/Documents\\/memes",
}
for k, v := range sample {
got := escapeBackSlash(k)
if got != v {
t.Errorf("escapeBackSlash(%s); expected %s, got %s", k, v, got)
}
}
}
func TestExpandTilde(t *testing.T) {
homeDir, err := os.UserHomeDir()
if err != nil {
t.Errorf("Unable to get home dir: %e", err)
}
sample := map[string]string{
"~/music": homeDir + "/music",
homeDir + "/Music": homeDir + "/Music",
}
for k, v := range sample {
got := expandTilde(k)
if got != v {
t.Errorf("expected %s; got %s", v, got)
}
}
}
func TestEmbedLyric(t *testing.T) {
testFile := "./test/sample"
lyricString := "[offset:1000]\n[00:12.000]Lyrics beginning ...\n[00:15.300]Some more lyrics ...\n"
descriptor := "en"
f, err := os.Create(testFile)
if err != nil {
t.Error(err)
}
f.Close()
defer func() {
err := os.Remove(testFile)
if err != nil {
t.Error(err)
}
}()
var lyric lyric.Lyric
err = lyric.NewFromLRC(lyricString)
if err != nil {
t.Error(err)
}
fmt.Println(lyric)
lyric.LangExt = descriptor
err = embedLyric(testFile, &lyric, false)
if err != nil {
t.Error(err)
}
tag, err := id3v2.Open(testFile, id3v2.Options{Parse: true})
if err != nil {
t.Error(err)
} else if tag == nil {
t.Error("unable to read tag")
}
usltFrames := tag.GetFrames(tag.CommonID("Unsynchronised lyrics/text transcription"))
frame, ok := usltFrames[0].(id3v2.UnsynchronisedLyricsFrame)
if !ok {
t.Error("invalid type")
}
assert.Equal(t, lyricString, frame.Lyrics)
assert.Equal(t, descriptor, frame.ContentDescriptor)
}