/// <summary> /// /// </summary> /// <param name="url"></param> /// <param name="isDlOrg"></param> /// <returns></returns> public static string getSingleOriginalImage(string url) { string sReturn = "Fail"; string PageSource = RequestMethod(url); string OrgImgURL = getOriginalImaage(PageSource, "", 2); string shutterstockOrgFolder = Properties.Settings.Default.shutterstockFolder; string shutterstockLargeFolder = Properties.Settings.Default.shutterstockLargeFolder; try { if (!OrgImgURL.Equals("")) { //string pattern = @"//"; //Regex rgx = new Regex(pattern); //OrgImgURL = rgx.Replace(OrgImgURL.Trim(), "/"); OrgImgURL = OrgImgURL.Replace("/", ""); OrgImgURL = OrgImgURL.Replace("\\", "/"); OrgImgURL = "http://" + OrgImgURL; List <ImageDTO> arrImageList = new List <ImageDTO>(); ImageDTO _ImageDTO = new ImageDTO(); _ImageDTO.sArtistName = "hoang dinh thanh"; _ImageDTO.sArtistUserName = "******"; _ImageDTO.sDescription = ""; _ImageDTO.sTitle = ""; _ImageDTO.sUrl = url; _ImageDTO.sFolderName = "ShutterStock"; arrImageList.Add(_ImageDTO); long nIndex = DatabaseController.saveShutterImageInfo(arrImageList); string LargeImgURL = getOriginalImaage(PageSource, "", 3); if (!LargeImgURL.Equals("")) { sReturn = DownloadImage(LargeImgURL, shutterstockLargeFolder, nIndex + ".jpg"); } sReturn = DownloadImage(OrgImgURL, shutterstockOrgFolder, nIndex + ".jpg"); if (sReturn == "0") { sReturn = "Success"; } else { sReturn = "Fail"; } } } catch (Exception ex) { // nothing } return(sReturn); }
/// <summary> /// /// </summary> /// <param name="url"></param> /// <returns></returns> public static string getSingleLargeImage(string url, string savePath, string saveFolder) { string sReturn = "false"; string PageSource = RequestMethod(url); string LargeFolder = savePath + "\\" + saveFolder; if (saveFolder == null || saveFolder == "" || savePath == null || savePath == "") { LargeFolder = Properties.Settings.Default.LargeFolder; } string LargeImgURL = getOriginalImaage(PageSource, "", 3); if (!LargeImgURL.Equals("")) { List <ImageDTO> arrImageList = new List <ImageDTO>(); ImageDTO _ImageDTO = new ImageDTO(); _ImageDTO.sArtistName = "hoang dinh thanh"; _ImageDTO.sArtistUserName = "******"; _ImageDTO.sDescription = ""; _ImageDTO.sTitle = ""; _ImageDTO.sUrl = url; _ImageDTO.sFolderName = "LargeImage"; if (saveFolder != null && saveFolder != "") { _ImageDTO.sFolderName = saveFolder; } //_ImageDTO. arrImageList.Add(_ImageDTO); long nIndex = DatabaseController.saveLargeImageInfo(arrImageList); sReturn = DownloadImage(LargeImgURL, LargeFolder, nIndex + ".jpg"); if (sReturn == "0") { sReturn = "Success"; } else { sReturn = "fail"; } } return(sReturn); }
/// <summary> /// /// </summary> /// <param name="json"></param> /// <param name="folder"></param> /// <param name="folderName"></param> /// <returns></returns> public static string DownloadImageJSON(string json, string folderName) { string sMessage = ""; List <ImageDTO> arrImageList = new List <ImageDTO>(); List <ImageDTO> arrOrgImageList = new List <ImageDTO>(); ImageDTO objImageDTO; ImageDTO objOrgImageDTO; try { dynamic jsonResponse = JObject.Parse(json); string ImageFolder = Properties.Settings.Default.ImageFolder; string OriginalFoder = Properties.Settings.Default.OriginalFolder; //string ImageFolder = @"F:\PRIVATE\MMO\images\Flickr\"; string dir = ImageFolder + folderName; string orgdir = OriginalFoder + folderName; System.IO.Directory.CreateDirectory(dir); System.IO.Directory.CreateDirectory(orgdir); string url; string urlP; string urlO; string PageSource; int nIndex = 0; int nCountOrgImage = 0; string OrgImgURL; foreach (dynamic img in jsonResponse.photos._data) { try { #region get Large Image nIndex++; try { url = img.sizes.l.url.Value; } catch (Exception ex) { continue; } url = "https:" + url; urlO = "https://www.flickr.com/photos/" + img.pathAlias + "/" + img.id; objImageDTO = new ImageDTO(); DownloadImage(url, dir, nIndex + ".jpg"); objImageDTO.sUrl = urlO; objImageDTO.sTitle = img.title; objImageDTO.sArtistName = img.realname; objImageDTO.sArtistUserName = img.username; objImageDTO.nFaveCount = img.faveCount; objImageDTO.nCommentCount = img.commentCount; objImageDTO.nLicense = img.license; objImageDTO.nWidth = img.sizes.l.width; objImageDTO.nHeight = img.sizes.l.height; objImageDTO.sDescription = img.description; objImageDTO.sFolderName = folderName; objImageDTO.nIndex = nIndex; arrImageList.Add(objImageDTO); #endregion #region get Original Image urlP = url.Substring(0, url.Length - 17); PageSource = CommonFunction.RequestMethod(urlO); OrgImgURL = getOriginalImaage(PageSource, urlP, 1); if (!OrgImgURL.Equals("")) { //nCountOrgImage++; DownloadImage(OrgImgURL, orgdir, nIndex + ".jpg"); //objOrgImageDTO = objImageDTO; //objOrgImageDTO.sUrl = OrgImgURL; //objOrgImageDTO.nIndex = nCountOrgImage; //arrOrgImageList.Add(objOrgImageDTO); } #endregion } catch (Exception ex) { continue; } } sMessage = nCountOrgImage.ToString(); DatabaseController.saveImageInfo(arrImageList); //DatabaseController.saveImageInfo(arrOrgImageList, true); } catch (Exception ex) { sMessage = ConstantValue.Fail; } return(sMessage); }