Пример #1
0
 public YouKuCollection()
 {
     http             = new HttpHelper();
     movie_bll        = new Movie_BLL();
     player_bll       = new Player_BLL();
     douBanCollection = new DouBanCollection();
 }
Пример #2
0
        /// <summary>
        /// 采集电影的播放地址
        /// </summary>
        /// <param name="movieID"></param>
        /// <param name="hash"></param>
        public void CollectionMoviePlayer(int movieID, string hash, Family family)
        {
            try
            {
                ////http://list.youku.com/show/episode?id=310138&stage=reload_41&callback=w&_=w
                //初始化参数
                int pageSize = 40;
                int maxPage  = 1;
                for (int page = 1; page <= maxPage; page++)
                {
                    int result_num = 0;
                    //发送请求
                    var httpResult = new HttpHelper().GetHtml(new HttpItem()
                    {
                        URL              = "http://list.youku.com/show/episode?callback=w&_=w&id=" + hash + "&stage=reload_" + ((page - 1) * pageSize) + 1,
                        Accept           = "application/json",
                        ReadWriteTimeout = 1000 * 60,
                        Timeout          = 1000 * 60
                    });

                    //判断请求是否成功
                    if (httpResult.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        //将结果处理成实体集合
                        var resHtml = httpResult.Html.Replace("var tvInfoJs=", "").Trim().TrimEnd(';');
                        var res_obj = resHtml.ParseJSON <Models.iQiYi.Palyer.Rootobject>();
                        if (res_obj.mixinVideos != null)
                        {
                            //加载数据成功
                            res_obj.mixinVideos.ForEach_(m => {
                                if (m.contentType.ToInt_() == 1)
                                {
                                    //将数据写入数据库
                                    int playerID = new Player_BLL().SavePlayer(new Domain.Entity.Player_Repository()
                                    {
                                        Guid        = Guid.NewGuid().ToString().ToUpper(),
                                        Name        = m.albumName,
                                        CreateTime  = DateTime.Now,
                                        Description = string.IsNullOrWhiteSpace(m.description) ? null : m.description,
                                        Episodes    = family == Family.电影 ? null : m.order,
                                        HasVip      = m.isPurchase,
                                        MovieID     = movieID,
                                        Platform    = "iqiyi",
                                        PlayerUrl   = m.url,
                                        VID         = m.vid
                                    });
                                    if (movieID > 0)
                                    {
                                        Console.WriteLine(m.name + "\t写入数据库成功!");
                                    }
                                }
                            });
                        }
                        //最大页码
                        maxPage = (res_obj.total.ToInt_() / pageSize) + ((res_obj.total.ToInt_() % pageSize) > 0 ? 1 : 0);
                    }
                    else
                    {
                        Console.WriteLine("请求发生错误\tStatusCode:" + httpResult.StatusCode);
                    }
                    maxPage = (result_num / pageSize) + ((result_num % pageSize) > 0 ? 1 : 0);
                }
            }
            catch (Exception ex)
            {
            }
        }