Exemple #1
0
        /// <summary>
        /// Marks the favorite.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        /// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
        /// <returns>Task.</returns>
        protected async Task <UserItemDataDto> MarkFavorite(Guid userId, string type, string name, bool isFavorite)
        {
            var item = GetItemByName(name, type, LibraryManager);

            var key = item.GetUserDataKey();

            // Get the user data for this item
            var data = UserDataRepository.GetUserData(userId, key);

            // Set favorite status
            data.IsFavorite = isFavorite;

            await UserDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);

            data = UserDataRepository.GetUserData(userId, key);

            return(_dtoService.GetUserItemDataDto(data));
        }
Exemple #2
0
        /// <summary>
        /// Marks the favorite.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
        /// <returns>Task{UserItemDataDto}.</returns>
        private async Task <UserItemDataDto> MarkFavorite(Guid userId, string itemId, bool isFavorite)
        {
            var user = _userManager.GetUserById(userId);

            var item = string.IsNullOrEmpty(itemId) ? user.RootFolder : _dtoService.GetItemByDtoId(itemId, user.Id);

            var key = item.GetUserDataKey();

            // Get the user data for this item
            var data = _userDataRepository.GetUserData(user.Id, key);

            // Set favorite status
            data.IsFavorite = isFavorite;

            await _userDataRepository.SaveUserData(user.Id, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);

            data = _userDataRepository.GetUserData(user.Id, key);

            return(_dtoService.GetUserItemDataDto(data));
        }
        private async Task SendNotifications(IEnumerable <KeyValuePair <Guid, List <string> > > changes, CancellationToken cancellationToken)
        {
            foreach (var pair in changes)
            {
                var userId       = pair.Key;
                var userSessions = _sessionManager.Sessions
                                   .Where(u => u.UserId.HasValue && u.UserId.Value == userId && u.SessionController != null && u.IsActive)
                                   .ToList();

                if (userSessions.Count > 0)
                {
                    var dtoList = pair.Value
                                  .Select(i => _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(userId, i)))
                                  .ToList();

                    var info = new UserDataChangeInfo
                    {
                        UserId = userId.ToString("N"),

                        UserDataList = dtoList
                    };

                    foreach (var userSession in userSessions)
                    {
                        try
                        {
                            await userSession.SessionController.SendUserDataChangeInfo(info, cancellationToken).ConfigureAwait(false);
                        }
                        catch (Exception ex)
                        {
                            _logger.ErrorException("Error sending UserDataChanged message", ex);
                        }
                    }
                }
            }
        }
        public RecordingInfoDto GetRecordingInfoDto(ILiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null)
        {
            var info = recording.RecordingInfo;

            var dto = new RecordingInfoDto
            {
                Id              = GetInternalRecordingId(service.Name, info.Id).ToString("N"),
                SeriesTimerId   = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
                Type            = recording.GetClientTypeName(),
                Overview        = info.Overview,
                EndDate         = info.EndDate,
                Name            = info.Name,
                StartDate       = info.StartDate,
                ExternalId      = info.Id,
                ChannelId       = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
                Status          = info.Status,
                StatusName      = GetStatusName(info.Status),
                Path            = info.Path,
                Genres          = info.Genres,
                IsRepeat        = info.IsRepeat,
                EpisodeTitle    = info.EpisodeTitle,
                ChannelType     = info.ChannelType,
                MediaType       = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video,
                CommunityRating = GetClientCommunityRating(info.CommunityRating),
                OfficialRating  = info.OfficialRating,
                Audio           = info.Audio,
                IsHD            = info.IsHD,
                ServiceName     = service.Name,
                IsMovie         = info.IsMovie,
                IsSeries        = info.IsSeries,
                IsSports        = info.IsSports,
                IsLive          = info.IsLive,
                IsNews          = info.IsNews,
                IsKids          = info.IsKids,
                IsPremiere      = info.IsPremiere,
                RunTimeTicks    = (info.EndDate - info.StartDate).Ticks,
                OriginalAirDate = info.OriginalAirDate,

                MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery
                {
                    ItemId = recording.Id
                }).ToList()
            };

            if (info.Status == RecordingStatus.InProgress)
            {
                var now   = DateTime.UtcNow.Ticks;
                var start = info.StartDate.Ticks;
                var end   = info.EndDate.Ticks;

                var pct = now - start;
                pct /= end;
                pct *= 100;
                dto.CompletionPercentage = pct;
            }

            var imageTag = GetImageTag(recording);

            if (imageTag.HasValue)
            {
                dto.ImageTags[ImageType.Primary] = imageTag.Value;
            }

            if (user != null)
            {
                dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, recording.GetUserDataKey()));

                dto.PlayAccess = recording.GetPlayAccess(user);
            }

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
            }

            if (channel != null)
            {
                dto.ChannelName = channel.Name;

                if (!string.IsNullOrEmpty(channel.PrimaryImagePath))
                {
                    dto.ChannelPrimaryImageTag = GetImageTag(channel);
                }
            }

            return(dto);
        }