Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SERVICE = {}
- SERVICE.Name = "Vk"
- SERVICE.IsTimed = true
- function SERVICE:Match( url )
- return string.match( url.host, "vk.com" ) and string.match (url.path, "^/video([%d-_]+)") -- we are looking for ownerid_videoid bundle
- end
- function SERVICE:GetURLInfo( url )
- local info = {}
- info.Data = string.match(url.path, "^/video([%d-_]+)")
- return info
- end
- function SERVICE:GetVideoInfo( data, onSuccess, onFailure )
- local onReceive = function( body, length, headers, code )
- local info = {}
- info.title = string.match( body, "<title>([^\n]+)</title>" )
- info.duration = string.match( body, "<duration>(%d+)</duration>" ) --simmilar to youtube, there is a way to get json-info, but i didn't managed to get it work
- info.thumbnail = string.match( body, "<image_medium>(.+).jpg" )
- if onSuccess then
- pcall(onSuccess, info)
- end
- end
- -- sending request to vk.api with access token, that we gained from any application. It is permanent, so we didn't need to renew it. I hide it in pastebin, but could send you one if you ask.
- local url = string.format( "https://api.vk.com/method/video.get.xml?videos=%s&access_token=ACCESS_TOKEN", data )
- self:Fetch( url, onReceive, onFailure )
- end
- theater.RegisterService( 'vk', SERVICE )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement