Beispiel #1
0
func main() {
	doHelp := false
	flag.BoolVar(&doHelp, "help", false, "Display usage info.")
	flag.Parse()

	if doHelp || flag.NArg() != 1 {
		fmt.Println("Usage: info <file>")
		return
	}

	str := flag.Arg(1)
	v, err := vlc.New()
	if err != nil {
		fmt.Println("vlc.New():", err)
		return
	}
	m, err := v.MediaNewPath(str)
	if err != nil {
		fmt.Println("vlc.MediaNewPath:", err)
		return
	}
	m.Parse()
	err = vlc.LastError()
	if err != nil {
		fmt.Println("media.Parse():", err)
		return
	}

	player, err := v.NewPlayer()
	if err != nil {
		fmt.Println("vlc.NewPlayer():", err)
		return
	}

	player.SetMedia(m)

	err = player.Play()
	if err != nil {
		fmt.Println("player.Play():", err)
		return
	}

	for k, t := range vlc.MetaTags {
		v := m.GetMeta(t)
		err = vlc.LastError()
		if err != nil {
			fmt.Println("media.GetMeta():", err)
			return
		}
		fmt.Println(k, ":", v)
	}

	time.Sleep(time.Second * 20)
	fmt.Println("end.")
}
Beispiel #2
0
func (up *updater) analyze(path string, parent string, file string) error {
	//log.Log.Println("doing", path)

	tag, err := up.vlc.MediaNewPath(path)
	if err != nil {
		log.Log.Println("error reading file", path, "-", err)
		up.numInvalidFiles++
		return nil
	}
	defer tag.Release()
	tag.Parse()
	err = vlc.LastError()
	if err != nil {
		return err
	}

	title := tag.GetMeta(vlc.MetaTitle)
	artist := tag.GetMeta(vlc.MetaArtist)

	title, artist = TitleMagic(file, title, artist)

	item := Item{
		Title:       title,
		Artist:      artist,
		AlbumArtist: NullStr(nil),
		Album:       SqlStr(tag.GetMeta(vlc.MetaAlbum)),
		Genre:       SqlStr(tag.GetMeta(vlc.MetaGenre)),
		TrackNumber: SqlStr(tag.GetMeta(vlc.MetaTrackNumber)),
		Folder:      Folder{Path: parent},
		Filename:    SqlStr(file),
	}
	//TODO get albumartst, length, check ID etc
	err = vlc.LastError()
	if err != nil {
		return err
	}

	tx := <-up.tx
	err = tx.FirstOrCreate(&item.Folder, item.Folder).Error
	if err != nil {
		log.Log.Println("error inserting folder", item.Folder, err)
		return err
	}
	err = tx.Save(&item).Error
	up.tx <- tx
	if err != nil {
		log.Log.Println("error inserting item", item, err)
	} else {
		up.numImportedFiles++
		//log.Log.Println("inserted", item)
	}
	return err
}