Exemple #1
0
        public static async Task<Album> GetTopTrackListAsync(string link)
        {
            Album album = new Album();
            album.Link = link;
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.UserAgent.Add(new Windows.Web.Http.Headers.HttpProductInfoHeaderValue("Mozilla / 5.0(Windows NT 10.0; WOW64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 45.0.2454.101 Safari / 537.36"));
            string response = await client.GetStringAsync(new Uri(link));
            client.Dispose();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(response);

            //Lay album title tu header
            album.Title = doc.DocumentNode.ChildNodes["html"].ChildNodes["head"].ChildNodes["title"].InnerText;
            //Chon ra the ul chua danh sach bai hat
            var ulTags = from ul in doc.DocumentNode.Descendants("ul").Where(x => x.Attributes["class"].Value == "list_show_chart")
                         select ul;
            var ulTag = ulTags.First();

            //Moi node la 1 the li
            foreach (HtmlNode node in ulTag.ChildNodes)
            {
                //Loai bo the #text
                if (node.Name == "li")
                {
                    try
                    {
                        HtmlNode trackInfoNode = node.ChildNodes[5];
                        Track track = new Track();
                        track.Title = trackInfoNode.ChildNodes[3].ChildNodes[0].InnerText;
                        track.Info = trackInfoNode.ChildNodes[3].ChildNodes[0].Attributes["href"].Value;
                        track.Image = trackInfoNode.ChildNodes[1].ChildNodes["img"].Attributes["src"].Value;
                        track.Artist = trackInfoNode.ChildNodes[5].ChildNodes[1].InnerText;
                        track.ArtistLink = trackInfoNode.ChildNodes[5].ChildNodes[1].Attributes["href"].Value;
                        album.TrackList.Add(track);
                    }

                    catch (Exception)
                    { }

                }
            }

            return album;
        }
Exemple #2
0
 public TrackViewModel(Track track)
 {
     try
     {
         Title = track.Title;
         Artist = track.Artist;
         Song = track;
         Location = track.Location;
         if (track.Image != null)
         {
             Cover = new BitmapImage();
             Cover.UriSource = new Uri(track.Image);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemple #3
0
        public static async Task<List<Track>> GetRelatedTrackListAsync(Track track)
        {
            //Kiem tra an toan
            if (track.Info == null)
                return null;
            string link = track.Info;
            HttpClient hc = new HttpClient();
            hc.DefaultRequestHeaders.UserAgent.Add(new Windows.Web.Http.Headers.HttpProductInfoHeaderValue("Mozilla / 5.0(Windows NT 10.0; WOW64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 45.0.2454.101 Safari / 537.36"));
            string response = await hc.GetStringAsync(new Uri(link, UriKind.Absolute));
            hc.Dispose();
            HtmlDocument hdoc = new HtmlDocument();
            hdoc.LoadHtml(response);
            HtmlNode ultag = (from ultags in hdoc.DocumentNode.Descendants("ul").Where(x => x.Attributes["id"].Value == "recommendZone")
                              select ultags).First();
            var relatedTrackList = from litag in ultag.ChildNodes.Where(x => x.Name == "li")
                                   select new Track()
                                   {
                                       Info = litag.ChildNodes[3].ChildNodes[1].ChildNodes[0].Attributes["href"].Value,
                                       Title = litag.ChildNodes[3].ChildNodes[1].ChildNodes[0].InnerText,
                                       Artist = litag.ChildNodes[3].ChildNodes[3].ChildNodes[0].InnerText,
                                       ArtistLink = litag.ChildNodes[3].ChildNodes[3].ChildNodes[0].Attributes["href"].Value
                                   };

            return relatedTrackList.ToList();
        }