Advertisement
Guest User

Untitled

a guest
Jun 14th, 2014
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local SERVICE = {}
  2.  
  3. SERVICE.Name    = "Vk"
  4. SERVICE.IsTimed = true
  5.  
  6. function SERVICE:Match( url )
  7.     return string.match( url.host, "vk.com" ) and string.match (url.path, "^/video([%d-_]+)") -- we are looking for ownerid_videoid bundle
  8. end
  9.  
  10. function SERVICE:GetURLInfo( url )
  11.  
  12.     local info = {}
  13.     info.Data = string.match(url.path, "^/video([%d-_]+)")
  14. return info
  15. end
  16.  
  17. function SERVICE:GetVideoInfo( data, onSuccess, onFailure )
  18.  
  19.     local onReceive = function( body, length, headers, code )
  20.  
  21.  
  22.         local info = {}
  23.         info.title = string.match( body, "<title>([^\n]+)</title>" )
  24.         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
  25.         info.thumbnail = string.match( body, "<image_medium>(.+).jpg" )
  26.        
  27.  
  28.         if onSuccess then
  29.             pcall(onSuccess, info)
  30.         end
  31.  
  32.     end
  33.                     -- 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.
  34.     local url = string.format( "https://api.vk.com/method/video.get.xml?videos=%s&access_token=ACCESS_TOKEN", data )
  35.     self:Fetch( url, onReceive, onFailure )
  36.  
  37. end
  38.  
  39.  
  40.  
  41. theater.RegisterService( 'vk', SERVICE )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement