Ejemplo n.º 1
0
        public TvMazeSearchResult Serach(string showName)
        {
            try
            {
                var result = SearchShow(showName);

                if (result == null)
                {
                    return(new TvMazeSearchResult("Null object when deserialising data from TVMaze. Query url was: "));
                }

                if (result.Length < 1)
                {
                    return(new TvMazeSearchResult("No results found on TVMaze."));
                }
                else
                {
                    TvMazeShow show = result[0].show;
                    AddEpisodeInfo(show);
                    return(new TvMazeSearchResult(show));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(new TvMazeSearchResult(ex.Message));
            }
        }
Ejemplo n.º 2
0
        private static void TvSearchHandler(string queryTerm)
        {
            TVMazeClient tvMaze = new TVMazeClient();
            var          result = tvMaze.Serach(queryTerm);

            if (result.Found)
            {
                TvMazeShow    show   = result.Show;
                TvMazeEpisode lastEp = show.PrevEpisode;
                TvMazeEpisode nextEp = show.NextEpisode;
                string        line1  = $" 14{show.name} 15-- {Common.GenerateCommaList(show.schedule?.days)} {show.schedule?.time}  8(14{show.status}8) (14{show.network?.name}8)";
                Write(line1);
                string line2 = $"{CTRLK}14{CTRLB}Prev Episode {CTRLB}{CTRLK}15-- {lastEp?.airdate} {CTRLK}08({CTRLK}14{lastEp?.season}{CTRLK}08x{CTRLK}14{lastEp?.number}{CTRLK}08){CTRLK}14 - {lastEp?.name}";
                Write(line2);
                DateTime airing = Convert.ToDateTime(nextEp?.airstamp);
                TimeSpan span   = airing.Subtract(DateTime.UtcNow);
                if (nextEp != null && nextEp.HasAirDate)
                {
                    string line3 = $"{CTRLK}14{CTRLB}Next Episode {CTRLB}{CTRLK}15-- {nextEp.airdate} {CTRLK}08({CTRLK}14{nextEp.season}{CTRLK}08x{CTRLK}14{nextEp.number}{CTRLK}08){CTRLK}14 - {nextEp.name} - Airing in: {CTRLK}08{span.Days}{CTRLK}14 days {CTRLK}08{span.Hours}{CTRLK}14 hours {CTRLK}08{span.Minutes}{CTRLK}14 minutes {CTRLK}08{span.Seconds}{CTRLK}14 seconds";
                    Write(line3);
                }
            }
            else
            {
                Write(result.Message);
            }
        }
        public SearchTvShowQueryHandlerTests()
        {
            _show1 = CreateShow1();
            _show2 = CreateShow2();

            _tvMazeService = Substitute.For <ITvMazeService>();
            _subscriptionQueryDataSource = Substitute.For <ISubscriptionQueryDataSource>();
            _handler = new SearchTvShowQueryHandler(_tvMazeService, _subscriptionQueryDataSource);
        }
Ejemplo n.º 4
0
        public async Task <TvShowRequestBuilder> GetShowInfo(int id)
        {
            ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);

            DateTime.TryParse(ShowInfo.premiered, out DateTime dt);

            FirstAir = dt;

            // For some reason the poster path is always http
            PosterPath = ShowInfo.image?.medium.Replace("http:", "https:");

            return(this);
        }
Ejemplo n.º 5
0
        public async Task RunAsync(TvMazeShow tvMazeShow, IEnumerable <TvMazePerson> tvMazePersons)
        {
            var allActors = await GetDbActorsForShowAsync(tvMazePersons);

            var dbShow = new Show {
                Id = tvMazeShow.Id, Name = tvMazeShow.Name
            };

            dbShow.ShowActors = GetDbRelations(allActors, dbShow);

            await _dbContext.Shows.AddAsync(dbShow);

            await _dbContext.SaveChangesAsync();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds next and previous episode information into the given show
        /// </summary>
        /// <param name="show"></param>
        private void AddEpisodeInfo(TvMazeShow show)
        {
            try
            {
                if (show?._links != null)
                {
                    if (!string.IsNullOrWhiteSpace(show._links.previousepisode?.href))
                    {
                        try
                        {
                            string        prevousEpisode  = GetResponseFromUrl(show?._links?.previousepisode?.href);
                            TvMazeEpisode previousEpisode = JsonConvert.DeserializeObject <TvMazeEpisode>(prevousEpisode);
                            show.PrevEpisode = previousEpisode;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(show._links.nextepisode?.href))
                    {
                        try
                        {
                            string        nextEpisodeResponse = GetResponseFromUrl(show?._links?.nextepisode?.href);
                            TvMazeEpisode nextEpisode         = JsonConvert.DeserializeObject <TvMazeEpisode>(nextEpisodeResponse);
                            show.NextEpisode = nextEpisode;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
 public async Task RunAsync(TvMazeShow tvMazeShow, IEnumerable <TvMazePerson> tvMazePersons)
 {
     // To be implemented...
 }
        public async Task <bool> Handle(InsertOrUpdateShowAndCastCommand request,
                                        CancellationToken cancellationToken)
        {
            if (request is null)
            {
                return(false);
            }

            try
            {
                logger.LogInformation("Inserting data into database");

                var showIndex = new TvMazeShowIndex
                {
                    Duration   = request.Duration,
                    Timestamp  = DateTime.Now,
                    InProgress = true
                };
                await tvMazeShowIndexRepository.AddAsync(showIndex);

                await tvMazeShowIndexRepository.SaveChangesAsync();

                int showCreatedCounter = 0;

                foreach (var showModel in request.TvMazeShowModelCollection)
                {
                    var show = await tvMazeShowRepository.GetByTvMazeIdAsync(showModel.Id);

                    if (show == null)
                    {
                        show = new TvMazeShow
                        {
                            TvMazeId = showModel.Id,
                            Name     = showModel.Name
                        };

                        await tvMazeShowRepository.AddAsync(show);

                        showCreatedCounter++;
                    }

                    await ProcessPersonAndCastInformation(showModel.Id, request.TvMazeCastModelCollection);

                    // RTLDbContext.SaveChangesAsync() -> All the entities up to this point will be stored into the db.
                    await tvMazeShowRepository.SaveChangesAsync();
                }

                logger.LogInformation($"Records created: {showCreatedCounter}");

                showIndex.InProgress     = false;
                showIndex.RecordsCreated = showCreatedCounter;

                await tvMazeShowIndexRepository.SaveChangesAsync();

                logger.LogInformation("Done inserting");
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Failed when inserting data into database");
                return(false);
            }

            return(true);
        }
 private async Task <IEnumerable <TvMazeActor> > GetTvMazeCastAsync(TvMazeShow show)
 {
     return(await _tvMazeWebClient.GetCastForAsync(show.Id));
 }