/*public static MessageTemplate Random()
             * {
             *  Random random = new Random();
             *  int filmYearBottomLine = random.Next(1950, DateTime.Now.Year - 5);
             *  //int filmYearUpperLine = random.Next(filmYearBottomLine + 5, DateTime.Now.Year+1);
             *  string[] order = new string[] { "YEAR", "RATING", "NUM_VOTE" };
             *  //int filmRatingBottomLine = random.Next(4, 8);
             *
             *  var client = new RestClient("https://kinopoiskapiunofficial.tech/api/v2.1/films/search-by-filters");
             *  var request = new RestRequest(Method.GET);
             *  request.AddHeader("X-API-KEY", Bot._kp_key);
             *  request.AddQueryParameter("type", "TV_SHOW");
             *  request.AddQueryParameter("order", order[random.Next(0, order.Length)]);
             *  request.AddQueryParameter("genre", Film.PopularGenres[random.Next(0, Film.PopularGenres.Length)].ToString());
             *  request.AddQueryParameter("yearFrom", filmYearBottomLine.ToString());
             *  //request.AddQueryParameter("yearTo", filmYearUpperLine.ToString());
             *  //request.AddQueryParameter("ratingFrom", filmRatingBottomLine.ToString());
             *  IRestResponse response = client.Execute(request);
             *
             *  var results = JsonConvert.DeserializeObject<RandomTV.Results>(response.Content);
             *  return Keyboards.RandomTVResults(results);
             * }*/
            //------- not mobile -------

            /* public static void Random_inMessage(User user)
             * {
             *   Random random = new Random();
             *   int filmYearBottomLine = random.Next(1950, DateTime.Now.Year - 5);
             *   //int filmYearUpperLine = random.Next(filmYearBottomLine + 5, DateTime.Now.Year+1);
             *   string[] order = new string[] { "YEAR", "RATING", "NUM_VOTE" };
             *   //int filmRatingBottomLine = random.Next(4, 8);
             *
             *   var client = new RestClient("https://kinopoiskapiunofficial.tech/api/v2.1/films/search-by-filters");
             *   var request = new RestRequest(Method.GET);
             *   request.AddHeader("X-API-KEY", Bot._kp_key);
             *   request.AddQueryParameter("type", "TV_SHOW");
             *   request.AddQueryParameter("order", order[random.Next(0, order.Length)]);
             *   request.AddQueryParameter("genre", Film.PopularGenres[random.Next(0, Film.PopularGenres.Length)].ToString());
             *   request.AddQueryParameter("yearFrom", filmYearBottomLine.ToString());
             *   //request.AddQueryParameter("yearTo", filmYearUpperLine.ToString());
             *   //request.AddQueryParameter("ratingFrom", filmRatingBottomLine.ToString());
             *   IRestResponse response = client.Execute(request);
             *
             *   RandomTV.Results results;
             *   try { results = JsonConvert.DeserializeObject<RandomTV.Results>(response.Content); }
             *   catch(Exception) { results = null; }
             *   Keyboards.RandomTVResultsMessage(user, results);
             * }*/
            public static bool DownloadSoundtrack(string TVName, string addition, List <Audio> audios, int count)
            {
                string[] song_names;
                try
                {
                    song_names = SpotifyTracks.GetTracks(SpotifyPlaylists.SearchPlaylist($"{TVName} {addition}"), count.ToString()).ToArray();
                    //var tracks = yandex_api.GetAlbum(yandex_api.SearchAlbums($"{TVName} {addition}")[0].Id).Volumes[0];
                    //song_names = tracks.Take(Math.Min(count, tracks.Count)).Select(n => $"{n.Title} {string.Join(' ', n.Artists.Select(a => a.Name))}").ToArray();
                    for (int i = 0; i < song_names.Length; ++i)
                    {
                        var collection = private_vkapi.Audio.Search(new VkNet.Model.RequestParams.AudioSearchParams
                        {
                            Autocomplete = true,
                            Query        = song_names[i]
                        });
                        if (collection.Count > 0)
                        {
                            audios.Add(collection[0]);
                        }
                    }
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
Example #2
0
        private static async Task <List <PlaylistsModel> > GetPlaylists(string authToken)
        {
            string baseUrl = $"https://api.spotify.com/v1/users/domshyra/playlists?limit=40";

            try
            {
                using HttpClient client = new();
                //add the spotify auth
                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {authToken}");

                using HttpResponseMessage res = await client.GetAsync(baseUrl);

                using HttpContent content = res.Content;
                string data = await content.ReadAsStringAsync();

                if (data != null)
                {
                    dynamic playlistHeader = JObject.Parse(data);

                    //lets get these items into a list I can parse
                    //TODO query tracks for more info and get follower count
                    SpotifyPlaylists playlists = JsonConvert.DeserializeObject <SpotifyPlaylists>(data);

                    //I only want to display public playlists by me
                    List <PlaylistsModel> playlistsModels = playlists.items.ToList()
                                                            .Where(x => string.Equals(x.owner.display_name, "domshyra", StringComparison.OrdinalIgnoreCase) && x.@public)
                                                            .Select(playlist => new PlaylistsModel()
                    {
                        Description      = playlist.description,
                        ImageURL         = playlist.images[0].url,
                        SpotifyId        = playlist.id,
                        Title            = playlist.name,
                        TrackCount       = playlist.tracks.total,
                        SpotifyMusicLink = playlist.external_urls.spotify
                    }).ToList();

                    //decode the html
                    foreach (PlaylistsModel playlistModel in playlistsModels)
                    {
                        playlistModel.Description = HttpUtility.HtmlDecode(playlistModel.Description);
                    }

                    return(playlistsModels);
                }
                else
                {
                    Console.WriteLine("NO Data----------");
                }
            }

            catch (Exception exception)
            {
                Console.WriteLine("Exception Hit------------");
                Console.WriteLine(exception);
            }

            return(new List <PlaylistsModel>());
        }
        private async Task RefreshSpotifyPlaylists()
        {
            List <SimplePlaylist> spotifyPlaylists = await Spotify.RefreshPlaylists();

            spotifyPlaylists = spotifyPlaylists.OrderBy(p => p.Name).ToList();
            SpotifyPlaylists.Clear();
            spotifyPlaylists.ForEach(x => SpotifyPlaylists.Add(new CheckedListItem <SpotifyPlaylist>(new SpotifyPlaylist(x))));
            SpotifyPlaylistListBox.ItemsSource = SpotifyPlaylists;
        }
Example #4
0
        private static async Task <List <string> > GetPlaylistIds(string authToken)
        {
            string baseUrl = $"https://api.spotify.com/v1/users/domshyra/playlists?limit=40";

            try
            {
                using HttpClient client = new();
                //add the spotify auth
                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {authToken}");

                using HttpResponseMessage res = await client.GetAsync(baseUrl);

                using HttpContent content = res.Content;
                string data = await content.ReadAsStringAsync();

                if (data != null)
                {
                    dynamic playlistHeader = JObject.Parse(data);

                    //lets get these items into a list I can parse
                    SpotifyPlaylists playlists = JsonConvert.DeserializeObject <SpotifyPlaylists>(data);

                    //I only want to display public playlists by me
                    return(playlists.items.ToList()
                           .Where(x => string.Equals(x.owner.display_name, "domshyra", StringComparison.OrdinalIgnoreCase) && x.@public)
                           .Select(x => x.id).ToList());
                }
                else
                {
                    Console.WriteLine("NO Data----------");
                }
            }

            catch (Exception exception)
            {
                Console.WriteLine("Exception Hit------------");
                Console.WriteLine(exception);
            }

            return(new List <string>());
        }