public List <UrlContainer.UrlContainer> GetImageUrlList(UrlContainer.UrlContainer uc, string[] format) { var ret = new List <UrlContainer.UrlContainer>(); var mode = GetSeigaDisplayMode(uc); if (mode == "seiga") { Regex re = new Regex("https?://seiga.nicovideo.jp/seiga/im(?<Id>[0-9]+)$"); Match m = re.Match(uc.Url); if (m.Success) { uc.Url = "http://seiga.nicovideo.jp/image/source?id=" + m.Groups["Id"].Value; string resUrl = uc.GetResponseUrl(mUserAccount.CookieContainer); uc.DownloadUrl = resUrl.Replace("/o/", "/priv/"); if (!String.IsNullOrEmpty(uc.DownloadUrl)) { ret.Add(uc); } } } else if (mode == "watch") { var hc = new HtmlContainer.HtmlContainer(uc, mUserAccount.CookieContainer); hc.UpdateAttributeUrlList("img", "data-original", null); ret = hc.AttributeUrlList; } return(ret); }
private string GetSeigaDisplayMode(UrlContainer.UrlContainer uc) { Regex re = new Regex("https?://seiga.nicovideo.jp/(?<Mode>seiga|watch)"); Match m = re.Match(uc.Url); if (m.Success) { return(m.Groups["Mode"].Value); } return(null); }
ImageInfo InitImageInfo(HtmlContainer.HtmlContainer hc, UrlContainer.UrlContainer uc, string dir) { string tmpName = Utilities.Common.RemoveChars(uc.FileName, mInvalidCharsF, "_"); string fileName = mSettings.FileNameGenerator.Generate(dir, tmpName); ImageInfo info = new ImageInfo(); info.ImageUrl = uc.Url; info.ParentUrl = hc.UrlContainer.Url; info.ParentTitle = hc.Title; info.ImagePath = dir + fileName; return(info); }
private List <UrlContainer.UrlContainer> PixivImageUrls(HtmlContainer.HtmlContainer hc) { var html = hc.Html.Replace("\\/", "/"); var urls = new List <UrlContainer.UrlContainer>(); var re = new Regex(@"https?://i.pximg.net/img-original/[a-z0-9\./_]+"); foreach (Match m in re.Matches(html)) { if (m.Success) { var uc = new UrlContainer.UrlContainer(m.Value, hc.UrlContainer.Url); urls.Add(uc); } } return(urls); }
bool Download(UrlContainer.UrlContainer uc, ImageInfo info) { // ダウンロード if (!uc.Cache(mCookieContainer)) { return(false); } // ファイルサイズのフィルタリング var imageSize = (int)(uc.CacheSize / 1000); if (mSettings.ImageSizeFilter.Filter(imageSize)) { mSettings.Logger.Write("Downloader", "ファイルサイズフィルタが適用されました > " + uc.Url); return(false); } using (var cachedImage = new Bitmap(Image.FromStream(uc.CacheStream))) { // 解像度のフィルタリング if (mSettings.ResolutionFilter.Filter(cachedImage)) { mSettings.Logger.Write("Downloader", "解像度フィルタが適用されました > " + uc.Url); return(false); } // カラーフォーマットのフィルタリング if (mSettings.ColorFilter.Filter(cachedImage)) { mSettings.Logger.Write("Downloader", "カラーフィルタが適用されました > " + uc.Url); return(false); } } // ダウンロードした画像を保存 uc.SaveCache(info.ImagePath); // ダウンロード状況更新 mSettings.Logger.Write("Downloader", uc.Url + " を取得しました"); mTempStatus.Size += imageSize; mSumStatus.Size += imageSize; mTempStatus.Images++; mSumStatus.Images++; mSettings.OverlappedUrlFilter.Add(info); OnUpdateImageInfo(info); return(true); }
public List <UrlContainer.UrlContainer> GetLinkList(HtmlContainer.HtmlContainer hc) { List <UrlContainer.UrlContainer> ret = new List <UrlContainer.UrlContainer>(); var re = new Regex(@"""illustId"":""(?<Id>[0-9]+)"""); foreach (Match m in re.Matches(hc.Html)) { if (m.Success) { var uc = new UrlContainer.UrlContainer( "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=" + m.Groups["Id"].Value, hc.UrlContainer.Url); ret.Add(uc); } } return(ret); }
HtmlContainer.HtmlContainer GetHtmlContainerForImages(UrlContainer.UrlContainer uc) { if (IsIgnore(uc.Url)) { return(null); } // URLに対応するプラグインを検索,見つかればCookie取得 Plugins.IPlugin plugin = FindPlugin(uc); var hc = new HtmlContainer.HtmlContainer(uc, mCookieContainer); // Htmlを取得しない if (mSettings.UrlFilter.Filter(uc.Url)) { mSettings.Logger.Write("Downloader", "URL フィルタが適用されました > " + uc.Url); return(hc); } // Htmlを取得する if (mSettings.TitleFilter.Filter(hc.Title)) { mSettings.Logger.Write("Downloader", "タイトルフィルタが適用されました > " + hc.Title); return(hc); } mSettings.Logger.Write("Downloader", uc.Url + " を取得しました"); if (plugin != null && plugin.IsExclusive) { hc.AttributeUrlList = plugin.GetImageUrlList(uc, mSettings.Formats); } else { if (mSettings.ParseHrefAttr) { hc.UpdateAttributeUrlList("a", "href", mSettings.Formats); } if (mSettings.ParseImgTag) { hc.UpdateAttributeUrlList("img", "src", mSettings.Formats); hc.UpdateAttributeUrlList("img", "data-src", mSettings.Formats); } } return(hc); }
Plugins.IPlugin FindPlugin(UrlContainer.UrlContainer uc) { foreach (var plugin in mPlugins) { if (plugin.Enabled && plugin.IsParse(uc.Url)) { if (plugin.Login()) { mCookieContainer.Add(plugin.GetCookieCollection()); } else { throw new ApplicationException(plugin.Name + "\nログインに失敗しました"); } return(plugin); } } return(null); }
HtmlContainer.HtmlContainer GetHtmlContainerForLinks(UrlContainer.UrlContainer uc) { if (IsIgnore(uc.Url)) { return(null); } // URLに対応するプラグインを検索,見つかればCookie取得 Plugins.IPlugin plugin = FindPlugin(uc); var hc = new HtmlContainer.HtmlContainer(uc, mCookieContainer); if (plugin != null && plugin.IsExclusive) { hc.AttributeUrlList = plugin.GetLinkList(hc); } if (hc.AttributeUrlList.Count == 0) { hc.UpdateAttributeUrlList("a", "href", new string[] { "php", "phtml", "html", "htm", "" }); } return(hc); }
public void UpdateAttributeUrlList(string tag, string attr, string[] format) { if (Html == null) { return; } var hp = new HtmlParser(); hp.Source = Html; Regex re = new Regex(@"^(https?|ftp)://.+", RegexOptions.IgnoreCase); while (!hp.Eof()) { if (hp.Parse() == 0) { var attrList = hp.GetTag(); if (attrList.Name.ToLower() == tag && attrList[attr] != null) { string attrValue = attrList[attr].Value; if (!re.Match(attrValue).Success) { Uri baseUrl = new Uri(UrlContainer.Url); Uri abs = new Uri(baseUrl, attrValue); attrValue = abs.AbsoluteUri; } if (re.Match(attrValue).Success) { var uc = new UrlContainer.UrlContainer(attrValue, UrlContainer.RawUrl); uc.AttributeName = attr; if (format == null || format.Contains(uc.Extension)) { AttributeUrlList.Add(uc); } } } } } AttributeUrlList = AttributeUrlList.Distinct().ToList(); }
public List <UrlContainer.UrlContainer> GetImageUrlList(UrlContainer.UrlContainer uc, string[] format) { var ret = new List <UrlContainer.UrlContainer>(); Regex re = new Regex("https?://www.pixiv.net/member_illust.php.*?illust_id=(?<Id>[0-9]+)"); Match m = re.Match(uc.Url); if (m.Success) { var hc = new HtmlContainer.HtmlContainer(uc, mUserAccount.CookieContainer); foreach (var url in PixivImageUrls(hc)) { ret.Add(url); } hc = new HtmlContainer.HtmlContainer( new UrlContainer.UrlContainer("https://www.pixiv.net/member_illust.php?mode=manga&illust_id=" + m.Groups["Id"].Value), mUserAccount.CookieContainer); foreach (var url in PixivMangaUrls(hc, format)) { ret.Add(url); } } return(ret); }
public HtmlContainer(UrlContainer.UrlContainer uc, CookieContainer cc = null) { this.CookieContainer = cc; this.UrlContainer = uc; this.AttributeUrlList = new List <UrlContainer.UrlContainer>(); }
public DomainFilter(bool enabled, UrlContainer.UrlContainer uc) { mEnabled = enabled; this.mBaseUrl = uc; }
public List <UrlContainer.UrlContainer> GetImageUrlList(UrlContainer.UrlContainer uc, string[] format) { return(new List <UrlContainer.UrlContainer>()); }
private async void DownloadWebImages() { if (listViewEx1.SelectedItems.Count == 0) { return; } try { var cookies = new CookieContainer(); var urlList = new List <ImageInfo>(); foreach (ListViewItem lvi in listViewEx1.SelectedItems) { var info = lvi.Tag as ImageInfo; if (!File.Exists(info.ImagePath)) { string imageDir = Path.GetDirectoryName(info.ImagePath); if (!Directory.Exists(imageDir)) { Directory.CreateDirectory(imageDir); } urlList.Add(info); } } using (var progressForm = GetProgressForm("ダウンロード中", urlList.Count)) { progressForm.Show(); await Task.Run(() => { foreach (var info in urlList) { var uc = new UrlContainer.UrlContainer(info.ImageUrl); uc.Referer = info.ParentUrl; uc.Download(info.ImagePath, cookies); if (progressForm.isCancelled) { throw new OperationCanceledException(); } else { progressForm.IncrementProgressBar(); } } }); } MessageBox.Show("ダウンロードが完了しました", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (OperationCanceledException) { MessageBox.Show("ダウンロードはキャンセルされました", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("ダウンロードに失敗しました", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { ReloadHistory(); } }