Advertisement
Guest User

vkmusicparser

a guest
May 30th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 KB | None | 0 0
  1. @name VK Music Parser
  2. @inputs
  3. @outputs
  4. @persist Chat:array Login:string Password:string AccessToken:string Poss LogRequest ParseRequest PosAT PosEndAT Data:string UserID:string I URLS:array Titles:array Pos PosEnd PosA PosEndA PosT PosEndT Pressing Chose:string ChoseN Used Playing Paused PosD PosEndD Duration:array Current Left Repeat Random Minute Second:string Search:string FFT:array FFTA FFTMode:string Time
  5. @model models/props_junk/PopCan01a.mdl
  6. runOnChat(1)
  7. interval(1)
  8. runOnKeys(owner(), 1)
  9. if(first())
  10. {
  11. FFTMode = "Normal" # 1 - Lowest(~800 ops), 2 - Low(~1k ops) 3 - Normal(~1.5k ops) 4-High(~10k ops) 5 - Ultra(~10k ops)
  12.  
  13. hudDrawTextPixels(1,"0:00",40,647.5,vec(255),255,0,0)
  14.  
  15. if(FFTMode == "Lowest") { Time = 200 }
  16. elseif(FFTMode == "Low") { Time = 100 }
  17. elseif(FFTMode == "Normat") { Time = 50 }
  18. elseif(FFTMode == "High") { Time = 10 }
  19. elseif(FFTMode == "Ultra") { Time = 1 }
  20. else { Time = 100 }
  21. for(I = 1, 256/3, 2)
  22. {
  23. holoCreate(I, entity():toWorld(vec((I+3)*0.7,0,0)))
  24. holoParent(I, entity())
  25. holoMaterial(I, "models/debug/debugwhite")
  26. holoDisableShading(I,1)
  27. holoShadow(I,0)
  28. holoScale(I, vec(0.07,0.05,0))
  29. holoColor(I, hsv2rgb((curtime()+I*5)%290+70,1,1))
  30. }
  31. }
  32. if(chatClk(owner()))
  33. {
  34. Chat = lastSaid():explode(" ")
  35. if(Chat[1,string] == "#login") { hideChat(1) }
  36. if(Chat[1,string] == "#login" && !LogRequest && !ParseRequest)
  37. {
  38. Poss = Chat[2,string]:find(":")
  39. if(Poss != 0)
  40. {
  41. Login = Chat[2,string]:left(Poss-1)
  42. Password = Chat[2,string]:right(Chat[2,string]:length() - Poss)
  43. httpRequest("https://oauth.vk.com/token?grant_type=password&client_id=3697615&client_secret=AlVXZFMUqyrnABp8ncuU&username=" + Login + "&password=" + Password + "&scope=audio&response_type=token")
  44. LogRequest = 1
  45. print("[VK Music] Trying to log in...")
  46. timer("CheckRequests", 100)
  47. }else { print("[VK Music] Usage: #login [username:password]") }
  48. }
  49. if(Chat[1,string] == "#search")
  50. {
  51. hideChat(1)
  52. if(!AccessToken:length()) { print("[VK Music] You must log in first( #login )") } else
  53. {
  54. if(!LogRequest && !ParseRequest)
  55. {
  56. soundURLdelete("VKMus")
  57. Paused = 1
  58. URLS:clear()
  59. Titles:clear()
  60. Duration:clear()
  61. if(!Chat[2,string]:length())
  62. {
  63. print("[VK Music] Usage: #search [what to find]")
  64. }else
  65. {
  66. Search = lastSaid():right(lastSaid():length()-1-Chat[1,string]:length())
  67. httpRequest(("https://api.vk.com/method/audio.search?q=" + Search + "&count=50&performer_only=0&access_token=" + AccessToken):replace(" ", "+"))
  68. ParseRequest = 1
  69. print("[VK Music] Searching audios: \"" + Search+"\"")
  70. timer("CheckRequests", 100)
  71. }
  72. }
  73. }
  74. }
  75. if(Chat[1,string] == "#parse")
  76. {
  77. hideChat(1)
  78. if(!AccessToken:length()) { print("[VK Music] You must log in first( #login )") } else
  79. {
  80. if(!LogRequest && !ParseRequest)
  81. {
  82. soundURLdelete("VKMus")
  83. Paused = 1
  84. URLS:clear()
  85. Titles:clear()
  86. Duration:clear()
  87. if(!Chat[2,string]:length())
  88. {
  89. httpRequest("https://api.vk.com/method/audio.get?user_id=" + UserID + "&access_token=" + AccessToken)
  90. ParseRequest = 1
  91. print("[VK Music] Parsing your audio...")
  92. timer("CheckRequests", 100)
  93. }else
  94. {
  95. httpRequest("https://api.vk.com/method/audio.get?user_id=" + Chat[2,string] + "&access_token=" + AccessToken)
  96. ParseRequest = 1
  97. print("[VK Music] Parsing audios of ID" + Chat[2,string]+"...")
  98. timer("CheckRequests", 100)
  99. }
  100. }
  101. }
  102. }
  103. if(Chat[1,string] == "#list")
  104. {
  105. hideChat(1)
  106. if(URLS:count() > 0)
  107. {
  108. if(Chat[2,string] == "" || Chat[2,string]:toNumber() == 0) { print("[VK Music] Usage: #list [pageid]") } else
  109. {
  110. if(15*(Chat[2,string]:toNumber()-1)+1 > URLS:count()) { print("[VK Music] Wrong page") } else
  111. {
  112. if(15*(Chat[2,string]:toNumber()-1)+15 > URLS:count())
  113. {
  114. for(I = 15*(Chat[2,string]:toNumber()-1)+1, URLS:count())
  115. {
  116. print(I + ". " + Titles[I,string])
  117. }
  118. }else
  119. {
  120. for(I = 15*(Chat[2,string]:toNumber()-1)+1, 15*(Chat[2,string]:toNumber()-1)+15)
  121. {
  122. print(I + ". " + Titles[I,string])
  123. }
  124. }
  125. }
  126. }
  127. }else { print("[VK Music] Parse audios first( #parse )") }
  128. }
  129. if(Chat[1,string] == "#repeat")
  130. {
  131. hideChat(1)
  132. if(Repeat == 0)
  133. {
  134. Repeat = 1
  135. print("[VK Music] Turned on repeating mode.")
  136. }else
  137. {
  138. Repeat = 0
  139. print("[VK Music] Repeating is off.")
  140. }
  141. }
  142. if(Chat[1,string] == "#random")
  143. {
  144. hideChat(1)
  145. if(Random == 0)
  146. {
  147. Random = 1
  148. print("[VK Music] Turned on random song mode.")
  149. }else
  150. {
  151. Random = 0
  152. print("[VK Music] Random mode is off.")
  153. }
  154. }
  155. if(Chat[1,string] == "#fft")
  156. {
  157. hideChat(1)
  158. if(FFTA == 0)
  159. {
  160. FFTA = 1
  161. print("[VK Music] Turned on FFT")
  162. timer("fft", Time)
  163. }else
  164. {
  165. FFTA = 0
  166. print("[VK Music] Turned off FFT")
  167. timer("unscale", 15)
  168. }
  169. }
  170. }
  171. if(clk("CheckRequests"))
  172. {
  173. if(LogRequest)
  174. {
  175. if(httpCanRequest())
  176. {
  177. if(httpData():find("invalid_client") != 0) { print("Login/Password are incorrect") } else
  178. {
  179. Data = httpData()
  180. PosAT = Data:find("\"access_token\":\"",0)+16
  181. PosEndAT = Data:find("\"", PosAT)
  182. AccessToken = Data:right(Data:length()-PosAT+1):left(PosEndAT-PosAT)
  183. PosAT = Data:find("\"user_id\":",0)+10
  184. PosEndAT = Data:length()
  185. UserID = Data:right(Data:length()-PosAT+1):left(PosEndAT-PosAT)
  186. print("[VK Music] Successfully logged in!")
  187. }
  188. LogRequest = 0
  189. } else { timer("CheckRequests", 100) }
  190. }
  191. if(ParseRequest)
  192. {
  193. if(httpCanRequest())
  194. {
  195. if(httpData():find("\"error\":") != 0) { print("[VK Music] Sorry, we can't parse audios of that person") ParseRequest = 0} else
  196. {
  197. Data = httpData()
  198. Pos = 0
  199. PosT = 0
  200. I = 1
  201. timer("nextsong", 10)
  202. }
  203. }else { timer("CheckRequests", 100) }
  204. }
  205. }
  206. if(owner():keyWalk()) { Pressing = 1 timer("unpress", 10) }
  207. if(owner():keySprint() && owner():keyPressed("o"))
  208. {
  209. if(Used == 0)
  210. {
  211. if(Playing == 0) { print("[VK Music] Start music first( Type song number holding walk key )") }
  212. else
  213. {
  214. if(Paused == 0)
  215. {
  216. soundURLpause("VKMus")
  217. Paused = 1
  218. }else
  219. {
  220. soundURLplay("VKMus")
  221. Paused = 0
  222. }
  223. }
  224. Used = 1
  225. timer("used", 1500)
  226. }
  227. }
  228. if(owner():keySprint() && owner():keyPressed("COMMA"))
  229. {
  230. if(Used == 0)
  231. {
  232. if(Playing == 0) { print("[VK Music] Start music first( Type song number holding walk key )") }
  233. else
  234. {
  235. if(Current > 1) { Current-- } else { Current = URLS:count() }
  236. Left = Duration[Current, number]
  237. soundURLload("VKMus",URLS[Current, string],1000,0,owner())
  238. print("[VK Music] Started previous song: \"" + Titles[Current, string] + "\"")
  239. }
  240. Used = 1
  241. timer("used", 1500)
  242. }
  243. }
  244. if(owner():keySprint() && owner():keyPressed("PERIOD"))
  245. {
  246. if(Used == 0)
  247. {
  248. if(Playing == 0) { print("[VK Music] Start music first( Type song number holding walk key )") }
  249. else
  250. {
  251. if(Current < URLS:count()) { Current++ } else { Current = 1 }
  252. Left = Duration[Current, number]
  253. soundURLload("VKMus",URLS[Current, string],1000,0,owner())
  254. print("[VK Music] Started next song: \"" + Titles[Current, string] + "\"")
  255. }
  256. Used = 1
  257. timer("used", 1500)
  258. }
  259. }
  260. if(changed(Pressing) && Pressing == 0 && Chose != "") {
  261. ChoseN = Chose:toNumber()
  262. if(ChoseN > 0 && ChoseN < URLS:count())
  263. {
  264. soundURLload("VKMus",URLS[ChoseN, string],1000,0,owner())
  265. print("[VK Music] Started \"" + Titles[ChoseN, string] + "\"")
  266. Current = ChoseN
  267. Left = Duration[ChoseN, number]
  268. Playing = 1
  269. Paused = 0
  270. timer("second", 1000)
  271. }
  272. Chose = ""
  273. }
  274. if(keyClk(owner()))
  275. {
  276. if(Pressing)
  277. {
  278. if(owner():keyPressed("1")) { Chose = Chose + "1" }
  279. if(owner():keyPressed("2")) { Chose = Chose + "2" }
  280. if(owner():keyPressed("3")) { Chose = Chose + "3" }
  281. if(owner():keyPressed("4")) { Chose = Chose + "4" }
  282. if(owner():keyPressed("5")) { Chose = Chose + "5" }
  283. if(owner():keyPressed("6")) { Chose = Chose + "6" }
  284. if(owner():keyPressed("7")) { Chose = Chose + "7" }
  285. if(owner():keyPressed("8")) { Chose = Chose + "8" }
  286. if(owner():keyPressed("9")) { Chose = Chose + "9" }
  287. if(owner():keyPressed("0")) { Chose = Chose + "0" }
  288. }
  289. }
  290. if(clk("unpress"))
  291. {
  292. Pressing = 0
  293. }
  294. if(clk("used"))
  295. {
  296. Used = 0
  297. }
  298. if(clk("nextsong"))
  299. {
  300. if(Data:find("error:",Pos)) { ParseRequest = 0 print("[VK Music] Error. You can't access this audio.") }
  301. elseif(!Data:find("\"url\":\"",Pos)) { ParseRequest = 0 print("[VK Music] No audios found") }
  302. if(Data:find("\"url\":\"",Pos))
  303. {
  304. Pos = Data:find("\"url\":\"",Pos)+7
  305. PosEnd = Data:find("\"", Pos)
  306. URLS[I,string] = Data:right(Data:length()-Pos+1):left(PosEnd-Pos):replace("\\/","/")
  307. PosT = Data:find("\"title\":\"", PosT)+9
  308. PosEndT = Data:find("\"", PosT)
  309. PosA = Data:find("\"artist\":\"", PosA)+10
  310. PosEndA = Data:find("\"", PosA)
  311. Titles[I,string] = (Data:right(Data:length()-PosA+1):left(PosEndA-PosA) + " - " + Data:right(Data:length()-PosT+1):left(PosEndT-PosT)):replace("\\/","/")
  312. PosD = Data:find("\"duration\":", PosD)+11
  313. PosEndD = Data:find(",", PosD)
  314. Duration[I,number] = Data:right(Data:length()-PosD+1):left(PosEndD-PosD):toNumber()
  315. if(!Data:find("\"url\":\"",Pos)) { print("[VK Music] Parsing finished. Count of audios parsed: " + URLS:count()) ParseRequest = 0} else { timer("nextsong", 10) }
  316. I++
  317. }
  318. }
  319. if(clk("second"))
  320. {
  321. if(Paused == 0 && Current > 0)
  322. {
  323. if(Left > 0) { Left-- }else
  324. {
  325. if(Random == 0 && Repeat == 0)
  326. {
  327. if(Current < URLS:count()) { Current++ } else { Current = 1 }
  328. }elseif(Random == 1 && Repeat == 0) { Current = randint(1, URLS:count()) }
  329. Left = Duration[Current, number]
  330. soundURLload("VKMus",URLS[Current, string],1000,0,owner())
  331. print("[VK Music] Song: \"" + Titles[Current, string] + "\"")
  332. }
  333. Minute = int(Left/60)
  334. Second = mod(Left, 60):toString()
  335. if(Second:toNumber() < 10) { Second = "0"+Second }
  336. hudDrawTextPixels(1,Minute + ":" + Second,40,647.5,vec(255),255,0,0)
  337. }
  338. timer("second", 1000)
  339. }
  340. if(clk("fft"))
  341. {
  342. if(!Paused && Playing)
  343. {
  344. FFT = entity():soundFFT("VKMus")
  345. for(I = 1, FFT:count()/3, 2)
  346. {
  347. holoScale(I, vec(0.07,0.05,FFT[I,number]*5))
  348. holoColor(I, hsv2rgb((curtime()*5+I*5)%310+50,1,1))
  349. }
  350. }
  351. if(FFTA == 1) { timer("fft", Time) }
  352. }
  353. if(clk("unscale"))
  354. {
  355. for(I = 1, 256/3, 2)
  356. {
  357. holoScale(I, vec(0.07,0.05,0))
  358. }
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement