Beispiel #1
0
 public static void ClearMusicFilesAll()
 {
     LocalTracks.Clear();
     FilteredLocalTracks.Clear();
     SpotifyTracks.Clear();
     FilteredSpotifyTracks.Clear();
 }
Beispiel #2
0
        public async static void AddMusicFileSpotify(string trackID)
        {
            if (String.IsNullOrWhiteSpace(trackID))
            {
                throw new ArgumentException($"Cannot add new music file, since its ID is null or empty.", nameof(trackID));
            }

            try
            {
                ISpotifyService             spotifyService = DependencyInjector.GetService <ISpotifyService>();
                Dictionary <string, string> tagData        = await spotifyService.GetTrackData(trackID);

                MetaData trackData = UtilityHelper.FormatMetaDataSpotify(tagData, out string trackURI);

                TrackVirtual track = new TrackVirtual(trackData, false);
                track.SpotifyID  = trackID;
                track.SpotifyURI = trackURI;
                SpotifyTracks.Add(track);
                FilteredSpotifyTracks.Add(track);
            }
            catch (Exception) // TODO: more polished exception handling
            {
                UtilityHelper.ShowExceptionDialog(
                    "Track parsing error",
                    "Track parsing error happened while trying to parse a music file from Spotify. This file will be omitted from Playzone!",
                    $"Track URI: {trackID}");
            }
        }
Beispiel #3
0
        private async Task <string> GetSongUri(Song song)
        {
            string url  = string.Format("https://api.spotify.com/v1/search?q={0}&type=track", song.Query);
            string json = await HttpHelper.Get(url, this.AuthenticationToken, true);

            CheckForResponseErrors(json);

            SpotifyTracks response = JsonConvert.DeserializeObject <SpotifyTracks>(json, new JsonSerializerSettings());

            Item[] songsFound = response?.tracks?.items;

            // Nothing at all found
            if (songsFound == null || songsFound.Length == 0 || songsFound[0].artists == null)
            {
                return("");
            }

            // Find best match
            foreach (var candidate in songsFound)
            {
                // Ignore "(with" and "[" in my songs
                if (candidate.name.ToLower() != song.JustName.ToLower())
                {
                    continue;
                }
                // Ignore "The " on either side
                if (candidate.artists[0].name.TrimThe().ToLower() == song.Artist.TrimThe().ToLower())
                {
                    return(candidate.uri);
                }
            }

            return("");
        }
            /*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);
                }
            }
Beispiel #5
0
        public SpotifyTracks SearchTracks(string q)
        {
            string        token  = AuthorizeSpotify();
            string        url    = String.Format("https://api.spotify.com/v1/search?q={0}&type=track&include_external=audio", q);
            SpotifyTracks tracks = GetFromSpotify <SpotifyTracks>(url, token);

            return(tracks);
        }
Beispiel #6
0
        public static void RemoveMusicFileSpotify(string trackID)
        {
            TrackVirtual itemToRemove = SpotifyTracks.SingleOrDefault(t => t.SpotifyID == trackID);

            if (itemToRemove != null)
            {
                SpotifyTracks.Remove(itemToRemove);
                FilteredSpotifyTracks.Remove(itemToRemove);
            }
        }
        public async Task <JsonResult> Get()
        {
            //choose a random number and pull song on that id
            Random r    = new Random();
            int    rInt = r.Next(0, 64); //for ints

            SongReturned = await _songService.GetSong(rInt);

            var q = SongReturned.Title + " " + SongReturned.Artist;
            // var access_token = await HttpContext.GetTokenAsync("Spotify", "access_token");
            // SpotifyUser spotifyUser = _spotifyService.GetUserProfile(access_token);

            // SpotifyTracks songs = _spotifyService.SearchTracks(spotifyUser.UserId, access_token, q);
            SpotifyTracks songs = _spotifyService.SearchTracks(q);
            var           uri   = songs.Tracks.Items.Count() > 0 ? songs.Tracks.Items.FirstOrDefault().Uri : "";

            await SongReturned.GetLyrics();

            return(Json(new { lyrics = SongReturned.SongLyric, uri = uri }));
        }