예제 #1
0
        private VideoStartInfo GetStartInfo(PlaylistItem item, PlaybackStateEventArgs eventArgs)
        {
            var videoStartInfo = new VideoStartInfo();

            if (eventArgs == null)
            {
                videoStartInfo.StartTime = TimeSpan.Zero;
                videoStartInfo.EndTime   = TimeSpan.FromSeconds(item.Duration);
            }
            else
            {
                if (eventArgs.TimeRemaining != TimeSpan.Zero)
                {
                    videoStartInfo.StartTime = eventArgs.EndTime - eventArgs.TimeRemaining - eventArgs.StartTime;
                    videoStartInfo.EndTime   = eventArgs.TimeRemaining;
                }
                else
                {
                    videoStartInfo.StartTime = eventArgs.StartTime;
                    videoStartInfo.EndTime   = eventArgs.EndTime;
                }
            }

            videoStartInfo.EndTime = videoStartInfo.EndTime == TimeSpan.Zero
                                         ? TimeSpan.FromSeconds(item.Duration)
                                         : videoStartInfo.EndTime;
            videoStartInfo.Source = SubsonicService.GetUriForVideoStartingAt(
                item.Uri, videoStartInfo.StartTime.TotalSeconds);

            return(videoStartInfo);
        }
예제 #2
0
 public virtual void Handle(StartVideoPlaybackMessage message)
 {
     Item      = message.Item;
     StartTime = TimeSpan.FromSeconds(message.StartTime).Negate();
     EndTime   = TimeSpan.FromSeconds(message.EndTime);
     Source    = SubsonicService.GetUriForVideoStartingAt(message.Item.Uri, message.StartTime);
 }
예제 #3
0
 private async void LoadSongById(int songId)
 {
     await SubsonicService.GetSong(songId)
     .WithErrorHandler(this)
     .OnSuccess(song => Handle(new PlayFile {
         Model = song
     }))
     .Execute();
 }
예제 #4
0
 public override async Task ChildClick(ItemClickEventArgs eventArgs)
 {
     var subsonicModel = ((MenuItemViewModel)eventArgs.ClickedItem).Item;
     await
     SubsonicService.GetPlaylist(subsonicModel.Id)
     .WithErrorHandler(ErrorHandler)
     .OnSuccess(LoadPlaylist)
     .Execute();
 }
예제 #5
0
        public async void PerformSearch(string parameter)
        {
            State = SearchResultState.Busy;
            await SubsonicService.Search(parameter)
            .WithErrorHandler(this)
            .OnSuccess(PopulateMenuItems)
            .Execute();

            State = MenuItemViewModels.Any() ? SearchResultState.ResultsFound : SearchResultState.NoResultsFound;
        }
예제 #6
0
        private async Task AssureVideoPlaybackIsInitalized()
        {
            if (SubsonicService.IsVideoPlaybackInitialized)
            {
                return;
            }
            await SubsonicService.GetRandomSongs(1).Execute();

            SubsonicService.IsVideoPlaybackInitialized = true;
        }
예제 #7
0
        private async Task AddItemToPlaylist(ISubsonicModel item)
        {
            if (item.Type == SubsonicModelTypeEnum.Song || item.Type == SubsonicModelTypeEnum.Video)
            {
                var addItemsMessage = new AddItemsMessage {
                    Queue = new List <Client.Common.Models.PlaylistItem>(new[] { await LoadModel(item) })
                };
                EventAggregator.Publish(addItemsMessage);
                if (_playNextItem)
                {
                    _playNextItem = false;
                    EventAggregator.Publish(new PlayNextMessage());
                }
            }
            else
            {
                var children = new List <ISubsonicModel>();
                switch (item.Type)
                {
                case SubsonicModelTypeEnum.Album:
                {
                    await SubsonicService.GetAlbum(item.Id)
                    .WithErrorHandler(this)
                    .OnSuccess(result => children.AddRange(result.Songs))
                    .Execute();
                } break;

                case SubsonicModelTypeEnum.Artist:
                {
                    await SubsonicService.GetArtist(item.Id)
                    .WithErrorHandler(this)
                    .OnSuccess(result => children.AddRange(result.Albums))
                    .Execute();
                } break;

                case SubsonicModelTypeEnum.MusicDirectory:
                {
                    await SubsonicService.GetMusicDirectory(item.Id)
                    .WithErrorHandler(this)
                    .OnSuccess(result => children.AddRange(result.Children))
                    .Execute();
                } break;

                case SubsonicModelTypeEnum.Index:
                {
                    children.AddRange(((IndexItem)item).Artists);
                } break;
                }

                foreach (var subsonicModel in children)
                {
                    await AddItemToPlaylist(subsonicModel);
                }
            }
        }
예제 #8
0
        private async Task <IActionResult> AuthenticateUser(SubsonicRequest request)
        {
            var appUser = await SubsonicService.Authenticate(request).ConfigureAwait(false);

            if (!(appUser?.IsSuccess ?? false) || (appUser?.IsNotFoundResult ?? false))
            {
                return(BuildResponse(request, appUser.Adapt <SubsonicOperationResult <Response> >()));
            }
            SubsonicUser = UserModelForUser(appUser.Data.SubsonicUser);
            return(null);
        }
예제 #9
0
        public async Task <IActionResult> CreateBookmark(SubsonicRequest request, int position, string comment)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.CreateBookmark(request, SubsonicUser, position, comment).ConfigureAwait(false);

            return(BuildResponse(request, result));
        }
예제 #10
0
        public async Task <IActionResult> GetAlbumList(SubsonicRequest request)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetAlbumList(request, SubsonicUser, AlbumListVersions.One).ConfigureAwait(false);

            return(BuildResponse(request, result, "albumList"));
        }
예제 #11
0
        public async Task <IActionResult> GetUser(SubsonicRequest request, string username)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetUser(request, username ?? request.u).ConfigureAwait(false);

            return(BuildResponse(request, result, "user"));
        }
예제 #12
0
        public async Task <IActionResult> GetTopSongs(SubsonicRequest request, int?count = 50)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetTopSongs(request, SubsonicUser, count).ConfigureAwait(false);

            return(BuildResponse(request, result, "topSongs"));
        }
예제 #13
0
        public async Task <IActionResult> AddChatMessage(SubsonicRequest request)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.AddChatMessage(request, SubsonicUser).ConfigureAwait(false);

            return(BuildResponse(request, result));
        }
예제 #14
0
        public async Task <IActionResult> GetStarred2(SubsonicRequest request)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetStarred(request, SubsonicUser, StarredVersion.Two).ConfigureAwait(false);

            return(BuildResponse(request, result, "starred"));
        }
예제 #15
0
        public async Task <IActionResult> SetRating(SubsonicRequest request, short rating)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.SetRating(request, SubsonicUser, rating).ConfigureAwait(false);

            return(BuildResponse(request, result));
        }
예제 #16
0
        public async Task <IActionResult> GetIndexes(SubsonicRequest request, long?ifModifiedSince = null)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetIndexes(request, SubsonicUser, ifModifiedSince).ConfigureAwait(false);

            return(BuildResponse(request, result, "indexes"));
        }
예제 #17
0
        public async Task <IActionResult> GetChatMessages(SubsonicRequest request, long?since)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetChatMessages(request, SubsonicUser, since).ConfigureAwait(false);

            return(BuildResponse(request, result, "chatMessages"));
        }
예제 #18
0
        public async Task <IActionResult> UnStar(SubsonicRequest request, [FromQuery] string[] albumId, [FromQuery] string[] artistId)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.ToggleStar(request, SubsonicUser, false, albumId, artistId).ConfigureAwait(false);

            return(BuildResponse(request, result));
        }
예제 #19
0
        public async Task <IActionResult> GetSongsByGenre(SubsonicRequest request)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetSongsByGenre(request, SubsonicUser).ConfigureAwait(false);

            return(BuildResponse(request, result, "songsByGenre"));
        }
예제 #20
0
 public void Setup()
 {
     _subject = new SubsonicService
     {
         Configuration = new SubsonicServiceConfiguration
         {
             BaseUrl  = "http://test",
             Username = "******",
             Password = "******"
         }
     };
 }
예제 #21
0
        public async Task <IActionResult> Search3(SubsonicRequest request)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.Search(request, SubsonicUser, SearchVersion.Three).ConfigureAwait(false);

            return(BuildResponse(request, result, "searchResult3"));
        }
예제 #22
0
        private async Task <Client.Common.Models.PlaylistItem> LoadModelImpl(IId model)
        {
            Client.Common.Models.PlaylistItem playlistItem = null;
            if (model != null)
            {
                await SubsonicService.GetSong(model.Id)
                .WithErrorHandler(this)
                .OnSuccess(result => playlistItem = CreatePlaylistItemFromSong(result)).Execute();
            }

            return(playlistItem);
        }
예제 #23
0
        public async Task <IActionResult> SavePlayQueue(SubsonicRequest request, string current,
                                                        long?position)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.SavePlayQueue(request, SubsonicUser, current, position).ConfigureAwait(false);

            return(BuildResponse(request, result));
        }
예제 #24
0
        public async Task <IActionResult> GetArtistInfo2(SubsonicRequest request, int?count, bool?includeNotPresent)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result =
                await SubsonicService.GetArtistInfo(request, count, includeNotPresent ?? false, ArtistInfoVersion.Two).ConfigureAwait(false);

            return(BuildResponse(request, result, "artistInfo2"));
        }
예제 #25
0
        public async Task <IActionResult> CreatePlaylist(SubsonicRequest request, string playlistId, string name,
                                                         string[] songId)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.CreatePlaylist(request, SubsonicUser, name, songId, playlistId).ConfigureAwait(false);

            return(BuildResponse(request, result, "playlist"));
        }
예제 #26
0
 private async Task UpdatePlaylist(Playlist playlist)
 {
     var songIds             = GetSongIdsForActivePlaylist().ToList();
     var songIdsInPlaylist   = playlist.Entries.Select(entry => entry.Id).ToList();
     var songIdsToAdd        = songIds.Where(songId => !songIdsInPlaylist.Contains(songId));
     var songIndexesToRemove =
         songIdsInPlaylist.Where(songId => !songIds.Contains(songId))
         .Select(songId => songIdsInPlaylist.IndexOf(songId));
     await
     SubsonicService.UpdatePlaylist(playlist.Id, songIdsToAdd, songIndexesToRemove)
     .WithErrorHandler(ErrorHandler)
     .OnSuccess(OnSaveFinished)
     .Execute();
 }
예제 #27
0
        private async Task <bool> ShouldPopulate()
        {
            var populate          = true;
            var diagnosticsResult = SubsonicService.Ping();
            await diagnosticsResult.Execute();

            if (diagnosticsResult.Error != null)
            {
                populate = false;
                ErrorDialogViewModel.HandleError(diagnosticsResult.Error);
            }

            return(populate);
        }
예제 #28
0
        public async Task <IActionResult> UpdatePlaylist(SubsonicRequest request, [FromQuery] string playlistId,
                                                         [FromQuery] string name, [FromQuery] string comment, [FromQuery] bool? @public,
                                                         [FromQuery] string[] songIdToAdd, [FromQuery] int[] songIndexToRemove)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.UpdatePlaylist(request, SubsonicUser, playlistId, name, comment, @public,
                                                              songIdToAdd, songIndexToRemove).ConfigureAwait(false);

            return(BuildResponse(request, result));
        }
예제 #29
0
        public async Task <IActionResult> GetPlayQueue(SubsonicRequest request)
        {
            var authResult = await AuthenticateUser(request).ConfigureAwait(false);

            if (authResult != null)
            {
                return(authResult);
            }
            var result = await SubsonicService.GetPlayQueue(request, SubsonicUser).ConfigureAwait(false);

            if (result.IsEmptyResponse)
            {
                return(BuildResponse(request, result));
            }
            return(BuildResponse(request, result, "playQueue"));
        }
예제 #30
0
        public void PopulateMenuItems(SearchResultCollection result)
        {
            MenuItemViewModels.Clear();

            if (result == null)
            {
                return;
            }

            PopulateArtists(result.Artists);
            PopulateAlbums(result.Albums);
            PopulateSongs(result.Songs);

            foreach (var subsonicModel in _menuItemViewModels.Select(x => x.Item))
            {
                subsonicModel.CoverArt = SubsonicService.GetCoverArtForId(subsonicModel.CoverArt);
            }
        }