コード例 #1
0
ファイル: mp3_importer.go プロジェクト: arv/noms-old
func addMp3(ds *dataset.Dataset, filename string) {
	id3, err := id3go.Open(filename)
	if err != nil {
		log.Fatalf("Failed to read id3 data from %s: %s\n", filename, err)
	}
	defer id3.Close()

	mp3_file, err := os.Open(filename)
	if err != nil {
		log.Fatalf("Failed to open %s: %s\n", filename, err)
	}
	defer mp3_file.Close()

	new_song := SongDef{
		Title:  id3.Title(),
		Artist: id3.Artist(),
		Album:  id3.Album(),
		Year:   id3.Year(),
		Mp3:    types.NewBlob(bufio.NewReader(mp3_file)),
	}.New()
	songs := readSongsFromDataset(ds).Append(new_song)
	if _, err := ds.Commit(songs); err == nil {
		fmt.Println("Successfully committed", filename)
		printSong(new_song)
	} else {
		log.Fatalf("Failed to commit: %s, error: %s\n", filename, err)
	}
}
コード例 #2
0
ファイル: musicdownloader.go プロジェクト: xakep666/govkmedia
//reimplement download to insert info into id3 tags
func (dm *DownloadableMusic) Do() (resp curl.Response, err error) {
	resp, err = dm.DownloadableFile.Do()
	if err != nil {
		return
	}
	mp3file, err := id3.Open(dm.ActualPath())
	defer mp3file.Close()
	//add id3 info
	mp3file.SetTitle(dm.Title)
	mp3file.SetArtist(dm.Artist)
	if dm.Album != "" {
		mp3file.SetAlbum(dm.Album)
	}
	if dm.Genre != "" {
		mp3file.SetGenre(dm.Genre)
	}
	//download and insert lyrics
	if dm.LyricsId != 0 {
		rac := requestwrapper.RequestAccesser{Token: dm.AccessToken}
		parms := map[string]string{"lyrics_id": strconv.FormatFloat(dm.LyricsId, 'f', -1, 64)}
		vkresp, err := rac.MakeRequest("audio.getLyrics", parms)
		if err != nil {
			return resp, err
		}
		lyrics := vkresp["response"].(map[string]interface{})["text"].(string)
		frt := v2.V23FrameTypeMap["USLT"]
		lyricsFrame := v2.NewTextFrame(frt, lyrics)
		mp3file.AddFrames(lyricsFrame)
	}
	return
}
コード例 #3
0
ファイル: mpeg.go プロジェクト: dankomiocevic/mulifs
// GetMp3Tags returns a FileTags struct with
// all the information obtained from the tags in the
// MP3 file.
// Includes the Artist, Album and Song and defines
// default values if the values are missing.
// If the tags are missing, the default values will
// be stored on the file.
// If the tags are obtained correctly the first
// return value will be nil.
func GetMp3Tags(path string) (error, FileTags) {
	mp3File, err := id3.Open(path)
	if err != nil {
		_, file := filepath.Split(path)
		extension := filepath.Ext(file)
		songTitle := file[0 : len(file)-len(extension)]
		return err, FileTags{songTitle, "unknown", "unknown"}
	}

	defer mp3File.Close()

	title := mp3File.Title()
	if title == "" || title == "unknown" {
		_, file := filepath.Split(path)
		extension := filepath.Ext(file)
		title = file[0 : len(file)-len(extension)]
		mp3File.SetTitle(title)
	}

	artist := mp3File.Artist()
	if artist == "" {
		artist = "unknown"
		mp3File.SetArtist(artist)
	}

	album := mp3File.Album()
	if album == "" {
		album = "unknown"
		mp3File.SetAlbum(album)
	}

	ft := FileTags{title, artist, album}
	return nil, ft
}
コード例 #4
0
ファイル: files.go プロジェクト: ChartrandEtienne/musicdb
func getSongData(path string) (*SongFileData, error) {
	mp3File, err := id3.Open(path)
	if err != nil {
		fmt.Errorf("error with filepath |", path)
		fmt.Println("error with filepath |", path)
		return nil, err
	}
	defer mp3File.Close()
	// TODO: maybe fix the library, I dunno?
	return &SongFileData{artist: stripTerminalNull(mp3File.Artist()), album: stripTerminalNull(mp3File.Album()), title: stripTerminalNull(mp3File.Title())}, nil
}
コード例 #5
0
ファイル: mpeg.go プロジェクト: dankomiocevic/mulifs
// SetMp3Tags updates the Artist, Album and Title
// tags with new values in the song MP3 file.
func SetMp3Tags(artist string, album string, title string, songPath string) error {
	mp3File, err := id3.Open(songPath)
	if err != nil {
		return err
	}
	defer mp3File.Close()

	mp3File.SetTitle(title)
	mp3File.SetArtist(artist)
	mp3File.SetAlbum(album)

	return nil
}
コード例 #6
0
func (video *OrderedPlaylistItem) ConvertToMp3(artist, album string) error {
	if _, err := os.Stat(video.M4aFname()); os.IsNotExist(err) {
		return err
	}
	cmd := exec.Command(ffmpeg, "-i", video.M4aFname(), "-acodec", "libmp3lame", "-ab", "256k", video.Mp3Fname())
	output, err := cmd.Output()

	mp3File, err := id3.Open(video.Mp3Fname())
	defer mp3File.Close()
	if err == nil {
		mp3File.SetArtist(artist)
		mp3File.SetAlbum(album)
	} else {
		fmt.Println(output)
	}

	return err
}
コード例 #7
0
func tagIt(filename string, title string, album string, artist string, genre string) {
	mp3File, err := id3.Open(filename)
	if err != nil {
		panic(err)
	}
	defer mp3File.Close()
	fmt.Println("version " + mp3File.Version())
	if mp3File.Version() == "1.0" {
		//		title = changeStr(title)
		//		mp3File.SetTitle(title)
		//		mp3File.SetAlbum(album)
		//		mp3File.SetArtist(artist)
	} else {
		setFrame(mp3File, "TIT2", title)
		setFrame(mp3File, "TALB", album)
		setFrame(mp3File, "TPE1", artist)
	}
	mp3File.SetGenre("Hip-Hop")
}
コード例 #8
0
func read_tags(filename string) {
	mp3_file, err := id3.Open(filename)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open %s: %s\n", filename, err)
		return
	} else {
		defer mp3_file.Close()
		title := mp3_file.Title()
		prefix := search_for_key_slash_pattern(title)
		if prefix != "" {
			fmt.Println("Prefix: ", prefix)
			new_title := strings.TrimPrefix(title, prefix)
			if set_flag {
				mp3_file.SetTitle(new_title)
				fmt.Println("New Title:", mp3_file.Title())
			} else {
				fmt.Println("*New Title:", new_title)
			}
		}

		title = mp3_file.Title()
		prefix1 := search_for_key_pattern(title)
		if prefix1 != "" {
			fmt.Println("Prefix: ", prefix1)
			new_title := strings.TrimPrefix(title, prefix1)
			if set_flag {
				mp3_file.SetTitle(new_title)
				fmt.Println("New Title:", mp3_file.Title())
			} else {
				fmt.Println("*New Title:", new_title)
			}
		}

		if prefix != "" || prefix1 != "" {
			fmt.Println("Path:        ", filename)
			fmt.Println("ID3 Version: ", mp3_file.Version())
			fmt.Println("Artist:      ", mp3_file.Artist())
			fmt.Println("Title:       ", mp3_file.Title())
			fmt.Println("Album:       ", mp3_file.Album())
			fmt.Println("Year:        ", mp3_file.Year())
			fmt.Println("Genre:       ", mp3_file.Genre())

			bpm_frame := mp3_file.Frame("TBPM")
			if bpm_frame != nil {
				bpm := bpm_frame.String()
				fmt.Println("BPM:         ", bpm)
			}

			key_frame := mp3_file.Frame("TKEY")
			if key_frame != nil {
				key := key_frame.String()
				fmt.Println("KEY:         ", key)
			}

			comments := mp3_file.Comments()
			for _, comment := range comments {
				if strings.HasPrefix(comment, "eng") {
					tokens := strings.Split(comment, ":")
					if len(tokens) == 2 {
						fmt.Println("Comment [eng]:", tokens[1])
					}
				}
			}

			fmt.Println()
		}
	}
}