Esempio n. 1
0
        public async Task StartPlaybackTimer(PlaybackProgressEventArgs e)
        {
            _logger.LogInformation("StartPlaybackTimer : Entered");
            await Task.Delay(20000);

            try
            {
                var session = _sessionManager.GetSession(e.DeviceId, e.ClientName, "");
                if (session != null)
                {
                    string event_playing_id = e.Item.Id.ToString("N");

                    string event_user_id     = e.Users[0].Id.ToString("N");
                    long   event_user_id_int = e.Users[0].InternalId;

                    string session_playing_id = "";
                    if (session.NowPlayingItem != null)
                    {
                        session_playing_id = session.NowPlayingItem.Id.ToString("N");
                    }
                    string session_user_id = "";

                    _logger.LogInformation("session.RemoteEndPoint : {RemoteEndPoint}", session.RemoteEndPoint);

                    if (session.UserId != Guid.Empty)
                    {
                        session_user_id = session.UserId.ToString("N");
                    }

                    string play_method = "na";
                    if (session.PlayState != null && session.PlayState.PlayMethod != null)
                    {
                        play_method = session.PlayState.PlayMethod.Value.ToString();
                    }
                    if (session.PlayState != null && session.PlayState.PlayMethod == MediaBrowser.Model.Session.PlayMethod.Transcode)
                    {
                        if (session.TranscodingInfo != null)
                        {
                            string video_codec = "direct";
                            if (session.TranscodingInfo.IsVideoDirect == false)
                            {
                                video_codec = session.TranscodingInfo.VideoCodec;
                            }
                            string audio_codec = "direct";
                            if (session.TranscodingInfo.IsAudioDirect == false)
                            {
                                audio_codec = session.TranscodingInfo.AudioCodec;
                            }
                            play_method += " (v:" + video_codec + " a:" + audio_codec + ")";
                        }
                    }

                    string item_name = GetItemName(e.Item);
                    string item_id   = e.Item.Id.ToString("N");
                    string item_type = e.MediaInfo.Type;

                    _logger.LogInformation("StartPlaybackTimer : event_playing_id     = {EventPlayingId}", event_playing_id);
                    _logger.LogInformation("StartPlaybackTimer : event_user_id        = {EventUserId}", event_user_id);
                    _logger.LogInformation("StartPlaybackTimer : event_user_id_int    = {EventUserIdInternal}", event_user_id_int);
                    _logger.LogInformation("StartPlaybackTimer : session_playing_id   = {SessionPlayingId}", session_playing_id);
                    _logger.LogInformation("StartPlaybackTimer : session_user_id      = {SessionUserId}", session_user_id);
                    _logger.LogInformation("StartPlaybackTimer : play_method          = {PlayMethod}", play_method);
                    _logger.LogInformation("StartPlaybackTimer : e.ClientName         = {ClientName}", e.ClientName);
                    _logger.LogInformation("StartPlaybackTimer : e.DeviceName         = {DeviceName}", e.DeviceName);
                    _logger.LogInformation("StartPlaybackTimer : ItemName             = {ItemName}", item_name);
                    _logger.LogInformation("StartPlaybackTimer : ItemId               = {ItemId}", item_id);
                    _logger.LogInformation("StartPlaybackTimer : ItemType             = {ItemType}", item_type);

                    PlaybackInfo play_info = new PlaybackInfo
                    {
                        Id             = Guid.NewGuid().ToString("N"),
                        Date           = DateTime.Now,
                        ClientName     = e.ClientName,
                        DeviceName     = e.DeviceName,
                        PlaybackMethod = play_method,
                        UserId         = event_user_id,
                        ItemId         = item_id,
                        ItemName       = item_name,
                        ItemType       = item_type
                    };

                    if (event_playing_id == session_playing_id && event_user_id == session_user_id)
                    {
                        _logger.LogInformation("StartPlaybackTimer : All matches, playback registered");

                        // update tracker with playback info
                        string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N");
                        if (playback_trackers.ContainsKey(key))
                        {
                            _logger.LogInformation("Playback tracker found, adding playback info : {Key}", key);
                            PlaybackTracker tracker = playback_trackers[key];
                            tracker.TrackedPlaybackInfo = play_info;

                            _logger.LogInformation("Saving playback tracking activity in DB");
                            _repository.AddPlaybackAction(tracker.TrackedPlaybackInfo);
                        }
                        else
                        {
                            _logger.LogInformation("Playback trackler not found : {Key}", key);
                        }
                    }
                    else
                    {
                        _logger.LogInformation("StartPlaybackTimer : Details do not match for play item");
                    }
                }
                else
                {
                    _logger.LogInformation("StartPlaybackTimer : session Not Found");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "StartPlaybackTimer : Unexpected error occurred");
            }
            _logger.LogInformation("StartPlaybackTimer : Exited");
        }
        public async System.Threading.Tasks.Task StartPlaybackTimer(PlaybackProgressEventArgs e)
        {
            _logger.Info("StartPlaybackTimer : Entered");
            await System.Threading.Tasks.Task.Delay(20000);

            try
            {
                var session = _sessionManager.GetSession(e.DeviceId, e.ClientName, "");
                if (session != null)
                {
                    string event_playing_id = e.Item.Id.ToString("N");
                    string event_user_id    = e.Users[0].Id.ToString("N");

                    string session_playing_id = "";
                    if (session.NowPlayingItem != null)
                    {
                        session_playing_id = session.NowPlayingItem.Id.ToString("N");
                    }
                    string session_user_id = "";

                    _logger.Info("session.RemoteEndPoint : " + session.RemoteEndPoint);

                    if (session.UserId != null)
                    {
                        session_user_id = ((Guid)session.UserId).ToString("N");
                    }

                    string play_method = "na";
                    if (session.PlayState != null && session.PlayState.PlayMethod != null)
                    {
                        play_method = session.PlayState.PlayMethod.Value.ToString();
                    }
                    if (session.PlayState != null && session.PlayState.PlayMethod == MediaBrowser.Model.Session.PlayMethod.Transcode)
                    {
                        if (session.TranscodingInfo != null)
                        {
                            string video_codec = "direct";
                            if (session.TranscodingInfo.IsVideoDirect == false)
                            {
                                video_codec = session.TranscodingInfo.VideoCodec;
                            }
                            string audio_codec = "direct";
                            if (session.TranscodingInfo.IsAudioDirect == false)
                            {
                                audio_codec = session.TranscodingInfo.AudioCodec;
                            }
                            play_method += " (v:" + video_codec + " a:" + audio_codec + ")";
                        }
                    }

                    string item_name = GetItemName(e.Item);
                    string item_id   = e.Item.Id.ToString("N");
                    string item_type = e.MediaInfo.Type;

                    _logger.Info("StartPlaybackTimer : event_playing_id   = " + event_playing_id);
                    _logger.Info("StartPlaybackTimer : event_user_id      = " + event_user_id);
                    _logger.Info("StartPlaybackTimer : session_playing_id = " + session_playing_id);
                    _logger.Info("StartPlaybackTimer : session_user_id    = " + session_user_id);
                    _logger.Info("StartPlaybackTimer : play_method        = " + play_method);
                    _logger.Info("StartPlaybackTimer : e.ClientName       = " + e.ClientName);
                    _logger.Info("StartPlaybackTimer : e.DeviceName       = " + e.DeviceName);
                    _logger.Info("StartPlaybackTimer : ItemName           = " + item_name);
                    _logger.Info("StartPlaybackTimer : ItemId             = " + item_id);
                    _logger.Info("StartPlaybackTimer : ItemType           = " + item_type);

                    PlaybackInfo play_info = new PlaybackInfo();
                    play_info.Id             = Guid.NewGuid().ToString("N");
                    play_info.Date           = DateTime.Now;
                    play_info.ClientName     = e.ClientName;
                    play_info.DeviceName     = e.DeviceName;
                    play_info.PlaybackMethod = play_method;
                    play_info.UserId         = event_user_id;
                    play_info.ItemId         = item_id;
                    play_info.ItemName       = item_name;
                    play_info.ItemType       = item_type;

                    if (event_playing_id == session_playing_id && event_user_id == session_user_id)
                    {
                        _logger.Info("StartPlaybackTimer : All matches, playback registered");

                        // update tracker with playback info
                        string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N");
                        if (playback_trackers.ContainsKey(key))
                        {
                            _logger.Info("Playback tracker found, adding playback info : " + key);
                            PlaybackTracker tracker = playback_trackers[key];
                            tracker.TrackedPlaybackInfo = play_info;

                            _logger.Info("Saving playback tracking activity in DB");
                            _repository.AddPlaybackAction(tracker.TrackedPlaybackInfo);
                        }
                        else
                        {
                            _logger.Info("Playback trackler not found : " + key);
                        }
                    }
                    else
                    {
                        _logger.Info("StartPlaybackTimer : Details do not match for play item");
                    }
                }
                else
                {
                    _logger.Info("StartPlaybackTimer : session Not Found");
                }
            }
            catch (Exception exception)
            {
                _logger.Info("StartPlaybackTimer : Error = " + exception.Message + "\n" + exception.StackTrace);
            }
            _logger.Info("StartPlaybackTimer : Exited");
        }