Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
LinqPad example
Dim foo As New Foobar2000.Application07Class()
Dim artist As String = foo.Playback.FormatTitle("%artist%")
Dim title As String = foo.Playback.FormatTitle("%title%")
If Not String.IsNullOrEmpty(title) Then
Dim url As String = ""
Dim song As XDocument = XDocument.Load(String.Format("{0}/song/search?api_key={1}&artist={2}&title={3}&results=1&format=xml", _
url, Util.GetPassword("api.echonest"), System.Uri.EscapeDataString(artist), System.Uri.EscapeDataString(title)))
Dim id As XElement = song.XPathSelectElement("/response/songs/song/id")
If song.XPathSelectElement("/response/status/message").Value = "Success" AndAlso Not id Is Nothing Then
Dim pls As XDocument = XDocument.Load(String.Format( _
"{0}/playlist/static?api_key={1}&song_id={2}&results=100&type=song-radio&format=xml", _
url, Util.GetPassword("api.echonest"), id.Value))
Dim tracks = From x In pls.Descendants("song") _
Let matches = foo.MediaLibrary.GetTracks(String.Format("artist IS {0} AND title IS {1}", _
x.Element("artist_name").Value, x.Element("title").Value)) _
Where matches.Count > 0 _
Select Match = From i In Enumerable.Range(0, matches.Count) _
Let m = matches.Item(i) _
Select Author = m.FormatTitle("%artist%"), _
Track = New HyperLinq(Function() Process.Start(m.Path), _
String.Format("{0} [{1}]", m.FormatTitle("%title%"), m.FormatTitle("%album%"))), _
Duration = TimeSpan.FromSeconds(m.FormatTitle("%length_seconds%")), _
Type = m.FormatTitle("%codec%[ %codec_profile%]"), _
Bitrate = CInt(m.FormatTitle("%bitrate%"))
tracks.SelectMany(Function(x) x).Dump("Similar Tracks")
song.Dump("Error message.")
End If
Dim msg = "Track is undefined.".Dump("Error message.")
End If
Catch e As Exception
End Try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment