Пример #1
0
        public async Task <IActionResult> MatchTvgAsync([FromRoute] string id, [FromQuery] bool onlyNotMatched = true,
                                                        CancellationToken cancellationToken = default)
        {
            var idGuid = GetInternalPlaylistId(id);

            var playlistEntity = await _dbContext.Playlist.FirstOrDefaultAsync(x => x.UniqueId == idGuid, cancellationToken);

            if (playlistEntity == null)
            {
                return(NotFound(playlistEntity));
            }

            playlistEntity.TvgMedias
            .Where(m => m.MediaType == MediaType.LiveTv && (!onlyNotMatched || m.Tvg == null || string.IsNullOrEmpty(m.Tvg.Id)))
            .AsParallel()
            .WithCancellation(cancellationToken)
            .ForAll(media =>
            {
                var matched = _sitePackService.MatchMediaNameAndBySiteAsync(media.DisplayName, media.Tvg?.TvgSource.Site, cancellationToken).GetAwaiter().GetResult();
                if (matched != null)
                {
                    media.Tvg.Id            = matched.Xmltv_id;
                    media.Tvg.Name          = matched.Channel_name;
                    media.Tvg.TvgIdentify   = matched.Id;
                    media.Tvg.TvgSiteSource = matched.Site;
                }
            });

            //Matching movies
            var list = playlistEntity.TvgMedias.Where(m => m.MediaType == MediaType.Video).ToList();

            if (onlyNotMatched)
            {
                list = list.Where(x => x.Tvg == null || string.IsNullOrEmpty(x.Tvg.Logo)).ToList();
            }

            list
            .Where(x => x.Tvg?.TvgSource != null)
            .AsParallel()
            .WithCancellation(cancellationToken)
            .ForAll(media =>
            {
                var matched = _mediaScraper.SearchAsync(media.DisplayName, _globalOptions.TmdbAPI, _globalOptions.TmdbPosterBaseUrl, cancellationToken).GetAwaiter().GetResult();
                if (matched != null)
                {
                    media.Tvg.Logo = matched.FirstOrDefault()?.PosterPath;
                }
            });

            return(Ok(PlaylistModel.ToModel(playlistEntity, Url)));
        }
Пример #2
0
        public async Task <IActionResult> MatchTvgByMediaName([FromRoute] string mediaName, [FromQuery] string country,
                                                              CancellationToken cancellationToken = default)
        {
            var sitePack = await _sitePackService.MatchMediaNameAndBySiteAsync(mediaName, country, cancellationToken);

            return(Ok(sitePack));
        }