Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Web;
- //https://api.vk.com/method/photos.get?owner_id=-96461400&album_id=230961460
- namespace ArkadiaTV.VKapi
- {
- public static class VKapi
- {
- public static Album GetAlbum(string link)
- {
- Album photos = null;
- char[] seporators = { '_', '-' };
- string[] parts = link.Split(seporators);
- string responseLink = "https://api.vk.com/method/photos.get?owner_id=-" + parts[1] + "&album_id=" + parts[2];
- var json = new WebClient().DownloadString(responseLink);
- System.IO.StreamWriter file = new System.IO.StreamWriter("c:/Intel/" + parts[2] + ".txt");
- file.WriteLine(json);
- file.Close();
- photos = JsonConvert.DeserializeObject<Album>(json);
- photos.Randomize(10);
- string juson = JsonConvert.SerializeObject(photos);
- System.IO.StreamWriter file2 = new System.IO.StreamWriter("c:/Intel/Col" + parts[2] + ".txt");
- file2.WriteLine(juson);
- file2.Close();
- return null;
- }
- }
- public class Photo
- {
- public int pid { get; set; }
- public int aid { get; set; }
- public int owner_id { get; set; }
- public int user_id { get; set; }
- public string src { get; set; }
- public string src_big { get; set; }
- public string src_small { get; set; }
- public string src_xbig { get; set; }
- public string src_xxbig { get; set; }
- public int width { get; set; }
- public int height { get; set; }
- public string text { get; set; }
- public string target { get; set; }
- public int created { get; set; }
- public bool show { get; set; }
- Photo() {show = false;}
- }
- public class Album
- {
- public List<Photo> response { get; set; }
- public int Count() { if (response != null) return response.Count; return 0; }
- public int ShowCount() {
- int count = 0;
- foreach(Photo current in response) {
- if (current.show == true)
- ++count;
- }
- return count;
- }
- public void Randomize(int count)
- {
- int[] randArray = new int[count];
- bool catcher = false;
- Random rnd = new Random();
- for (int i = 0; i < count; )
- {
- int buffer = rnd.Next(0, response.Count);
- for(int j = 0; j < i; ++j)
- {
- if (randArray[j] == buffer)
- catcher = true;
- }
- if (catcher == false)
- {
- randArray[i] = buffer;
- response[buffer].show = true;
- catcher = false;
- ++i;
- }
- else
- catcher = false;
- }
- }
- public string[] getList()
- {
- string[] buffer = new string[this.ShowCount()];
- int current = 0;
- for (int i = 0; i < response.Count; ++i)
- {
- if (response[i].show == true)
- {
- buffer[current] = response[i].src_xxbig;
- ++current;
- }
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement