Beispiel #1
0
        public static async Task<Album> GetPlaylistAsync(string link)
        {
            try
            {
                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 htmlPage = await hc.GetStringAsync(new Uri(link));
                string xmlLink = Regex.Split(htmlPage, "amp;file=")[1].Split('\"')[0];
                XDocument xdoc = XDocument.Parse(await hc.GetStringAsync(new Uri(xmlLink)));
                hc.Dispose();

                //Parse xml
                var trackList = from t in xdoc.Descendants("track")
                                select new Track()
                                {
                                    Title = t.Element("title").Value,
                                    Artist = t.Element("creator").Value,
                                    Location = t.Element("location").Value,
                                    Info = t.Element("info").Value,
                                    ArtistLink = t.Element("newtab").Value,
                                    Image = t.Element("bgimage").Value
                                };

                Album album = new Album();
                album.Link = link;
                album.TrackList = trackList.ToList();
                return album;
            }
            catch (Exception)
            {
                return null;
            }

        }
Beispiel #2
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;
        }
Beispiel #3
0
        public AlbumViewModel(Album album)
        {
            try
            {
                title = album.Title;
                this.album = album;
                artist = album.Artist;
                if (album.Cover != null)
                    Cover = new BitmapImage(new Uri(album.Cover, UriKind.Absolute));
                TrackList = new ObservableCollection<TrackViewModel>();
                foreach (var track in album.TrackList)
                {
                    try
                    {
                        TrackViewModel trackVM = new TrackViewModel(track);
                        TrackList.Add(trackVM);
                    }
                    catch (Exception) { }
                }
            }
            catch (Exception) { }

        }
Beispiel #4
0
 public void Coppy(AlbumViewModel albumvm)
 {
     Title = albumvm.Title;
     if (TrackList != null)
         TrackList.Clear();
     if (albumvm.TrackList != null)
         foreach (var track in albumvm.TrackList)
             TrackList.Add(track);
     Cover = albumvm.Cover;
     Artist = albumvm.Artist;
     album = albumvm.album;
     IsDataLoaded = albumvm.IsDataLoaded;
 }