added id3 tagging process

This commit is contained in:
Paul Wilde 2021-05-26 11:57:55 +01:00
parent b68c5cc1b8
commit 4d82530fd7
2 changed files with 21 additions and 16 deletions

View file

@ -11,6 +11,8 @@ import (
"os" "os"
"log" "log"
"strings" "strings"
id3 "github.com/mikkyang/id3-go"
v2 "github.com/mikkyang/id3-go/v2"
) )
var Version string = "0.1" var Version string = "0.1"
var Settings Settings var Settings Settings
@ -137,6 +139,7 @@ func downloadCasts(podcast Podcast) {
ok := downloadMp3(item.Media.URL, dir + "/" + filename) ok := downloadMp3(item.Media.URL, dir + "/" + filename)
if ok { if ok {
// createNFO(item, strings.Replace(dir + "/" + filename,".mp3",".nfo",1)) // createNFO(item, strings.Replace(dir + "/" + filename,".mp3",".nfo",1))
addId3(podcast.Name, item,dir + "/" + filename)
markAsReceived(item) markAsReceived(item)
} else { } else {
markAsErrored(item) markAsErrored(item)
@ -184,19 +187,27 @@ func downloadMp3(url string, file string) bool {
ok = true ok = true
return ok return ok
} }
func createNFO(item Item, file string) { func addId3(artist string, item Item, file string) {
fmt.Printf("Saving NFO file %s",file) fmt.Printf("Saving ID3 to %s\r\n",file)
var nfo NFO fmt.Printf("%v\r\n",item)
nfo.Title = item.Title mp3File, err := id3.Open(file)
nfo.Outline = item.Description
nfo.Aired = item.PubDate
data, err := xml.Marshal(nfo)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = ioutil.WriteFile(file, data, 0775) defer mp3File.Close()
if err != nil { if mp3File.Artist() == "" {
log.Fatal(err) mp3File.SetArtist(artist)
}
if mp3File.Album() == "" {
mp3File.SetAlbum(artist)
}
if mp3File.Title() == "" {
mp3File.SetTitle(item.Title)
}
if len(mp3File.Comments()) == 0 {
ft := v2.V23FrameTypeMap["COMM"]
textFrame := v2.NewTextFrame(ft, item.Description)
mp3File.AddFrames(textFrame)
} }
} }
func markAsReceived(item Item) { func markAsReceived(item Item) {

View file

@ -12,12 +12,6 @@ type Podcast struct {
Directory string Directory string
RSS Rss RSS Rss
} }
type NFO struct {
XMLName xml.Name `xml:"podcast"`
Title string `xml:"title"`
Outline string `xml:"outline"`
Aired string `xml:"aired"`
}
type Rss struct { type Rss struct {
XMLName xml.Name `xml:"rss"` XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"` Version string `xml:"version,attr"`