Ejemplo n.º 1
0
        public static Season ConvertToSeason(this BaseItemDto dto, Logger logger)
        {
            try
            {
                var season = new Season
                {
                    Id             = dto.Id,
                    Name           = dto.Name,
                    ParentId       = dto.ParentId,
                    Path           = dto.Path,
                    DateCreated    = dto.DateCreated,
                    IndexNumber    = dto.IndexNumber,
                    IndexNumberEnd = dto.IndexNumberEnd,
                    PremiereDate   = dto.PremiereDate,
                    ProductionYear = dto.ProductionYear,
                    SortName       = dto.SortName,
                    LocationType   = LocationType.Disk
                };

                dto.MapImageTags(season);

                return(season);
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                logger.Debug("Tried to convert Season");
                logger.Debug(JsonConvert.SerializeObject(dto));
                return(null);
            }
        }
        public void MapImageTags_Should_Not_Map_Images()
        {
            var dto   = new BaseItemDto();
            var video = new Video();

            dto.MapImageTags(video);

            video.Logo.Should().BeNull();
            video.Banner.Should().BeNull();
            video.Thumb.Should().BeNull();
            video.Banner.Should().BeNull();
        }
Ejemplo n.º 3
0
        public static Movie ConvertToMovie(this BaseItemDto dto, string collectionId, Logger logger)
        {
            try
            {
                var movie = new Movie
                {
                    Id            = dto.Id,
                    CollectionId  = collectionId,
                    Name          = dto.Name,
                    ParentId      = dto.ParentId,
                    OriginalTitle = dto.OriginalTitle,
                    DateCreated   = dto.DateCreated,
                    Path          = dto.Path,
                    SortName      = dto.SortName,
                    MediaSources  = dto.MediaSources.Select(y => new MediaSource
                    {
                        Id           = y.Id,
                        Path         = y.Path,
                        BitRate      = y.Bitrate,
                        Container    = y.Container,
                        Protocol     = y.Protocol.ToString(),
                        RunTimeTicks = y.RunTimeTicks,
                        SizeInMb     = Math.Round(y.Size / (double)1024 / 1024 ?? 0, MidpointRounding.AwayFromZero)
                    }).ToList(),
                    RunTimeTicks    = dto.RunTimeTicks,
                    Container       = dto.Container,
                    CommunityRating = dto.CommunityRating,
                    MediaType       = dto.MediaType,
                    OfficialRating  = dto.OfficialRating,
                    PremiereDate    = dto.PremiereDate,
                    ProductionYear  = dto.ProductionYear,
                    Video3DFormat   = dto.Video3DFormat ?? 0,
                    Genres          = dto.Genres,
                };

                dto.MapImageTags(movie);
                dto.MapPeople(movie);
                dto.MapProviderIds(movie);
                dto.MapStreams(movie);
                dto.MapMediaSources(movie);

                return(movie);
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                logger.Debug("Tried to convert Movie");
                logger.Debug(JsonConvert.SerializeObject(dto));
                return(null);
            }
        }
        public void MapImageTags_Should_Map_To_Empty_Images()
        {
            var dto = new BaseItemDto {
                ImageTags = new Dictionary <ImageType, string>()
            };
            var video = new Video();

            dto.MapImageTags(video);

            video.Logo.Should().BeEmpty();
            video.Banner.Should().BeEmpty();
            video.Thumb.Should().BeEmpty();
            video.Banner.Should().BeEmpty();
        }
        public void MapImageTags_Should_Map_Images()
        {
            var dto = new BaseItemDto {
                ImageTags = new Dictionary <ImageType, string>()
                {
                    { ImageType.Banner, "banner" },
                    { ImageType.Logo, "logo" },
                    { ImageType.Thumb, "thumb" },
                    { ImageType.Primary, "primary" }
                }
            };
            var video = new Video();

            dto.MapImageTags(video);

            video.Logo.Should().Be("logo");
            video.Banner.Should().Be("banner");
            video.Thumb.Should().Be("thumb");
            video.Primary.Should().Be("primary");
        }
Ejemplo n.º 6
0
        public static Episode ConvertToEpisode(this BaseItemDto dto, string showId, Logger logger)
        {
            try
            {
                var episode = new Episode
                {
                    Id              = Guid.NewGuid().ToString(),
                    ShowId          = showId,
                    LocationType    = LocationType.Disk,
                    Name            = dto.Name,
                    Path            = dto.Path,
                    ParentId        = dto.ParentId,
                    CommunityRating = dto.CommunityRating,
                    Container       = dto.Container,
                    DateCreated     = dto.DateCreated,
                    IndexNumber     = dto.IndexNumber,
                    IndexNumberEnd  = dto.IndexNumberEnd,
                    MediaType       = dto.Type,
                    ProductionYear  = dto.ProductionYear,
                    PremiereDate    = dto.PremiereDate,
                    RunTimeTicks    = dto.RunTimeTicks,
                    SortName        = dto.SortName,
                    ShowName        = dto.SeriesName
                };

                dto.MapImageTags(episode);
                dto.MapProviderIds(episode);
                dto.MapStreams(episode);
                dto.MapMediaSources(episode);

                return(episode);
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                logger.Debug("Tried to convert Episode");
                logger.Debug(JsonConvert.SerializeObject(dto));
                return(null);
            }
        }
Ejemplo n.º 7
0
        public static Show ConvertToShow(this BaseItemDto dto, string libraryId, Logger logger)
        {
            try
            {
                var show = new Show
                {
                    Id              = dto.Id,
                    CollectionId    = libraryId,
                    Name            = dto.Name,
                    ParentId        = dto.ParentId,
                    Path            = dto.Path,
                    CommunityRating = dto.CommunityRating,
                    DateCreated     = dto.DateCreated,
                    OfficialRating  = dto.OfficialRating,
                    PremiereDate    = dto.PremiereDate,
                    ProductionYear  = dto.ProductionYear,
                    RunTimeTicks    = dto.RunTimeTicks,
                    SortName        = dto.SortName,
                    Status          = dto.Status,
                    Genres          = dto.Genres,
                    Seasons         = new List <Season>(),
                    Episodes        = new List <Episode>()
                };

                dto.MapPeople(show);
                dto.MapImageTags(show);
                dto.MapProviderIds(show);

                return(show);
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                logger.Debug("Tried to convert Show");
                logger.Debug(JsonConvert.SerializeObject(dto));
                return(null);
            }
        }