Ejemplo n.º 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)));
        }
Ejemplo n.º 2
0
        public IActionResult Match([FromBody] List <TvgMedia> tvgmedias,
                                   [FromQuery] int distance = 90,
                                   [FromQuery] bool shouldMatchChannelNumber = true,
                                   CancellationToken cancellationToken       = default)
        {
            tvgmedias.AsParallel().WithCancellation(cancellationToken).ForAll(m =>
            {
                if (m.Tvg == null)
                {
                    m.Tvg = new Tvg();
                }

                if (m.MediaType == MediaType.Video)
                {
                    var matched = _mediaScraper.SearchAsync(m.DisplayName, _globalOptions.TmdbAPI, _globalOptions.TmdbPosterBaseUrl, cancellationToken).GetAwaiter().GetResult();
                    if (matched != null)
                    {
                        m.Tvg.Logo = matched.FirstOrDefault().PosterPath;
                    }
                }
                else
                {
                    var picons = _piconsService.MatchAsync(m.DisplayName, shouldMatchChannelNumber ? m.GetChannelNumber() : null, distance, cancellationToken).GetAwaiter().GetResult();
                    m.Tvg.Logo = picons.FirstOrDefault()?.RawUrl;
                }
            });

            return(Ok(tvgmedias));
        }