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); }
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); }
private async void LoadSongById(int songId) { await SubsonicService.GetSong(songId) .WithErrorHandler(this) .OnSuccess(song => Handle(new PlayFile { Model = song })) .Execute(); }
public override async Task ChildClick(ItemClickEventArgs eventArgs) { var subsonicModel = ((MenuItemViewModel)eventArgs.ClickedItem).Item; await SubsonicService.GetPlaylist(subsonicModel.Id) .WithErrorHandler(ErrorHandler) .OnSuccess(LoadPlaylist) .Execute(); }
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; }
private async Task AssureVideoPlaybackIsInitalized() { if (SubsonicService.IsVideoPlaybackInitialized) { return; } await SubsonicService.GetRandomSongs(1).Execute(); SubsonicService.IsVideoPlaybackInitialized = true; }
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); } } }
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); }
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)); }
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")); }
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")); }
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")); }
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)); }
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")); }
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)); }
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")); }
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")); }
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)); }
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")); }
public void Setup() { _subject = new SubsonicService { Configuration = new SubsonicServiceConfiguration { BaseUrl = "http://test", Username = "******", Password = "******" } }; }
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")); }
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); }
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)); }
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")); }
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")); }
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(); }
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); }
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)); }
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")); }
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); } }