Пример #1
0
        public void GeneratePlaylist()
        {
            IEnumerable <ChannelStream> channelStreams = channelStreamRepository
                                                         .GetAll()
                                                         .ToServiceModels();

            List <Task> tasks = new List <Task>();
            ConcurrentDictionary <string, List <string> > foundChannelUrls =
                new ConcurrentDictionary <string, List <string> >();

            Parallel.ForEach(channelStreams, async channelStream =>
            {
                logger.Info(
                    MyOperation.ChannelStreamFetching,
                    OperationStatus.Started,
                    new LogInfo(MyLogInfoKey.ChannelStreamId, channelStream.Id));

                string url = urlRetriever.GetStreamUrlAsync(channelStream).Result;

                if (string.IsNullOrWhiteSpace(url))
                {
                    logger.Debug(
                        MyOperation.ChannelStreamFetching,
                        OperationStatus.Failure,
                        new LogInfo(MyLogInfoKey.ChannelStreamId, channelStream.Id));
                }
                else
                {
                    logger.Debug(
                        MyOperation.ChannelStreamFetching,
                        OperationStatus.Success,
                        new LogInfo(MyLogInfoKey.ChannelStreamId, channelStream.Id));

                    if (!foundChannelUrls.ContainsKey(channelStream.ChannelName))
                    {
                        foundChannelUrls.TryAdd(channelStream.ChannelName, new List <string>());
                    }

                    foundChannelUrls[channelStream.ChannelName].Add(url);
                }
            });

            Dictionary <string, List <string> > channelUrls = foundChannelUrls
                                                              .OrderBy(x => x.Key)
                                                              .ToDictionary(x => x.Key, x => x.Value);

            if (string.IsNullOrWhiteSpace(options.OutputDirectory))
            {
                GeneratePlaylistFile(channelUrls);
            }
            else
            {
                GeneratePlaylistDirectory(channelUrls);
            }
        }
Пример #2
0
        static void GetPlaylistForStream(Options options)
        {
            StreamInfo streamInfo = new StreamInfo();

            streamInfo.Provider  = options.Provider;
            streamInfo.ChannelId = options.ChannelId;
            streamInfo.Title     = options.Title;
            streamInfo.Url       = options.Url;

            IPlaylistUrlRetriever urlRetriever = serviceProvider.GetService <IPlaylistUrlRetriever>();
            string playlistUrl = urlRetriever.GetStreamUrlAsync(streamInfo).Result;

            Console.WriteLine(playlistUrl);
        }