Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. import 'isomorphic-fetch'
  2.  
  3. var array = [
  4. {
  5. "id": "natusvinceretv",
  6. "name": "Na'Vi Dota2",
  7. "title": "Natus Vincere dota team channel"
  8. },
  9. {
  10. "id": "Dendiboss",
  11. "name": "Dendi",
  12. "title": "Na'Vi.Dendi channel"
  13. },
  14. {
  15. "id": "VirtusproDOTA",
  16. "name": "Virtuspro",
  17. "title": "Virtus.pro dota team channel"
  18. },
  19. {
  20. "id": "Teamicecret",
  21. "name": "Secret Team",
  22. "title": "Secret Team dota channel"
  23. },
  24. {
  25. "id": "hrdota2",
  26. "name": "HellRaisers",
  27. "title": "HellRaisers dota team channel"
  28. },
  29. {
  30. "id": "noobfromua",
  31. "name": "NoobFromUA",
  32. "title": "Dota 2 Channel NoobFromUA"
  33. },
  34. {
  35. "name": "Dota2RuHub",
  36. "youtubeId": "UCA6WssVVOv_xSB-PdQ7vYYA",
  37. "title": "Канал посвященный игре Dota2 и международным турнирам по этой игре.Официальный YouTube канал русскоязычных экспертов и журналистов игры Dota2."
  38. },
  39. {
  40. "name": "Storm Studio",
  41. "youtubeId": "UCpPpXo2ATn0BQsMpCTTI0yg",
  42. "title": "Storm Studio"
  43. },
  44. {
  45. "id": "DarduinMyMenlon",
  46. "name": "Dota Watafak",
  47. "title": "Suscribe or Feed!!!"
  48. }
  49. ]
  50.  
  51. let all = []
  52.  
  53. getAllVideos(array)
  54.  
  55. function getAllVideos (array) {
  56. array.map((item) => {
  57. const name = item.id
  58. const url = 'https://www.googleapis.com/youtube/v3/channels?' +
  59. 'part=contentDetails&' +
  60. 'forUsername=' + name + '&' +
  61. 'key=AIzaSyB857qDfoTXwdCBaIFDqxEUD3j2W_hCMVg'
  62. makeFetch(url)
  63. })
  64. }
  65. function makeFetch (url) {
  66. fetch(url).then((response) => {
  67. return response.json()
  68. }).then((json) => {
  69. const pid = json.items[0].id
  70. // let arr = []
  71. // arr.push(pid)
  72. // makeXuyetch(pid)
  73. makeXuyetch(pid)
  74. }).catch(function (ex) {
  75. console.log('parsing failed', ex)
  76. })
  77. }
  78. function makeXuyetch (pid) {
  79. const vidResults = 8
  80. const url = 'https://www.googleapis.com/youtube/v3/search?' +
  81. 'maxResults=' + vidResults + '&' +
  82. 'part=snippet&' +
  83. 'channelId=' + pid + '&' +
  84. 'order=date&' +
  85. 'key=AIzaSyB857qDfoTXwdCBaIFDqxEUD3j2W_hCMVg'
  86. fetch(url).then((response) => {
  87. return response.json()
  88. }).then((json) => {
  89.  
  90. const gg = json.items
  91.  
  92. gg.map((item) => {
  93. all.push(item)
  94. })
  95.  
  96. }).catch(function (ex) {
  97. console.log('parsing failed', ex)
  98. })
  99. }
  100.  
  101. console.log(all)
  102.  
  103. // const reduced = all.reduce((acc, x) => { return acc.concat(x) }, []);
  104. //
  105. // console.log(reduced)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement