Beispiel #1
0
        public async void LoadPlaylist(PlaylistObject selectedPlaylist)
        {
            AddNewLoadingStatus("Getting playlist info");

            //Store that this playlist was selected
            FileManager.AddPlaylist(selectedPlaylist);

            //Get songs in playlist
            PreviousStepComplete();
            AddNewLoadingStatus("Gathering songs in playlist");
            var songsInPlayListClient = new PlaylistItemsSearch();
            var songs = await songsInPlayListClient.GetPlaylistItems(selectedPlaylist.Url);

            PreviousStepComplete();
            AddNewLoadingStatus("Shuffling");
            songs.Shuffle();

            var chosenPlaylist = new List <Song>(songs.Select(x => new Song(x.getTitle(), x.getThumbnail(), GetSongIdFromUrl(x.getUrl()))));

            PreviousStepComplete();
            AddNewLoadingStatus("Retrieving album art");
            chosenPlaylist.FirstOrDefault().GetDataFromItunes();

            PreviousStepComplete();
            AddNewLoadingStatus("Getting stream");
            await chosenPlaylist.FirstOrDefault().GetStream();

            PreviousStepComplete();
            AddNewLoadingStatus("Playing");

            //load media player page
            await Navigation.PushModalAsync(new NavigationPage(new MediaPlayerPage(chosenPlaylist)));
        }
        private void SongSelectBtn_Click(object sender, RoutedEventArgs e)
        {
            Config.InitializeConfig();

            SongList.ItemsSource = PC.GetPllFromFile(Config.OsuPlaylist).Songs;
            CurrentPlaylist      = PC.GetPllFromFile(Config.OsuPlaylist);

            searchBarTxt.IsEnabled = true;
        }
 public SpotifyPlaylist(PlaylistObject playlist)
 {
     Collaborative = playlist.Collaborative;
     Id            = playlist.Id;
     Name          = playlist.Name;
     Description   = playlist.Description;
     Public        = playlist.Public;
     Uri           = playlist.Uri;
     Tracks        = new List <SpotifyPlaylistTrack>();
 }
Beispiel #4
0
        // base method to create a new playlist
        // @param name - name of the playlist
        // @param access_token - token for authorization of the current user
        // @param user - the user's id
        public static PlaylistObject CreatePlaylist(string name, string access_token, string user)
        {
            string playlistEndpoint = "" + baseUrl + "/v1/users/" + user + "/playlists";
            string body             = ("{\"name\":\"" + name + "\"}");

            string json = CreatePostRequest(playlistEndpoint, access_token, body);

            PlaylistObject playlist = JsonConvert.DeserializeObject <PlaylistObject>(json); //turn json string to defined playlist object

            return(playlist);
        }
        private void PlaylistCreateBtn_Click(object sender, RoutedEventArgs e)
        {
            //ManagePlaylistJson MPJ = new ManagePlaylistJson();

            //MPJ.WritePlaylist(MainWindow.CurrentPlaylist, Path.Combine(Environment.CurrentDirectory, "jsonFiles", "playlist1.json"));

            PlaylistObject p = new PlaylistObject();

            p.PlaylistName = "playlist";
            p.sepDir       = null;
            p.Songs        = MainWindow.CurrentPlaylist.Songs;

            WritePlaylist(p, Path.Combine(Environment.CurrentDirectory, "jsonFiles", "playlist1.pll"));
        }
Beispiel #6
0
        //generates a playlist of a user's top songs
        public IActionResult TopSongCreator()
        {
            string access_token = Request.Cookies["access_token"];
            string user         = Request.Cookies["user"];
            string URL          = "" + baseUrl + "/v1/me/top/tracks" + "?limit=50";

            string json = Helpers.CreateGetRequest(URL, access_token);                                               //create a get request and get the returned song data

            PagingObject <TrackObject> songData = JsonConvert.DeserializeObject <PagingObject <TrackObject> >(json); //deserialize json into song data
            List <TrackObject>         data     = songData.Items;

            PlaylistObject playlist = Helpers.CreatePlaylist("Top Tracks", access_token, user);

            ViewBag.songs = Helpers.AddTracksToPlaylist(playlist.Id, access_token, data);
            return(View("Done"));
        }
Beispiel #7
0
        public LoadingPage(PlaylistObject selectedPlaylist = null, bool recentlyPlayedPlaylist = false, bool savedSongs = false)
        {
            InitializeComponent();

            if (recentlyPlayedPlaylist)
            {
                LoadRecentlyPlayedPlaylists();
            }
            else if (savedSongs)
            {
                LoadSavedSongs();
            }
            else
            {
                LoadPlaylist(selectedPlaylist);
            }
        }
        private void AddPlaylist(object obj)
        {
            var dialog   = new TextBoxWindow();
            var playlist = new PlaylistObject();

            if (dialog.ShowDialog() == true)
            {
                playlist.Name = dialog.ResponseText;
                if (String.IsNullOrWhiteSpace(playlist.Name))
                {
                    return;
                }
            }

            _musicLog.AddPlaylist(playlist);
            Playlists.Add(playlist);
        }
Beispiel #9
0
        public async void WriteOsuDB(string osuDBFile)
        {
            CheckIfDirectoryExists();

            PlaylistObject p = new PlaylistObject();

            p.PlaylistName = "defaultOsuPlaylist";
            p.sepDir       = null;
            p.Songs        = await DS.PopulateFromOsuDb(osuDBFile);


            string json = JsonConvert.SerializeObject(p, Formatting.Indented);

            File.WriteAllText(Path.Combine(osuWritePath, @"defaultOsuPlaylist.json"), json);

            GC.WaitForPendingFinalizers();
            GC.Collect();
        }
Beispiel #10
0
        // Create a custom playlist from the user's specfied preferences
        // @param seed - the user's preferences for artists, tempo, and danceability
        public IActionResult Custom(UserPreference seed)
        {
            //validate the preference fields
            if (!Helpers.PreferenceValidation(seed))
            {
                ViewBag.Message = "Please enter valid fields.";
                return(View("CustomPlaylist"));
            }

            string access_token = Request.Cookies["access_token"];
            string user         = Request.Cookies["user"];
            string findIdUrl    = "" + baseUrl + "/v1/search";
            string artistName   = "";
            string type         = "&type=artist";

            if (ModelState.IsValid)
            {
                artistName = seed.ArtistName.Replace(" ", "%20"); //encoded URI
            }

            findIdUrl = findIdUrl + "?q=" + artistName + type;
            string              json    = Helpers.CreateGetRequest(findIdUrl, access_token); //search spotify for artists matching the given name
            SearchQuery         query   = JsonConvert.DeserializeObject <SearchQuery>(json);
            List <ArtistObject> artists = query.artists.Items;

            if (!artists.Any())
            {
                ViewBag.Message = "No artists with that name could be found"; //validation
                return(View("CustomPlaylist"));
            }

            //gets all main recommended songs
            string URL             = "" + baseUrl + "/v1/recommendations";
            string seeds           = "?seed_artists=" + artists[0].Id + "&limit=50" + "&target_tempo=" + seed.Tempo + "&target_danceability=" + seed.Danceable;
            string jsonRecommended = Helpers.CreateGetRequest(URL + seeds, access_token);

            RecommendationObject recommendation = JsonConvert.DeserializeObject <RecommendationObject>(jsonRecommended);
            List <TrackObject>   tracks         = recommendation.Tracks.Cast <TrackObject>().ToList();

            PlaylistObject playlist = Helpers.CreatePlaylist("Recommended", access_token, user);

            ViewBag.songs = Helpers.AddTracksToPlaylist(playlist.Id, access_token, tracks);
            return(View("Done"));
        }
        public MainPage()
        {
            InitializeComponent();
            _playlistSearchClient = new PlaylistSearch();
            _playlistitemsClient  = new PlaylistItemsSearch();

            try
            {
                FileManager.InitFolders();

                InitPlaylists();
            }
            catch (Exception ex)
            {
                FileManager.LogError("Error setting up home page", ex);
            }

            BindingContext = new PlaylistObject();
        }
Beispiel #12
0
        //creates a playlist of the user's most recently played songs
        public IActionResult RecentlyPlayed()
        {
            string access_token = Request.Cookies["access_token"];
            string user         = Request.Cookies["user"];
            string URL          = "" + baseUrl + "/v1/me/player/recently-played" + "?limit=50";

            string json = Helpers.CreateGetRequest(URL, access_token);
            CursorPagingObject <PlayHistoryObject> songData = JsonConvert.DeserializeObject <CursorPagingObject <PlayHistoryObject> >(json);
            List <PlayHistoryObject> data  = songData.Items;
            List <TrackObject>       songs = new List <TrackObject>();

            for (int i = 0; i < data.Count; ++i)
            {
                songs.Add(data[i].Track);
            }

            PlaylistObject playlist = Helpers.CreatePlaylist("Recently Played", access_token, user);

            ViewBag.songs = Helpers.AddTracksToPlaylist(playlist.Id, access_token, songs);

            return(View("Done"));
        }
        //Recently Played playlist methods
        public static void AddPlaylist(PlaylistObject sel)
        {
            var fullPath = BASE_DIR + SAVED_FOLDER + RECENTLY_PLAYED_PLAYLISTS_FILE_NAME;

            var playlists = GetPlaylists();

            if (playlists.Any(x => x.Id == sel.Id))  //remove if already in list and readd to refresh spot in list
            {
                playlists.Remove(playlists.FirstOrDefault(x => x.Id == sel.Id));
            }

            if (playlists.Count >= 20) //keep 20 last played only
            {
                playlists.Remove(playlists.LastOrDefault());
            }

            sel.CleanTitle();
            playlists.Insert(0, sel); //add playlist to beginning of list
            var serializedPlaylists = JsonConvert.SerializeObject(playlists);

            File.WriteAllText(fullPath, serializedPlaylists);
        }
Beispiel #14
0
        public void WritePlaylist(PlaylistObject playlist, string outputPath)
        {
            string json = JsonConvert.SerializeObject(playlist, Formatting.Indented);

            File.WriteAllText(outputPath, json);
        }