Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. @name VK_Player#2
  2. @persist [Table]:table [N MaxCount Duration DurMax]:number [ReqURL Title Artist]:string
  3.  
  4. #include "libs/chatCmd"
  5.  
  6. if(first())
  7. {
  8. noDuplications()
  9.  
  10. function void searchMP3(SongName:string) {
  11. N = 1
  12. ReqURL = "https://radejka.ru/music/"+httpUrlEncode(SongName)
  13. timer("ReqClk",20)
  14. stoptimer("Time")
  15. }
  16.  
  17. function void entity:playUrl(Id, Url:string, Volume)
  18. {
  19. #ifdef streamDisable3D(number)
  20. streamDisable3D(1)
  21. This:streamStart(Id, Url, Volume)
  22. #else
  23. soundURLpause(Id)
  24. soundURLload(Id, Url, Volume, 0, This)
  25. #endif
  26. }
  27.  
  28. function string timeFormat(Seconds:number) {
  29. local H = floor(Seconds / 3600)
  30. local M = floor(Seconds / 60) % 60
  31. local S = Seconds % 60
  32. return H ? format("%02d:%02d:%02d", H, M, S) : format("%02d:%02d", M, S)
  33. }
  34.  
  35. function void updName(Dur:number) {
  36. if(MaxCount) {
  37. local Coeff = ((DurMax - Duration)/DurMax)*80
  38. local Bar = ""
  39.  
  40. for(K=1,80) {
  41. #S2 = (Coeff >= K & Coeff < K+10) ? "l" : "."
  42. S2 = (Coeff >= K-5 & Coeff < K+5) ? "l" : "."
  43. Bar = Bar + S2
  44. }
  45. Bar = ""+Bar+""
  46.  
  47. #setName(format("[%s/%s] %s - %s [%s]\n%s",N,MaxCount,Artist,Title,timeFormat(Dur),Bar))
  48. setName(format("[%s/%s] %s - %s [%s]\n[%s] %s [%s]",
  49. N,MaxCount,Artist,Title,timeFormat(DurMax),timeFormat(DurMax-Duration),Bar,timeFormat(Duration)))
  50. }
  51. }
  52.  
  53. function selectSong(Num:number) {
  54. local Track = Table[Num, array]
  55.  
  56. Artist = Track:string(1)
  57. Title = Track:string(2)
  58. local TimeStr = Track:string(3)
  59. local URL = "https://radejka.ru/play/"+Track:string(4)
  60.  
  61. local DurEx = TimeStr:explode(":")
  62. local Min = DurEx:string(1):toNumber()
  63. local Sec = DurEx:string(2):toNumber()
  64. Duration = DurMax = Min*60 + Sec + 1
  65.  
  66. updName(Duration)
  67. stoptimer("Time") timer("Time",1000)
  68. entity():playUrl(1, URL, 10)
  69. }
  70.  
  71. function void nextSong(Arg:number) {
  72. N = Arg ? floor(Arg) : N+1
  73. if(N < 1 | N > MaxCount) { N = 1 }
  74. selectSong(N)
  75. }
  76.  
  77. regChatCmd("#", "CMD_Search", CHAT_FLAG_FRIENDS)
  78. regChatCmd("#f", "CMD_Search", CHAT_FLAG_FRIENDS)
  79. regChatCmd("!f", "CMD_Search", CHAT_FLAG_FRIENDS)
  80.  
  81. regChatCmd("#n", "CMD_Next", CHAT_FLAG_FRIENDS)
  82. regChatCmd("!n", "CMD_Next", CHAT_FLAG_FRIENDS)
  83.  
  84. regChatCmd("#s", "CMD_Stop", CHAT_FLAG_FRIENDS)
  85. regChatCmd("!s", "CMD_Stop", CHAT_FLAG_FRIENDS)
  86.  
  87. hideOwnerCmd(1)
  88.  
  89. runOnHTTP(1)
  90. }
  91.  
  92. if(clk("CMD_Search")) {
  93. searchMP3(getCmdArgsString())
  94. }
  95.  
  96. if(clk("CMD_Next")) {
  97. local Arg = getCmdArgsString():toNumber()
  98. nextSong(Arg)
  99. print(format("[%s/%s] %s - %s [%s]",N,MaxCount,Artist,Title,timeFormat(Duration)))
  100. }
  101.  
  102. if(clk("CMD_Stop")) {
  103. soundURLpause(1)
  104. setName("VK_Player")
  105. stoptimer("Time")
  106. }
  107.  
  108. if(clk("ReqClk")) {
  109. if(httpCanRequest()) { httpRequest(ReqURL) } else { timer("ReqClk",20) }
  110. }
  111.  
  112. if(httpClk()) {
  113. Table = httpData():gmatch("<div class=\"name\">\n<i>(.-)</i>.-0px;\">(.-)<.-<span class=\"time\">(.-)<.-download_link', '(.-)'")
  114.  
  115. if(Table:count()) {
  116. MaxCount = Table:count()
  117. selectSong(N)
  118.  
  119. print(format("[%s/%s] %s - %s [%s]",N,MaxCount,Artist,Title,timeFormat(Duration)))
  120. } else {
  121. MaxCount = 0
  122. print("Not found!")
  123. entity():soundPlaySingle("garrysmod/content_downloaded.wav",100,29)
  124. }
  125. }
  126.  
  127. if(clk("Time")) {
  128. Duration -= 1
  129. if(Duration < 1) {
  130. nextSong(0)
  131. } else {
  132. updName(Duration)
  133. timer("Time",1000)
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement