Skip to content

Commit 51d0dac

Browse files
author
unreal-system
committed
Update Program.cs
1 parent a69a07d commit 51d0dac

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Program.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -279,26 +279,34 @@ static void Main(string[] args)
279279

280280
private static void DownloadMedia(DateTime time, string sourceUrl, string downloadPath)
281281
{
282-
Console.WriteLine($"SourceTime: {time} Downloading: {sourceUrl}");
283-
try
282+
if (File.Exists(downloadPath) == true)
284283
{
285-
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(sourceUrl);
286-
webReq.Method = "GET";
287-
webReq.Headers.Add("Accept-Encoding", "gzip, deflate");
288-
webReq.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9");
289-
webReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
290-
webReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
291-
292-
using (var Response = (HttpWebResponse)webReq.GetResponse())
284+
Console.WriteLine($"SourceTime: {time} Downloading: {sourceUrl} Has Exist!");
285+
}
286+
else
287+
{
288+
Console.WriteLine($"SourceTime: {time} Downloading: {sourceUrl}");
289+
try
293290
{
294-
using (var fs = File.OpenWrite(downloadPath))
291+
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(sourceUrl);
292+
webReq.Method = "GET";
293+
webReq.Headers.Add("Accept-Encoding", "gzip, deflate");
294+
webReq.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9");
295+
webReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
296+
webReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
297+
298+
using (var Response = (HttpWebResponse)webReq.GetResponse())
295299
{
296-
using (var sr = new StreamReader(Response.GetResponseStream(), Encoding.UTF8))
300+
using (var fs = File.OpenWrite(downloadPath))
297301
{
298-
sr.BaseStream.CopyTo(fs);
302+
using (var sr = new StreamReader(Response.GetResponseStream(), Encoding.UTF8))
303+
{
304+
sr.BaseStream.CopyTo(fs);
305+
}
299306
}
300307
}
301308
}
302-
} catch (Exception ex) { Console.WriteLine(ex.Message); }
309+
catch (Exception ex) { Console.WriteLine(ex.Message); }
310+
}
303311
}
304312
}

0 commit comments

Comments
 (0)