public static QpiroJSON SelectedInstagramPhotos(string UserName) { qprPath resources = new qprPath(UserName); QpiroJSON resp = new QpiroJSON(); try { string[] file = Directory.GetFiles(resources.Current_User, resources.UserXmlInfo); string lst2 = HttpContext.Current.Request.Form[0]; JsonSerializerSettings serSettings = new JsonSerializerSettings(); serSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); InstagramProfile.InstaPhoto[] outObject = JsonConvert.DeserializeObject<InstagramProfile.InstaPhoto[]>(lst2, serSettings); if (file.Count() != 1) throw new Exception("Geçersiz kullanıcı bilgileri"); XDocument doc = XDocument.Load(file[0]); XElement root = doc.Elements("_" + resources.UserName).First(); XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault(); IEnumerable<XElement> photos = InstagramP.Elements("Photos"); if (outObject.Count() > 0) { foreach (XElement photo in photos) { foreach (InstagramProfile.InstaPhoto selectedPhoto in outObject) { if (photo.Value == selectedPhoto.name) { XAttribute useths = photo.Attribute("useThis"); useths.Value = selectedPhoto.UseThis.ToString(); break; } } } doc.Save(file[0]); } } catch (Exception e) { resp.Message = e.Message; } return resp; }
public static QpiroJSON GetInstaPhotos(string UserName) { qprPath resources = new qprPath(UserName); QpiroJSON resp = new QpiroJSON(); try { string[] file = Directory.GetFiles(resources.Current_User, resources.UserXmlInfo); if (file.Count() != 1) throw new Exception("Geçersiz kullanıcı bilgileri."); XDocument doc = XDocument.Load(file[0]); XElement root = doc.Elements("_" + resources.UserName).First(); XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault(); resp = XmlInstaPhotos(UserName, InstagramP); InstagramP = null; } catch (Exception e) { resp.Message = e.Message; } return resp; }
public static QpiroJSON XmlInstaPhotos(string UserName, string file) { qprPath resources = new qprPath(UserName); QpiroJSON resp = new QpiroJSON(); XDocument doc = XDocument.Load(file); XElement root = doc.Elements("_" + resources.UserName).First(); resp = XmlInstaPhotos(resources.UserName, root.Elements("InstagramPhotos").FirstOrDefault()); doc = null; root = null; return resp; }
public static bool DownloadInstaPhotos(string UserName, string[] photos) { qprPath resources = new qprPath(UserName); QpiroJSON resp = new QpiroJSON(); try { string[] file = Directory.GetFiles(resources.Current_User, resources.UserXmlInfo); if (file.Count() != 1) throw new Exception("Geçersiz kullanıcı bilgileri."); string _range = "0-1000";// ilk kaç resim ? int min = int.Parse(_range.Split('-')[0]); int max = int.Parse(_range.Split('-')[1]); XDocument doc = XDocument.Load(file[0]); XElement root = doc.Elements("_" + resources.UserName).First(); XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault(); List<XElement> potos = InstagramP.Elements("Photos").ToList(); //download List<string> imglist = photos.ToList();// InstagramProfile.UserPhotos(); if (imglist.Count > 0) { //https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/ for (int i = 0; i < imglist.Count; i++) { if (i >= min && i <= max) { string filname = Path.GetFileName(imglist[i]); if (potos.FindIndex(p => Path.GetFileName(p.Value) == filname) == -1) { Bitmap btm = InstagramProfile.DownloadImage(imglist[i]); if (btm == null) continue; XElement photo = new XElement("Photos", new XAttribute("useThis", true.ToString()) ); photo.Value = imglist[i]; InstagramP.Add(photo); using (MagickImage mini = new MagickImage(btm)) { mini.Quality = 100; mini.Resize(94, 94); mini.Write(Path.Combine(resources.Data_InstagramPhotos, filname)); mini.Dispose(); } } } } doc.Save(file[0]); resp.Data.Add("Resimler Güncellendi"); } else { throw new Exception("Instagram hesabınızda hiç fotoğrafınız bulunmuyor"); } InstagramP = null; potos.Clear(); imglist.Clear(); return true; } catch (Exception e) { resp.Message = e.Message; return false; } }
public static QpiroJSON XmlInstaPhotos(string UserName, XElement _InstagramP) { qprPath resources = new qprPath(UserName); QpiroJSON resp = new QpiroJSON(); List<XElement> potos = _InstagramP.Elements("Photos").ToList(); if (potos.Count > 0) { foreach (XElement item in potos) { string usethis = item.Attribute("useThis").Value.ToLower(); string imgname = item.Value; if (imgname.ToLower().IndexOf("/black.jpg") != -1) { continue; } bool b = false; if (usethis == "true") { b = true; } else { b = false; } resp.Data.Add(new InstagramProfile.InstaPhoto() { UseThis = b, name = imgname }); } potos.Clear(); } else { resp.Message = "Instagram resiminiz bulunmamaktadır."; } return resp; }