/// <summary> /// 将文件信息写入数据库 /// </summary> /// <param name="info"></param> /// <returns></returns> internal int InsertFiles(NnPanInfos info, Account account) { int count = 0; try { using (OleDbCommand cmd = new OleDbCommand("INSERT INTO fileinfo ([server_mtime],[category],[unlist],[fs_id],[size],[isdir],[iper_id],[server_ctime],[thumbs],[lodocpreview],[local_mtime],[md5],[docpreview],[share],[path],[local_ctime],[server_filename],[empty],[accountid]) VALUES(@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19)", mConnection)) { foreach (var v in info.list) { cmd.Parameters.Clear(); foreach (var v2 in _getFileObjects(v, account)) { cmd.Parameters.AddWithValue("", v2); } try { count += cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } } }catch (Exception e) { Console.WriteLine(e.ToString()); } return(count); }
public string ScanFile(int page = 1, int num = 500, string dir = "%2F") { List <NnPanFile> list = new List <NnPanFile>();// 文件夹 while (true) { string url = $"https://pan.baidu.com/api/list?order=time&desc=1&showempty=0&web=1&page={page}&num={num}&dir={dir}&t=0.9934258251250032&channel=chunlei&web=1&app_id=250528&bdstoken={m_account.BDStoken}&logid={m_account.LogId}&clienttype=0&startLogTime=1571497395535"; NnPanInfos info = _getPanInfos(url); if (info == null) { continue; } if (info.list != null) { foreach (var v in info.list)// 处理文件夹 { if (v.isdir == 1) { list.Add(v); } } } // 将数据写入数据库 int count = NnReader.Instance.InsertFiles(info, m_account); if (info.errno != 0) { return(info.errno.ToString()); } else if (info.list.Count < num) { break; } ++page; } // 处理文件夹 foreach (var v in list) { if (v.empty > 0) { continue; } string s = v.path; string ss = System.Web.HttpUtility.UrlEncode(v.path); ScanFile(1, 500, ss); } return("success"); }
/// <summary> /// 获取网盘文件夹列表 /// </summary> private NnPanInfos _getPanInfos(string url) { HttpWebRequest request = WebRequest.CreateHttp(url); request.CookieContainer = m_cookie; request.Host = "pan.baidu.com"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"; request.Method = "GET"; request.KeepAlive = true; WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string str = reader.ReadToEnd(); response.Close(); JavaScriptSerializer serializer = new JavaScriptSerializer(); NnPanInfos info = serializer.Deserialize <NnPanInfos>(str); return(info); }