public override void HandleTvgMedia(TvgMedia tvgMedia)
        {
            if (_contextTvgMediaHandler is ContextTvgMediaHandler context)
            {
                var reg = new Regex(context.MediaConfiguration.StartChannelsHeadLinePattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                if (reg.IsMatch(tvgMedia.Name) && !reg.Match(tvgMedia.Name).Groups[1].Value.Equals(tvgMedia.Name))
                {
                    context.StartChannelsHeadLineLastMatched = reg.Match(tvgMedia.Name).Groups[1].Value;
                    tvgMedia.IsValid = false;
                }
                else
                {
                    if (!string.IsNullOrEmpty(context.StartChannelsHeadLineLastMatched))
                    {
                        tvgMedia.MediaGroup = new PlaylistBaseLibrary.Entities.MediaGroup(context.StartChannelsHeadLineLastMatched);
                        tvgMedia.Tags.Add($"{{StartChannelsHeadLineLastMatched:{context.StartChannelsHeadLineLastMatched}}}");
                    }
                }
            }

            if (_successor != null)
            {
                _successor.HandleTvgMedia(tvgMedia);
            }
        }
 /// <summary>
 /// Update Group and Tags selon la config sauvegardée dans l'elastic
 /// </summary>
 /// <param name="tvgMedia"></param>
 public override void HandleTvgMedia(TvgMedia tvgMedia)
 {
     if (_contextTvgMediaHandler is ContextTvgMediaHandler context)
     {
         foreach (var tag in context.MediaConfiguration.Tags.OrderByDescending(x => x.Position))
         {
             if (tag.ChannelPatternMatcher != null)
             {
                 foreach (var matcher in tag.ChannelPatternMatcher)
                 {
                     var reg = new Regex(matcher, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                     if (reg.IsMatch(tvgMedia.Name) && tag.Lang != null && tag.Lang.Any())
                     {
                         tvgMedia.Lang = tag.Lang.FirstOrDefault();
                         if (tvgMedia.Tags == null)
                         {
                             tvgMedia.Tags = new List <string>();
                         }
                         tvgMedia.Tags.Add(tag.Name);
                         break;
                     }
                 }
             }
         }
     }
     if (_successor != null)
     {
         _successor.HandleTvgMedia(tvgMedia);
     }
 }
Exemple #3
0
        private static void GetTvg(string[] tab1, TvgMedia channel)
        {
            foreach (var item in tab1[0].Split(' '))
            {
                var tabTags = item.Split('=');
                if (tabTags.Length > 1)
                {
                    var value = tabTags[1].Replace("\"", "");

                    if (item.Trim().StartsWith("tvg-id"))
                    {
                        channel.Tvg.TvgIdentify = value;
                    }
                    else
                    if (item.Trim().StartsWith("tvg-logo"))
                    {
                        channel.Tvg.Logo = value;
                    }
                    else
                    if (item.Trim().StartsWith("tvg-name"))
                    {
                        channel.Tvg.Name = value;
                    }
                    else
                    if (item.Trim().StartsWith("group-title"))
                    {
                        channel.MediaGroup = new Entities.MediaGroup(value);
                    }
                    //else
                    //    channel.ExtendedProperties.Add(tabTags[0].Replace("\"", "").Replace("ext-", string.Empty), value);
                }
            }
        }
Exemple #4
0
 public static Channels TvgMediaToChannels(TvgMedia x)
 => new Channels
 {
     Num           = x.Position,
     Name          = x.Name,
     Category_name = x.MediaGroup?.Name,
     Stream_id     = x.StreamId,
     Stream_type   = "live"
 };
Exemple #5
0
        public void TvgCultureIsNotSetTest(string channelName)
        {
            var handler  = new TvgMediaCultureMatcherHandler(null);
            var tvgMedia = new TvgMedia
            {
                Name = channelName,
                Lang = string.Empty
            };

            handler.HandleTvgMedia(tvgMedia);
            Assert.True(string.IsNullOrEmpty(tvgMedia.Lang));
        }
Exemple #6
0
        public void TvgShiftIsSetTest(string channelName)
        {
            var handler  = new TvgMediaShiftMatcherHandler(null);
            var tvgMedia = new TvgMedia
            {
                Name = channelName
            };

            handler.HandleTvgMedia(tvgMedia);
            Assert.True(!string.IsNullOrEmpty(tvgMedia.Tvg.Shift));
            Assert.True(tvgMedia.Tvg.Shift.StartsWith('+'));
        }
Exemple #7
0
        public void TvgCultureIsSetTest(string channelName, string lang = "")
        {
            var handler  = new TvgMediaCultureMatcherHandler(null);
            var tvgMedia = new TvgMedia
            {
                Name = channelName
            };

            handler.HandleTvgMedia(tvgMedia);
            Assert.True(tvgMedia.Lang != null);
            if (!string.IsNullOrEmpty(lang))
            {
                Assert.Equal(tvgMedia.Lang, lang);
            }
        }
Exemple #8
0
        private static int FillTvgMedia(List <TvgMedia> listChannels, string line, int position)
        {
            if (line != string.Empty)
            {
                var row     = line.Split(' ');
                var channel = new TvgMedia
                {
                    Name     = string.Join(" ", row.Take(row.Length - 1)),
                    Url      = row.Last().Trim(),
                    Position = position++,
                };
                listChannels.Add(channel);
            }

            return(position);
        }
Exemple #9
0
        protected override async Task <IEnumerable <TvgMedia> > PullMediasFromProviderAsync(StreamReader streamReader, CancellationToken cancellationToken)
        {
            var listChannels = new List <TvgMedia>();

            using (var stringReader = new StringReader(await streamReader.ReadToEndAsync()))
            {
                var line = stringReader.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    return(new Playlist <TvgMedia>(listChannels));
                }
                var i     = 1;
                var isM3u = line.Equals(HeaderFile, StringComparison.OrdinalIgnoreCase);
                while ((line = await stringReader.ReadLineAsync()) != null)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    if (line != string.Empty && line.StartsWith(HeaderUrl))
                    {
                        var tab1    = line.Split(',');
                        var tab2    = tab1[0].Split(' ');
                        var live    = tab2.FirstOrDefault().Equals(HeaderUrl + "0") || tab2.FirstOrDefault().Equals(HeaderUrl + "-1");
                        var channel = new TvgMedia
                        {
                            Name     = tab1.Last().Trim(),
                            Position = i++,
                            //IsLive = live,
                            //OriginalHeaderLine = line
                        };

                        do
                        {
                            channel.Url = await stringReader.ReadLineAsync();
                        } while (string.IsNullOrWhiteSpace(channel.Url));
                        channel.StreamId = channel.StreamId;
                        GetTvg(tab1, channel);
                        listChannels.Add(channel);
                    }
                }
            }
            return(new Playlist <TvgMedia>(listChannels));
        }
Exemple #10
0
        public override void HandleTvgMedia(TvgMedia tvgMedia)
        {
            var reg   = new Regex("\\b(?<lang>(?!(f?h|s)d)(u|a)?\\w{2}(-\\w{2})?)\\b", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
            var match = reg.Match(tvgMedia.Name);

            if (match.Success && match.Groups["lang"] != null && !string.IsNullOrEmpty(match.Groups["lang"].Value))
            {
                var lang = match.Groups["lang"].Value.Trim();
                lang = FixLang(lang);

                var(EnglishName, ThreeLetterISOLanguageName) = Common.TryGet(x =>
                {
                    var cul = new CultureInfo(x);
                    if (cul != null && !cul.EnglishName.StartsWith("Unknown Language"))
                    {
                        return(cul.EnglishName, cul.ThreeLetterISOLanguageName);
                    }
                    return(null, default);
        public override void HandleTvgMedia(TvgMedia tvgMedia)
        {
            var reg   = new Regex(@"(?<channelName>[a-z\s\d{0,1}]+)(?<shift>\s\+\d{1})", RegexOptions.IgnoreCase);
            var match = reg.Match(tvgMedia.Name);

            if (match.Success && match.Groups["shift"] != null && !string.IsNullOrEmpty(match.Groups["shift"].Value))
            {
                if (tvgMedia.Tvg == null)
                {
                    tvgMedia.Tvg = new Tvg();
                }
                tvgMedia.Tvg.Shift = match.Groups["shift"].Value.Trim();
            }

            if (_successor != null)
            {
                _successor.HandleTvgMedia(tvgMedia);
            }
        }
 /// <summary>
 /// Clean DisplayName selon la config sauvegardée dans Elastic
 /// </summary>
 /// <param name="tvgMedia"></param>
 public override void HandleTvgMedia(TvgMedia tvgMedia)
 {
     if (_contextTvgMediaHandler is ContextTvgMediaHandler context)
     {
         if (context.FixChannelNames != null && context.FixChannelNames.Any())
         {
             context.FixChannelNames.AsParallel().OrderBy(x => x.Order).ForAll(pattern =>
             {
                 var reg = new Regex(pattern.Pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                 if (reg.IsMatch(tvgMedia.Name))
                 {
                     tvgMedia.DisplayName = reg.Replace(tvgMedia.Name, pattern.ReplaceBy);
                 }
             });
         }
     }
     if (_successor != null)
     {
         _successor.HandleTvgMedia(tvgMedia);
     }
 }
Exemple #13
0
        protected override IEnumerable <TvgMedia> PullMediasFromProvider(StreamReader streamReader)
        {
            var mediasList = new List <TvgMedia>();
            var line       = streamReader.ReadLine();

            if (line != null)
            {
                var i     = 1;
                var isM3u = line.Equals(HeaderFile, StringComparison.OrdinalIgnoreCase);
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    if (line != string.Empty && line.StartsWith(HeaderUrl))
                    {
                        var tab1    = line.Split(',');
                        var tab2    = tab1[0].Split(' ');
                        var live    = tab2.FirstOrDefault().Equals(HeaderUrl + "0") || tab2.FirstOrDefault().Equals(HeaderUrl + "-1");
                        var channel = new TvgMedia
                        {
                            Name     = tab1.Last().Trim(),
                            Position = i++,
                            //IsLive = live,
                            //OriginalHeaderLine = line
                        };

                        do
                        {
                            channel.Url = streamReader.ReadLine();
                        } while (string.IsNullOrWhiteSpace(channel.Url));
                        GetTvg(tab1, channel);
                        yield return(channel);
                    }
                }
            }
        }
Exemple #14
0
        public override void HandleTvgMedia(TvgMedia tvgMedia)
        {
            var result = _sitePackService.MatchMediaNameAndCountryAsync(tvgMedia.DisplayName, tvgMedia.Culture?.Country, CancellationToken.None).GetAwaiter().GetResult();

            if (result != null)
            {
                tvgMedia.Tvg = new Tvg
                {
                    Name          = result.Xmltv_id,
                    Id            = result.Id,
                    Logo          = result.Logo,
                    TvgIdentify   = result.Xmltv_id,
                    TvgSiteSource = result.Site,
                    TvgSource     = new PlaylistBaseLibrary.Entities.TvgSource {
                        Site = result.Site, Code = result.Site_id, Country = result.Country
                    }
                };
                tvgMedia.Lang = result.Country;
            }
            if (_successor != null)
            {
                _successor.HandleTvgMedia(tvgMedia);
            }
        }
Exemple #15
0
 public static string TvgMediaToChannelsJson(TvgMedia x)
 => JsonConvert.SerializeObject(TvgMediaToChannels(x));
        public async Task <IActionResult> MatchTvgByMedia([FromBody] TvgMedia media, CancellationToken cancellationToken = default)
        {
            var sitePack = await _sitePackService.MatchMediaNameAndBySiteAsync(media.DisplayName, media.Tvg.TvgSource.Site, cancellationToken);

            return(Ok(sitePack));
        }
Exemple #17
0
 public abstract void HandleTvgMedia(TvgMedia tvgMedia);
Exemple #18
0
 public IActionResult Post([FromBody] TvgMedia value)
 {
     return(Ok());
 }
Exemple #19
0
 public IActionResult Put(int id, [FromBody] TvgMedia value)
 {
     return(Ok());
 }