/// <summary> /// Save the photos returned from a result to disk /// </summary> /// <param name="i_collection">Results of a Flickr API Photo Search</param> /// /// <param name="i_rootpath">Output root path on disk</param> /// <param name="i_min_size">Minimum size of the expected file</param> /// <returns>Number of successfully retrieved photos</returns> override public int SearchAndDownloadImages( SearchTerm i_search_term, string i_rootpath = DatabaseDefines.DefaultDatabaseFlickrPath, int i_min_filesize = DatabaseDefines.PhotoNotAvailableSize) { SearchOptions = CreatePhotoSearchOption(i_search_term); if (SearchOptions == null) { return(0); } var results = ApplyPhotoSearch(SearchOptions).Where(o => o.DoesLargeExist); // Create database directory string database_path = Path.Combine(i_rootpath, i_search_term.SearchName); FileSystemHelpers.MakeDirectory(database_path); // Download image int invalid_count = 0; var client = new MyWebClient(); foreach (var result in results) { string filename = Path.Combine( database_path, i_search_term.SearchName + "_" + result.PhotoId + TargetFileExtension); if (!client.DownloadFile(result.LargeUrl, filename)) { ++invalid_count; } } return(results.Count() - invalid_count); }
/// <summary> /// Save the photos returned from a result to disk /// </summary> /// <param name="i_collection">Results of a Flickr API Photo Search</param> /// /// <param name="i_rootpath">Output root path on disk</param> /// <param name="i_min_size">Minimum size of the expected file</param> /// <returns>Number of successfully retrieved photos</returns> override public int SearchAndDownloadImages( SearchTerm i_search_term, string i_rootpath = DatabaseDefines.DefaultDatabaseImageNetPath, int i_min_filesize = DatabaseDefines.PhotoNotAvailableSize) { var synetID = FindSynetIDFromSearchTerm(i_search_term.SearchName); var tagImageURLs = ExtractSynetURLs(synetID); if (tagImageURLs == null) { return(0); } // Create database directory string database_path = Path.Combine(i_rootpath, i_search_term.SearchName); FileSystemHelpers.MakeDirectory(database_path); // Download image int invalid_count = 0; var client = new MyWebClient(); foreach (var url in tagImageURLs) { string filename = Path.Combine( database_path, Path.GetFileName(url)); if (!client.DownloadFile(url, filename)) { ++invalid_count; } } return(tagImageURLs.Count() - invalid_count); }