/
dumparttofile.go
85 lines (81 loc) · 2.3 KB
/
dumparttofile.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
package ampgosetup
import (
// "context"
// "crypto/rand"
// "encoding/hex"
// "encoding/json"
"fmt"
"github.com/bogem/id3v2"
// "github.com/disintegration/imaging"
// "go.mongodb.org/mongo-driver/bson"
// "go.mongodb.org/mongo-driver/mongo"
// "go.mongodb.org/mongo-driver/mongo/options"
// "io/ioutil"
// "log"
"os"
"path/filepath"
// "strconv"
"strings"
// "time"
)
func folderjpg_check(apath string) Fjpg {
fjpg := "folder.jpg"
dir, _ := filepath.Split(apath)
testfile := dir + fjpg
_, error := os.Stat(testfile)
if os.IsNotExist(error) {
var pic Fjpg
pic.exists = false
pic.path = testfile
return pic
} else {
var pic Fjpg
pic.exists = true
pic.path = testfile
return pic
}
}
func DumpArtToFile(apath string) (string, string, string, string, string) {
folderjpgcheck := folderjpg_check(apath)
tag, err := id3v2.Open(apath, id3v2.Options{Parse: true})
if err != nil {
fmt.Println(err)
fmt.Println(apath)
return "None", "None", "None", "None", "None"
}
defer tag.Close()
if folderjpgcheck.exists {
artist := tag.Artist()
album := tag.Album()
title := tag.Title()
genre := tag.Genre()
albumart := folderjpgcheck.path
return artist, album, title, genre, albumart
} else {
artist := tag.Artist()
album := tag.Album()
title := tag.Title()
genre := tag.Genre()
pictures := tag.GetFrames(tag.CommonID("Attached picture"))
newdumpOutFile2 := ""
newdumpOutFileThumb := ""
for _, f := range pictures {
pic, ok := f.(id3v2.PictureFrame)
if !ok {
fmt.Println("DumpArtToFile: Couldn't assert picture frame")
}
dumpOutFile2 := os.Getenv("AMPGO_THUMB_PATH") + tag.Artist() + "_-_" + tag.Album() + ".jpg"
newdumpOutFile2 = strings.Replace(dumpOutFile2, " ", "_", -1)
dumpOutFileThumb := os.Getenv("AMPGO_THUMB_PATH") + tag.Artist() + "_-_" + tag.Album() + "_thumb.jpg"
newdumpOutFileThumb = strings.Replace(dumpOutFileThumb, " ", "_", -1)
g, err := os.Create(newdumpOutFile2)
CheckError(err, "DumpArtToFile: Unable to create newdumpOutFile2")
defer g.Close()
n3, err := g.Write(pic.Picture)
CheckError(err, "DumpArtToFile: newdumpOutfile2 Write has fucked up")
fmt.Println(n3, "DumpArtToFile: bytes written successfully")
}
outfile22 := resizeImage(newdumpOutFile2, newdumpOutFileThumb)
return artist, album, title, genre, outfile22
}
}