Advertisement
MKlegoman357

Screenrecord

Jul 23rd, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. -- by MKlegoman357
  2.  
  3. if _G.term.record then
  4.   printError("Recorder is already recording, exit the program (shell) to stop recording.")
  5.   return
  6. end
  7.  
  8. local whitelist = {
  9.   ["write"] = "a";
  10.   ["setCursorPos"] = "b";
  11.   ["setCursorBlink"] = "c";
  12.   ["setTextColor"] = "d";
  13.   ["setBackgroundColor"] = "e";
  14.   ["setTextColour"] = "f";
  15.   ["setBackgroundColour"] = "g";
  16.   ["clear"] = "h";
  17.   ["clearLine"] = "i";
  18.   ["scroll"] = "j";
  19. }
  20.  
  21. local program = {...}
  22.  
  23. program[1] = program[1] or "rom/programs/advanced/multishell"
  24.  
  25. local clock = os.clock
  26. local prevTerm = term.current()
  27. local actions = ""
  28. local termObject = {}
  29.  
  30. for name, func in pairs(term.native()) do
  31.   termObject[name] = function (...)
  32.     if whitelist[name] then
  33.       actions = actions .. whitelist[name] .. "|" .. clock() .. "|"
  34.  
  35.       for i, v in pairs({...}) do
  36.         actions = actions .. textutils.serialize(v) .. "|"
  37.       end
  38.  
  39.       actions = actions .. "\n"
  40.     end
  41.  
  42.     return prevTerm[name](...)
  43.   end
  44. end
  45.  
  46. _G.term.record = true
  47.  
  48. term.redirect(termObject)
  49.  
  50. shell.run(unpack(program))
  51.  
  52. term.redirect(prevTerm)
  53.  
  54. _G.term.record = nil
  55.  
  56. local key = "0ec2eb25b6166c0c27a394ae118ad829" -- Extracted from 'pastebin' program
  57.  
  58. -- Taken from 'pastebin' program
  59. local response = http.post(
  60.   "http://pastebin.com/api/api_post.php",
  61.   "api_option=paste&"..
  62.   "api_dev_key="..key.."&"..
  63.   "api_paste_format=lua&"..
  64.   "api_paste_name=Screenrecord&"..
  65.   "api_paste_code="..textutils.urlEncode(actions)
  66. )
  67.    
  68. if response then
  69.   print("Success.")
  70.  
  71.   local sResponse = response.readAll()
  72.   response.close()
  73.          
  74.   local sCode = string.match(sResponse, "[^/]+$")
  75.   print("Uploaded as "..sResponse)
  76. else
  77.   _G.term.recording = actions
  78.  
  79.   print("Failed to upload the video.")
  80.   print("The video was saved in _G.term.recording (a string).")
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement