Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Web;
  7.  
  8. //https://api.vk.com/method/photos.get?owner_id=-96461400&album_id=230961460
  9.  
  10. namespace ArkadiaTV.VKapi
  11. {
  12. public static class VKapi
  13. {
  14. public static Album GetAlbum(string link)
  15. {
  16. Album photos = null;
  17. char[] seporators = { '_', '-' };
  18. string[] parts = link.Split(seporators);
  19. string responseLink = "https://api.vk.com/method/photos.get?owner_id=-" + parts[1] + "&album_id=" + parts[2];
  20. var json = new WebClient().DownloadString(responseLink);
  21. System.IO.StreamWriter file = new System.IO.StreamWriter("c:/Intel/" + parts[2] + ".txt");
  22. file.WriteLine(json);
  23. file.Close();
  24. photos = JsonConvert.DeserializeObject<Album>(json);
  25. photos.Randomize(10);
  26. string juson = JsonConvert.SerializeObject(photos);
  27. System.IO.StreamWriter file2 = new System.IO.StreamWriter("c:/Intel/Col" + parts[2] + ".txt");
  28. file2.WriteLine(juson);
  29. file2.Close();
  30. return null;
  31. }
  32. }
  33.  
  34. public class Photo
  35. {
  36. public int pid { get; set; }
  37. public int aid { get; set; }
  38. public int owner_id { get; set; }
  39. public int user_id { get; set; }
  40. public string src { get; set; }
  41. public string src_big { get; set; }
  42. public string src_small { get; set; }
  43. public string src_xbig { get; set; }
  44. public string src_xxbig { get; set; }
  45. public int width { get; set; }
  46. public int height { get; set; }
  47. public string text { get; set; }
  48. public string target { get; set; }
  49. public int created { get; set; }
  50. public bool show { get; set; }
  51. Photo() {show = false;}
  52. }
  53.  
  54. public class Album
  55. {
  56. public List<Photo> response { get; set; }
  57. public int Count() { if (response != null) return response.Count; return 0; }
  58. public int ShowCount() {
  59. int count = 0;
  60. foreach(Photo current in response) {
  61. if (current.show == true)
  62. ++count;
  63. }
  64. return count;
  65. }
  66. public void Randomize(int count)
  67. {
  68. int[] randArray = new int[count];
  69. bool catcher = false;
  70. Random rnd = new Random();
  71. for (int i = 0; i < count; )
  72. {
  73. int buffer = rnd.Next(0, response.Count);
  74. for(int j = 0; j < i; ++j)
  75. {
  76. if (randArray[j] == buffer)
  77. catcher = true;
  78. }
  79. if (catcher == false)
  80. {
  81. randArray[i] = buffer;
  82. response[buffer].show = true;
  83. catcher = false;
  84. ++i;
  85. }
  86. else
  87. catcher = false;
  88. }
  89. }
  90. public string[] getList()
  91. {
  92. string[] buffer = new string[this.ShowCount()];
  93. int current = 0;
  94. for (int i = 0; i < response.Count; ++i)
  95. {
  96. if (response[i].show == true)
  97. {
  98. buffer[current] = response[i].src_xxbig;
  99. ++current;
  100. }
  101. }
  102. return null;
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement