Skip to content

Instantly share code, notes, and snippets.

@cd01
Created October 27, 2013 06:32
Show Gist options
  • Save cd01/7178548 to your computer and use it in GitHub Desktop.
Save cd01/7178548 to your computer and use it in GitHub Desktop.
iTunes の Podcast の音声が聞きづらいことが結構あるのでイコライザを "Spoken Word" に設定したり、デッドリンクを削除したりする
package main
import (
"github.com/mattn/go-ole"
"github.com/mattn/go-ole/oleutil"
"fmt"
"strconv"
)
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("iTunes.Application")
itunes, _ := unknown.QueryInterface(ole.IID_IDispatch)
library := oleutil.MustGetProperty(itunes, "LibraryPlaylist").ToIDispatch()
tracks := oleutil.MustGetProperty(library, "Tracks").ToIDispatch()
cnt := int(oleutil.MustGetProperty(tracks, "Count").Val)
for i := 1; i <= cnt; i++ {
if oleutil.MustGetProperty(tracks, "item", i).Val != 0 {
track := oleutil.MustGetProperty(tracks, "item", i).ToIDispatch()
name := getTrackProperty(track, "name")
fmt.Println(strconv.FormatUint(uint64(i), 10) + ":" + name)
// Delete dead link
location := getTrackProperty(track, "location")
if location == "" {
oleutil.CallMethod(track, "delete")
fmt.Println("Delete dead link ("+ location + ")")
continue
}
// Set equalizer
genre := getTrackProperty(track, "genre")
eq := getTrackProperty(track, "eq")
if genre == "Podcast" && eq != "Spoken Word" {
oleutil.PutProperty(track, "eq", "Spoken Word")
}
}
}
}
func getTrackProperty(track *ole.IDispatch, property string) string {
oleVariant := oleutil.MustGetProperty(track, property)
ret := ""
if oleVariant.Val != 0 {
ret = oleVariant.ToString()
}
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment