Skip to content

Commit

Permalink
Fix issue #21: continue to next image if encount 404/403 for member a…
Browse files Browse the repository at this point in the history
…nd tags batch download
  • Loading branch information
Nandaka committed Jun 20, 2014
1 parent 18a65b8 commit 841a43a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 3 additions & 3 deletions NijieDownloader.Library/Nijie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ public string Download(string url, string referer, string filename, Action<strin
Thread.Sleep(1000);
if (cancelToken != null && cancelToken.IsCancellationRequested)
{
throw new NijieException(string.Format("Cancel requested, error when downloading: {0} to {1} ==> {2}", url, tempFilename, ex.Message), ex, NijieException.DOWNLOAD_ERROR);
throw new NijieException(string.Format("Cancel requested, error when downloading: {0} to {1} ==> {2}", url, tempFilename, ex.Message), ex, NijieException.DOWNLOAD_CANCELLED);
}
}
++retry;

if (retry > Properties.Settings.Default.RetryCount)
throw new NijieException(string.Format("Error when downloading: {0} to {1} ==> {2}", url, tempFilename, ex.Message), ex, NijieException.DOWNLOAD_ERROR);
throw new NijieException(string.Format("Error when downloading: {0} to {1} ==> {2}", url, tempFilename, ex.Message), ex, NijieException.DOWNLOAD_UNKNOWN_ERROR);
}
}

Expand Down Expand Up @@ -322,7 +322,7 @@ public byte[] DownloadData(string url, string referer)

++retry;
if (retry > Properties.Settings.Default.RetryCount)
throw new NijieException(String.Format("Error when downloading data: {0} ==> {1}", url, ex.Message), ex, NijieException.DOWNLOAD_ERROR);
throw new NijieException(String.Format("Error when downloading data: {0} ==> {1}", url, ex.Message), ex, NijieException.DOWNLOAD_UNKNOWN_ERROR);
}
}
return result;
Expand Down
2 changes: 2 additions & 0 deletions NijieDownloader.Library/NijieException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class NijieException : Exception
public const int RENAME_ERROR = 1003;
public const int DOWNLOAD_SKIPPED = 1004;
public const int DB_ERROR = 1005;
public const int DOWNLOAD_CANCELLED = 1006;
public const int DOWNLOAD_UNKNOWN_ERROR = 1999;

public const int MEMBER_REDIR = 2000;
public const int MEMBER_UNKNOWN_ERROR = 2999;
Expand Down
30 changes: 28 additions & 2 deletions NijieDownloader.UI/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,20 @@ private static void doSearchJob(JobDownloadViewModel job)
continue;
}

processImage(job, null, image);
try
{
processImage(job, null, image);
}
catch (NijieException ne)
{
if (ne.ErrorCode == NijieException.DOWNLOAD_ERROR)
{
job.Exceptions.Add(ne);
continue;
}
else
throw;
}

if (job.DownloadCount > limit && limit != 0)
{
Expand Down Expand Up @@ -233,7 +246,20 @@ private static void doMemberJob(JobDownloadViewModel job)
{
if (isJobCancelled(job)) return;

processImage(job, memberPage, imageTemp);
try
{
processImage(job, memberPage, imageTemp);
}
catch (NijieException ne)
{
if (ne.ErrorCode == NijieException.DOWNLOAD_ERROR)
{
job.Exceptions.Add(ne);
continue;
}
else
throw;
}

if (job.CurrentPage > job.EndPage && job.EndPage != 0)
{
Expand Down

0 comments on commit 841a43a

Please sign in to comment.