func SongFromFile(file *taglib.File) (*Song, error) {
	title := file.Title()
	artist := file.Artist()
	if title == "" || artist == "" {
		return nil, ErrSongTags
	}
	bitrate := file.Bitrate()
	channels := file.Channels()
	length := int(file.Length().Seconds())
	sampleRate := file.Samplerate()
	if bitrate == 0 || channels == 0 || length == 0 || sampleRate == 0 {
		return nil, ErrSongProperties
	}
	return &Song{
		Album:      file.Album(),
		Artist:     artist,
		Bitrate:    bitrate,
		Channels:   channels,
		Comment:    file.Comment(),
		Genre:      file.Genre(),
		Length:     length,
		SampleRate: sampleRate,
		Title:      title,
		Track:      file.Track(),
		Year:       file.Year(),
	}, nil
}
SongFromFile creates a new Song from a TagLib file, extracting its tags and properties
into the fields of the struct.
package data
import (
	"errors"
	"io"
	"os"
	"github.com/wtolson/go-taglib"
)
const (
	APE = iota
	FLAC
	M4A
	MP3
	MPC
	OGG
	WMA
	WV
)
var (
	ErrSongTags = errors.New("song: required tags could not be extracted from TagLib file")
	ErrSongProperties = errors.New("song: required properties could not be extracted from TagLib file")
)
var FileTypeMap = map[string]int{
	".ape":  APE,
	".flac": FLAC,
	".m4a":  M4A,
	".mp3":  MP3,
	".mpc":  MPC,
	".ogg":  OGG,
	".wma":  WMA,
	".wv":   WV,
}
var CodecMap = map[int]string{
	APE:  "APE",
	FLAC: "FLAC",
	M4A:  "M4A",
	MP3:  "MP3",
	MPC:  "MPC",
	OGG:  "OGG",
	WMA:  "WMA",
	WV:   "WV",
}
var MIMEMap = map[int]string{
	APE:  "audio/ape",
	FLAC: "audio/flac",
	M4A:  "audio/aac",
	MP3:  "audio/mpeg",
	MPC:  "audio/mpc",
	OGG:  "audio/ogg",
	WMA:  "audio/wma",
	WV:   "audio/wv",
}
type Song struct {
	ID           int    `json:"id"`
	Album        string `json:"album"`
	AlbumID      int    `db:"album_id" json:"albumId"`
	ArtID        int    `db:"art_id" json:"artId"`
	Artist       string `json:"artist"`
	ArtistID     int    `db:"artist_id" json:"artistId"`
	Bitrate      int    `json:"bitrate"`
	Channels     int    `json:"channels"`
	Comment      string `json:"comment"`
	FileName     string `db:"file_name" json:"fileName"`
	FileSize     int64  `db:"file_size" json:"fileSize"`
	FileTypeID   int    `db:"file_type_id" json:"fileTypeId"`
	FolderID     int    `db:"folder_id" json:"folderId"`
	Genre        string `json:"genre"`
	LastModified int64  `db:"last_modified" json:"lastModified"`
	Length       int    `json:"length"`
	SampleRate   int    `db:"sample_rate" json:"sampleRate"`
	Title        string `json:"title"`
	Track        int    `json:"track"`
	Year         int    `json:"year"`
}