Пример #1
0
        public List <CastMember> GetCast(string id)
        {
            var show = id.StartsWith("tt")
                ? GetShows().FirstOrDefault(s => s.ExternalIds.ImdbId == id)
                : GetShows().FirstOrDefault(s => s.Id == id);

            return(show != null?TvMazeService.GetCast(show.Id) : null);
        }
Пример #2
0
        public static ITvShow FindShow(string query, string locale, bool localOnly = false)
        {
            query = FixQuery(query);
            var searchResults = FindShowLocally(query).ToList();

            if (!localOnly)
            {
                searchResults = searchResults.Concat(TvMazeService.FindShow(query)).ToList();
            }
            searchResults.ForEach(x => x.Score = CalcLevenshteinDistance(x.Show.Name.ToLower(), query.ToLower()));
            var result = searchResults.Any() ? searchResults.OrderBy(x => x.Score).First().Show : null;

            return(result);
        }
Пример #3
0
        public static void StoreShows()
        {
            var tasks = new List <Task>();

            for (var i = 0; i < int.MaxValue; i++)
            {
                try
                {
                    var response = TvMazeService.GetShows(i.ToString());
                    tasks.AddRange(response.Where(x => x.Language == "English").Select(x => DocumentRepository <TvShow> .CreateItemAsync((TvShow)x)));
                }
                catch (Exception)
                {
                    break;
                }
            }

            Task.Run(() => tasks);
        }
        public static AlexaResponse GetTvShowResponse(string intent, AlexaRequest request)
        {
            var showName = GetSlotValue(request, "showtitle");

            if (string.IsNullOrEmpty(showName))
            {
                return(new AlexaResponse("Sorry, I didn't hear a show name.", "Show not found"));
            }


            var show = TvInfoService.FindShow(showName, request.Request.Locale);

            if (show == null)
            {
                return(new AlexaResponse($"Sorry, I wasn't able to find the show '{showName}', please try again.", "Show not found"));
            }

            string     showId;
            ITvService tvService;

            if (request.Request.Locale == "en-GB")
            {
                showId    = show.ExternalIds.ImdbId;
                tvService = new ImdbService();
            }
            else
            {
                showId    = show.Id;
                tvService = new TvMazeService();
            }

            using (var tvInfoService = new TvInfoService(tvService))
            {
                switch (intent)
                {
                case "ShowSynopsisIntent":
                    return(GetSynopsis(show.Name, show.Summary));

                case "ShowStartIntent":
                {
                    var originalAirDate = tvInfoService.GetStartDate(showId);
                    return(GetStartDate(show.Name, originalAirDate));
                }

                case "ShowNextEpisodeIntent":
                {
                    var episode = show.Status == "Ended"
                                ? tvInfoService.GetLastEpisodeAirDate(showId)
                                : tvInfoService.GetNextEpisodeAirDate(showId);
                    return(GetNextEpisode(show.Name, show.Status, episode));
                }

                case "ShowCastIntent":
                {
                    var personName = GetSlotValue(request, "person");
                    if (!string.IsNullOrEmpty(personName))
                    {
                        var person = tvInfoService.GetCharacter(showId, personName);
                        return(GetPerson(show.Name, personName, person));
                    }

                    var characterName = GetSlotValue(request, "character");
                    if (!string.IsNullOrEmpty(characterName))
                    {
                        var person = tvInfoService.GetActor(showId, characterName);
                        return(GetCharacter(show.Name, characterName, person));
                    }

                    var cast = tvInfoService.GetCast(showId);
                    return(GetCast(show.Name, cast));
                }
                }

                return(new AlexaResponse("Sorry, I don't know how to respond to your request.", "Unknown Intent"));
            }
        }