Last active
August 29, 2015 13:58
-
-
Save rornor/10009197 to your computer and use it in GitHub Desktop.
LinqPad example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Try | |
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 = "http://developer.echonest.com/api/v4" | |
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") | |
Else | |
song.Dump("Error message.") | |
End If | |
Else | |
Dim msg = "Track is undefined.".Dump("Error message.") | |
End If | |
Catch e As Exception | |
e.Message.Dump("Exception") | |
End Try |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment