Skip to content

Commit dd92865

Browse files
committed
Supported attachment content-disposition
1 parent 39f1bc7 commit dd92865

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

Query printabrick.org.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
http://web.archive.org/cdx/search/cdx?url=printabrick.org/*&fl=original,mimetype&collapse=digest&pageSize=1&gzip=false&filter=statuscode:200&from=2019&to=2019&filter=mimetype:^.*\b(application/zip).*\b$
2+
3+
http://web.archive.org/cdx/search/cdx?url=printabrick.org/*&fl=original,mimetype&collapse=digest&pageSize=1&gzip=false&filter=statuscode:200&from=2019&to=2019&limit=10&filter=mimetype:^.*\b(application/zip).*\b$
4+
5+
http://web.archive.org/cdx/search/cdx?url=printabrick.org/*&fl=timestamp,original,mimetype&collapse=digest&pageSize=1&gzip=false&filter=statuscode:200&from=2019&to=2019&filter=mimetype:^.*\b(application/zip).*\b$&output=json&limit=20
6+
7+
http://web.archive.org/cdx/search/cdx?url=printabrick.org/*&fl=timestamp,original,mimetype&collapse=digest&pageSize=1&gzip=false&filter=statuscode:200&from=2019&to=2019&filter=mimetype:^.*\b(application/zip).*\b$&output=json&limit=20

WaybackDownloader.NET.CLI/Program.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Web;
1515
using System.IO;
1616
using System.Net;
17+
using System.Net.Mime;
1718
using System.Threading;
1819

1920
namespace com.erlange.wbmdl
@@ -276,6 +277,7 @@ static List<Archive> GetResponse(string url)
276277
request.Method = "GET";
277278
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
278279
{
280+
279281
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
280282
{
281283
string line, original, urlId, timestamp, fileName, localPath, localPathTimestamp;
@@ -286,12 +288,20 @@ static List<Archive> GetResponse(string url)
286288
timestamp = line.Split(' ')[2];
287289
fileName = urlId.Split('/')[urlId.Split('/').Length - 1].Split('?')[0];
288290
original = @line.Split(' ')[3];
289-
291+
290292
uri = new Uri(original);
291293

294+
292295
if (urlId.EndsWith("/") || !fileName.Contains("."))
293296
fileName = defaultIndexFile;
294297

298+
299+
if (!string.IsNullOrEmpty(response.GetResponseHeader("content-disposition")) )
300+
{
301+
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition(response.GetResponseHeader("content-disposition"));
302+
fileName = cd.FileName;
303+
}
304+
295305
localPath = uri.Host + "/" + uri.AbsolutePath.Replace(fileName, "");
296306
localPath += HttpUtility.UrlEncode(uri.Query.Replace("?", ""));
297307
localPath += "/" + fileName;
@@ -413,6 +423,7 @@ static void DownloadArchives(List<Archive> archives, string path, bool isAllTime
413423
{
414424
using (WebClient client = new WebClient())
415425
{
426+
//client.DownloadFileCompleted += Client_DownloadFileCompleted;
416427
foreach (Archive archive in archives)
417428
{
418429
uri = new Uri(archive.Original);
@@ -422,8 +433,16 @@ static void DownloadArchives(List<Archive> archives, string path, bool isAllTime
422433
}
423434
}
424435
}
436+
437+
private static void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
438+
{
439+
throw new NotImplementedException();
440+
}
441+
425442
static void DownloadSingleArchive(WebClient client, Archive archive, string path, bool isAllHttpStatus)
426443
{
444+
445+
427446
string dirPath = path.Replace(archive.Filename, "");
428447
string filePath = path;
429448
try
@@ -432,6 +451,16 @@ static void DownloadSingleArchive(WebClient client, Archive archive, string path
432451
Directory.CreateDirectory(dirPath);
433452

434453
client.DownloadFile(archive.UrlId, filePath);
454+
if (!string.IsNullOrEmpty(client.ResponseHeaders["Content-Disposition"]))
455+
{
456+
ContentDisposition cd = new ContentDisposition(client.ResponseHeaders["Content-Disposition"]);
457+
string cdFilePath = System.IO.Path.Combine(dirPath, cd.FileName);
458+
if (System.IO.File.Exists(cdFilePath))
459+
File.Delete(cdFilePath);
460+
461+
System.IO.File.Move(filePath, cdFilePath);
462+
filePath = cdFilePath;
463+
}
435464

436465
lock (threadLocker)
437466
archiveCount++;

0 commit comments

Comments
 (0)