public async Task <List <PhotoAlbumType> > GetPhotoAlbum() { List <Photo> photos = await GenericSerivce.GetResponse <List <Photo> >(Settings.Settings.PhotoAPI); List <Album> albums = await GenericSerivce.GetResponse <List <Album> >(Settings.Settings.AlbumAPI); List <PhotoAlbumType> photoAlbums = new List <PhotoAlbumType>(); foreach (var album in albums) { foreach (var photo in photos.Where(p => p.AlbumId == album.Id)) { PhotoAlbumType photoAlbum = new PhotoAlbumType() { AlbumId = album.Id, AlbumName = album.Title, UserId = album.UserId, PhotoId = photo.Id, Title = photo.Title, Url = photo.Url, ThumbnailUrl = photo.ThumbnailUrl }; photoAlbums.Add(photoAlbum); } } return(photoAlbums); }
public async Task <List <string> > GetLinksFromAlbum(string linkAlbum) { var listLinks = new List <string>(); var id = ParseId(linkAlbum); var requestParam = new PhotoGetParams { Count = 50, OwnerId = Convert.ToInt64(id.Split("_")[0]), AlbumId = PhotoAlbumType.Id(Convert.ToInt64(id.Split("_")[1])), Offset = 0 }; int total = 1; while (total > 0) { var photos = await vkApi.Photo.GetAsync(requestParam); foreach (var photo in photos) { var maxSize = photo.Sizes.Max(w => w.Width); var valid = photo.Sizes.First(w => w.Width == maxSize); listLinks.Add(valid.Url.AbsoluteUri); } requestParam.Offset += 50; total = photos.Count; Thread.Sleep(100); //prevent spaming vk API } return(listLinks); }
static void Postfix(PhotoAlbumMgr __instance, PhotoAlbumType type, ref PhotoAlbumData __result) { if (!enabled || type != PhotoAlbumType.Other || __result == null) { return; } __result.photos = customPhotos; }
public PageGetter <Photo> PhotosInAlbum(long id, PhotoAlbumType albumIdType) => async(count, offset) => await vkApi.Photo.GetAsync(new PhotoGetParams() { OwnerId = id, AlbumId = albumIdType, Extended = true, PhotoSizes = true, Count = (ulong)count, Offset = (ulong)offset });
public void PhotoAlbumType_ToString_NormalCase() { PhotoAlbumType wall = PhotoAlbumType.Wall; PhotoAlbumType profile = PhotoAlbumType.Profile; PhotoAlbumType saved = PhotoAlbumType.Saved; wall.ToString().ShouldEqual("wall"); profile.ToString().ShouldEqual("profile"); saved.ToString().ShouldEqual("saved"); }
public void PhotoAlbumTypeTest() { // get test Assert.That(PhotoAlbumType.Wall.ToString(), Is.EqualTo("wall")); Assert.That(PhotoAlbumType.Profile.ToString(), Is.EqualTo("profile")); Assert.That(PhotoAlbumType.Saved.ToString(), Is.EqualTo("saved")); // parse test Assert.That(PhotoAlbumType.FromJsonString("wall"), Is.EqualTo(PhotoAlbumType.Wall)); Assert.That(PhotoAlbumType.FromJsonString("profile"), Is.EqualTo(PhotoAlbumType.Profile)); Assert.That(PhotoAlbumType.FromJsonString("saved"), Is.EqualTo(PhotoAlbumType.Saved)); }
private void LoadAlbums(string FileName) { var res = (jAlbums)Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(FileName), typeof(jAlbums)); foreach (jAlbum album in res.Albums) { var k = api.Photo.Get(new PhotoGetParams { OwnerId = album.OwnerId, AlbumId = PhotoAlbumType.Id(album.AlbumId) }); Albums.Add(album.Name, new Album(k)); } }
public void PhotoAlbumTypeTest() { // get test Assert.That(actual: PhotoAlbumType.Wall.ToString(), expression: Is.EqualTo(expected: "wall")); Assert.That(actual: PhotoAlbumType.Profile.ToString(), expression: Is.EqualTo(expected: "profile")); Assert.That(actual: PhotoAlbumType.Saved.ToString(), expression: Is.EqualTo(expected: "saved")); // parse test Assert.That(actual: PhotoAlbumType.FromJsonString(response: "wall"), expression: Is.EqualTo(expected: PhotoAlbumType.Wall)); Assert.That(actual: PhotoAlbumType.FromJsonString(response: "profile") , expression: Is.EqualTo(expected: PhotoAlbumType.Profile)); Assert.That(actual: PhotoAlbumType.FromJsonString(response: "saved"), expression: Is.EqualTo(expected: PhotoAlbumType.Saved)); }
public VkCollection <Photo> GetAlbumAsCollection(PhotoAlbum album) { folderName = FolderCheck(album.Title.ToString(), album.OwnerId.ToString()); try { return(this.apiInst.Photo.Get(new PhotoGetParams { OwnerId = album.OwnerId, AlbumId = PhotoAlbumType.Id(album.Id) })); } catch (AccessTokenInvalidException) { MessageBox.Show("Invalid access token."); } return(null); }
private void DownloadAlbum() { string directory = TryGetDownloadedFolderName(DownloadOptions.AlbumId); PhotoGetParams getParams = new PhotoGetParams() { AlbumId = PhotoAlbumType.Id(DownloadOptions.AlbumId), Count = (ulong)DownloadOptions.Limit, Offset = (ulong)DownloadOptions.Offset }; foreach (Photo photo in API.Photo.Get(getParams)) { Console.WriteLine($"Файл {photo.Id} начал скачиваться в локальное хранилище"); Client.DownloadFile(photo.Sizes.Last().Url, Path.Combine(directory, photo.Id + ".jpg")); } }
private static PhotoAlbumType GetAlbumType(long albumId) { switch (albumId) { case -6: return(PhotoAlbumType.Profile); case -7: return(PhotoAlbumType.Wall); case -15: return(PhotoAlbumType.Saved); default: return(PhotoAlbumType.Id(albumId)); } }
/// <summary> /// Fetch info about album portion. /// </summary> private static VkCollection <Photo> _FetchInfo() { var photoParams = new PhotoGetParams() { OwnerId = _ownerId, Offset = _offset, Count = _portion }; switch (_albumId.ToLowerInvariant()) { case "wall": photoParams.AlbumId = PhotoAlbumType.Wall; break; case "profile": photoParams.AlbumId = PhotoAlbumType.Profile; break; case "saved": photoParams.AlbumId = PhotoAlbumType.Saved; break; default: if (long.TryParse(_albumId, out long number)) { photoParams.AlbumId = PhotoAlbumType.Id(number); } break; } var result = _api.Photo.Get(photoParams); if (ReferenceEquals(result, null) || result.Count == 0) { Console.WriteLine("Photo is over"); return(null); } Console.WriteLine($"Portion size: {result.Count}"); return(result); }
private void DownloadAlbum() { string path = GetDownloadedDirectoryPath(); uint photosDownloaded = 0; PhotoGetParams getParams = new PhotoGetParams() { AlbumId = PhotoAlbumType.Id(DownloadOptions.AlbumId), Count = (ulong)DownloadOptions.Limit, Offset = (ulong)DownloadOptions.Offset }; foreach (Photo photo in API.Photo.Get(getParams)) { photosDownloaded++; Client.DownloadFile(photo.Sizes.Last().Url, Path.Combine(path, photo.Id + ".jpg")); } Console.WriteLine($"Всего скачано фотографий: {photosDownloaded}"); }
public async Task GetPhotoAlbumIntegrationTest() { //Get Photo var photos = await GenericSerivce.GetResponse <List <Photo> >(Settings.Settings.PhotoAPI); //Get Album var albums = await GenericSerivce.GetResponse <List <Album> >(Settings.Settings.AlbumAPI); List <PhotoAlbumType> photoAlbums = new List <PhotoAlbumType>(); foreach (var album in albums) { foreach (var photo in photos.Where(p => p.AlbumId == album.Id)) { PhotoAlbumType photoAlbum = new PhotoAlbumType() { AlbumId = album.Id, AlbumName = album.Title, UserId = album.UserId, PhotoId = photo.Id, Title = photo.Title, Url = photo.Url, ThumbnailUrl = photo.ThumbnailUrl }; photoAlbums.Add(photoAlbum); } } Assert.IsTrue(photoAlbums.Count > 0); //Extract Photo Album Assert.IsTrue(photoAlbums.Count() > 0); }
private void btnSnd_Click(object sender, EventArgs e) { string[] rf = new string[4]; var wc = new WebClient(); if (dataGridView1.ColumnCount > 3) { for (int row = 0; dataGridView1.RowCount - 1 > row; row++) { var groupId = long.Parse(dataGridView1.Rows[row].Cells[2].Value.ToString()); if (albumID.Text != "") { var photos = vk.Photo.Get(new PhotoGetParams { Count = 4, AlbumId = PhotoAlbumType.Id(int.Parse(albumID.Text)), OwnerId = vk.UserId }); WallPostParams wpp = new WallPostParams { Message = msgWall.Text, OwnerId = 0 - groupId, Attachments = photos }; vk.Wall.Post(wpp); } else { WallPostParams wpp = new WallPostParams { Message = msgWall.Text, OwnerId = 0 - groupId }; vk.Wall.Post(wpp); } for (int cel = 3; dataGridView1.ColumnCount - 1 > cel && dataGridView1.Rows[row].Cells[cel].Value != null; cel++) { if (dataGridView1.Rows[row].Cells[cel].Value.ToString() != "") { try { long albumId = long.Parse(dataGridView1.Rows[row].Cells[cel].Value.ToString()); var ups = vk.Photo.GetUploadServer(albumId, groupId); rf[0] = Encoding.ASCII.GetString(wc.UploadFile(ups.UploadUrl, Application.StartupPath + @"\file1.jpg")); rf[1] = Encoding.ASCII.GetString(wc.UploadFile(ups.UploadUrl, Application.StartupPath + @"\file2.jpg")); rf[2] = Encoding.ASCII.GetString(wc.UploadFile(ups.UploadUrl, Application.StartupPath + @"\file3.jpg")); rf[3] = Encoding.ASCII.GetString(wc.UploadFile(ups.UploadUrl, Application.StartupPath + @"\file4.jpg")); for (int i = 0; i < 4; i++) { var sPhotos = vk.Photo.Save(new PhotoSaveParams { SaveFileResponse = rf[i], GroupId = groupId, AlbumId = albumId }); Thread.Sleep(500); } // for (int i = 0; i < 4; i++) } catch { Debugger.Log(1, "Exception", "Exception"); } Thread.Sleep(1000 * (int)numKD1.Value); // КД между альбомами } // for (int cel = 3; dataGridView1.ColumnCount - 1 > cel && dataGridView1.Rows[row].Cells[cel].Value != null; cel++) Thread.Sleep(1000 * (int)numKD2.Value); // КД между группами } } // for (int row = 0; dataGridView1.RowCount - 1 > row; row++) } // if (dataGridView1.ColumnCount > 3) }
static void Main(string[] args) { var api = new VkApi(); string linkHead = "https://vk.com/"; int groupId = -37583795; MyWebClient webClient = new MyWebClient(); System.IO.File.Create("wallPhotoList.csv").Close(); System.IO.File.Create("albumPhotoList.csv").Close(); Services fromServices = new Services(); List <wallPhotoModel> wallPhotoList = new List <wallPhotoModel>(); List <albumPhotoModel> albumPhotoList = new List <albumPhotoModel>(); int offsertPostExit; int offsetPhotoExit; int offsetAlbumExit; int offsetWallPhotoSave; int offsetAlbumPhotoSave; int countPosts = 0; int countPhotos = 0; int countPhotosWSave = 0; int countPhotosASave = 0; //summary //authorization //summary api.Authorize(new ApiAuthParams { ApplicationId = //Token here, Login = "******", Password = "******", Settings = Settings.All }); /*=============================Тянем фото со стены================================*/ var getPosts = api.Wall.Get(new WallGetParams { OwnerId = groupId, Filter = WallFilter.Owner, Extended = true, Count = 1 }); offsertPostExit = (int)(getPosts.TotalCount + (100 - getPosts.TotalCount % 100)); Console.WriteLine(getPosts.TotalCount); for (int i = 0; i < offsertPostExit; i += 100) { getPosts = api.Wall.Get(new WallGetParams { OwnerId = groupId, Filter = WallFilter.Owner, Extended = true, Count = 100, Offset = (ulong)i }); foreach (var gPos in getPosts.WallPosts) { var photoDetector = 0; foreach (var x in gPos.Attachments) { if (x.Type.ToString().Equals("VkNet.Model.Attachments.Photo")) { photoDetector++; } } if (photoDetector > 0) { var fsModel = new wallPhotoModel { PostLink = linkHead + "wall" + groupId + "_" + gPos.Id, //ссылка на пост + PostCreateTime = gPos.Date.Value.AddHours(2).ToString(), //дата создания записи + PhotoLink = fromServices.GetPhotoLink(gPos), //ссылка на фото в вк + PostLikes = gPos.Likes.Count.ToString(), //лайки к фото+ PostShares = gPos.Reposts.Count.ToString(), //репосты к фото+ PostComents = fromServices.GetCommentsOfPost(gPos.Id, api, groupId) //коменты и их авторы + }; wallPhotoList.Add(fsModel); Console.WriteLine(countPosts + " // " + gPos.Id); countPosts++; //пишем в файл модели постов using (StreamWriter streamReaderWall = new StreamWriter("wallPhotoList.csv")) { using (CsvWriter csvReader = new CsvWriter(streamReaderWall)) { csvReader.Configuration.Delimiter = ";"; csvReader.WriteRecords(wallPhotoList); } } } } } /*=============================Тянем фото с альбома================================*/ var albums = api.Photo.GetAlbums(new PhotoGetAlbumsParams { OwnerId = groupId, }); Console.WriteLine(albums.Count.ToString()); //int countAlbumPhotos = 0; //проходимся по всем альбомам foreach (var a in albums) { //кидаем запрос чтобы узнать сколько всего фото в альбоме var albumPhotos = api.Photo.Get(new PhotoGetParams { OwnerId = groupId, AlbumId = PhotoAlbumType.Id(a.Id) }); //округляем ко-во фото в альбоме offsetPhotoExit = (int)(albumPhotos.TotalCount + (100 - albumPhotos.TotalCount % 100)); //countAlbumPhotos = countAlbumPhotos + (int)albumPhotos.TotalCount; Console.WriteLine(albumPhotos.TotalCount); //делаем цикл с шагом 100 чтобы пройти по всем фото for (var j = 0; j < offsetPhotoExit; j += 100) { //кидаем уже подробный запрос по фоткам albumPhotos = api.Photo.Get(new PhotoGetParams { OwnerId = groupId, AlbumId = PhotoAlbumType.Id(a.Id), Reversed = true, Extended = true, PhotoSizes = true, Count = 100, Offset = (ulong)j, }); //проходимся по фоткам в альбома foreach (var ap in albumPhotos) { //заполняем модель var apModel = new albumPhotoModel { AlbumId = a.Id.ToString(), AlbumName = a.Title, PhotoDate = ap.CreateTime.Value.AddHours(2).ToString(), PhotoLink = linkHead + "photo" + groupId + ap.Id, PhotoUri = fromServices.GetUrlOfBigPhoto(ap), PhotoLikes = ap.Likes.Count.ToString(), //PhotoShares = "reposts here", //PhotoComents = fromServices.GetCommentsOfPost(ap.PostId, api, groupId) }; //добавляем модель в список albumPhotoList.Add(apModel); Console.WriteLine(countPhotos + " // " + ap.Id); countPhotos++; //пишем в файл модели фоток using (StreamWriter streamReaderAlbum = new StreamWriter("albumPhotoList.csv")) { using (CsvWriter csvReader = new CsvWriter(streamReaderAlbum)) { csvReader.Configuration.Delimiter = ";"; csvReader.WriteRecords(albumPhotoList); } } } } } //Console.WriteLine("Count photos in all albums " + countAlbumPhotos); /*=============================Сохраняем фото со стены================================*/ var getPhotos = api.Photo.Get(new PhotoGetParams { OwnerId = groupId, AlbumId = VkNet.Enums.SafetyEnums.PhotoAlbumType.Wall, }); offsetWallPhotoSave = (int)(getPhotos.TotalCount + (1000 - getPhotos.TotalCount % 1000)); Console.WriteLine(getPhotos.TotalCount); for (var i = 0; i < offsetWallPhotoSave; i += 1000) { getPhotos = api.Photo.Get(new PhotoGetParams { OwnerId = groupId, AlbumId = VkNet.Enums.SafetyEnums.PhotoAlbumType.Wall, Reversed = true, Extended = true, PhotoSizes = true, Count = 1000, Offset = (ulong)i }); using (webClient) { foreach (var gp in getPhotos) { webClient.DownloadFile(fromServices.GetUrlOfBigPhoto(gp), "wallPhotos\\" + gp + ".jpg"); Console.WriteLine(countPhotosWSave + " // " + linkHead + gp); countPhotosWSave++; } } } /*=============================Сохраняем фото с альбомов================================*/ var albumsForSave = api.Photo.GetAlbums(new PhotoGetAlbumsParams { OwnerId = groupId, }); Console.WriteLine(albumsForSave.Count.ToString()); foreach (var a in albumsForSave) { Directory.CreateDirectory("albumPhotos\\" + a.Id); Console.WriteLine(" Создан albumPhotos\\" + a.Id); } foreach (var a in albumsForSave) { var getPhotosSave = api.Photo.Get(new PhotoGetParams { OwnerId = groupId, AlbumId = PhotoAlbumType.Id(a.Id) }); offsetAlbumPhotoSave = (int)(getPhotosSave.TotalCount + (1000 - getPhotosSave.TotalCount % 1000)); countPhotosASave = countPhotosASave + (int)getPhotosSave.TotalCount; Console.WriteLine(getPhotosSave.TotalCount); for (var i = 0; i < offsetAlbumPhotoSave; i += 1000) { getPhotosSave = api.Photo.Get(new PhotoGetParams { OwnerId = groupId, AlbumId = PhotoAlbumType.Id(a.Id), Reversed = true, Extended = true, PhotoSizes = true, Count = 1, Offset = (ulong)i }); using (webClient) { foreach (var gp in getPhotosSave) { webClient.DownloadFile(fromServices.GetUrlOfBigPhoto(gp), "albumPhotos\\" + a.Id + "\\" + gp + ".jpg"); Console.WriteLine(countPhotosASave + " // " + linkHead + gp); countPhotosASave++; } } } } Console.WriteLine("Всего фоток " + countPhotosASave); Console.WriteLine("END PROGRAM//PRESS ANY KEY"); Console.ReadKey(); }
public void TestMethod() { PhotoAlbumType.Id(237935674); }