public void FindTest()
        {
            var fileInfo = new FileInfo(
                Path.Combine(
                    settings.Object.Value.MediaLibraryPath,
                    "TV Shows",
                    "The Big Bang Theory",
                    "Season 01",
                    "The Big Bang Theory - S10E01 - The Conjugal Conjecture.mp4"));

            fileInfo.Directory.Create();
            File.WriteAllText(fileInfo.FullName, "abcd");

            var repo = new MediaItemRepository(logger.Object, settings.Object);

            var file = repo.Find(
                "TV Shows/The Big Bang Theory/Season 01/The Big Bang Theory - S10E01 - The Conjugal Conjecture.mp4");

            Assert.AreEqual(file.Parent, "TV Shows/The Big Bang Theory/Season 01");
            Assert.AreEqual(4, file.Size);


            var dir = repo.Find("TV Shows/The Big Bang Theory/Season 01");

            Assert.AreEqual(dir.Parent, "TV Shows/The Big Bang Theory");
            Assert.Null(dir.Size);

            Assert.Null(repo.Find("TV Shows/inexistant_file.mkc"));
            Assert.Null(repo.Find(""));
            Assert.Null(repo.Find(".."));
        }
        public void FindAllTest()
        {
            var fileInfo = new FileInfo(Path.Combine(settings.Object.Value.MediaLibraryPath, "TV Shows", "The Big Bang Theory", "Season 01", "The Big Bang Theory - S10E01 - The Conjugal Conjecture.mp4"));

            fileInfo.Directory.Create();
            File.WriteAllText(fileInfo.FullName, "abcd");

            var expectedItems = new List <PlainMediaItem>();

            expectedItems.AddRange(
                NetpipsSettings.MediaFolders.Select(
                    f => new PlainMediaItem(new DirectoryInfo(Path.Combine(settings.Object.Value.MediaLibraryPath, f)), settings.Object.Value.MediaLibraryPath)));
            expectedItems.Add(
                new PlainMediaItem(
                    new DirectoryInfo(Path.Combine(settings.Object.Value.MediaLibraryPath, "TV Shows", "The Big Bang Theory")),
                    settings.Object.Value.MediaLibraryPath));
            expectedItems.Add(
                new PlainMediaItem(
                    new DirectoryInfo(Path.Combine(settings.Object.Value.MediaLibraryPath, "TV Shows", "The Big Bang Theory", "Season 01")),
                    settings.Object.Value.MediaLibraryPath));
            expectedItems.Add(new PlainMediaItem(fileInfo, settings.Object.Value.MediaLibraryPath));

            var repo = new MediaItemRepository(logger.Object, settings.Object);

            var items = repo.FindAll();

            Assert.That(items, Is.EquivalentTo(expectedItems).Using(new PlainMediaItem(fileInfo, settings.Object.Value.MediaLibraryPath)));
        }
Exemplo n.º 3
0
 public MediaItemMutations(
     MediaItemRepository mediaItemRepository,
     UserRepository userRepository
     )
 {
     this.MediaItemRepository = mediaItemRepository;
     this.UserRepository      = userRepository;
 }
Exemplo n.º 4
0
        public RootQueryGraphType(
            MovieRepository movieRepository,
            SourceRepository sourceRepository,
            LibraryGenerator libraryGenerator,
            MovieMetadataProcessor MovieMetadataProcessor,
            MediaItemRepository mediaItemRepository,
            UserRepository userRepository,
            MovieGraphType movieGraphType,
            DatabaseGraphType databaseGraphType
            )
        {
            this.Name = "Query";
            databaseGraphType.Register(this);

            Field <ListGraphType <MovieGraphType>, IEnumerable <Movie> >()
            .Name("movies")
            .Description("A list of movies")
            .Argument <ListGraphType <IntGraphType> >("ids", "A list of ids of the polls to fetch")
            .Argument <IntGraphType>("top", "Pick the top N results")
            .Argument <IntGraphType>("skip", "skip the first N results")
            .ResolveAsync(async(ctx) =>
            {
                var filters = movieRepository.GetArgumentFilters(ctx);
                var results = await movieRepository.Query(filters, ctx.SubFields.Keys);
                return(results);
            });

            Field <ListGraphType <SourceGraphType> >()
            .Name("sources")
            .Description("The sources of media for this library")
            .ResolveAsync(async(ctx) =>
            {
                var results = await sourceRepository.GetAll();
                return(results);
            });

            Field <LibraryGeneratorStatusGraphType>()
            .Name("libraryGeneratorStatus")
            .Description("The status of the library generator")
            .Resolve((ResolveFieldContext <object> ctx) =>
            {
                var status = libraryGenerator.GetStatus();
                return(status);
            });

            Field <ListGraphType <MovieMetadataSearchResultGraphType> >()
            .Name("movieMetadataSearchResults")
            .Description("A list of TMDB movie search results")
            .Argument <StringGraphType>("searchText", "The text to use to search for results")
            .ResolveAsync(async(ctx) =>
            {
                var searchText = ctx.GetArgument <string>("searchText");
                return(await MovieMetadataProcessor.GetSearchResultsAsync(searchText));
            });

            Field <MovieMetadataComparisonGraphType>()
            .Name("movieMetadataComparison")
            .Description("A comparison of a metadata search result to what is currently in the system")
            .Argument <IntGraphType>("tmdbId", "The TMDB of the incoming movie")
            .Argument <IntGraphType>("movieId", "The id of the current movie in the system")
            .ResolveAsync(async(ctx) =>
            {
                var tmdbId  = ctx.GetArgument <int>("tmdbId");
                var movieId = ctx.GetArgument <int>("movieId");
                return(await MovieMetadataProcessor.GetComparisonAsync(tmdbId, movieId));
            });

            Field <ListGraphType <MediaHistoryRecordGraphType> >().Name("mediaHistory")
            .Description("A list of media items consumed and their current progress and duration of viewing")
            .Argument <ListGraphType <IntGraphType> >("mediaItemIds", "A list of mediaItem IDs")
            .ResolveAsync(async(ctx) =>
            {
                var arguments = ctx.GetArguments(new MediaHistoryArguments());
                var results   = await mediaItemRepository.GetHistory(userRepository.CurrentProfileId, null, null, arguments.MediaItemIds);
                return(results);
            });

            Field <ListGraphType <MediaItemGraphType> >().Name("mediaItems")
            .Description("A list of media items (i.e. movies, shows, episodes, etc). This is a union graph type, so you must specify inline fragments ")
            .Argument <ListGraphType <IntGraphType> >("mediaItemIds", "A list of mediaItem IDs")
            .Argument <StringGraphType>("searchText", "A string to use to search for media items")
            .ResolveAsync(async(ctx) =>
            {
                var arguments = ctx.GetArguments(new MediaItemArguments());
                if (arguments.MediaItemIds != null)
                {
                    return(await mediaItemRepository.GetByIds(arguments.MediaItemIds));
                }
                else if (arguments.SearchText != null)
                {
                    return(await mediaItemRepository.GetSearchResults(arguments.SearchText));
                }
                else
                {
                    throw new Exception("No valid arguments provided");
                }
            });
        }
Exemplo n.º 5
0
 public MediaHistoryRecordMutations(
     MediaItemRepository mediaItemRepository
     )
 {
     this.MediaItemRepository = mediaItemRepository;
 }
Exemplo n.º 6
0
        public MovieGraphType(
            IDataLoaderContextAccessor dlca,
            MediaItemRepository mediaItemRepository,
            UserRepository userRepository,
            IDataLoaderContextAccessor dla
            )
        {
            this.Name = "Movie";
            Field(x => x.Id).Description("The ID of the video.");
            Field(x => x.Title).Description("The formal title of the movie. This is also known as the movie's name.");
            Field(x => x.SortTitle).Description("The title used to sort this movie.");
            Field(x => x.ShortSummary, nullable: true).Description("A short summary of the movie. This is shorter than the standard summary field.");
            Field(x => x.Summary, nullable: true).Description("The summary of the movie.");
            Field(x => x.Rating, nullable: true).Description("This is the MPAA rating for the video (i.e. 'PG', 'R', etc...");
            Field(x => x.ReleaseYear, nullable: true).Description("The year this movie was first released.");
            Field(x => x.RuntimeSeconds, nullable: true).Description("How long the movie is, in seconds.");
            Field(x => x.TmdbId, nullable: true).Description("TMDB (The Movie DataBase) ID for this movie.");
            Field(x => x.SourceId, nullable: true).Description("The Source ID for this movie.");
            Field(x => x.VideoUrl).Description("The full url to the video file. This is the file that will be used when streaming");
            Field <MediaTypeEnumGraphType>().Name("mediaType")
            .Description("The media type for this movie. Will always be the same value since all movies have the same media type")
            .Resolve(x => x.Source.MediaType);

            Field <ListGraphType <StringGraphType> >()
            .Name("posterUrls")
            .Description("Poster urls for the movie")
            .Argument <IntGraphType>("width", "The width of the poster. Can be 100 or 200")
            .Resolve((ctx) =>
            {
                var widthWhitelist = new List <int?> {
                    100, 200
                };
                var width = ctx.GetArgumentOrDefault("width", (int?)null);

                if (width != null && widthWhitelist.Contains(width) == false)
                {
                    throw new Exception("Invalid width. Must be one of " + JsonSerializer.Serialize(widthWhitelist));
                }

                var urls = ctx.Source.PosterUrls;
                if (width != null)
                {
                    urls = urls.Select(x => x.Replace(".jpg", $"w{width}.jpg"));
                }
                ;
                return(urls);
            });

            Field <ListGraphType <StringGraphType> >("backdropUrls", resolve: (context) =>
            {
                return(context.Source.BackdropUrls);
            });

            Field(x => x.CompletionSeconds).Description("The number of seconds at which time this video would be considered fully watched (i.e. the number of seconds at which time the credits start rolling).");
            Field <ListGraphType <MediaHistoryRecordGraphType> >().Name("history")
            .Description("The viewing history for this movie")
            .ResolveAsync(async(ctx) =>
            {
                var columnNames = ctx.SubFields.Keys;
                //manager.Media.PrefetchHistoryForMediaItem(manager.Users.CurrentProfileId, context.Source.Id);
                return(await mediaItemRepository.GetHistoryForMediaItem(userRepository.CurrentProfileId, ctx.Source.Id));
            });

            Field(x => x.ResumeSeconds).Description("If the user stopped in the middle of watching this video, resumeSeconds will be the number of seconds where playback should start back up. If the user has never watched this movie, or if they have already completely watched the movie, this field will be set to 0");
            Field(x => x.ProgressPercentage).Description("The percentage of the movie that the user watched");
        }