Exemple #1
0
        public async Task <List <AutocompleteSearch> > GetTopArtists()
        {
            try
            {
                string url = "http://fildo.net/topartistsjson.html";
                List <AutocompleteSearch> autocompleteSearches = new List <AutocompleteSearch>();

                using (HttpClient client = new HttpClient())
                {
                    string content = await client.GetStringAsync(url);

                    var data = JToken.Parse(content);

                    foreach (var albumJsonMain in data)
                    {
                        foreach (var albumJson in albumJsonMain)
                        {
                            AutocompleteSearch autocompleteSearch = new AutocompleteSearch();
                            autocompleteSearch.Name       = albumJson["name"].ToString();
                            autocompleteSearch.PicUrl     = albumJson["picUrl"].ToString();
                            autocompleteSearch.Id         = albumJson["id"].ToString();
                            autocompleteSearch.ResultType = "Artist";
                            autocompleteSearches.Add(autocompleteSearch);
                        }
                    }
                }

                return(autocompleteSearches);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #2
0
 private void OpenSimilar(AutocompleteSearch similar)
 {
     //this.historyItems.Add(this.currentItem);
     similar.ResultType = "Artist";
     this.ShowViewModel <ListSongViewModel>(similar);
     //this.Init(similar);
 }
Exemple #3
0
        private void SelectArtistHandler(AutocompleteSearch item)
        {
            if (string.IsNullOrEmpty(item.ResultType))
            {
                item.ResultType = "Artist";
            }

            this.ShowViewModel <ListSongViewModel>(item);
        }
Exemple #4
0
        public async Task <List <SongNetease> > GetXiamiSongs(AutocompleteSearch autocompleteSearch)
        {
            List <SongNetease> result = new List <SongNetease>();

            if (autocompleteSearch.ResultType == "Artist")
            {
                string url = "http://www.xiami.com/song/playlist/id/" + autocompleteSearch.Id + "/type/2/cat/json";

                result = await this.ParseAutocompleteXiami(url);
            }
            else if (autocompleteSearch.ResultType == "Album")
            {
                string url = "http://www.xiami.com/song/playlist/id/" + autocompleteSearch.Id + "/type/1/cat/json";

                result = await this.ParseAutocompleteXiami(url);
            }
            else if (autocompleteSearch.ResultType == "Song")
            {
                string url = "http://www.xiami.com/song/playlist/id/" + autocompleteSearch.Id + "/cat/json";

                result = await this.ParseAutocompleteXiami(url);
            }
            return(result);
        }
Exemple #5
0
        public async void Init(AutocompleteSearch autocompleteSearch)
        {
            if (string.IsNullOrEmpty(autocompleteSearch.Id) || string.IsNullOrEmpty(autocompleteSearch.ResultType))
            {
                return;
            }

            this.IsBusy      = true;
            this.currentItem = new SongListInitItem()
            {
                ItemType = SongListEnum.AutoComplete, Item = autocompleteSearch
            };
            if (!string.IsNullOrEmpty(autocompleteSearch.PicUrl))
            {
                this.PicUrl = autocompleteSearch.PicUrl.Replace("Small", string.Empty);
            }
            if (autocompleteSearch.AutoCompleteType == AutoCompleteType.Xiami)
            {
                List <SongNetease> tempSong = new List <SongNetease>();
                tempSong = await this.netEase.GetXiamiSongs(autocompleteSearch);

                this.Songs = new ObservableCollection <ItemWrap>();

                if (tempSong == null)
                {
                    this.dialog.ShowAlert(Texts.ErrorGettingResults, 5000);
                }
                else
                {
                    foreach (var item in tempSong)
                    {
                        this.Songs.Add(new ItemWrap(item, this));
                    }
                }
            }
            else
            {
                //this.Songs = await this.netEase.Autocomplete(toSearch);
                List <SongNetease> tempSong = new List <SongNetease>();
                if (autocompleteSearch.ResultType == "Album")
                {
                    tempSong = await this.netEase.GetSongsForAlbum(autocompleteSearch.Id, autocompleteSearch.ArtistName);
                }
                else if (autocompleteSearch.ResultType == "Song")
                {
                    List <SongNetease> songs = new List <SongNetease>();
                    SongNetease        song  = await this.netEase.GetSong(autocompleteSearch.Id);

                    if (song != null)
                    {
                        tempSong.Add(song);
                    }
                    else
                    {
                        tempSong = null;
                    }
                }
                else if (autocompleteSearch.ResultType == "Artist")
                {
                    this.IsArtist = true;
                    tempSong      = await this.netEase.SearchArtist(autocompleteSearch.Id, autocompleteSearch.Name);

                    this.Albums = await this.netEase.SearchAlbums(autocompleteSearch.Id, autocompleteSearch.Name);

                    this.SimilarArtists = await this.netEase.GetSimilar(autocompleteSearch.Name);

                    if ((this.Albums == null) || (this.SimilarArtists == null))
                    {
                        this.dialog.ShowAlert(Texts.ErrorGettingResults, 5000);
                    }
                }
                this.Songs = new ObservableCollection <ItemWrap>();

                if (tempSong == null)
                {
                    this.dialog.ShowAlert(Texts.ErrorGettingResults, 5000);
                }
                else
                {
                    foreach (var item in tempSong)
                    {
                        this.Songs.Add(new ItemWrap(item, this));
                    }
                }
            }
            this.RaisePropertyChanged(() => this.Songs);
            this.IsBusy = false;
            this.RaisePropertyChanged(() => this.TitleView);
        }
Exemple #6
0
        private void CompleteResults(JToken jtoken, string type)
        {
            if (jtoken == null)
            {
                return;
            }

            foreach (var item in jtoken)
            {
                string artistInfo = item.ToString();
                var    artistData = JToken.Parse(artistInfo);
                if (type == "Artist")
                {
                    var artistImage = artistData["picUrl"];
                    if (string.IsNullOrEmpty(artistImage.ToString()))
                    {
                        artistImage = artistData["img1v1Url"];
                    }

                    this.autocompleteSearches.Add(new AutocompleteSearch()
                    {
                        ResultType = type,
                        PicUrl     = artistImage.ToString(),
                        Name       = artistData["name"].ToString(),
                        Id         = artistData["id"].ToString()
                    });
                }
                else if (type == "Album")
                {
                    string artistImage = artistData["picId"].ToString();
                    string url         = "http://p3.music.126.net/" + this.Decrypt(artistImage) + "/" + artistImage + ".jpg";
                    var    tempauto    = new AutocompleteSearch()
                    {
                        ResultType = type,
                        PicUrl     = url,
                        Name       = artistData["name"].ToString(),
                        Id         = artistData["id"].ToString()
                    };
                    try
                    {
                        tempauto.ArtistName = artistData["artist"]["name"].ToString();
                    }
                    catch (Exception)
                    {
                    }
                    this.autocompleteSearches.Add(tempauto);
                }
                else if (type == "Song")
                {
                    var    artistImage = artistData["album"]["picId"].ToString();
                    string url         = "http://p3.music.126.net/" + this.Decrypt(artistImage) + "/" + artistImage + ".jpg";

                    this.autocompleteSearches.Add(new AutocompleteSearch()
                    {
                        ResultType = type,
                        PicUrl     = url,
                        Name       = artistData["name"].ToString(),
                        Id         = artistData["id"].ToString(),
                        Duration   = item["duration"].ToString()
                    });
                }
            }
        }
Exemple #7
0
        public async Task <List <AutocompleteSearch> > SearchXiami(string toSearch)
        {
            try
            {
                var result = new List <AutocompleteSearch>();

                string url = "http://www.xiami.com/search/json?t=4&k=" + toSearch + "&n=10";

                using (HttpClient client = new HttpClient())
                {
                    client.Timeout = new TimeSpan(0, 0, 20);

                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
                    request.Headers.Referrer = new Uri("http://www.xiami.com");

                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        var xiamiDto = JsonConvert.DeserializeObject <XiamiAutocompleteDto>(content);
                        foreach (XiamiSongDto xiamiSongDto in xiamiDto.songs)
                        {
                            AutocompleteSearch song = new AutocompleteSearch();
                            song.AutoCompleteType = AutoCompleteType.Xiami;
                            song.Id         = xiamiSongDto.song_id;
                            song.ArtistName = xiamiSongDto.artist_name;
                            song.ResultType = "Song";
                            song.Name       = xiamiSongDto.song_name;
                            result.Add(song);
                        }

                        foreach (var dto in xiamiDto.albums)
                        {
                            AutocompleteSearch album = new AutocompleteSearch();
                            album.AutoCompleteType = AutoCompleteType.Xiami;
                            album.PicUrl           = "http://img.xiami.net/" + dto.album_logo;
                            album.Name             = dto.title;
                            album.ArtistName       = dto.artist_name;
                            album.Id         = dto.album_id;
                            album.ResultType = "Album";
                            result.Add(album);
                        }

                        foreach (var dto in xiamiDto.artists)
                        {
                            AutocompleteSearch artist = new AutocompleteSearch();
                            artist.AutoCompleteType = AutoCompleteType.Xiami;

                            artist.PicUrl     = "http://img.xiami.net/" + dto.logo;
                            artist.Name       = dto.name;
                            artist.Id         = dto.artist_id;
                            artist.ResultType = "Artist";
                            result.Add(artist);
                        }
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #8
0
 private void SelectItemHandler(AutocompleteSearch item)
 {
     this.ShowViewModel <ListSongViewModel>(item);
 }
Exemple #9
0
 public async Task <List <SongNetease> > GetXiamiSongs(AutocompleteSearch autocompleteSearch)
 {
     return(await this.netEaseService.GetXiamiSongs(autocompleteSearch));
 }