Beispiel #1
0
        public static async Task <AlbumModel> FromLibrary(Album unmanagedAlbum, LoadifySession session)
        {
            var albumModel = new AlbumModel(unmanagedAlbum);

            if (unmanagedAlbum == null)
            {
                return(albumModel);
            }
            await SpotifyObject.WaitForInitialization(unmanagedAlbum.IsLoaded);

            albumModel.Name        = unmanagedAlbum.Name();
            albumModel.ReleaseYear = unmanagedAlbum.Year();
            albumModel.AlbumType   = unmanagedAlbum.Type();

            try
            {
                // retrieve the cover image of the album...
                var coverImage = session.GetImage(unmanagedAlbum.Cover(ImageSize.Large));
                await SpotifyObject.WaitForInitialization(coverImage.IsLoaded);

                albumModel.Cover = coverImage.Data();
            }
            catch (AccessViolationException)
            {
                // nasty work-around - swallow if the cover image could not be retrieved
                // since the ImageId class does not expose a property or function for checking if the buffer/handle is null/0
            }

            return(albumModel);
        }
Beispiel #2
0
        public static async Task <TrackModel> FromLibrary(Track unmanagedTrack, LoadifySession session)
        {
            var trackModel = new TrackModel(unmanagedTrack);

            if (unmanagedTrack == null)
            {
                return(trackModel);
            }
            await SpotifyObject.WaitForInitialization(unmanagedTrack.IsLoaded);

            trackModel.Name     = unmanagedTrack.Name();
            trackModel.Duration = TimeSpan.FromMilliseconds(unmanagedTrack.Duration());
            trackModel.Rating   = unmanagedTrack.Popularity();
            trackModel.Album    = await AlbumModel.FromLibrary(unmanagedTrack.Album(), session);

            for (var j = 0; j < unmanagedTrack.NumArtists(); j++)
            {
                var unmanagedArtist = unmanagedTrack.Artist(j);
                if (unmanagedArtist == null)
                {
                    continue;
                }

                trackModel.Artists.Add(await ArtistModel.FromLibrary(unmanagedArtist, session));
            }

            return(trackModel);
        }
Beispiel #3
0
        public static async Task <ArtistModel> FromLibrary(Artist unmanagedArtist, LoadifySession session)
        {
            var artistModel = new ArtistModel(unmanagedArtist);

            if (unmanagedArtist == null)
            {
                return(artistModel);
            }
            await SpotifyObject.WaitForInitialization(unmanagedArtist.IsLoaded);

            artistModel.Name = unmanagedArtist.Name();
            return(artistModel);
        }
Beispiel #4
0
 public MainViewModel(LoadifySession session, UserViewModel loggedInUser,
                      IEventAggregator eventAggregator,
                      IWindowManager windowManager,
                      ISettingsManager settingsManager) :
     base(eventAggregator, windowManager, settingsManager)
 {
     _Session     = session;
     LoggedInUser = loggedInUser;
     Menu         = new MenuViewModel(_EventAggregator, _WindowManager);
     Status       = new StatusViewModel(loggedInUser, new DownloaderViewModel(_EventAggregator, _SettingsManager), _EventAggregator);
     Playlists    = new PlaylistsViewModel(_EventAggregator, settingsManager);
     Settings     = new SettingsViewModel(_EventAggregator, _SettingsManager);
 }
Beispiel #5
0
 public LoginViewModel(IEventAggregator eventAggregator, IWindowManager windowManager, ISettingsManager settingsManager) :
     base(eventAggregator, windowManager, settingsManager)
 {
     _User    = new UserViewModel();
     _Session = new LoadifySession();
 }
Beispiel #6
0
 public AddPlaylistReplyEvent(string content, LoadifySession session, bool permanent = false) :
     base(session)
 {
     Content   = content;
     Permanent = permanent;
 }
Beispiel #7
0
 public DownloadContractResumedEvent(LoadifySession session, int downloadIndex = 0) :
     base(session)
 {
     DownloadIndex = downloadIndex;
 }
Beispiel #8
0
        public async void StartDownload(LoadifySession session, int startIndex = 0)
        {
            _CancellationToken = new CancellationTokenSource();

            var remainingTracksToDownload = RemainingTracks.Count > startIndex
                                            ? new ObservableCollection <TrackViewModel>(RemainingTracks.Skip(startIndex))
                                            : new ObservableCollection <TrackViewModel>();

            foreach (var track in remainingTracksToDownload)
            {
                CurrentTrack = track;

                try
                {
                    var trackDownloadService = new TrackDownloadService(CurrentTrack.Track,
                                                                        _SettingsManager.BehaviorSetting.AudioProcessor,
                                                                        _SettingsManager.BehaviorSetting.DownloadPathConfigurator)
                    {
                        Cleanup             = _SettingsManager.BehaviorSetting.CleanupAfterConversion,
                        OutputDirectory     = _SettingsManager.DirectorySetting.DownloadDirectory,
                        AudioConverter      = _SettingsManager.BehaviorSetting.AudioConverter,
                        AudioFileDescriptor = _SettingsManager.BehaviorSetting.AudioFileDescriptor,
                        Mp3MetaData         = new Mp3MetaData()
                        {
                            Title   = CurrentTrack.Name,
                            Artists = CurrentTrack.Artists.Select(artist => artist.Name),
                            Album   = CurrentTrack.Album.Name,
                            Year    = CurrentTrack.Album.ReleaseYear,
                            Cover   = CurrentTrack.Album.Cover
                        },
                        DownloadProgressUpdated = progress =>
                        {
                            TrackProgress = progress;
                        }
                    };

                    _Logger.Debug(String.Format("Configured Track download service: OutputDirectory {0}, Cleanup? {1}, Track: {2}",
                                                trackDownloadService.OutputDirectory,
                                                trackDownloadService.Cleanup ? "Yes" : "No",
                                                CurrentTrack.ToString()));
                    _Logger.Info(String.Format("Downloading {0}...", CurrentTrack.ToString()));
                    await session.DownloadTrack(trackDownloadService, _CancellationToken.Token);

                    _Logger.Debug(String.Format("Track downloaded with result: {0}", trackDownloadService.Cancellation.ToString()));

                    if (trackDownloadService.Cancellation == TrackDownloadService.CancellationReason.UserInteraction)
                    {
                        _Logger.Info("Download contract was cancelled");
                        _EventAggregator.PublishOnUIThread(new NotificationEvent("Download cancelled",
                                                                                 String.Format("The download contract was cancelled. \n" +
                                                                                               "Tracks downloaded: {0}\n" +
                                                                                               "Tracks remaining: {1}\n",
                                                                                               DownloadedTracks.Count, RemainingTracks.Count)));
                        break;
                    }

                    if (trackDownloadService.Cancellation == TrackDownloadService.CancellationReason.None)
                    {
                        DownloadedTracks.Add(CurrentTrack);
                        RemainingTracks.Remove(CurrentTrack);
                        _EventAggregator.PublishOnUIThread(new TrackDownloadComplete(CurrentTrack));
                        _Logger.Info(String.Format("{0} was successfully downloaded to directory {1}", CurrentTrack.ToString(), trackDownloadService.OutputDirectory));
                    }
                    else
                    {
                        _EventAggregator.PublishOnUIThread(new DownloadContractPausedEvent(
                                                               String.Format("{0} could not be downloaded because the account being used triggered an action in another client.",
                                                                             CurrentTrack.ToString()),
                                                               RemainingTracks.IndexOf(CurrentTrack)));
                        _Logger.Info("Download was paused because the account being used triggered an action in another client");
                        return;
                    }
                }
                catch (ConfigurationException exception)
                {
                    _Logger.Error("A configuration error occured", exception);
                    _EventAggregator.PublishOnUIThread(new DownloadContractPausedEvent(exception.ToString(), RemainingTracks.IndexOf(CurrentTrack)));
                    return;
                }
                catch (SpotifyException exception)
                {
                    _Logger.Error("A Spotify error occured", exception);
                    _EventAggregator.PublishOnUIThread(new DownloadContractPausedEvent(String.Format("{0} could not be download because a Spotify error occured.",
                                                                                                     CurrentTrack.ToString()),
                                                                                       RemainingTracks.IndexOf(CurrentTrack)));
                    return;
                }
            }

            _EventAggregator.PublishOnUIThread(new DownloadContractCompletedEvent());
            TrackProgress = 0;
        }
Beispiel #9
0
 public DownloadContractRequestEvent(LoadifySession session)
     : base(session)
 {
 }
Beispiel #10
0
 public DataRefreshAuthorizedEvent(LoadifySession session) :
     base(session)
 {
 }
Beispiel #11
0
 public RemovePlaylistReplyEvent(LoadifySession session, PlaylistViewModel playlist, bool permanent = false)
 {
     Session   = session;
     Playlist  = playlist;
     Permanent = permanent;
 }
Beispiel #12
0
 public SessionEvent(LoadifySession session)
 {
     Session = session;
 }
Beispiel #13
0
        public static async Task <PlaylistModel> FromLibrary(Playlist unmanagedPlaylist, LoadifySession session)
        {
            var playlistModel = new PlaylistModel(unmanagedPlaylist);

            if (unmanagedPlaylist == null)
            {
                return(playlistModel);
            }
            await SpotifyObject.WaitForInitialization(unmanagedPlaylist.IsLoaded);

            playlistModel.Name        = unmanagedPlaylist.Name() ?? "";
            playlistModel.Subscribers = unmanagedPlaylist.Subscribers().ToList();
            playlistModel.Creator     = unmanagedPlaylist.Owner().DisplayName() ?? "";
            playlistModel.Description = unmanagedPlaylist.GetDescription() ?? "";

            var playlistImageId = unmanagedPlaylist.GetImage();

            if (playlistImageId != null)
            {
                var playlistImage = session.GetImage(playlistImageId);
                await SpotifyObject.WaitForInitialization(playlistImage.IsLoaded);

                playlistModel.Image = playlistImage.Data();
            }

            for (var i = 0; i < unmanagedPlaylist.NumTracks(); i++)
            {
                var unmanagedTrack = unmanagedPlaylist.Track(i);
                if (unmanagedTrack == null)
                {
                    continue;
                }
                var managedTrack = await TrackModel.FromLibrary(unmanagedTrack, session);

                managedTrack.Playlist = playlistModel;

                playlistModel.Tracks.Add(managedTrack);
            }

            return(playlistModel);
        }
Beispiel #14
0
 public DownloadContractStartedEvent(LoadifySession session, IEnumerable <TrackViewModel> selectedTracks) :
     base(session)
 {
     SelectedTracks = selectedTracks;
 }
Beispiel #15
0
 public AddTrackReplyEvent(string content, PlaylistViewModel playlist, LoadifySession session) :
     base(session)
 {
     Content  = content;
     Playlist = playlist;
 }