コード例 #1
0
ファイル: SearchKTV.cs プロジェクト: makotowzhang/MyKTV
        public List <MTVInfo> GetMTVList(string mtvName)
        {
            //using (KTVDataBase db = new KTVDataBase())
            //{
            //    if (db.SearchCache.Any(m => m.SearchName == mtvName))
            //    {
            //        var cache = db.SearchCache.FirstOrDefault(m => m.SearchName == mtvName);
            //        return JsonConvert.DeserializeObject<List<MTVInfo>>(cache.SearchContent);
            //    }
            //}
            var       list   = new List <MTVInfo>();
            WebClient client = new WebClient();
            string    url    = MTVDomain + "/search_mtv.asp?Type=1&File=1&bSearch=MV%CB%D1%CB%F7&ktv=" + HttpUtility.UrlEncode(mtvName, Encoding.GetEncoding("GBK"));
            string    html   = client.DownloadString(url).Replace("\r\n", "").Replace("\n", "").Replace("\r", "");

            html = Regex.Match(html, "<ul class=\"clearfix\" id=\"f1\">.*</ul>", RegexOptions.IgnoreCase).Value;
            int i = 0;

            foreach (Match m in Regex.Matches(html, "<li>.*?</li>", RegexOptions.IgnoreCase))
            {
                if (i++ == 9)
                {
                    break;
                }
                if (m.Value.Contains("文件大小"))
                {
                    continue;
                }
                MTVInfo model = new MTVInfo();
                //<a class='songName' href='/mv/mtv15/ktv148493.htm' title='阿生-七里香_国语_流行_NCB18664_MTVP2P.mkv'>七里香</a>
                string nameDetail = Regex.Match(m.Value, "<a class='songName' .*?</a>").Value;
                //  href='/mv/mtv15/ktv148493.htm'
                string songNameDetail = Regex.Match(nameDetail, "href='.*?'").Value;
                model.DetailUrl = MTVDomain + songNameDetail.Replace("href=", "").Replace("'", "");
                //  title='阿生-七里香_国语_流行_NCB18664_MTVP2P.mkv'
                string songTitleDetail = Regex.Match(nameDetail, "title='.*?'").Value;
                model.SouceFileName = songTitleDetail.Replace("title=", "").Replace("'", "");
                model.MTVName       = nameDetail.Replace("<a class='songName' " + songNameDetail + " " + songTitleDetail + ">", "").Replace("</a>", "");
                //<a class='singerName' href='/star/?周杰伦' title='点击进入歌手专题'>周杰伦</a>
                string singerName = Regex.Match(m.Value, "<a class='singerName' .*?</a>").Value;
                model.Artist  = singerName.RemoveRegexStr("<a class='singerName' href='.*?' title='.*?'>").Replace("</a>", "");
                model.MTVSize = Regex.Match(m.Value, "<span class='albumName'>.*?</span>").Value.Replace("<span class='albumName'>", "").Replace("</span>", "");
                GetMTVDownloadInfo(model);
                list.Add(model);
            }
            using (KTVDataBase db = new KTVDataBase())
            {
                if (db.SearchCache.Where(m => m.SearchName == mtvName).Count() == 0)
                {
                    db.SearchCache.Add(new SearchCache()
                    {
                        SearchName    = mtvName,
                        SearchContent = JsonConvert.SerializeObject(list),
                        CreateTime    = DateTime.Now
                    });
                    db.SaveChanges();
                }
            }
            return(list);
        }
コード例 #2
0
ファイル: OrderMTV.cs プロジェクト: makotowzhang/MyKTV
 public static List <MyMTV> SearchMyMTV(string MTVName)
 {
     using (KTVDataBase db = new KTVDataBase())
     {
         var temp = db.MyMTV.Where(m => m.MTVName.Contains(MTVName) || m.Artist.Contains(MTVName)).OrderBy(m => m.MTVName);
         return(temp.ToList());
     }
 }
コード例 #3
0
 public DownloadSearchLabel(MTVInfo mtv, string sort)
 {
     InitializeComponent();
     labelSort.Text = sort;
     labelName.Text = mtv.MTVName + "-" + mtv.Artist;
     mtvInfo        = mtv;
     mtvInfo.Id     = Guid.NewGuid();
     using (KTVDataBase db = new KTVDataBase())
     {
         if (db.MyMTV.Any(m => m.DetailUrl == mtv.DetailUrl) || RunTimeData.DownloadQueue.Any(m => m.MTV.DetailUrl == mtv.DetailUrl))
         {
             LabelServerDownload.Visible = false;
             LabelCloudDownload.Visible  = false;
         }
     }
     if (int.Parse(sort) % 2 == 0)
     {
         Appearance.BackColor = Color.FromArgb(204, 204, 204);
     }
 }
コード例 #4
0
ファイル: DownLoadMTV.cs プロジェクト: makotowzhang/MyKTV
        public static void BeginDownload()
        {
            List <DownloadInfo> DownloadQeueu = KTVStatus.RunTimeData.DownloadQueue;

            lock (DownloadQeueu)
            {
                foreach (DownloadInfo di in DownloadQeueu.OrderBy(m => m.Sort))
                {
                    if (di.IsDownloading || di.IsCompelet)
                    {
                        continue;
                    }
                    if (di.DownloadType == KTVEnum.MTVDownloadType.Server ||
                        (di.DownloadType == KTVEnum.MTVDownloadType.Cloud && DownloadQeueu.Where(m => m.DownloadType == KTVEnum.MTVDownloadType.Cloud).All(m => m.IsDownloading == false)))
                    {
                        WebClient client = new WebClient();
                        if (di.ProcessChange != null)
                        {
                            client.DownloadProgressChanged += di.ProcessChange;
                        }
                        if (di.Complete != null)
                        {
                            client.DownloadFileCompleted += di.Complete;
                        }
                        client.DownloadFileCompleted += (sender, e) =>
                        {
                            di.IsDownloading = false;
                            di.IsCompelet    = true;
                            using (var db = new KTVDataBase())
                            {
                                var entity = new MyMTV()
                                {
                                    Id            = di.MTV.Id.ToString(),
                                    Artist        = di.MTV.Artist,
                                    CloudDiskUrl  = di.MTV.CloudDiskUrl,
                                    DetailUrl     = di.MTV.DetailUrl,
                                    ED2KUrl       = di.MTV.ED2KUrl,
                                    FileName      = di.MTV.MTVName + "-" + di.MTV.Artist + ".mkv",
                                    MTVImage      = di.MTV.MTVImage,
                                    MTVName       = di.MTV.MTVName,
                                    SavePath      = di.SavePath,
                                    MTVSize       = di.MTV.MTVSize,
                                    ServerUrl     = di.MTV.ServerUrl,
                                    SouceFileName = di.MTV.SouceFileName
                                };
                                db.MyMTV.Add(entity);
                                db.SaveChanges();
                                VideoScreenShot.ShotMTV(entity);
                            }
                            BeginDownload();
                        };
                        if (di.DownloadType == KTVEnum.MTVDownloadType.Cloud)
                        {
                            di.WebUrl = di.MTV.CloudDiskUrl;
                        }
                        if (di.DownloadType == KTVEnum.MTVDownloadType.Server)
                        {
                            di.WebUrl = di.MTV.ServerUrl;
                        }
                        di.IsDownloading = true;
                        client.DownloadFileAsync(new Uri(di.WebUrl), di.SavePath.Replace("~", PathHelper.GetDownloadDir(di.MTV.Id)));
                    }
                }
            }
        }