Skip to content

Instantly share code, notes, and snippets.

@yaegaki
Created February 14, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaegaki/8bcc154327a378116e3a to your computer and use it in GitHub Desktop.
Save yaegaki/8bcc154327a378116e3a to your computer and use it in GitHub Desktop.
golangでiTunes内の曲情報を取得する(Windows)
package main
import (
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
"log"
"fmt"
)
func main() {
ole.CoInitialize(0)
obj, err := oleutil.CreateObject("iTunes.Application")
if err != nil {
log.Fatal(err)
}
itunes := obj.MustQueryInterface(ole.IID_IDispatch)
playlist := oleutil.MustGetProperty(itunes, "LibraryPlaylist").ToIDispatch()
tracks := oleutil.MustGetProperty(playlist, "Tracks").ToIDispatch()
count := int(oleutil.MustGetProperty(tracks, "Count").Val)
fmt.Printf("count: %v\n\n", count)
for i := 1; i <= count; i++ {
item := oleutil.MustGetProperty(tracks, "Item", i).ToIDispatch()
name := oleutil.MustGetProperty(item, "Name").ToString()
artist := oleutil.MustGetProperty(item, "Artist").ToString()
fmt.Printf("Index:%v Name:%v\n Artist:%v\n", i, name, artist)
}
ole.CoUninitialize()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment