Exemple #1
0
        public static async Task DownloadShowAsync(One show, Live live, IDown d)
        {
            DownManager.down = d;
            // http://media2.neu6.edu.cn/review/program-1524520800-1524526860-chchd.m3u8
            var url = String.Format("http://media2.neu6.edu.cn/review/program-{0}-{1}-{2}.m3u8",
                                    show.start, show.end, live.GetSimpleName());

            Debug.WriteLine(url);
            //创建下载目录
            var downloadDic = await KnownFolders.VideosLibrary.CreateFolderAsync("NEUTV download",
                                                                                 CreationCollisionOption.OpenIfExists);

            //下载m3u8文件
            HttpClient httpClient = new HttpClient();
            var        response   = await httpClient.GetAsync(new Uri(url));

            var res = await response.Content.ReadAsStringAsync();

            Regex           re      = new Regex(@"(?<url>http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)");
            MatchCollection mc      = re.Matches(res);
            List <String>   urlList = new List <string>();
            var             tsRe    = new Regex(@"(?<ts>[0-9]+\.ts)");

            foreach (Match m in mc)
            {
                var clipUrl = m.Result("${url}");
                urlList.Add(clipUrl);
            }
            if (down != null)
            {
                down.Start(urlList.Count);
            }
            //创建临时文件夹
            var tempDic = await downloadDic.CreateFolderAsync("temp",
                                                              CreationCollisionOption.GenerateUniqueName);

            //下载 视频分片
            var         Tasks = new List <Task>();
            TaskFactory fac   = new TaskFactory();

            Debug.WriteLine("start all");
            try
            {
                Task.Run(() =>
                {
                    Parallel.ForEach <string>(urlList, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = 10
                    },
                                              videoUrl => {
                        Act(videoUrl, httpClient, tempDic).Wait();
                    });
                }).ContinueWith((obj) =>
                {
                    Debug.WriteLine("end all");
                    SaveVideoFile(tempDic, downloadDic, urlList);
                });
            }
            catch (Exception e)
            {
            }
        }
Exemple #2
0
 public void RemoveLive(Live live)
 {
     this.Livelist.Remove(live);
 }
Exemple #3
0
 public void AddLive(Live live)
 {
     this.Livelist.Add(live);
 }
Exemple #4
0
        //添加一个pivot页面
        public void AddItem(PlayList playList)
        {
            GridView g = new GridView();

            g.HorizontalAlignment = HorizontalAlignment.Center;

            PivotItem pi1 = new PivotItem
            {
                Header  = playList.Name,
                Content = g
            };

            mainpage_pivot.Items.Add(pi1);
            foreach (Live obj in playList.Livelist)
            {
                TextBlock t = new TextBlock
                {
                    Text                = obj.Name,
                    FontSize            = 24,
                    HorizontalAlignment = HorizontalAlignment.Center,
                };


                Button b = new Button
                {
                    Content             = "\xE006",
                    FontSize            = 24,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Tag        = obj,
                    Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)),
                    FontFamily = font,
                    Width      = 50,
                    Height     = 50,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0))
                };
                b.Name   = obj.Name;       //方便查找相应的btn
                b.Click += MainPage_Click; //主界面的点击事件
                btns.Add(b);               //将主界面的每个btn都加到列表里


                Image img = new Image
                {
                    Source = new BitmapImage(new Uri("https://hdtv.neu6.edu.cn/wall/img/" + obj.GetSimpleName() + "_s.png")),
                    //TODO 可以换一种更睿智的方法,目前显示效果不够好
                    //高清频道和非高清频道图片分辨率不同,手动设置图片宽高
                    //否则非高清频道 textblock无法显示
                    Width  = 300,
                    Height = 225
                };


                bool a = false;
                foreach (Live live1 in playList1.Livelist)
                {
                    if (obj.Name == live1.Name)
                    {
                        a = true;
                    }
                }
                if (a)
                {
                    b.Content = "\xE00B";
                }                               //初始化主界面button的值

                StackPanel itemPanel = new StackPanel();
                itemPanel.Margin = new Thickness(8);
                itemPanel.Children.Add(img);
                itemPanel.Children.Add(t);
                itemPanel.Children.Add(b);
                itemPanel.Tag = obj;
                g.Items.Add(itemPanel);
            }



            g.IsItemClickEnabled = true;
            g.ItemClick         += new ItemClickEventHandler((sender, arg) => {
                Live live = (Live)((StackPanel)arg.ClickedItem).Tag;
                //Debug.WriteLine(live.Name);
                root.Navigate(typeof(PlayerPage), live);
            });
        }
Exemple #5
0
        // https://docs.microsoft.com/zh-cn/uwp/api/windows.storage.pickers.fileopenpicker#examples

        public async Task Gets(Uri uri)
        {
            try
            {
                HttpClient httpClient = new HttpClient();
                var        response   = await httpClient.GetAsync(uri);

                var buffer = await response.Content.ReadAsBufferAsync();

                //转为UTF-8格式
                DataReader reader      = DataReader.FromBuffer(buffer);
                byte[]     fileContent = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(fileContent);
                Encoding encoding = Encoding.GetEncoding("UTF-8");
                var      str      = encoding.GetString(fileContent);

                JsonObject jsonObject = JsonObject.Parse(str);
                JsonArray  types      = jsonObject["type"].GetArray();
                JsonArray  lives      = jsonObject["live"].GetArray();

                //储存节目单
                Dictionary <String, PlayList> listMap = new Dictionary <string, PlayList>();

                foreach (JsonValue obj in types)
                {
                    String name = obj.GetObject()["name"].GetString();
                    String uid  = obj.GetObject()["id"].GetString();
                    listMap.Add(uid, new PlayList(name, uid));
                }

                // Live json格式
                // "num":50001,
                // "itemid":"uid0",
                // "name":"CCTV-1高清",
                // "urllist":"http:....."

                foreach (JsonValue obj in lives)
                {
                    String name    = obj.GetObject()["name"].GetString();
                    String itemid  = obj.GetObject()["itemid"].GetString();
                    String urllist = obj.GetObject()["urllist"].GetString();
                    listMap[itemid].AddLive(new Live(urllist, name, itemid));
                }


                GridView    grid       = this.createGridView(playList1);//创建我的收藏的gridview
                StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt", CreationCollisionOption.OpenIfExists);

                String timestamp = await FileIO.ReadTextAsync(sampleFile);

                string[] Array = timestamp.Split(new char[] { '+' });
                for (int i = 1; i < Array.Length - 2; i = i + 3)
                {
                    Live live = new Live(Array[i], Array[i + 1], Array[i + 2]);
                    playList1.AddLive(live);
                    AddLivesToPivot(grid, live);
                } //把我的收藏里面的频道加到gridview里


                //添加到页面
                foreach (KeyValuePair <String, PlayList> pair in listMap)
                {
                    PlayList playList = pair.Value;
                    this.AddItem(playList);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("xxxxx{0}", e);
                button_open.Visibility = Visibility.Visible;
            }
            finally
            {
                mainpage_progress_ring.IsActive = false;
            }
        }
Exemple #6
0
 public String GetSimpleName()
 {
     return(Live.GetLiveName(this.GetUrlList()[0]));
 }