Beispiel #1
0
        public async Task Execute(IJobExecutionContext job)
        {
            var jellyfinSettings = await _settings.GetSettingsAsync();

            if (!jellyfinSettings.Enable)
            {
                return;
            }

            Api = _apiFactory.CreateClient(jellyfinSettings);

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

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

                    _logger.LogError(e, "Exception when caching Jellyfin for server {0}", server.Name);
                }
            }
            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Content Sync Finished");

            // Episodes

            await OmbiQuartz.TriggerJob(nameof(IJellyfinEpisodeSync), "Jellyfin");
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TesterController" /> class.
 /// </summary>
 public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN,
                         IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
                         IPlexApi plex, IEmbyApiFactory emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger <TesterController> log, IEmailProvider provider,
                         ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, ILegacyMobileNotification mobileNotification,
                         ILidarrApi lidarrApi, IGotifyNotification gotifyNotification, IWhatsAppApi whatsAppApi, OmbiUserManager um, IWebhookNotification webhookNotification,
                         IJellyfinApi jellyfinApi)
 {
     Service                = service;
     DiscordNotification    = notification;
     EmailNotification      = emailN;
     PushbulletNotification = pushbullet;
     SlackNotification      = slack;
     PushoverNotification   = po;
     MattermostNotification = mm;
     PlexApi                = plex;
     RadarrApi              = radarr;
     EmbyApi                = emby;
     SonarrApi              = sonarr;
     Log                  = log;
     EmailProvider        = provider;
     CouchPotatoApi       = cpApi;
     TelegramNotification = telegram;
     SickRageApi          = srApi;
     Newsletter           = newsletter;
     MobileNotification   = mobileNotification;
     LidarrApi            = lidarrApi;
     GotifyNotification   = gotifyNotification;
     WhatsAppApi          = whatsAppApi;
     UserManager          = um;
     WebhookNotification  = webhookNotification;
     _jellyfinApi         = jellyfinApi;
 }
Beispiel #3
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, "Jellyfin Episode Sync Started");

            foreach (var server in settings.Servers)
            {
                if (server.JellyfinSelectedLibraries.Any() && server.JellyfinSelectedLibraries.Any(x => x.Enabled))
                {
                    var tvLibsToFilter = server.JellyfinSelectedLibraries.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, "Jellyfin Episode Sync Finished");

            _logger.LogInformation("Jellyfin Episode Sync Finished - Triggering Metadata refresh");
            await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System");
        }
    public async Task <Either <BaseError, List <JellyfinMovie> > > GetMovieLibraryItems(
        string address,
        string apiKey,
        int mediaSourceId,
        string libraryId)
    {
        try
        {
            if (_memoryCache.TryGetValue($"jellyfin_admin_user_id.{mediaSourceId}", out string userId))
            {
                IJellyfinApi service = RestService.For <IJellyfinApi>(address);
                JellyfinLibraryItemsResponse items = await service.GetMovieLibraryItems(apiKey, userId, libraryId);

                return(items.Items
                       .Map(ProjectToMovie)
                       .Somes()
                       .ToList());
            }

            return(BaseError.New("Jellyfin admin user id is not available"));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting jellyfin movie library items");
            return(BaseError.New(ex.Message));
        }
    }
    public async Task <Either <BaseError, List <JellyfinCollection> > > GetCollectionLibraryItems(
        string address,
        string apiKey,
        int mediaSourceId)
    {
        try
        {
            if (_memoryCache.TryGetValue($"jellyfin_admin_user_id.{mediaSourceId}", out string userId))
            {
                // TODO: should we enumerate collection libraries here?

                if (_memoryCache.TryGetValue("jellyfin_collections_library_item_id", out string itemId))
                {
                    IJellyfinApi service = RestService.For <IJellyfinApi>(address);
                    JellyfinLibraryItemsResponse items =
                        await service.GetCollectionLibraryItems(apiKey, userId, itemId);

                    return(items.Items
                           .Map(ProjectToCollection)
                           .Somes()
                           .ToList());
                }

                return(BaseError.New("Jellyfin collection item id is not available"));
            }

            return(BaseError.New("Jellyfin admin user id is not available"));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting jellyfin collection library items");
            return(BaseError.New(ex.Message));
        }
    }
Beispiel #6
0
 public LandingPageController(ISettingsService <PlexSettings> plex, ISettingsService <EmbySettings> emby,
                              IPlexApi plexApi, IEmbyApiFactory embyApi, ISettingsService <JellyfinSettings> jellyfin, IJellyfinApi jellyfinApi)
 {
     _plexSettings = plex;
     _embySettings = emby;
     _plexApi      = plexApi;
     _embyApi      = embyApi;
     _jellyfin     = jellyfin;
     _jellyfinApi  = jellyfinApi;
 }
    public async Task <Either <BaseError, List <JellyfinLibrary> > > GetLibraries(string address, string apiKey)
    {
        try
        {
            IJellyfinApi service = RestService.For <IJellyfinApi>(address);
            List <JellyfinLibraryResponse> libraries = await service.GetLibraries(apiKey);

            return(libraries
                   .Map(Project)
                   .Somes()
                   .ToList());
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting jellyfin libraries");
            return(BaseError.New(ex.Message));
        }
    }
Beispiel #8
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, "Jellyfin Episode Sync Started");

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

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

            _logger.LogInformation("Jellyfin Episode Sync Finished - Triggering Metadata refresh");
            await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System");
        }
    public async Task <Either <BaseError, string> > GetAdminUserId(string address, string apiKey)
    {
        try
        {
            IJellyfinApi service = RestService.For <IJellyfinApi>(address);
            List <JellyfinUserResponse> users = await service.GetUsers(apiKey);

            Option <string> maybeUserId = users
                                          .Filter(user => user.Policy.IsAdministrator)
                                          .Map(user => user.Id)
                                          .HeadOrNone();

            return(maybeUserId.ToEither(BaseError.New("Unable to locate jellyfin admin user")));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting jellyfin admin user id");
            return(BaseError.New(ex.Message));
        }
    }
 public async Task <Either <BaseError, JellyfinServerInformation> > GetServerInformation(
     string address,
     string apiKey)
 {
     try
     {
         IJellyfinApi service = RestService.For <IJellyfinApi>(address);
         var          cts     = new CancellationTokenSource();
         cts.CancelAfter(TimeSpan.FromSeconds(5));
         return(await service.GetSystemInformation(apiKey, cts.Token)
                .Map(response => new JellyfinServerInformation(response.ServerName, response.OperatingSystem)));
     }
     catch (OperationCanceledException ex)
     {
         _logger.LogError(ex, "Timeout getting jellyfin server name");
         return(BaseError.New("Jellyfin did not respond in time"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error getting jellyfin server name");
         return(BaseError.New(ex.Message));
     }
 }
Beispiel #11
0
 private async Task StartJellyfin(JellyfinSettings s)
 {
     JellyfinApi = _jellyfinApiFactory.CreateClient(s);
     await StartJellyfinMovies(s);
     await StartJellyfinTv();
 }
Beispiel #12
0
        public async Task Execute(IJobExecutionContext job)
        {
            var userManagementSettings = await _userManagementSettings.GetSettingsAsync();

            if (!userManagementSettings.ImportJellyfinUsers)
            {
                return;
            }
            var settings = await _jellyfinSettings.GetSettingsAsync();

            if (!settings.Enable)
            {
                return;
            }

            Api = _apiFactory.CreateClient(settings);

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

            var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.JellyfinUser).ToListAsync();

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

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

                foreach (var jellyfinUser in jellyfinUsers)
                {
                    // Check if we should import this user
                    if (userManagementSettings.BannedJellyfinUserIds.Contains(jellyfinUser.Id))
                    {
                        // Do not import these, they are not allowed into the country.
                        continue;
                    }
                    // Check if this Jellyfin User already exists
                    var existingJellyfinUser = allUsers.FirstOrDefault(x => x.ProviderUserId == jellyfinUser.Id);
                    if (existingJellyfinUser == null)
                    {
                        if (!jellyfinUser.Name.HasValue())
                        {
                            _log.LogInformation("Could not create Jellyfin user since the have no username, JellyfinUserId: {0}", jellyfinUser.Id);
                            continue;
                        }
                        // Create this users
                        var newUser = new OmbiUser
                        {
                            UserName            = jellyfinUser.Name,
                            UserType            = UserType.JellyfinUser,
                            ProviderUserId      = jellyfinUser.Id,
                            MovieRequestLimit   = userManagementSettings.MovieRequestLimit,
                            EpisodeRequestLimit = userManagementSettings.EpisodeRequestLimit,
                            StreamingCountry    = userManagementSettings.DefaultStreamingCountry
                        };
                        _log.LogInformation("Creating Jellyfin user {0}", newUser.UserName);
                        var result = await _userManager.CreateAsync(newUser);

                        if (!result.Succeeded)
                        {
                            foreach (var identityError in result.Errors)
                            {
                                _log.LogError(LoggingEvents.JellyfinUserImporter, 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?
                        existingJellyfinUser.UserName = jellyfinUser.Name;

                        await _userManager.UpdateAsync(existingJellyfinUser);
                    }
                }
            }

            await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
            .SendAsync(NotificationHub.NotificationEvent, "Jellyfin User Importer Finished");
        }