예제 #1
0
        public SearchModule(ICacheProvider cache, ISettingsService <CouchPotatoSettings> cpSettings,
                            ISettingsService <PlexRequestSettings> prSettings, IAvailabilityChecker checker,
                            IRequestService request, ISonarrApi sonarrApi, ISettingsService <SonarrSettings> sonarrSettings,
                            ISettingsService <SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
                            INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService <HeadphonesSettings> hpService,
                            ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi,
                            ISettingsService <PlexSettings> plexService, ISettingsService <AuthenticationSettings> auth, IRepository <UsersToNotify> u, ISettingsService <EmailNotificationSettings> email) : base("search", prSettings)
        {
            Auth                      = auth;
            PlexService               = plexService;
            PlexApi                   = plexApi;
            CpService                 = cpSettings;
            PrService                 = prSettings;
            MovieApi                  = new TheMovieDbApi();
            Cache                     = cache;
            Checker                   = checker;
            CpCacher                  = cpCacher;
            SonarrCacher              = sonarrCacher;
            SickRageCacher            = sickRageCacher;
            RequestService            = request;
            SonarrApi                 = sonarrApi;
            SonarrService             = sonarrSettings;
            CouchPotatoApi            = cpApi;
            SickRageService           = sickRageService;
            SickrageApi               = srApi;
            NotificationService       = notify;
            MusicBrainzApi            = mbApi;
            HeadphonesApi             = hpApi;
            HeadphonesService         = hpService;
            UsersToNotifyRepo         = u;
            EmailNotificationSettings = email;


            Get["/", true] = async(x, ct) => await RequestLoad();

            Get["movie/{searchTerm}", true] = async(x, ct) => await SearchMovie((string)x.searchTerm);

            Get["tv/{searchTerm}", true] = async(x, ct) => await SearchTvShow((string)x.searchTerm);

            Get["music/{searchTerm}", true] = async(x, ct) => await SearchMusic((string)x.searchTerm);

            Get["music/coverArt/{id}"] = p => GetMusicBrainzCoverArt((string)p.id);

            Get["movie/upcoming", true] = async(x, ct) => await UpcomingMovies();

            Get["movie/playing", true] = async(x, ct) => await CurrentlyPlayingMovies();

            Post["request/movie", true] = async(x, ct) => await RequestMovie((int)Request.Form.movieId);

            Post["request/tv", true] = async(x, ct) => await RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);

            Post["request/album", true] = async(x, ct) => await RequestAlbum((string)Request.Form.albumId);

            Post["/notifyuser", true] = async(x, ct) => await NotifyUser((bool)Request.Form.notify);

            Get["/notifyuser", true] = async(x, ct) => await GetUserNotificationSettings();

            Get["/seasons"] = x => GetSeasons();
        }
예제 #2
0
        public ActionResult Search(string title, int page = 1)
        {
            var movieList = TheMovieDbApi.SearchMovie(title, page);
            var genres    = TheMovieDbApi.GetGenres();

            ViewBag.Title = title;
            return(View(Tuple.Create(movieList, genres)));
        }
예제 #3
0
        public ActionResult View(int id)
        {
            var movie  = TheMovieDbApi.GetMovie(id);
            var videos = TheMovieDbApi.ListVideos(id);

            ViewBag.Title = movie.title;
            return(View(Tuple.Create(movie, videos)));
        }
예제 #4
0
        public ActionResult Index()
        {
            var genres     = TheMovieDbApi.GetGenres();
            var listMovies = TheMovieDbApi.DiscoverMovies();

            ViewBag.Title = "Página principal";
            return(View(Tuple.Create(genres, listMovies)));
        }
예제 #5
0
        public async Task <JsonResult> Autocomplete(string term)
        {
            TheMovieDbApi _themovieapi = new TheMovieDbApi();
            List <Movie>  movies       = await _themovieapi.GetSuggestions(term);

            var suggestions = _themovieapi.ReturnSuggestions(movies, term);

            return(Json(suggestions, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public ActionResult Category(int page, int id)
        {
            var movieList = TheMovieDbApi.DiscoverMovies(page, id.ToString(), "");
            var genres    = TheMovieDbApi.GetGenres();
            var genre     = genres.genres.Find(x => x.id == id);

            ViewBag.Title = genre.name;
            ViewBag.id    = genre.id;
            return(View(Tuple.Create(movieList, genres)));
        }
예제 #7
0
 public PlexRecentlyAddedNewsletter(IPlexApi api, ISettingsService <PlexSettings> plexSettings,
                                    ISettingsService <EmailNotificationSettings> email,
                                    ISettingsService <NewletterSettings> newsletter, IRepository <RecentlyAddedLog> log,
                                    IRepository <PlexContent> embyContent, IRepository <PlexEpisodes> episodes)
 {
     Api                = api;
     PlexSettings       = plexSettings;
     EmailSettings      = email;
     NewsletterSettings = newsletter;
     Content            = embyContent;
     MovieApi           = new TheMovieDbApi();
     TvApi              = new TvMazeApi();
     Episodes           = episodes;
     RecentlyAddedLog   = log;
 }
예제 #8
0
        public SearchModule(ICacheProvider cache, ISettingsService <CouchPotatoSettings> cpSettings,
                            ISettingsService <PlexRequestSettings> prSettings, IAvailabilityChecker checker,
                            IRequestService request, ISonarrApi sonarrApi, ISettingsService <SonarrSettings> sonarrSettings,
                            ISettingsService <SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
                            INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService <HeadphonesSettings> hpService,
                            ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi,
                            ISettingsService <PlexSettings> plexService, ISettingsService <AuthenticationSettings> auth) : base("search")
        {
            Auth                = auth;
            PlexService         = plexService;
            PlexApi             = plexApi;
            CpService           = cpSettings;
            PrService           = prSettings;
            MovieApi            = new TheMovieDbApi();
            TvApi               = new TheTvDbApi();
            Cache               = cache;
            Checker             = checker;
            CpCacher            = cpCacher;
            SonarrCacher        = sonarrCacher;
            SickRageCacher      = sickRageCacher;
            RequestService      = request;
            SonarrApi           = sonarrApi;
            SonarrService       = sonarrSettings;
            CouchPotatoApi      = cpApi;
            SickRageService     = sickRageService;
            SickrageApi         = srApi;
            NotificationService = notify;
            MusicBrainzApi      = mbApi;
            HeadphonesApi       = hpApi;
            HeadphonesService   = hpService;


            Get["/"] = parameters => RequestLoad();

            Get["movie/{searchTerm}"]  = parameters => SearchMovie((string)parameters.searchTerm);
            Get["tv/{searchTerm}"]     = parameters => SearchTvShow((string)parameters.searchTerm);
            Get["music/{searchTerm}"]  = parameters => SearchMusic((string)parameters.searchTerm);
            Get["music/coverArt/{id}"] = p => GetMusicBrainzCoverArt((string)p.id);

            Get["movie/upcoming"] = parameters => UpcomingMovies();
            Get["movie/playing"]  = parameters => CurrentlyPlayingMovies();

            Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId);
            Post["request/tv"]    = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);
            Post["request/album"] = parameters => RequestAlbum((string)Request.Form.albumId);
        }
예제 #9
0
        private Response RequestMovie(int movieId)
        {
            var movieApi      = new TheMovieDbApi();
            var movieInfo     = movieApi.GetMovieInformation(movieId).Result;
            var fullMovieName = $"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";

            Log.Trace("Getting movie info from TheMovieDb");
            Log.Trace(movieInfo.DumpJson);
            //#if !DEBUG

            var settings = PrService.GetSettings();

            // check if the movie has already been requested
            Log.Info("Requesting movie with id {0}", movieId);
            var existingRequest = RequestService.CheckRequest(movieId);

            if (existingRequest != null)
            {
                // check if the current user is already marked as a requester for this movie, if not, add them
                if (!existingRequest.UserHasRequested(Username))
                {
                    existingRequest.RequestedUsers.Add(Username);
                    RequestService.UpdateRequest(existingRequest);
                }

                return(Response.AsJson(new JsonResponseModel {
                    Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{fullMovieName} was successfully added!" : $"{fullMovieName} has already been requested!"
                }));
            }

            Log.Debug("movie with id {0} doesnt exists", movieId);

            try
            {
                var movies = Checker.GetPlexMovies();
                if (Checker.IsMovieAvailable(movies.ToArray(), movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString()))
                {
                    return(Response.AsJson(new JsonResponseModel {
                        Result = false, Message = $"{fullMovieName} is already in Plex!"
                    }));
                }
            }
            catch (ApplicationSettingsException)
            {
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = $"We could not check if {fullMovieName} is in Plex, are you sure it's correctly setup?"
                }));
            }
            //#endif

            var model = new RequestedModel
            {
                ProviderId     = movieInfo.Id,
                Type           = RequestType.Movie,
                Overview       = movieInfo.Overview,
                ImdbId         = movieInfo.ImdbId,
                PosterPath     = "http://image.tmdb.org/t/p/w150/" + movieInfo.PosterPath,
                Title          = movieInfo.Title,
                ReleaseDate    = movieInfo.ReleaseDate ?? DateTime.MinValue,
                Status         = movieInfo.Status,
                RequestedDate  = DateTime.UtcNow,
                Approved       = false,
                RequestedUsers = new List <string> {
                    Username
                },
                Issues = IssueState.None,
            };

            Log.Trace(settings.DumpJson());
            if (ShouldAutoApprove(RequestType.Movie, settings))
            {
                var cpSettings = CpService.GetSettings();

                Log.Trace("Settings: ");
                Log.Trace(cpSettings.DumpJson);
                if (cpSettings.Enabled)
                {
                    Log.Info("Adding movie to CP (No approval required)");
                    var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title,
                                                         cpSettings.FullUri, cpSettings.ProfileId);
                    Log.Debug("Adding movie to CP result {0}", result);
                    if (result)
                    {
                        model.Approved = true;
                        Log.Info("Adding movie to database (No approval required)");
                        RequestService.AddRequest(model);


                        if (ShouldSendNotification())
                        {
                            var notificationModel = new NotificationModel
                            {
                                Title            = model.Title,
                                User             = Username,
                                DateTime         = DateTime.Now,
                                NotificationType = NotificationType.NewRequest
                            };
                            NotificationService.Publish(notificationModel);
                        }
                        return(Response.AsJson(new JsonResponseModel {
                            Result = true, Message = $"{fullMovieName} was successfully added!"
                        }));
                    }
                    return
                        (Response.AsJson(new JsonResponseModel
                    {
                        Result = false,
                        Message =
                            "Something went wrong adding the movie to CouchPotato! Please check your settings."
                    }));
                }
                else
                {
                    model.Approved = true;
                    Log.Info("Adding movie to database (No approval required)");
                    RequestService.AddRequest(model);

                    if (ShouldSendNotification())
                    {
                        var notificationModel = new NotificationModel
                        {
                            Title            = model.Title,
                            User             = Username,
                            DateTime         = DateTime.Now,
                            NotificationType = NotificationType.NewRequest
                        };
                        NotificationService.Publish(notificationModel);
                    }

                    return(Response.AsJson(new JsonResponseModel {
                        Result = true, Message = $"{fullMovieName} was successfully added!"
                    }));
                }
            }

            try
            {
                Log.Info("Adding movie to database");
                var id = RequestService.AddRequest(model);

                var notificationModel = new NotificationModel {
                    Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest
                };
                NotificationService.Publish(notificationModel);

                return(Response.AsJson(new JsonResponseModel {
                    Result = true, Message = $"{fullMovieName} was successfully added!"
                }));
            }
            catch (Exception e)
            {
                Log.Fatal(e);

                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings."
                }));
            }
        }
예제 #10
0
        private async Task <Response> ReportNonRequestIssue(int providerId, string type, IssueState issue, string comment)
        {
            var currentIssues = await IssuesService.GetAllAsync();

            var notifyModel = new NotificationModel
            {
                User             = Username,
                NotificationType = NotificationType.Issue,
                DateTime         = DateTime.Now,
                Body             = issue == IssueState.Other ? comment : issue.ToString().ToCamelCaseWords()
            };
            var model = new IssueModel
            {
                Issue        = issue,
                UserReported = Username,
                UserNote     = !string.IsNullOrEmpty(comment)
                ? $"{Username} - {comment}"
                : string.Empty,
            };

            var existing = currentIssues.FirstOrDefault(x => x.ProviderId == providerId && !x.Deleted && x.IssueStatus == IssueStatus.PendingIssue);

            if (existing != null)
            {
                existing.Issues.Add(model);
                await IssuesService.UpdateIssueAsync(existing);

                return(Response.AsJson(new JsonResponseModel {
                    Result = true
                }));
            }

            if (type == "movie")
            {
                var movieApi = new TheMovieDbApi();

                var result = await movieApi.GetMovieInformation(providerId);

                if (result != null)
                {
                    notifyModel.Title = result.Title;
                    // New issue
                    var issues = new IssuesModel
                    {
                        Title       = result.Title,
                        PosterUrl   = "https://image.tmdb.org/t/p/w150/" + result.PosterPath,
                        ProviderId  = providerId,
                        Type        = RequestType.Movie,
                        IssueStatus = IssueStatus.PendingIssue
                    };
                    issues.Issues.Add(model);

                    var issueId = await IssuesService.AddIssueAsync(issues);

                    await NotificationService.Publish(notifyModel);

                    return(Response.AsJson(new JsonResponseModel {
                        Result = true
                    }));
                }
            }

            if (type == "tv")
            {
                var tv     = new TvMazeApi();
                var result = tv.ShowLookupByTheTvDbId(providerId);
                if (result != null)
                {
                    var banner = result.image?.medium;
                    if (!string.IsNullOrEmpty(banner))
                    {
                        banner = banner.Replace("http", "https");
                    }

                    notifyModel.Title = result.name;
                    // New issue
                    var issues = new IssuesModel
                    {
                        Title       = result.name,
                        PosterUrl   = banner,
                        ProviderId  = providerId,
                        Type        = RequestType.TvShow,
                        IssueStatus = IssueStatus.PendingIssue
                    };
                    issues.Issues.Add(model);

                    var issueId = await IssuesService.AddIssueAsync(issues);

                    await NotificationService.Publish(notifyModel);

                    return(Response.AsJson(new JsonResponseModel {
                        Result = true
                    }));
                }
            }



            return(Response.AsJson(new JsonResponseModel {
                Result = false, Message = "Album Reports are not supported yet!"
            }));
        }