troubleshooting Question

How to get Album art on amazon.com

Avatar of BlackWolfNo1
BlackWolfNo1 asked on
Visual Basic.NETWeb ServicesAWS
5 Comments1 Solution1888 ViewsLast Modified:
I have a program where i used to get the album art for my mp3´s but now it only gives me "(400) bad request" from the remote server.
I cant find how to make it work again.
Please help.

Public Function Amazon(ByVal Artist As String, ByRef Album As String, ByVal Year As String, ByRef ListV As ListView, ByRef ImageL As ImageList)
        'clear the images
        ImageL.Images.Clear()
        ListV.Items.Clear()
        Dim Code = "XXXXXXXXXXXXXXXXX"
        Dim n As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xDoc.NameTable)
        n.AddNamespace("a", "http://webservices.amazon.com/AWSECommerceService/2005-10-05")
        xDoc.Load("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=" & Code & "&Operation=ItemSearch&SearchIndex=Music&ItemPage=1&ResponseGroup=ItemAttributes,Images&Keywords=" + Replace((Artist + " " + Album), " ", "%20"))
        Dim results = xDoc.SelectNodes("a:ItemSearchResponse/a:Items/a:Item[a:LargeImage/a:URL]", n) 'Only want results with large images
        'Dim coverart.SetCountEstimate(results.Count)
        Dim tempnumber As Integer = 0
        For Each Node As System.Xml.XmlNode In results
            Dim TitleNode = Node.SelectSingleNode("a:ItemAttributes/a:Title", n).InnerText 'Can Title ever not exist? Assume it always exists.
            Dim ArtistNode = Node.SelectSingleNode("a:ItemAttributes/a:Artist", n)
            Dim ArtistTemp = Nothing
            If ArtistNode Is Nothing Then 'No artist is supplied check for Creator
                ArtistNode = Node.SelectSingleNode("a:ItemAttributes/a:Creator", n)
                If ArtistNode Is Nothing Then 'No artist is supplied jump to next node 
                    ArtistTemp = "bajs"
                    ' Continue For
                Else
                    ArtistTemp = ArtistNode.InnerText.ToString
                End If
            Else
                ArtistTemp = ArtistNode.InnerText.ToString
            End If
            If UCase(ArtistTemp) <> UCase(Artist) Or UCase(TitleNode.ToString) <> UCase(Album) Then
                Continue For
            End If

            Dim width = -1
            Dim height = -1
            Dim widthNode = Node.SelectSingleNode("a:LargeImage/a:Width", n)
            Dim heightNode = Node.SelectSingleNode("a:LargeImage/a:Height", n)
            If widthNode.InnerText.Length > 0 And heightNode.InnerText.Length > 0 Then
                width = Integer.Parse(widthNode.InnerText)
                height = Integer.Parse(heightNode.InnerText)
            End If
            Dim fullsize = Node.SelectSingleNode("a:LargeImage/a:URL", n).InnerText
            Dim thumbnail = fullsize 'Unless a Medium image is present, in which case use that instead
            Dim thumbNode = Node.SelectSingleNode("a:MediumImage/a:URL", n)
            If thumbNode.InnerText.Length > 0 Then
                thumbnail = thumbNode.InnerText
            End If
            ListV.Items.Add(ArtistTemp & " - " & TitleNode.ToString, tempnumber) '& thumbnail.ToString)
            ListV.Items(tempnumber).Tag = fullsize
            'WEB CLIENT IS NEEDED TO DO THE DOWNLOAD

            Dim MyWebClient As New System.Net.WebClient



            'BYTE ARRAY HOLDS THE DATA

            Dim ImageInBytes() As Byte = MyWebClient.DownloadData(fullsize)



            'CREATE A MEMORY STREAM USING THE BYTES

            Dim ImageStream As New IO.MemoryStream(ImageInBytes)



            'CREATE A BITMAP FROM THE MEMORY STREAM

            Dim Imaget As New System.Drawing.Bitmap(ImageStream)
            ImageL.Images.Add(tempnumber, Imaget)

            'this does the same but in one row
            'CoverArt_2008.Form1.PictureBox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(thumbnail)))



            tempnumber = tempnumber + 1
            'MsgBox("haha")
        Next Node
        Return True
    End Function




End Class
ASKER CERTIFIED SOLUTION
HainKurt
Sr. System Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros