/// <summary> /// 本地是否存在 /// </summary> /// <param name="url"></param> /// <returns></returns> public bool IsLocal(CoverDb coverDb, string url) { Cover cover = coverDb.QueryByUrl(url); return(cover != null); }
/// <summary> /// 返回图片md5值 /// </summary> /// <param name="coverDb"></param> /// <param name="url"></param> /// <returns></returns> public string LocalCover(CoverDb coverDb, string url) { Cover cover = coverDb.QueryByUrl(url); return(cover.Md5); }
/// <summary> /// 获取封面 /// </summary> /// <param name="aid"></param> /// <param name="bvid"></param> /// <param name="cid"></param> /// <param name="url"></param> /// <returns></returns> public string GetCover(long avid, string bvid, long cid, string url) { CoverDb coverDb = new CoverDb(); Cover cover = coverDb.QueryByUrl(url); // 如果存在,直接返回 // 如果不存在,则先下载 if (cover != null) { string coverPath = $"{StorageManager.GetCover()}/{cover.Md5}"; if (File.Exists(coverPath)) { Cover newCover = new Cover { Avid = avid, Bvid = bvid, Cid = cid, Url = url, Md5 = cover.Md5 }; coverDb.Update(newCover); //coverDb.Close(); return($"{StorageManager.GetCover()}/{cover.Md5}"); } else { string md5 = DownloadImage(url); if (md5 != null) { Cover newCover = new Cover { Avid = avid, Bvid = bvid, Cid = cid, Url = url, Md5 = md5 }; coverDb.Update(newCover); //coverDb.Close(); return($"{StorageManager.GetCover()}/{md5}"); } else { //coverDb.Close(); return(null); } } } else { string md5 = DownloadImage(url); if (md5 != null) { Cover newCover = new Cover { Avid = avid, Bvid = bvid, Cid = cid, Url = url, Md5 = md5 }; coverDb.Insert(newCover); //coverDb.Close(); return($"{StorageManager.GetCover()}/{md5}"); } else { //coverDb.Close(); return(null); } } }