Exemplo n.º 1
0
 public virtual bool DownloadFile(string url, string saveFilePath)
 {
     return(NetWorkHandle.DownFileMethod(url, saveFilePath));
 }
Exemplo n.º 2
0
        public static void DownLoadFiles()
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }
            if (!File.Exists(VideoInfoPath))
            {
                File.Create(VideoInfoPath);
            }
            var results = SingleSpider();

            foreach (var item in results)
            {
                var id    = item.Id.ToString();
                var title = item.Title.Trim();
                try
                {
                    if (string.IsNullOrEmpty(title))
                    {
                        title = DateTime.Now.ToString("yyyyMMddHHmmss");
                    }
                    var url       = item.videoUrl;
                    var videoName = title + ".mp4";
                    var imgName   = "";
                    if (!string.IsNullOrEmpty(item.ImgUrl))
                    {
                        var imgUrl = item.ImgUrl;
                        Console.WriteLine($"开始下载--{item.ImgUrl}");
                        imgName = title + ".jpg";
                        var imgFilePath = Path.Combine(basePath, imgName);
                        if (NetWorkHandle.DownFileMethod(imgUrl, imgFilePath))
                        {
                            Console.WriteLine($"下载--{item.ImgUrl}--成功");
                        }
                        else
                        {
                            Console.WriteLine($"下载--{item.ImgUrl}--失败");
                        }
                    }

                    var videoFilePath = Path.Combine(basePath, videoName);

                    if (NetWorkHandle.DownFileMethod(url, videoFilePath))
                    {
                        Console.WriteLine($"下载--{item.videoUrl}--成功");
                        //RecordFile(id, RecordFileName: existsFileName, path: basePath);
                        VideoSpiderTools.RecordFile(title, recordFile: existsFileName, path: basePath);
                    }
                    else
                    {
                        Console.WriteLine($"下载--{item.videoUrl}--失败");
                    }
                    Console.WriteLine($"{title}--完成");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("异常:" + title + "  " + ex.Message);
                    VideoSpiderTools.RecordFile(title + " @ " + "异常信息:" + ex.Message, exceptionFileName);
                }
            }
        }