static void Main(string[] args) { Console.Title = $"VKLoader {version}"; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"VKLoader {version} by hexc0der"); Console.WriteLine("Download all images from an album hosted on VK in one go!"); Console.WriteLine("If you liked this program or have any doubts contact me at https://github.com/hexc0der"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; do { Console.WriteLine("Enter a valid VK Album url i.e http://vk.com/album-22382023_240601069 : "); albumUrl = Console.ReadLine(); } while (!IsValidUrl(albumUrl)); var albumIDFromUrl = albumUrl.Substring(albumUrl.LastIndexOf('/') + 1); var tempRequestData = new NameValueCollection { { "act", "show" }, { "al", "1" }, { "al_ad", "0" }, { "list", albumIDFromUrl }, { "module", "photos" }, { "photo", "" }, //encontramos cuantas fotos hay en el album 7u7 }; albumPhotoCount = GetAlbumPhotoCount(wc, tempRequestData); for (offset = 0; offset <= albumPhotoCount; offset += offsetSize) { Console.Write($"\rGetting images in offset {offset}."); offsetBasedRequestData = new NameValueCollection { { "al", "1" }, { "al_ad", "0" }, { "offset", offset.ToString() }, // 40 - 80 - 120 - ... - 520 { "part", "1" }, { "rev", "" } }; GetAlbumInfo(offsetBasedRequestData); } // Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\n{downloadQueue.Count} images have been found in this album."); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; //After getting images for all offsets we start getting info for each img and available res int counter = 1; foreach (var item in downloadQueue) { Console.Write($"\rProcessing {counter} of {downloadQueue.Count} total images."); VKPhoto asd = GetVKPhoto(wc, albumIDFromUrl, item); counter++; photos.Add(asd); } //Once we finally have all info, we start downloading uwu Console.WriteLine("\nStarting download now"); using (var progress = new ProgressBar()) { for (int i = 0; i < photos.Count; i++) { DownloadFromUrl(wc, photos[i].GetHighestResUrl(), photos[i].id); progress.Report((double)i / 100); } } exit("Download Complete."); }
public static VKPhoto GetVKPhoto(WebClient wc, string albumID, string photoID) { var requestData = new NameValueCollection { { "act", "show" }, { "al", "1" }, { "al_ad", "0" }, { "list", albumID }, //unico para un album { "module", "photos" }, { "photo", photoID }, //cada foto }; byte[] response = wc.UploadValues("http://vk.com/al_photos.php", "POST", requestData); string decodedResponse = Encoding.UTF8.GetString(response); var idx = decodedResponse.IndexOf("<!json>"); int indexFrom = decodedResponse.IndexOf("<!json>") + "<!json>".Length; int indexTo = decodedResponse.NthIndexOf("<!>", 9); string jsonData = decodedResponse.Substring(indexFrom, indexTo - indexFrom); dynamic dyn = JsonConvert.DeserializeObject(jsonData); VKPhoto photo = new VKPhoto(); foreach (var item in dyn) { if (item.id.ToString() == photoID) { photo.id = item.id; photo.baseUrl = item.author_href.ToString(); //i know this sucks, but it works :) if (item.x_ != null && item.x_src != null) { if (item.x_.Count > 1) { photo.addResolution(int.Parse(item.x_[1].ToString()), int.Parse(item.x_[2].ToString()), item.x_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.x_src.ToString()); } } if (item.y_ != null && item.y_src != null) { if (item.y_.Count > 1) { photo.addResolution(int.Parse(item.y_[1].ToString()), int.Parse(item.y_[2].ToString()), item.y_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.y_src.ToString()); } } if (item.z_ != null && item.z_src != null) { if (item.z_.Count > 1) { photo.addResolution(int.Parse(item.z_[1].ToString()), int.Parse(item.z_[2].ToString()), item.z_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.z_src.ToString()); } } if (item.w_ != null && item.w_src != null) { if (item.w_.Count > 1) { photo.addResolution(int.Parse(item.w_[1].ToString()), int.Parse(item.w_[2].ToString()), item.w_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.w_src.ToString()); } } if (item.o_ != null && item.o_src != null) { if (item.o_.Count > 1) { photo.addResolution(int.Parse(item.o_[1].ToString()), int.Parse(item.o_[2].ToString()), item.o_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.o_src.ToString()); } } if (item.p_ != null && item.p_src != null) { if (item.p_.Count > 1) { photo.addResolution(int.Parse(item.p_[1].ToString()), int.Parse(item.p_[2].ToString()), item.p_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.p_src.ToString()); } } if (item.q_ != null && item.q_src != null) { if (item.q_.Count > 1) { photo.addResolution(int.Parse(item.q_[1].ToString()), int.Parse(item.q_[2].ToString()), item.q_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.q_src.ToString()); } } if (item.r_ != null && item.r_src != null) { if (item.r_.Count > 1) { photo.addResolution(int.Parse(item.r_[1].ToString()), int.Parse(item.r_[2].ToString()), item.r_src.ToString()); } else { photo.addResolution(defaultWidth, defaultHeight, item.r_src.ToString()); } //Console.WriteLine(item.z_src.ToString()); Console.WriteLine(item.z_[0].ToString()); } } } return(photo); }