Skip to content

Commit

Permalink
Supported attachment content-disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
erlange committed Nov 6, 2019
1 parent 39f1bc7 commit dd92865
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Query printabrick.org.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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$

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$

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

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
31 changes: 30 additions & 1 deletion WaybackDownloader.NET.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Web;
using System.IO;
using System.Net;
using System.Net.Mime;
using System.Threading;

namespace com.erlange.wbmdl
Expand Down Expand Up @@ -276,6 +277,7 @@ static List<Archive> GetResponse(string url)
request.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{

using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
string line, original, urlId, timestamp, fileName, localPath, localPathTimestamp;
Expand All @@ -286,12 +288,20 @@ static List<Archive> GetResponse(string url)
timestamp = line.Split(' ')[2];
fileName = urlId.Split('/')[urlId.Split('/').Length - 1].Split('?')[0];
original = @line.Split(' ')[3];

uri = new Uri(original);


if (urlId.EndsWith("/") || !fileName.Contains("."))
fileName = defaultIndexFile;


if (!string.IsNullOrEmpty(response.GetResponseHeader("content-disposition")) )
{
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition(response.GetResponseHeader("content-disposition"));
fileName = cd.FileName;
}

localPath = uri.Host + "/" + uri.AbsolutePath.Replace(fileName, "");
localPath += HttpUtility.UrlEncode(uri.Query.Replace("?", ""));
localPath += "/" + fileName;
Expand Down Expand Up @@ -413,6 +423,7 @@ static void DownloadArchives(List<Archive> archives, string path, bool isAllTime
{
using (WebClient client = new WebClient())
{
//client.DownloadFileCompleted += Client_DownloadFileCompleted;
foreach (Archive archive in archives)
{
uri = new Uri(archive.Original);
Expand All @@ -422,8 +433,16 @@ static void DownloadArchives(List<Archive> archives, string path, bool isAllTime
}
}
}

private static void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
throw new NotImplementedException();
}

static void DownloadSingleArchive(WebClient client, Archive archive, string path, bool isAllHttpStatus)
{


string dirPath = path.Replace(archive.Filename, "");
string filePath = path;
try
Expand All @@ -432,6 +451,16 @@ static void DownloadSingleArchive(WebClient client, Archive archive, string path
Directory.CreateDirectory(dirPath);

client.DownloadFile(archive.UrlId, filePath);
if (!string.IsNullOrEmpty(client.ResponseHeaders["Content-Disposition"]))
{
ContentDisposition cd = new ContentDisposition(client.ResponseHeaders["Content-Disposition"]);
string cdFilePath = System.IO.Path.Combine(dirPath, cd.FileName);
if (System.IO.File.Exists(cdFilePath))
File.Delete(cdFilePath);

System.IO.File.Move(filePath, cdFilePath);
filePath = cdFilePath;
}

lock (threadLocker)
archiveCount++;
Expand Down

0 comments on commit dd92865

Please sign in to comment.