public PhotoSearchOptions CreatePhotoSearchOption(
            string i_name          = "",
            List <string> i_tags   = null,
            int i_max_result_count = 500)
        {
            SearchTerm options = new SearchTerm();

            options.SearchName = i_name;
            options.Tags       = i_tags;

            return(CreatePhotoSearchOption(options, i_max_result_count));
        }
        /// <summary>
        /// Create search option for Flickr database
        /// </summary>
        /// <param name="i_name">Photo name</param>
        /// <param name="i_tags">Photo Tags</param>
        /// <param name="i_max_result_count">Number of top results returned</param>
        /// <returns>Search results</returns>
        public PhotoSearchOptions CreatePhotoSearchOption(
            SearchTerm i_search_term,
            int i_max_result_count = 500)
        {
            PhotoSearchOptions options = new PhotoSearchOptions();

            options.Extras    = PhotoSearchExtras.All;
            options.SortOrder = PhotoSearchSortOrder.Relevance;
            options.Tags      = string.Join(",", i_search_term.Tags);
            options.Text      = i_search_term.SearchName;
            options.TagMode   = TagMode.AllTags;
            options.PerPage   = i_max_result_count;

            return(options);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load search tags and ids from the database CSV file with whitespace delimeter
        /// </summary>
        /// <param name="i_xml_path"></param>
        /// <returns></returns>
        public static Dictionary <string, List <SearchTerm> > LoadDatabaseSearchTagsFromXML(
            string i_xml_filepath = DatabaseDefines.DefaultTagXMLFilePath)
        {
            var ret = new Dictionary <string, List <SearchTerm> >();

            XmlTextReader reader = new XmlTextReader(i_xml_filepath);

            // optimise parsing
            string     current = String.Empty;
            SearchTerm item    = new SearchTerm();

            while (reader.Read())
            {
                if (AcceptedTagGroupNames.Contains(reader.Name))
                {
                    current = Convert.ToString(reader.GetAttribute("Value"));

                    if (!ret.ContainsKey(current))
                    {
                        throw new XmlException(
                                  "XML file " + i_xml_filepath + " is in an invalid format");
                    }
                }
                else if (reader.Name == "Item")
                {
                    if (current == String.Empty)
                    {
                        throw new XmlException(
                                  "XML file " + i_xml_filepath + " is in an invalid format");
                    }

                    item.Tags = new List <string> {
                        reader.GetAttribute("Tag")
                    };
                    item.SearchName = reader.GetAttribute("Name");
                    ret[current].Add(item);
                }
            }

            return(ret);
        }
        /// <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);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Save the photos returned from a result to disk
 /// </summary>
 /// <param name="i_results">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>
 abstract public int SearchAndDownloadImages(
     SearchTerm i_search_term,
     string i_rootpath,
     int i_min_filesize = DatabaseDefines.PhotoNotAvailableSize);