Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name VK_Player#2
- @persist [Table]:table [N MaxCount Duration DurMax]:number [ReqURL Title Artist]:string
- #include "libs/chatCmd"
- if(first())
- {
- noDuplications()
- function void searchMP3(SongName:string) {
- N = 1
- ReqURL = "https://radejka.ru/music/"+httpUrlEncode(SongName)
- timer("ReqClk",20)
- stoptimer("Time")
- }
- function void entity:playUrl(Id, Url:string, Volume)
- {
- #ifdef streamDisable3D(number)
- streamDisable3D(1)
- This:streamStart(Id, Url, Volume)
- #else
- soundURLpause(Id)
- soundURLload(Id, Url, Volume, 0, This)
- #endif
- }
- function string timeFormat(Seconds:number) {
- local H = floor(Seconds / 3600)
- local M = floor(Seconds / 60) % 60
- local S = Seconds % 60
- return H ? format("%02d:%02d:%02d", H, M, S) : format("%02d:%02d", M, S)
- }
- function void updName(Dur:number) {
- if(MaxCount) {
- local Coeff = ((DurMax - Duration)/DurMax)*80
- local Bar = ""
- for(K=1,80) {
- #S2 = (Coeff >= K & Coeff < K+10) ? "l" : "."
- S2 = (Coeff >= K-5 & Coeff < K+5) ? "l" : "."
- Bar = Bar + S2
- }
- Bar = ""+Bar+""
- #setName(format("[%s/%s] %s - %s [%s]\n%s",N,MaxCount,Artist,Title,timeFormat(Dur),Bar))
- setName(format("[%s/%s] %s - %s [%s]\n[%s] %s [%s]",
- N,MaxCount,Artist,Title,timeFormat(DurMax),timeFormat(DurMax-Duration),Bar,timeFormat(Duration)))
- }
- }
- function selectSong(Num:number) {
- local Track = Table[Num, array]
- Artist = Track:string(1)
- Title = Track:string(2)
- local TimeStr = Track:string(3)
- local URL = "https://radejka.ru/play/"+Track:string(4)
- local DurEx = TimeStr:explode(":")
- local Min = DurEx:string(1):toNumber()
- local Sec = DurEx:string(2):toNumber()
- Duration = DurMax = Min*60 + Sec + 1
- updName(Duration)
- stoptimer("Time") timer("Time",1000)
- entity():playUrl(1, URL, 10)
- }
- function void nextSong(Arg:number) {
- N = Arg ? floor(Arg) : N+1
- if(N < 1 | N > MaxCount) { N = 1 }
- selectSong(N)
- }
- regChatCmd("#", "CMD_Search", CHAT_FLAG_FRIENDS)
- regChatCmd("#f", "CMD_Search", CHAT_FLAG_FRIENDS)
- regChatCmd("!f", "CMD_Search", CHAT_FLAG_FRIENDS)
- regChatCmd("#n", "CMD_Next", CHAT_FLAG_FRIENDS)
- regChatCmd("!n", "CMD_Next", CHAT_FLAG_FRIENDS)
- regChatCmd("#s", "CMD_Stop", CHAT_FLAG_FRIENDS)
- regChatCmd("!s", "CMD_Stop", CHAT_FLAG_FRIENDS)
- hideOwnerCmd(1)
- runOnHTTP(1)
- }
- if(clk("CMD_Search")) {
- searchMP3(getCmdArgsString())
- }
- if(clk("CMD_Next")) {
- local Arg = getCmdArgsString():toNumber()
- nextSong(Arg)
- print(format("[%s/%s] %s - %s [%s]",N,MaxCount,Artist,Title,timeFormat(Duration)))
- }
- if(clk("CMD_Stop")) {
- soundURLpause(1)
- setName("VK_Player")
- stoptimer("Time")
- }
- if(clk("ReqClk")) {
- if(httpCanRequest()) { httpRequest(ReqURL) } else { timer("ReqClk",20) }
- }
- if(httpClk()) {
- Table = httpData():gmatch("<div class=\"name\">\n<i>(.-)</i>.-0px;\">(.-)<.-<span class=\"time\">(.-)<.-download_link', '(.-)'")
- if(Table:count()) {
- MaxCount = Table:count()
- selectSong(N)
- print(format("[%s/%s] %s - %s [%s]",N,MaxCount,Artist,Title,timeFormat(Duration)))
- } else {
- MaxCount = 0
- print("Not found!")
- entity():soundPlaySingle("garrysmod/content_downloaded.wav",100,29)
- }
- }
- if(clk("Time")) {
- Duration -= 1
- if(Duration < 1) {
- nextSong(0)
- } else {
- updName(Duration)
- timer("Time",1000)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement