public MovieFileResource EnsureMovieFile(MovieResource movie, Quality quality)
        {
            var result = Movies.Get(movie.Id);

            if (result.MovieFile == null)
            {
                var path = Path.Combine(MovieRootFolder, movie.Title, string.Format("{0} ({1}) - {2}.strm", movie.Title, movie.Year, quality.Name));

                Directory.CreateDirectory(Path.GetDirectoryName(path));

                var sourcePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "ApiTests", "Files", "H264_sample.mp4");

                //File.Copy(sourcePath, path);
                File.WriteAllText(path, "Fake Movie");

                Commands.PostAndWait(new RefreshMovieCommand(new List <int> {
                    movie.Id
                }));
                Commands.WaitAll();

                result = Movies.Get(movie.Id);

                result.MovieFile.Should().NotBeNull();
            }

            return(result.MovieFile);
        }
Beispiel #2
0
        public static MovieFileResource ToResource(this MovieFile model)
        {
            if (model == null)
            {
                return(null);
            }

            MovieResource movie = null;

            /*if (model.Movie != null)
             * {
             *  //model.Movie.LazyLoad();
             *  if (model.Movie.Value != null)
             *  {
             *      //movie = model.Movie.Value.ToResource();
             *  }
             * }*/

            return(new MovieFileResource
            {
                Id = model.Id,
                RelativePath = model.RelativePath,
                Path = model.Path,
                Size = model.Size,
                DateAdded = model.DateAdded,
                SceneName = model.SceneName,
                ReleaseGroup = model.ReleaseGroup,
                Quality = model.Quality,
                Movie = movie,
                MediaInfo = model.MediaInfo,
                Edition = model.Edition
            });
        }
        public async Task CreateMovie_WhenAnExceptionIsThrownInTheDomainLayer_ShouldThrow()
        {
            // Arrange
            var expectedMessage   = "Some Exception Message";
            var expectedException = new DuplicateMovieException(expectedMessage);
            var moviesController  = new MovieControllerForTest(expectedException);
            var movieResource     = new MovieResource
            {
                Title    = "Some Title",
                Genre    = GenreParser.ToString(Genre.Action),
                ImageUrl = "Some Url",
                Year     = 1900
            };

            // Act
            try
            {
                await moviesController.CreateMovie(movieResource);

                Assert.Fail("We were expecting an exception of type: DuplicateMovieException to be thrown, but no exception was thrown");
            }
            catch (DuplicateMovieException e)
            {
                // Assert
                Assert.AreEqual(expectedMessage, e.Message);
            }
        }
        public async Task <ActionResult> CreateMovie([FromBody] MovieResource movieResource)
        {
            var movie = ModelToResourceMapper.MapToMovie(movieResource);
            var newId = await CreateMovie(movie);

            return(CreatedAtAction(nameof(GetMovie), new { Id = newId }, movieResource));
        }
 public static Movie MapToMovie(MovieResource movieResource)
 {
     return(new Movie(
                title: movieResource.Title,
                imageUrl: movieResource.ImageUrl,
                genre: GenreParser.Parse(movieResource.Genre),
                year: movieResource.Year));
 }
Beispiel #6
0
        public void should_be_able_to_add_to_blacklist()
        {
            _movie = EnsureMovie(11, "The Blacklist");

            Blacklist.Post(new Api.Blacklist.BlacklistResource
            {
                MovieId     = _movie.Id,
                SourceTitle = "Blacklist.S01E01.Brought.To.You.By-BoomBoxHD"
            });
        }
Beispiel #7
0
        private Movie MapSearchResult(MovieResource result)
        {
            var movie = _movieService.FindByTmdbId(result.TmdbId);

            if (movie == null)
            {
                movie = MapMovie(result);
            }
            else
            {
                movie.Translations = _movieTranslationService.GetAllTranslationsForMovie(movie.Id);
            }

            return(movie);
        }
        public async Task CreateMovie_WhenProvidedWithAValidMovieResource_Succeeds()
        {
            // Arrange
            var movieResource = new MovieResource
            {
                Title    = "Some Title",
                Genre    = GenreParser.ToString(Genre.Action),
                ImageUrl = "Some Url",
                Year     = 1900
            };

            var moviesController = new MovieControllerForTest(movies: null);

            // Act
            await moviesController.CreateMovie(movieResource);

            // Assert
            // Nothing to Assert
            Assert.IsTrue(true);
        }
Beispiel #9
0
        public MovieFileResource EnsureMovieFile(MovieResource movie, Quality quality)
        {
            var result = Movies.Get(movie.Id);

            if (result.MovieFile == null)
            {
                var path = Path.Combine(MovieRootFolder, movie.Title, string.Format("{0} - {1}.mkv", movie.Title, quality.Name));

                Directory.CreateDirectory(Path.GetDirectoryName(path));
                File.WriteAllText(path, "Fake Movie");

                Commands.PostAndWait(new CommandResource {
                    Name = "refreshmovie", Body = new RefreshMovieCommand(movie.Id)
                });
                Commands.WaitAll();

                result = Movies.Get(movie.Id);

                result.MovieFile.Should().NotBeNull();
            }

            return(result.MovieFile);
        }
Beispiel #10
0
        public IActionResult Put(int id, [FromBody] MovieResource model)
        {
            if (model == null || id != model.Id)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var    obj     = mapper.Map <Movie>(model);
            string message = string.Empty;

            if (movieService.Save(obj, ref message))
            {
                return(Ok("Success"));
            }
            else
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #11
0
        public Movie MapMovie(MovieResource resource)
        {
            var movie     = new Movie();
            var altTitles = new List <AlternativeTitle>();

            movie.TmdbId        = resource.TmdbId;
            movie.ImdbId        = resource.ImdbId;
            movie.Title         = resource.Title;
            movie.OriginalTitle = resource.OriginalTitle;
            movie.TitleSlug     = resource.TitleSlug;
            movie.CleanTitle    = resource.Title.CleanMovieTitle();
            movie.SortTitle     = Parser.Parser.NormalizeTitle(resource.Title);
            movie.Overview      = resource.Overview;

            movie.AlternativeTitles.AddRange(resource.AlternativeTitles.Select(MapAlternativeTitle));

            movie.Translations.AddRange(resource.Translations.Select(MapTranslation));

            movie.OriginalLanguage = IsoLanguages.Find(resource.OriginalLanguage.ToLower())?.Language ?? Language.English;

            movie.Website         = resource.Homepage;
            movie.InCinemas       = resource.InCinema;
            movie.PhysicalRelease = resource.PhysicalRelease;
            movie.DigitalRelease  = resource.DigitalRelease;

            movie.Year = resource.Year;

            //If the premier differs from the TMDB year, use it as a secondary year.
            if (resource.Premier.HasValue && resource.Premier?.Year != movie.Year)
            {
                movie.SecondaryYear = resource.Premier?.Year;
            }

            movie.Images = resource.Images.Select(MapImage).ToList();

            if (resource.Runtime != null)
            {
                movie.Runtime = resource.Runtime.Value;
            }

            var certificationCountry = _configService.CertificationCountry.ToString();

            movie.Certification   = resource.Certifications.FirstOrDefault(m => m.Country == certificationCountry)?.Certification;
            movie.Ratings         = resource.Ratings.Select(MapRatings).FirstOrDefault() ?? new Ratings();
            movie.Genres          = resource.Genres;
            movie.Recommendations = resource.Recommendations?.Select(r => r.TmdbId).ToList() ?? new List <int>();

            var now = DateTime.Now;

            movie.Status = MovieStatusType.Announced;

            if (resource.InCinema.HasValue && now > resource.InCinema)
            {
                movie.Status = MovieStatusType.InCinemas;

                if (!resource.PhysicalRelease.HasValue && !resource.DigitalRelease.HasValue && now > resource.InCinema.Value.AddDays(90))
                {
                    movie.Status = MovieStatusType.Released;
                }
            }

            if (resource.PhysicalRelease.HasValue && now >= resource.PhysicalRelease)
            {
                movie.Status = MovieStatusType.Released;
            }

            if (resource.DigitalRelease.HasValue && now >= resource.DigitalRelease)
            {
                movie.Status = MovieStatusType.Released;
            }

            movie.YouTubeTrailerId = resource.YoutubeTrailerId;
            movie.Studio           = resource.Studio;

            if (resource.Collection != null)
            {
                movie.Collection = new MovieCollection {
                    Name = resource.Collection.Name, TmdbId = resource.Collection.TmdbId
                };
            }

            return(movie);
        }
Beispiel #12
0
        private Response SaveAll()
        {
            var resources = Request.Body.FromJson <List <MovieResource> >();

            var Movies = resources.Select(MovieResource => _movieSearch.MapMovieToTmdbMovie(MovieResource.ToModel())).Where(m => m != null).DistinctBy(m => m.TmdbId).ToList();

            return(_movieService.AddMovies(Movies).ToResource().AsResponse(HttpStatusCode.Accepted));
        }