public static void AddTopAlbum(Album album) { TopAlbums.Add(Database.AddAlbum(album)); }
public async Task LoadDataForAlbumAndTracks(int count = 5) { Popular = new ObservableCollection <Base>(); NewReleases = new ObservableCollection <Base>(); TopAlbums = new ObservableCollection <Base>(); try { var o = await _misc.GetTopTracksAsync(count);//GetNewRelesedSong(count); if (o != null && o.Songs.Count > 0) { int indexToAdd = -1; foreach (var oSong in o.Songs) { indexToAdd++; Popular.Add(oSong); if (indexToAdd == 2 || indexToAdd == 10 || indexToAdd == 22 || indexToAdd == 34 || indexToAdd == 49 || indexToAdd == 63 || indexToAdd == 78 || indexToAdd == 88 || indexToAdd == 99) { Popular.Insert(indexToAdd, new Advert()); } } } else { Popular = new ObservableCollection <Base>(); } if (o != null) { o = null; } if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.Mobile") { SmallPopular = Popular.Take(3).ToList(); } loadedCount++; } catch { //ignored } await Task.Delay(50); try { var newR = await _misc.GetNewRelesedSong(count); if (newR != null && newR.Count > 0) { int indexToAdd = -1; foreach (var oSong in newR) { indexToAdd++; NewReleases.Add(oSong); if (indexToAdd == 2 || indexToAdd == 10 || indexToAdd == 22 || indexToAdd == 34 || indexToAdd == 49 || indexToAdd == 63 || indexToAdd == 78 || indexToAdd == 88 || indexToAdd == 99) { NewReleases.Insert(indexToAdd, new ListAdvert()); } } } else { NewReleases = new ObservableCollection <Base>(); } if (newR != null) { newR = null; } loadedCount++; } catch { //ignored } try { var o = await _misc.GetTopAlbumsAsync(count); if (o != null && o.Albums != null && o.Albums.Count > 0) { int indexToAdd = -1; foreach (var oAlbum in o.Albums) { indexToAdd++; TopAlbums.Add(oAlbum); if (indexToAdd == 2 || indexToAdd == 10 || indexToAdd == 22 || indexToAdd == 34 || indexToAdd == 49 || indexToAdd == 63 || indexToAdd == 78 || indexToAdd == 88 || indexToAdd == 99) { TopAlbums.Insert(indexToAdd, new Advert()); } } } else { TopAlbums = new ObservableCollection <Base>(); } if (o != null) { o = null; } if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.Mobile") { SmallTopAlbums = TopAlbums.Take(3).ToList(); } loadedCount++; } catch { //ignored } }
public async Task <IResult <List <TopAlbums> > > GetTop100Albums(string tipo, int mes, int ano) { try { var url = $"{VagalumeApiConstants.TOP100_ALBUMS_URL}{ProviderHelper.TratarParametrosTop100(tipo, mes, ano)}"; var html = await ProviderHelper.GetDefaultHtmlText(url, _httpRequestProcessor); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); List <TopAlbums> result = new List <TopAlbums>(); var htmlBody = htmlDoc.GetElementbyId("top100Page"); var olElem = htmlBody.Descendants("ol").Where(c => c.GetAttributeValue("class", "").Equals("topCard")).ToList(); foreach (HtmlNode li in olElem[0].ChildNodes) { HtmlNode topPosition = li.ChildNodes.Where(c => c.Name == "div").FirstOrDefault(); var position = topPosition.ChildNodes.Where(c => c.Name == "p").FirstOrDefault()?.InnerText?.ToString()?.Trim(); HtmlNode cardCenterCol = li.ChildNodes.Where(c => c.Name == "div").LastOrDefault(); HtmlNode aElem = cardCenterCol.ChildNodes.Where(c => c.Name == "div").FirstOrDefault().ChildNodes.Where(x => x.Name == "a").FirstOrDefault(); var link = aElem.Attributes.Where(c => c.Name == "href").FirstOrDefault()?.Value?.Trim(); var name = cardCenterCol.Descendants("a").Where(c => c.GetAttributeValue("class", "").Equals("w1 h22")).FirstOrDefault()?.InnerText?.Trim(); var artistname = cardCenterCol.Descendants("p").Where(c => c.GetAttributeValue("class", "").Equals("styleBlack")).FirstOrDefault()?.InnerText?.Trim(); HtmlNode pictureElem = aElem.ChildNodes.Where(c => c.Name == "picture").FirstOrDefault(); var webp = pictureElem.ChildNodes.Where(c => c.Name == "source").FirstOrDefault()?.Attributes.Where(c => c.Name == "srcset").FirstOrDefault()?.Value; var img = pictureElem.ChildNodes.Where(c => c.Name == "img").FirstOrDefault()?.Attributes.Where(c => c.Name == "src").FirstOrDefault()?.Value; if (webp == null) { webp = pictureElem.ChildNodes.Where(c => c.Name == "source").FirstOrDefault()?.Attributes.Where(c => c.Name == "data-src").FirstOrDefault()?.Value; } if (img == null) { img = pictureElem.ChildNodes.Where(c => c.Name == "img").FirstOrDefault()?.Attributes.Where(c => c.Name == "data-src").FirstOrDefault()?.Value; } TopAlbums TopAlbums = new TopAlbums() { Position = position, Name = name, Url = link, Art = link.Split('/')[1], Alb = link.Split('/')[3].Replace(".html", ""), ArtistName = artistname, FotoAlbum = new FotoAlbum { Webp = webp, Url = img } }; result.Add(TopAlbums); } return(Result.Success(result)); } catch (Exception ex) { return(Result.Fail <List <TopAlbums> >(ex.Message)); } }