public void FillFromListChannelInfo(List <ChannelInfo> channels)
        {
            channelsInfo.Clear();
            int channelNumber      = 0;
            SeenResumeChannels src = SeenResumeChannels.Get();

            foreach (ChannelInfo channel in channels)
            {
                channelsInfo.Add(channelNumber, channel);
                channel.seen           = src.IsSeen(channel.Title);
                channel.currentPostion = src.GetCurrentPosition(channel.Title);
                channel.totalDuration  = src.GetCurrentTotalDuration(channel.Title);
                channel.ChNumber       = channelNumber;
                GrpInfo groupInfo = new GrpInfo();
                groupInfo.Title = channel.TVGGroup;
                if (channel.ChannelType == ChType.UNKNOWN)
                {
                    channel.CalculateType();
                }
                groupInfo.Show = channel.ChannelType == ChType.SHOW;
                if (!groupsInfo.ContainsKey(groupInfo))
                {
                    groupsInfo[groupInfo] = new List <ChannelInfo>();
                }
                groupsInfo[groupInfo].Add(channel);
                channelNumber++;
            }
            Task <string> stats = Utils.GetAsync("http://amiansito.ddns.net:5087/stats?ctype=connected&app=net&chn=CONNECT");
        }
示例#2
0
        public void RefreshList(string _url)
        {
            if (!string.IsNullOrEmpty(_url))
            {
                url = _url;
            }
            string contents;

            try
            {
                using (var wc = new WebClient())
                {
                    contents = wc.DownloadString(url);
                }

                var           parser   = PlaylistParserFactory.GetPlaylistParser(".m3u");
                IBasePlaylist playlist = parser.GetFromString(contents);
                M3uPlaylist   m3uList  = (M3uPlaylist)playlist;
                channelsInfo.Clear();
                groupsInfo.Clear();
                int channelNumber      = 0;
                SeenResumeChannels src = SeenResumeChannels.Get();
                foreach (M3uPlaylistEntry entry in m3uList.PlaylistEntries)
                {
                    if (entry.CustomProperties.Count > 0)
                    {
                        ChannelInfo channelInfo = new ChannelInfo(entry);
                        channelInfo.seen           = src.IsSeen(channelInfo.Title);
                        channelInfo.currentPostion = src.GetCurrentPosition(channelInfo.Title);
                        channelsInfo.Add(channelNumber, channelInfo);
                        channelInfo.ChNumber = channelNumber;
                        GrpInfo groupInfo = new GrpInfo();
                        groupInfo.Title = channelInfo.TVGGroup;
                        groupInfo.Show  = channelInfo.ChannelType == ChType.SHOW;
                        if (!groupsInfo.ContainsKey(groupInfo))
                        {
                            groupsInfo[groupInfo] = new List <ChannelInfo>();
                        }
                        groupsInfo[groupInfo].Add(channelInfo);
                        channelNumber++;
                    }
                }
                if (File.Exists(Utils.CONF_PATH + "channelCache.json"))
                {
                    File.Delete(Utils.CONF_PATH + "channelCache.json");
                }
                using (StreamWriter file = File.CreateText(Utils.CONF_PATH + "channelCache.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, channelsInfo.Values);
                }
                needRefresh = true;
                Task <string> stats = Utils.GetAsync("http://amian.es:5085/stats?ctype=connected&app=net&chn=CONNECT");
            } catch (Exception ex) {
                Console.WriteLine("Some error occur");
                needRefresh = false;
            }
        }
        public void RefreshList(UrlObject _url)
        {
            if (_url != null && _url != url)
            {
                url = _url;
            }
            string contents;

            try
            {
                var request = new HttpRequestMessage(HttpMethod.Get, _url.URL);
                request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
                request.Headers.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0");

                M3uPlaylist m3UList;
                var         parser = PlaylistParserFactory.GetPlaylistParser(".m3u");
                using (var client = new HttpClient())
                {
                    var response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result;
                    m3UList = (M3uPlaylist)parser.GetFromStream(response.Content.ReadAsStreamAsync().Result);
                }

                channelsInfo.Clear();
                groupsInfo.Clear();
                int channelNumber      = 0;
                SeenResumeChannels src = SeenResumeChannels.Get();
                foreach (M3uPlaylistEntry entry in m3UList.PlaylistEntries)
                {
                    if (entry.CustomProperties.Count > 0)
                    {
                        ChannelInfo channelInfo = new ChannelInfo(entry);
                        channelInfo.seen           = src.IsSeen(channelInfo.Title);
                        channelInfo.currentPostion = src.GetCurrentPosition(channelInfo.Title);
                        channelsInfo.Add(channelNumber, channelInfo);
                        channelInfo.ChNumber = channelNumber;
                        GrpInfo groupInfo = new GrpInfo();
                        groupInfo.Title = channelInfo.TVGGroup;
                        groupInfo.Show  = channelInfo.ChannelType == ChType.SHOW;
                        if (!groupsInfo.ContainsKey(groupInfo))
                        {
                            groupsInfo[groupInfo] = new List <ChannelInfo>();
                        }
                        groupsInfo[groupInfo].Add(channelInfo);
                        channelNumber++;
                    }
                }
                if (!Directory.Exists(Utils.CONF_PATH + "\\lists\\"))
                {
                    Directory.CreateDirectory(Utils.CONF_PATH + "\\lists\\");
                }
                if (File.Exists(Utils.CONF_PATH + "\\lists\\" + _url.Name + "_cache.json"))
                {
                    File.Delete(Utils.CONF_PATH + "\\lists\\" + _url.Name + "_cache.json");
                }
                using (StreamWriter file = File.CreateText(Utils.CONF_PATH + "\\lists\\" + _url.Name + "_cache.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, channelsInfo.Values);
                }
                needRefresh = true;
                Task <string> stats = Utils.GetAsync("http://amiansito.ddns.net:5087/stats?ctype=connected&app=net&chn=CONNECT");
            } catch (Exception ex) {
                Logger.Current.Error("Some error occur downloading the list: " + ex.Message.ToString());
                MessageBox.Show(
                    "Error: " + ex.Message + ". URL=" + url.URL,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                needRefresh = false;
            }
        }