Ejemplo n.º 1
0
        /// <summary>
        /// Only include <see cref="PlexLibrary"/> related data based on the <see cref="PlexMediaType"/>.
        /// </summary>
        /// <param name="type">The <see cref="PlexMediaType"/> to use to include the related data.</param>
        /// <param name="includeServer">Optionally include the <see cref="PlexServer"/> this <see cref="PlexLibrary"/> belongs to.</param>
        /// <param name="includeMedia"></param>
        /// <param name="topLevelMediaOnly"></param>
        /// <returns>The <see cref="IQueryable"/> of <see cref="PlexLibrary"/>.</returns>
        protected IQueryable <PlexLibrary> GetPlexLibraryQueryableByType(PlexMediaType type, bool includeServer = false, bool includeMedia = false,
                                                                         bool topLevelMediaOnly = false)
        {
            var plexLibraryQuery = PlexLibraryQueryable;

            if (includeServer)
            {
                plexLibraryQuery = plexLibraryQuery.IncludeServer();
            }

            if (includeMedia)
            {
                switch (type)
                {
                case PlexMediaType.Movie:
                    return(plexLibraryQuery.IncludeMovies(topLevelMediaOnly));

                case PlexMediaType.TvShow:
                    return(plexLibraryQuery.IncludeTvShows(topLevelMediaOnly));

                default:
                    Log.Error($"PlexLibrary with MediaType {type} is currently not supported");
                    return(plexLibraryQuery);
                }
            }

            return(plexLibraryQuery);
        }
Ejemplo n.º 2
0
        public async Task <Result <byte[]> > GetThumbnailImage(int mediaId, PlexMediaType mediaType, int width = 0, int height = 0)
        {
            var thumbUrl = await _mediator.Send(new GetThumbUrlByPlexMediaIdQuery(mediaId, mediaType));

            if (thumbUrl.IsFailed)
            {
                return(thumbUrl.ToResult());
            }

            var plexServer = await _mediator.Send(new GetPlexServerByPlexMediaIdQuery(mediaId, mediaType));

            if (plexServer.IsFailed)
            {
                return(plexServer.ToResult());
            }

            var token = await _plexAuthenticationService.GetPlexServerTokenAsync(plexServer.Value.Id);

            if (token.IsFailed)
            {
                return(token.ToResult());
            }

            byte[] image = await _plexServiceApi.GetThumbnailAsync(thumbUrl.Value, token.Value, width, height);

            if (image == null || image.Length == 0)
            {
                return(Result.Fail("Failed to retrieve image."));
            }

            return(Result.Ok(image));
        }
Ejemplo n.º 3
0
        public async Task <Result> DownloadMediaAsync(List <int> mediaIds, PlexMediaType type, int libraryId, int accountId = 0)
        {
            await _signalRService.SendDownloadTaskCreationProgressUpdate(libraryId, 0, mediaIds.Count);

            for (int i = 0; i < mediaIds.Count; i++)
            {
                await DownloadMediaAsync(mediaIds[i], type, accountId);

                await _signalRService.SendDownloadTaskCreationProgressUpdate(libraryId, i, mediaIds.Count);
            }

            await _signalRService.SendDownloadTaskCreationProgressUpdate(libraryId, mediaIds.Count, mediaIds.Count);

            return(Result.Ok());
        }
Ejemplo n.º 4
0
        public async Task <Result <bool> > DownloadMediaAsync(int mediaId, PlexMediaType type, int plexAccountId = 0)
        {
            var result = await _folderPathService.CheckIfFolderPathsAreValid();

            if (result.IsFailed)
            {
                return(result);
            }

            switch (type)
            {
            case PlexMediaType.Movie:
                return(await DownloadMovieAsync(mediaId, plexAccountId));

            case PlexMediaType.TvShow:
                return(await DownloadTvShowAsync(mediaId, plexAccountId));

            case PlexMediaType.Season:
                return(await DownloadTvShowSeasonAsync(mediaId, plexAccountId));

            case PlexMediaType.Episode:
                return(await DownloadTvShowEpisodeAsync(mediaId, plexAccountId));

            case PlexMediaType.Music:
            case PlexMediaType.Album:
                return(Result.Fail("PlexMediaType was Music or Album, this is not yet supported").LogWarning());

            case PlexMediaType.None:
                return(Result.Fail("PlexMediaType was none in DownloadMediaAsync").LogWarning());

            case PlexMediaType.Unknown:
                return(Result.Fail("PlexMediaType was Unknown in DownloadMediaAsync").LogWarning());

            default:
                return(Result.Fail($"PlexMediaType defaulted with value {type.ToString()} in DownloadMediaAsync").LogWarning());
            }
        }
 public GetThumbUrlByPlexMediaIdQuery(int mediaId, PlexMediaType plexMediaType)
 {
     MediaId       = mediaId;
     PlexMediaType = plexMediaType;
 }
Ejemplo n.º 6
0
 public GetPlexServerByPlexMediaIdQuery(int mediaId, PlexMediaType plexMediaType)
 {
     MediaId       = mediaId;
     PlexMediaType = plexMediaType;
 }
Ejemplo n.º 7
0
        public static Faker <PlexLibrary> GetPlexLibrary(int serverId, int plexLibraryId, PlexMediaType type, int numberOfMedia = 0)
        {
            var plexLibrary = new Faker <PlexLibrary>()
                              .RuleFor(x => x.Id, f => plexLibraryId)
                              .RuleFor(x => x.Title, f => f.Company.CompanyName())
                              .RuleFor(x => x.Type, f => type)
                              .RuleFor(x => x.PlexServerId, f => serverId)
                              .RuleFor(x => x.UpdatedAt, f => f.Date.Recent());

            if (numberOfMedia == 0)
            {
                return(plexLibrary);
            }

            if (type == PlexMediaType.Movie)
            {
                var plexMovies = GetPlexMovies(plexLibraryId);
                plexLibrary.RuleFor(x => x.Movies, f => plexMovies.Generate(numberOfMedia).ToList());
            }

            if (type == PlexMediaType.TvShow)
            {
                var plexTvShows = GetPlexTvShows(plexLibraryId);
                plexLibrary.RuleFor(x => x.TvShows, f => plexTvShows.Generate(numberOfMedia).ToList());
            }

            return(plexLibrary);
        }