示例#1
0
        public async Task Execute(IJobExecutionContext job)
        {
            var settings = await _settings.GetSettingsAsync();

            Api = _apiFactory.CreateClient(settings);
            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started");

            foreach (var server in settings.Servers)
            {
                if (server.EmbySelectedLibraries.Any() && server.EmbySelectedLibraries.Any(x => x.Enabled))
                {
                    var tvLibsToFilter = server.EmbySelectedLibraries.Where(x => x.Enabled && x.CollectionType == "tvshows");
                    foreach (var tvParentIdFilter in tvLibsToFilter)
                    {
                        _logger.LogInformation($"Scanning Lib for episodes '{tvParentIdFilter.Title}'");
                        await CacheEpisodes(server, tvParentIdFilter.Key);
                    }
                }
                else
                {
                    await CacheEpisodes(server, string.Empty);
                }
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Finished");

            _logger.LogInformation("Emby Episode Sync Finished - Triggering Metadata refresh");
            await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System");
        }
示例#2
0
        public async Task Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap             = context.JobDetail.JobDataMap;
            var        recentlyAddedSearch = false;

            if (dataMap.TryGetValue(JobDataKeys.EmbyRecentlyAddedSearch, out var recentlyAddedObj))
            {
                recentlyAddedSearch = Convert.ToBoolean(recentlyAddedObj);
            }

            var embySettings = await _settings.GetSettingsAsync();

            if (!embySettings.Enable)
            {
                return;
            }

            Api = _apiFactory.CreateClient(embySettings);

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, recentlyAddedSearch ? "Emby Recently Added Started" : "Emby Content Sync Started");

            foreach (var server in embySettings.Servers)
            {
                try
                {
                    await StartServerCache(server, recentlyAddedSearch);
                }
                catch (Exception e)
                {
                    await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                    .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Failed");

                    _logger.LogError(e, "Exception when caching Emby for server {0}", server.Name);
                }
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Finished");

            // Episodes


            await OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IEmbyEpisodeSync), "Emby"), new JobDataMap(new Dictionary <string, string> {
                { JobDataKeys.EmbyRecentlyAddedSearch, recentlyAddedSearch.ToString() }
            }));
        }
示例#3
0
        /// <summary>
        /// Sign the user into Emby
        /// <remarks>We do not check if the user is in the owners "friends" since they must have a local user account to get this far.
        /// We also have to try and authenticate them with every server, the first server that work we just say it was a success</remarks>
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private async Task <bool> CheckEmbyPasswordAsync(OmbiUser user, string password)
        {
            var embySettings = await _embySettings.GetSettingsAsync();

            var client = _embyApi.CreateClient(embySettings);

            if (user.IsEmbyConnect)
            {
                var result = await client.LoginConnectUser(user.UserName, password);

                if (result.AccessToken.HasValue())
                {
                    // We cannot update the email address in the user importer due to there is no way
                    // To get this info from Emby Connect without the username and password.
                    // So we do it here!
                    var email = user.Email ?? string.Empty;
                    if (!email.Equals(result.User?.Email))
                    {
                        user.Email = result.User?.Email;
                        await UpdateAsync(user);
                    }

                    return(true);
                }
            }

            foreach (var server in embySettings.Servers)
            {
                try
                {
                    var result = await client.LogIn(user.UserName, password, server.ApiKey, server.FullUri);

                    if (result != null)
                    {
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError(e, "Emby Login Failed");
                }
            }
            return(false);
        }
示例#4
0
        public async Task Execute(IJobExecutionContext job)
        {
            var settings = await _settings.GetSettingsAsync();

            Api = _apiFactory.CreateClient(settings);
            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started");

            foreach (var server in settings.Servers)
            {
                await CacheEpisodes(server);
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Finished");

            _logger.LogInformation("Emby Episode Sync Finished - Triggering Metadata refresh");
            await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System");
        }
示例#5
0
        public async Task <bool> EmbySettings([FromBody] EmbySettings emby)
        {
            if (emby.Enable)
            {
                var client = await _embyApi.CreateClient();

                foreach (var server in emby.Servers)
                {
                    var users = await client.GetUsers(server.FullUri, server.ApiKey);

                    var admin = users.FirstOrDefault(x => x.Policy.IsAdministrator);
                    server.AdministratorId = admin?.Id;
                }
            }
            var result = await Save(emby);

            if (result)
            {
                await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync), "Emby");
            }
            return(result);
        }
示例#6
0
        public async Task Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap             = context.MergedJobDataMap;
            var        recentlyAddedSearch = false;

            if (dataMap.TryGetValue(JobDataKeys.EmbyRecentlyAddedSearch, out var recentlyAddedObj))
            {
                recentlyAddedSearch = Convert.ToBoolean(recentlyAddedObj);
            }

            var settings = await _settings.GetSettingsAsync();

            Api = _apiFactory.CreateClient(settings);
            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started");

            foreach (var server in settings.Servers)
            {
                if (server.EmbySelectedLibraries.Any() && server.EmbySelectedLibraries.Any(x => x.Enabled))
                {
                    var tvLibsToFilter = server.EmbySelectedLibraries.Where(x => x.Enabled && x.CollectionType == "tvshows");
                    foreach (var tvParentIdFilter in tvLibsToFilter)
                    {
                        _logger.LogInformation($"Scanning Lib for episodes '{tvParentIdFilter.Title}'");
                        await CacheEpisodes(server, recentlyAddedSearch, tvParentIdFilter.Key);
                    }
                }
                else
                {
                    await CacheEpisodes(server, recentlyAddedSearch, string.Empty);
                }
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Finished");

            _logger.LogInformation("Emby Episode Sync Finished - Triggering Metadata refresh");
            await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System");
        }
示例#7
0
        public async Task Execute(IJobExecutionContext job)
        {
            var embySettings = await _settings.GetSettingsAsync();

            if (!embySettings.Enable)
            {
                return;
            }

            Api = _apiFactory.CreateClient(embySettings);

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Started");

            foreach (var server in embySettings.Servers)
            {
                try
                {
                    await StartServerCache(server, embySettings);
                }
                catch (Exception e)
                {
                    await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
                    .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Failed");

                    _logger.LogError(e, "Exception when caching Emby for server {0}", server.Name);
                }
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Finished");

            // Episodes

            await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync), "Emby");
        }
示例#8
0
        public async Task <MediaSeverAvailibilityViewModel> GetMediaServerStatus()
        {
            var model = new MediaSeverAvailibilityViewModel();

            var plex = await _plexSettings.GetSettingsAsync();

            if (plex.Enable)
            {
                foreach (var s in plex.Servers)
                {
                    try
                    {
                        var result = await _plexApi.GetStatus(s.PlexAuthToken, s.FullUri);

                        if (!string.IsNullOrEmpty(result.MediaContainer?.version))
                        {
                            model.ServersAvailable++;
                        }
                        else
                        {
                            model.ServersUnavailable++;
                        }
                    }
                    catch (Exception)
                    {
                        model.ServersUnavailable++;
                    }
                }
            }

            var emby = await _embySettings.GetSettingsAsync();

            if (emby.Enable)
            {
                var client = _embyApi.CreateClient(emby);
                foreach (var server in emby.Servers)
                {
                    try
                    {
                        var result = await client.GetUsers(server.FullUri, server.ApiKey);

                        if (result.Any())
                        {
                            model.ServersAvailable++;
                        }
                        else
                        {
                            model.ServersUnavailable++;
                        }
                    }
                    catch (Exception)
                    {
                        model.ServersUnavailable++;
                    }
                }
            }


            var jellyfin = await _jellyfin.GetSettingsAsync();

            if (jellyfin.Enable)
            {
                foreach (var server in jellyfin.Servers)
                {
                    try
                    {
                        var result = await _jellyfinApi.GetUsers(server.FullUri, server.ApiKey);

                        if (result.Any())
                        {
                            model.ServersAvailable++;
                        }
                        else
                        {
                            model.ServersUnavailable++;
                        }
                    }
                    catch (Exception)
                    {
                        model.ServersUnavailable++;
                    }
                }
            }
            return(model);
        }
示例#9
0
        public async Task Execute(IJobExecutionContext job)
        {
            var userManagementSettings = await _userManagementSettings.GetSettingsAsync();

            if (!userManagementSettings.ImportEmbyUsers)
            {
                return;
            }
            var settings = await _embySettings.GetSettingsAsync();

            if (!settings.Enable)
            {
                return;
            }

            Api = _apiFactory.CreateClient(settings);

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, $"Emby User Importer Started");

            var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.EmbyUser || x.UserType == UserType.EmbyConnectUser).ToListAsync();

            foreach (var server in settings.Servers)
            {
                if (string.IsNullOrEmpty(server.ApiKey))
                {
                    continue;
                }

                var embyUsers = await Api.GetUsers(server.FullUri, server.ApiKey);

                foreach (var embyUser in embyUsers)
                {
                    // Check if we should import this user
                    if (userManagementSettings.BannedEmbyUserIds.Contains(embyUser.Id))
                    {
                        // Do not import these, they are not allowed into the country.
                        continue;
                    }
                    // Check if this Emby User already exists
                    var existingEmbyUser = allUsers.FirstOrDefault(x => x.ProviderUserId == embyUser.Id);
                    if (existingEmbyUser == null)
                    {
                        if (!embyUser.ConnectUserName.HasValue() && !embyUser.Name.HasValue())
                        {
                            _log.LogInformation("Could not create Emby user since the have no username, PlexUserId: {0}", embyUser.Id);
                            continue;
                        }
                        var isConnectUser = embyUser.ConnectUserName.HasValue();
                        // Create this users
                        var newUser = new OmbiUser
                        {
                            UserType            = isConnectUser ? UserType.EmbyConnectUser : UserType.EmbyUser,
                            UserName            = isConnectUser ? embyUser.ConnectUserName : embyUser.Name,
                            ProviderUserId      = embyUser.Id,
                            Alias               = isConnectUser ? embyUser.Name : string.Empty,
                            MovieRequestLimit   = userManagementSettings.MovieRequestLimit,
                            EpisodeRequestLimit = userManagementSettings.EpisodeRequestLimit,
                            StreamingCountry    = userManagementSettings.DefaultStreamingCountry
                        };
                        var result = await _userManager.CreateAsync(newUser);

                        if (!result.Succeeded)
                        {
                            foreach (var identityError in result.Errors)
                            {
                                _log.LogError(LoggingEvents.EmbyUserImporter, identityError.Description);
                            }
                            continue;
                        }
                        if (userManagementSettings.DefaultRoles.Any())
                        {
                            foreach (var defaultRole in userManagementSettings.DefaultRoles)
                            {
                                await _userManager.AddToRoleAsync(newUser, defaultRole);
                            }
                        }
                    }
                    else
                    {
                        // Do we need to update this user?
                        existingEmbyUser.UserName = embyUser.Name;

                        if (existingEmbyUser.IsEmbyConnect)
                        {
                            // Note: We do not have access to any of the emby connect details e.g. email
                            // Since we need the username and password to connect to emby connect,
                            // We update the email address in the OmbiUserManager when the emby connect user logs in
                            existingEmbyUser.UserName = embyUser.ConnectUserName;
                            existingEmbyUser.Alias    = embyUser.Name;
                        }

                        await _userManager.UpdateAsync(existingEmbyUser);
                    }
                }
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Emby User Importer Finished");
        }
示例#10
0
 private async Task StartEmby(EmbySettings s)
 {
     EmbyApi = _embyApiFactory.CreateClient(s);
     await StartEmbyMovies(s);
     await StartEmbyTv();
 }