Пример #1
0
func tag(t track.Track, trackPath string) error {
	tag, err := id3v2.Open(trackPath)
	if err != nil {
		return err
	}
	defer tag.Close()

	// If there are already frames in tag, do nothing
	if tag.Count() > 0 {
		return nil
	}

	tag.SetArtist(t.Artist())
	tag.SetTitle(t.Title())
	return tag.Save()
}
Пример #2
0
func tag(t track.Track, trackPath string, artwork []byte) error {
	tag, err := id3v2.Open(trackPath)
	if err != nil {
		return err
	}
	defer tag.Close()

	tag.SetArtist(t.Artist())
	tag.SetTitle(t.Title())
	tag.SetYear(t.Year())

	if artwork != nil {
		pic := id3v2.PictureFrame{
			Encoding:    id3v2.ENUTF8,
			MimeType:    "image/jpeg",
			PictureType: id3v2.PTFrontCover,
			Picture:     artwork,
		}
		tag.AddAttachedPicture(pic)
	}

	return tag.Save()
}
Пример #3
0
func tagMp3File(mp3FilePath string, bc broadcast) error {
	m := regexp.MustCompile(`([^/]+)/(\d{4})/\d{2}/\d{2}/\d{4}(?:\s.*)?\.mp3$`).FindStringSubmatch(mp3FilePath)
	station := m[1]
	if "" == station {
		return tagError{reason: "Couldn't find station in mp3 file name '" + mp3FilePath + "'"}
	}

	tag, err := id3v2.Open(mp3FilePath)
	if nil != err {
		return err
	}
	defer tag.Close()

	tag.SetTitle(bc.title)
	tag.SetArtist("Station " + station)
	if "" != bc.title_series {
		tag.SetAlbum(bc.title_series)
	}
	tag.SetGenre("Radio")
	tag.SetYear(strconv.Itoa(bc.format_timestart.Year()))

	txt := bc.identifier + "\n"
	txt += bc.source.String() + "\n\n"
	if "" != bc.title_series {
		txt += bc.title_series + "\n\n"
	}
	if "" != bc.title_episode {
		txt += bc.title_episode + "\n\n"
	}
	txt += bc.description

	tag.AddCommentFrame(id3v2.CommentFrame{
		Encoding: id3v2.ENUTF8,
		Language: bc.language, // validate language?
		Text:     txt,
	})

	tag.AddUnsynchronisedLyricsFrame(id3v2.UnsynchronisedLyricsFrame{
		Encoding:          id3v2.ENUTF8,
		Language:          bc.language, // validate language?
		ContentDescriptor: "Content descriptor",
		Lyrics:            txt,
	})

	if "" != bc.image.String() {
		resp, err := http.Get(bc.image.String())
		if err != nil {
			return err
		}
		defer resp.Body.Close()
		b, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return err
		}
		tag.AddAttachedPicture(id3v2.PictureFrame{
			Encoding: id3v2.ENUTF8,
			MimeType: "image/jpeg",
			// Description: "Front cover",
			Picture:     b,
			PictureType: id3v2.PTFrontCover,
		})
	}
	return tag.Save()
}