当前位置: 首页>>代码示例>>C#>>正文


C# Page.DownloadImage方法代码示例

本文整理汇总了C#中DotNetWikiBot.Page.DownloadImage方法的典型用法代码示例。如果您正苦于以下问题:C# Page.DownloadImage方法的具体用法?C# Page.DownloadImage怎么用?C# Page.DownloadImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DotNetWikiBot.Page的用法示例。


在下文中一共展示了Page.DownloadImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateSourceField

        private static void UpdateSourceField(Page page)
        {
            Match m;
            if ((m = picasaAlbumUrlRegex.Match(page.text)).Success ||
                (m = picasaUserUrlRegex.Match(page.text)).Success)
            {
                page.DownloadImage("temp_wiki_image");

                string userId = m.Groups[2].ToString();
                string chosenAlbumName = m.Groups.Count >= 3 ? m.Groups[3].ToString() : null;

                // A common existing error
                if (chosenAlbumName == "Eakins")
                {
                    chosenAlbumName = "EakinsThomas";
                }

                string userApiUrl = "http://picasaweb.google.com/data/feed/api/user/" + userId;
                string userApiPage = WgetToString(userApiUrl);
                if (userApiPage == null) return;

                Console.WriteLine("Searching for image URL. Retrieving info about candidate images...");
                List<string> photoIds = new List<string>();
                foreach (Match m2 in userPageAlbumIdRegex.Matches(userApiPage))
                {
                    string albumName = m2.Groups[2].ToString();
                    if (chosenAlbumName == null || albumName == chosenAlbumName)
                    {
                        string albumId = m2.Groups[1].ToString();
                        string albumApiUrl = "http://picasaweb.google.com/data/feed/api/user/" + userId + "/albumid/" + albumId;
                        string albumApiPage = WgetToString(albumApiUrl);

                        foreach (Match m3 in albumPageImageIdRegex.Matches(albumApiPage))
                        {
                            string photoId = m3.Groups[1].ToString();
                            string licenseName = null;
                            PhotoInfo info = new PhotoInfo();
                            info.albumId = albumId;
                            info.albumName = albumName;

                            photoIds.Add(photoId);
                            if (idToPhotoInfo.ContainsKey(photoId)) continue;
                            if (!GetImageInfo(userId, albumId, photoId, out licenseName, out info.mediaUrl, out info.summary))
                            {
                                photoIds.Remove(photoId);
                                continue;
                            }
                            idToPhotoInfo.Add(photoId, info);
                        }
                    }
                }

                // Sort by the longest common substring between the summary and filename
                photoIds.Sort(new Comparison<string>(delegate(string leftId, string rightId)
                    {
                        string titleNoPrefix = page.title.Substring("File:".Length);
                        return LongestCommonSubstring(idToPhotoInfo[rightId].summary, titleNoPrefix)
                              .CompareTo(LongestCommonSubstring(idToPhotoInfo[leftId].summary, titleNoPrefix));
                    }));

                Console.WriteLine("Doing image comparisons...");
                foreach (string photoId in photoIds)
                {
                    PhotoInfo info = idToPhotoInfo[photoId];
                    string photoCachedFilename = "photo" + photoId;

                    while (!File.Exists(photoCachedFilename) || new FileInfo(photoCachedFilename).Length == 0)
                    {
                        string mediaUrlFull = new Regex("^(.*)/([^/]*)$").Replace(info.mediaUrl, "${1}/d/${2}");
                        Console.WriteLine("Fetching photo with ID " + photoId + "...");
                        WgetToFile(mediaUrlFull, photoCachedFilename);
                    }

                    if (FilesAreIdentical(photoCachedFilename, "temp_wiki_image"))
                    {
                        UpdateSource(page, userId, info.albumName, photoId);
                        return;
                    }

                    string failureReason;
                    if (UploadOriginalVersion(out failureReason, page, info.mediaUrl, "temp_wiki_image", photoCachedFilename, /*fetchThumbnailVersion*/false, /*allowWikiBigger*/true))
                    {
                        UpdateSource(page, userId, info.albumName, photoId);
                        return;
                    }
                }

                Console.WriteLine("Image not found");
            }
            else
            {
                if (!page.text.Contains("waldemar"))
                {
                    // For debugging, catch ones where we couldn't figure out the Picasa URL
                    //Debugger.Break();
                }
            }
        }
开发者ID:wikigit,项目名称:Picasa-Review-Bot,代码行数:98,代码来源:Program.cs


注:本文中的DotNetWikiBot.Page.DownloadImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。