Skip to content

Commit

Permalink
Merge pull request #113 from usaginya/MaxMadcc
Browse files Browse the repository at this point in the history
Maxmadcc
  • Loading branch information
usaginya authored Jan 19, 2021
2 parents b3b016d + 31ba8d9 commit dcd1ed3
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 23 deletions.
48 changes: 40 additions & 8 deletions MoeLoaderDelta/Control/DownloadControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public struct MiniDownloadItem
public int id;
public bool noVerify;
public string searchWord;
public MiniDownloadItem(string file, string url, string host, string author, string localName, string localfileName, int id, bool noVerify)
//当前下载对象的站点接口检索号
public int siteIntfcIndex;
public MiniDownloadItem(string file, string url, string host, string author, string localName, string localfileName, int id, bool noVerify, int siteIntfcIndex)
{
//原始后缀名
string ext = string.Empty;
Expand All @@ -50,6 +52,7 @@ public MiniDownloadItem(string file, string url, string host, string author, str
this.id = id;
this.noVerify = noVerify;
this.searchWord = MainWindow.SearchWordPu;
this.siteIntfcIndex = siteIntfcIndex;
}
}

Expand All @@ -74,20 +77,23 @@ private class DownloadTask
public bool IsStop { set; get; }
public string NeedReferer { get; set; }
public bool NoVerify { get; set; }
public SessionHeadersCollection SiteHeaders { get; set; }

/// <summary>
/// 下载任务
/// </summary>
/// <param name="url">目标地址</param>
/// <param name="saveLocation">保存位置</param>
/// <param name="referer">是否需要伪造Referer</param>
public DownloadTask(string url, string saveLocation, string referer, bool noVerify)
/// <param name="shc">指定请求头</param>
public DownloadTask(string url, string saveLocation, string referer, bool noVerify, SessionHeadersCollection shc)
{
SaveLocation = saveLocation;
Url = url;
NeedReferer = referer;
NoVerify = noVerify;
IsStop = false;
SiteHeaders = shc;
}
}
public ObservableCollection<DownloadItem> DownloadItems { get; } = new ObservableCollection<DownloadItem>();
Expand Down Expand Up @@ -191,8 +197,10 @@ public void AddDownload(IEnumerable<MiniDownloadItem> items, DLWorkMode dLWork)
{
downloadItemsDic.Remove(item.url);
}*/
DownloadItem itm = new DownloadItem(fileName, item.url, item.host, item.author, item.localName, item.localfileName, item.id, item.noVerify, item.searchWord);

DownloadItem itm = new DownloadItem(
fileName, item.url, item.host, item.author, item.localName,
item.localfileName, item.id, item.noVerify, item.searchWord, item.siteIntfcIndex
);
downloadItemsDic.Add(item.url, itm);
DownloadItems.Add(itm);
NumLeft++;
Expand All @@ -214,7 +222,8 @@ public void AddDownload(IEnumerable<MiniDownloadItem> items, DLWorkMode dLWork)
/// <summary>
/// 添加下载通用
/// </summary>
/// <param name="items"></param>
/// <param name="items">下载物</param>
/// <param name="site">站点接口</param>
public void AddDownload(IEnumerable<MiniDownloadItem> items)
{
AddDownload(items, DLWorkMode.Retry);
Expand Down Expand Up @@ -353,7 +362,9 @@ private void RefreshList()

DownloadItems[DownloadItems.Count - NumLeft].StatusE = DLStatus.DLing;

DownloadTask task = new DownloadTask(url, file, MainWindow.IsNeedReferer(url), dlitem.NoVerify);
SessionHeadersCollection shc = new SessionHeadersCollection();
shc = SiteManager.Instance.Sites[dlitem.SiteIntfcIndex].SiteHeaders;
DownloadTask task = new DownloadTask(url, file, MainWindow.IsNeedReferer(url), dlitem.NoVerify, shc);
webs.Add(url, task);

//异步下载开始
Expand All @@ -379,6 +390,7 @@ private void Download(object o)
FileStream fs = null;
Stream str = null;
SessionHeadersCollection shc = new SessionHeadersCollection();
shc = task.SiteHeaders;
SessionClient sc = new SessionClient();
System.Net.WebResponse res = null;
double downed = 0;
Expand Down Expand Up @@ -792,14 +804,15 @@ private void itmLst_Click(object sender, RoutedEventArgs e)

if (!isexists)
{
//url|文件名|域名|上传者|ID(用于判断重复)|免文件校验
//url|文件名|域名|上传者|ID(用于判断重复)|免文件校验|下载对象的站点接口检索号
text += i.Url
+ "|" + i.LocalFileName
+ "|" + i.Host
+ "|" + i.Author
+ "|" + i.Id
+ "|" + (i.NoVerify ? 'v' : 'x')
+ "|" + i.SearchWord
+ "|" + i.SiteIntfcIndex
+ "\r\n";
success++;
}
Expand Down Expand Up @@ -929,7 +942,7 @@ private void ExecuteDownloadListTask(DLWorkMode dlworkmode)
downloadItemsDic.Remove(item.Url);
AddDownload(new MiniDownloadItem[] {
new MiniDownloadItem(item.FileName, item.Url, item.Host, item.Author, item.LocalName, item.LocalFileName,
item.Id, item.NoVerify)
item.Id, item.NoVerify, item.SiteIntfcIndex)
}, dlworkmode);
}
break;
Expand Down Expand Up @@ -1271,6 +1284,25 @@ public void DownLoadFromFile(string fileName)
if (parts.Length > 6 && parts[6].Trim().Length > 0)
di.searchWord = parts[6];

//下载对象的站点接口检索号
if (parts.Length > 7 && parts[7].Trim().Length > 0)
{
try
{
di.siteIntfcIndex = int.Parse(parts[7]);
}
catch
{
//设为默认站点接口检索号
di.siteIntfcIndex = 10;
}
}
else
{
//设为默认站点接口检索号
di.siteIntfcIndex = 10;
}

items.Add(di);
}

Expand Down
4 changes: 3 additions & 1 deletion MoeLoaderDelta/Control/DownloadItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class DownloadItem : INotifyPropertyChanged
public int Id { get; set; }
public bool NoVerify { get; set; }
public string SearchWord { get; set; }
public int SiteIntfcIndex { get; set; }

/// <summary>
/// 是否选中
Expand Down Expand Up @@ -139,7 +140,7 @@ public void SetSpeed(double sp)
/// <param name="localName">本地路径文件名</param>
/// <param name="localfileName">本地文件名</param>
/// <param name="id">作品ID</param>
public DownloadItem(string fileName, string url, string host, string author, string localName, string localfileName, int id, bool? noVerify, string searchWord)
public DownloadItem(string fileName, string url, string host, string author, string localName, string localfileName, int id, bool? noVerify, string searchWord, int siteIntfcIndex)
{
FileName = fileName;
Size = "N/A";
Expand All @@ -153,6 +154,7 @@ public DownloadItem(string fileName, string url, string host, string author, str
Id = id;
NoVerify = noVerify != null ? (bool)noVerify : false;
SearchWord = searchWord;
SiteIntfcIndex = siteIntfcIndex;
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
1 change: 1 addition & 0 deletions MoeLoaderDelta/Control/ImgControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public ImgControl(Img img, int index, IMageSite site)
this.site = site;
Image = img;
this.index = index;
shc = site.SiteHeaders;
shc.Add("Accept-Ranges", "bytes");
shc.Accept = null;
shc.Referer = site.Referer;
Expand Down
2 changes: 2 additions & 0 deletions MoeLoaderDelta/PreFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public void PreFetchPage(int page, int count, string word, IMageSite site)
ContentType = SessionHeadersValue.ContentTypeAuto,
Referer = site.Referer
};

shc = site.SiteHeaders;
shc.Add("Accept-Ranges", "bytes");

imgs = site.FilterImg(imgs, MainWindow.MainW.MaskInt, MainWindow.MainW.MaskRes,
Expand Down
4 changes: 2 additions & 2 deletions MoeLoaderDelta/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ private void Img_imgDLed(object sender, EventArgs e)
string fileName = GenFileName(dlimg, oriUrls[c]);
string domain = SiteManager.Instance.Sites[nowSelectedIndex].ShortName;
downloadC.AddDownload(new MiniDownloadItem[] {
new MiniDownloadItem(fileName, oriUrls[c], domain, dlimg.Author, string.Empty, string.Empty, dlimg.Id, dlimg.NoVerify)
new MiniDownloadItem(fileName, oriUrls[c], domain, dlimg.Author, string.Empty, string.Empty, dlimg.Id, dlimg.NoVerify, nowSelectedIndex)
});
}
if (ClearDownloadSelected)
Expand Down Expand Up @@ -2359,7 +2359,7 @@ private void DownloadWork()
}
string fileName = GenFileName(dlimg, oriUrls[c]);
string domain = SiteManager.Instance.Sites[nowSelectedIndex].ShortName;
urls.Add(new MiniDownloadItem(fileName, oriUrls[c], domain, dlimg.Author, string.Empty, string.Empty, dlimg.Id, dlimg.NoVerify));
urls.Add(new MiniDownloadItem(fileName, oriUrls[c], domain, dlimg.Author, string.Empty, string.Empty, dlimg.Id, dlimg.NoVerify,nowSelectedIndex));
}
if (ClearDownloadSelected)
{ ((ImgControl)imgPanel.Children[i]).SetChecked(false); }
Expand Down
13 changes: 13 additions & 0 deletions MoeSite/AbstractImageSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ public virtual string LoginPwd
/// </summary>
public virtual bool IsVisible => true;

/// <summary>
/// 该站点的请求头
/// </summary>
public virtual SessionHeadersCollection SiteHeaders
{
get
{
SessionHeadersCollection shc = new SessionHeadersCollection();
return shc;
}

}

/// <summary>
/// 站点扩展设置,用于在站点子菜单加入扩展设置选项
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions MoeSite/ImageSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public interface IMageSite
/// </summary>
bool IsVisible { get; }

/// <summary>
/// 该站点的请求头
/// </summary>
SessionHeadersCollection SiteHeaders { get; }

/// <summary>
/// 站点列表中显示的图标
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions SitePack/SiteATFBooru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SiteATFBooru : AbstractImageSite
private SiteBooru booru;
private SessionClient Sweb = new SessionClient();
private readonly SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;
private const string Cookieflag = "atfbooru=t;";
private static string cookie = string.Empty, nowUser = cookie;
private static bool IsLoginSite = false, IsRunLogin = IsLoginSite, onceLogin = true;
Expand Down
13 changes: 7 additions & 6 deletions SitePack/SiteBooru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SiteBooru : AbstractImageSite
protected BooruProcessor.SourceType srcType;
protected SessionClient Sweb = new SessionClient();
protected SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;

private Dictionary<string, string> siteLoginUser = new Dictionary<string, string>();
private Dictionary<string, string> siteLoginCookie = new Dictionary<string, string>();
Expand Down Expand Up @@ -84,7 +85,10 @@ public SiteBooru(string siteUrl, string url, string tagUrl, string siteName, str
this.shc = shc;
this.loginUrl = loginUrl;
siteLoginUser.Add(shortName, null);
siteLoginCookie.Add(shortName, null);
if (string.IsNullOrEmpty(shc.Get("Cookie")))
siteLoginCookie.Add(shortName, null);
else
siteLoginCookie.Add(shortName, shc.Get("Cookie"));
}

public override string SiteUrl => siteUrl;
Expand Down Expand Up @@ -180,11 +184,8 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
break;
}

if (count > 0)
url = string.Format(Url, pagestr, count, keyWord);
else
url = string.Format(Url, pagestr, keyWord);

url = (count > 0) ? string.Format(Url, pagestr, count, keyWord) : string.Format(Url, pagestr, keyWord);

url = keyWord.Length < 1 ? url.Substring(0, url.Length - 6) : url;

return Sweb.Get(url, proxy, shc);
Expand Down
1 change: 1 addition & 0 deletions SitePack/SiteGelbooru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SiteGelbooru : AbstractImageSite
private SiteBooru booru;
private SessionClient Sweb = new SessionClient();
private SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;
private APImode apiMode = APImode.NULL;
public override string SiteUrl { get { return "https://gelbooru.com"; } }
public override string SiteName { get { return "gelbooru.com"; } }
Expand Down
1 change: 1 addition & 0 deletions SitePack/SitePixiv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public override bool IsSupportCount //fixed 20
private static string tempPage = null;
private SessionClient Sweb = new SessionClient();
private SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;
private readonly PixivSrcType srcType = PixivSrcType.Author;
private string referer = "https://www.pixiv.net/";
private string LoginUrl => "https://accounts.pixiv.net/login?lang=zh&source=pc&view_type=page&ref=";
Expand Down
1 change: 1 addition & 0 deletions SitePack/SiteRule34.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SiteRule34 : AbstractImageSite
private SiteBooru booru;
private SessionClient Sweb = new SessionClient();
private SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;
public override string ShortName { get { return "rule34"; } }
private Rule34srcType srcType = Rule34srcType.Filter;
public enum Rule34srcType { Filter, Full }
Expand Down
22 changes: 16 additions & 6 deletions SitePack/SiteSankaku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SiteSankaku : AbstractImageSite
private SiteBooru booru;
private SessionClient Sweb = new SessionClient();
private SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;
private static bool IsLoginSite = false, IsRunLogin = IsLoginSite;
private string sitePrefix, temppass, tempappkey, ua, pageurl;
private static string cookie = string.Empty, authorization = cookie, nowUser = cookie, nowPwd = cookie, prevSitePrefix = cookie;
Expand All @@ -39,6 +40,12 @@ public SiteSankaku(string prefix)
{
shc.Timeout = 18000;
sitePrefix = prefix;

if (sitePrefix == "idol")
{
ua = "SCChannelApp/3.2 (Android; idol)";
}

CookieRestore();
}

Expand All @@ -57,12 +64,7 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
IsLoginSite = false;
prevSitePrefix = sitePrefix;
}

if (sitePrefix == "idol")
{
ua = "SCChannelApp/3.2 (Android; idol)";
}


//Fix date:
try
{
Expand All @@ -79,6 +81,10 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
}
catch { }

//对获取数添加限制
if (count >= 40)
count = 40;

if (!IsLoginSite)
{
LoadUser();
Expand Down Expand Up @@ -193,6 +199,8 @@ private void Login()
if (jobj.Property("token_type") != null)
{
authorization = $"{jobj["token_type"]} {jobj["access_token"]} ";
//在请求头中添加登录关键信息Authorization
shc.Add(HttpRequestHeader.Authorization, authorization);
}

if (string.IsNullOrWhiteSpace(authorization))
Expand Down Expand Up @@ -256,6 +264,8 @@ private void Login()
else
{
cookie = $"{subdomain }.sankaku;{cookie}";
//在请求头中添加cookie
shc.Add(HttpRequestHeader.Cookie, cookie);
}

pageurl = $"{loginhost}/post/index.json?login={nowUser}&password_hash={temppass}" +
Expand Down
1 change: 1 addition & 0 deletions SitePack/SiteYuriimg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SiteYuriimg : AbstractImageSite

private SessionClient Sweb = new SessionClient();
private SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders => shc;
private static string authorization = string.Empty, nowUser = authorization, nowPwd = authorization;
private static bool IsLoginSite = false, IsRunLogin = IsLoginSite, onceLogin = true;

Expand Down
1 change: 1 addition & 0 deletions SitePack/SiteZeroChan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public override string SiteName

private SessionClient Sweb = new SessionClient();
private SessionHeadersCollection shc = new SessionHeadersCollection();
public override SessionHeadersCollection SiteHeaders { get { return shc; } }
private string[] user = { "zerouser1" };
private readonly string[] pass = { "zeropass" };
private string cookie = "", beforeWord = "", beforeUrl = "";
Expand Down

0 comments on commit dcd1ed3

Please sign in to comment.