Exemple #1
0
        public async void Handle(AddPlaylistReplyEvent message)
        {
            if (String.IsNullOrEmpty(message.Content))
            {
                return;
            }

            var invalidUrlEvent = new NotificationEvent(Localization.Common.Error,
                                                        String.Format(Localization.Playlists.AddPlaylistInvalidLinkDialogMessage, message.Content));

            if (!Regex.IsMatch(message.Content,
                               @"((?:(?:http|https)://open.spotify.com/user/[a-zA-Z0-9]+/playlist/[a-zA-Z0-9]+)|(?:spotify:user:[a-zA-Z0-9]+:playlist:[a-zA-Z0-9]+))"))
            {
                _Logger.Info("Loadify detected that the playlist link entered is not a valid Spotify playlist link");
                _EventAggregator.PublishOnUIThread(invalidUrlEvent);
            }
            else
            {
                try
                {
                    _EventAggregator.PublishOnUIThread(new DisplayProgressEvent("Adding Playlist...",
                                                                                Localization.Playlists.AddPlaylistProcessingDialogMessage));
                    _Logger.Debug(String.Format("Resolving playlist link {0}...", message.Content));
                    var playlist = await PlaylistModel.FromLibrary(message.Session.GetPlaylist(message.Content), message.Session);

                    _Logger.Info(String.Format("Playlist {0} ({1} tracks) was resolved and added to the playlist collection", playlist.Name, playlist.Tracks.Count));
                    Playlists.Add(new PlaylistViewModel(playlist, _EventAggregator, _SettingsManager));

                    if (message.Permanent)
                    {
                        var playlistCollection = await message.Session.GetPlaylistCollection();

                        _Logger.Debug(String.Format("Adding playlist {0} permanently to the logged-in Spotify account...", playlist.Name));
                        await playlistCollection.Add(playlist.UnmanagedPlaylist);

                        _Logger.Info(String.Format("Playlist {0} was added permanently to the logged-in Spotify account", playlist.Name));
                    }

                    _EventAggregator.PublishOnUIThread(new HideProgressEvent());
                }
                catch (InvalidSpotifyUrlException exception)
                {
                    _Logger.Error(String.Format("Playlist link {0} is invalid but was not detected to be invalid by Loadify. Please report this incident", message.Content), exception);
                    _EventAggregator.PublishOnUIThread(invalidUrlEvent);
                }
            }
        }
Exemple #2
0
        public async void Handle(DataRefreshAuthorizedEvent message)
        {
            _Logger.Info("Retrieving playlists of the logged-in Spotify user...");
            _EventAggregator.PublishOnUIThread(new DisplayProgressEvent(Localization.Playlists.RetrievingPlaylistsDialogTitle,
                                                                        Localization.Playlists.RetrievingPlaylistsDialogMessage));
            var playlistCollection = await message.Session.GetPlaylistCollection();

            var playlists = new List <Playlist>(await playlistCollection.GetPlaylists());

            _Logger.Debug(String.Format("{0} playlists were retrieved from the playlist container", playlists.Count));
            _Logger.Debug("Fetching playlists and applying them to the collection...");

            Playlists = new ObservableCollection <PlaylistViewModel>();
            foreach (var playlist in playlists)
            {
                var fetchedPlaylistViewModel = new PlaylistViewModel(await PlaylistModel.FromLibrary(playlist, message.Session),
                                                                     _EventAggregator, _SettingsManager);
                Playlists.Add(fetchedPlaylistViewModel);
                _Logger.Info(String.Format("Added playlist {0} ({1} tracks)", fetchedPlaylistViewModel.Name, fetchedPlaylistViewModel.Tracks.Count));
            }

            _Logger.Info("Retrieving playlists finished");
            _EventAggregator.PublishOnUIThread(new HideProgressEvent());
        }