Guest User

Untitled

a guest
Jan 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. require 'cherrypicker'
  2. require 'rvideo'
  3. require 'pg'
  4.  
  5. $ROOT = "/home/admin/vidso/shared/video"
  6. #$ROOT = "/Volumes/Storage/Dropbox/Uni/vidso/video"
  7.  
  8. #db = PGconn.open(:dbname => 'vidso_production')
  9. #db = PGconn.open(:dbname => 'vidso_development')
  10.  
  11. db = PGconn.connect("localhost", 5432, '', '', "vidso_production", "vidso", '')
  12. #db = PGconn.connect("localhost", 5432, '', '', "vidso_development", "postgres", 'password')
  13.  
  14.  
  15. job "video.webm" do |args|
  16. db.exec("INSERT INTO statuses(status, video_id) VALUES(9, #{args["id"]})")
  17. res = db.exec("select * from videos where id=#{args["id"]}")
  18. filename = res[0]['clip_file_name']
  19. location = id_to_folder(args["id"])
  20. webm(filename, location)
  21. db.exec("INSERT INTO statuses(status, video_id) VALUES(8, #{args["id"]})")
  22. end
  23.  
  24. job "video.h264" do |args|
  25. db.exec("INSERT INTO statuses(status, video_id) VALUES(7, #{args["id"]})")
  26. res = db.exec("select * from videos where id=#{args["id"]}")
  27. filename = res[0]['clip_file_name']
  28. location = id_to_folder(args["id"])
  29. h264(filename, location)
  30. db.exec("INSERT INTO statuses(status, video_id) VALUES(6, #{args["id"]})")
  31. end
  32.  
  33. job "video.mobile" do |args|
  34. db.exec("INSERT INTO statuses(status, video_id) VALUES(5, #{args["id"]})")
  35. res = db.exec("select * from videos where id=#{args["id"]}")
  36. filename = res[0]['clip_file_name']
  37. location = id_to_folder(args["id"])
  38. mobile(filename, location)
  39. db.exec("INSERT INTO statuses(status, video_id) VALUES(4, #{args["id"]})")
  40. end
  41.  
  42. job "video.screenshot" do |args|
  43. res = db.exec("select * from videos where id=#{args["id"]}")
  44. filename = res[0]['clip_file_name']
  45. duration = res[0]['duration'].to_i
  46. location = id_to_folder(args["id"])
  47. screenshot(filename, location, (duration / 2))
  48. db.exec("INSERT INTO statuses(status, video_id) VALUES(3, #{args["id"]})")
  49. end
  50.  
  51.  
  52. job "video.thumbnails" do |args|
  53. res = db.exec("select * from videos where id=#{args["id"]}")
  54. filename = res[0]['clip_file_name']
  55. location = id_to_folder(args["id"])
  56. file = RVideo::Inspector.new(:file => "\"#{$ROOT}/#{location}/#{filename}\"")
  57. file.raw_response[/Duration: (\d{2}):(\d{2}):(\d{2})/]
  58. hours = Regexp.last_match(1).to_i
  59. mins = Regexp.last_match(2).to_i
  60. secs = Regexp.last_match(3).to_i
  61.  
  62. filename = res[0]['clip_file_name']
  63. duration = res[0]['duration'].to_i
  64. location = id_to_folder(args["id"])
  65. thumbnails(filename, location, duration)
  66. db.exec("INSERT INTO statuses(status, video_id) VALUES(2, #{args["id"]})")
  67. end
  68.  
  69. job "video.duration" do |args|
  70. res = db.exec("select * from videos where id=#{args["id"]}")
  71. filename = res[0]['clip_file_name']
  72. location = id_to_folder(args["id"])
  73. file = RVideo::Inspector.new(:file => "\"#{$ROOT}/#{location}/#{filename}\"")
  74. file.raw_response[/Duration: (\d{2}):(\d{2}):(\d{2})/]
  75. hours = Regexp.last_match(1).to_i
  76. mins = Regexp.last_match(2).to_i
  77. secs = Regexp.last_match(3).to_i
  78. db.exec("update videos set duration=#{hours_mins_secs_to_secs(hours, mins, secs)} where id=#{args["id"]}")
  79. db.exec("INSERT INTO statuses(status, video_id) VALUES(1, #{args["id"]})")
  80. end
  81.  
  82. job "video.cleanup" do |args|
  83. res = db.exec("select * from videos where id=#{args["id"]}")
  84. filename = res[0]['clip_file_name']
  85. location = id_to_folder(args["id"])
  86. system("rm -rf \"#{$ROOT}/#{location}/#{filename}\"")
  87. end
  88.  
  89. job "video.download" do |args|
  90. db.results_as_hash = true
  91. db.execute("select * from host_downloads where id=?", args["id"]) do |row|
  92. @url = row['urls']
  93. @username = row['host_username']
  94. @password = row['host_password']
  95. end
  96.  
  97. check = @url.split(/\r\n/)
  98. result = LinkChecker.new(check).status
  99.  
  100. if result["Dead"]
  101. # db.execute("update host_downloads set status=? where id=?", "false", args["id"])
  102. else
  103. result["Alive"].each do |link|
  104. Rapidshare.new("#{link[0]}", "#{@username}", "#{@password}", link[1]).download
  105. end
  106. #db.execute("update host_downloads set status=? where id=?", "true", args["id"])
  107. end
  108. system("unrarall")
  109. end
  110.  
  111. def webm(filename, location)
  112. system("ffmpeg -pass 1 -passlogfile \"#{$ROOT}/#{location}/#{filename}\" -threads 16 -keyint_min 0 -g 250 \
  113. -b 614400 -skip_threshold 0 -qmin 10 -qmax 51 -i \"#{$ROOT}/#{location}/#{filename}\" -vcodec libvpx \
  114. -an -y \"#{$ROOT}/#{location}/output.webm\"")
  115. system("ffmpeg -pass 2 -passlogfile \"#{$ROOT}/#{location}/#{filename}\" -threads 16 -keyint_min 0 -g 250 \
  116. -b 614400 -skip_threshold 0 -qmin 10 -qmax 51 -i \"#{$ROOT}/#{location}/#{filename}\" -vcodec libvpx \
  117. -acodec libvorbis -y \"#{$ROOT}/#{location}/output.webm\"")
  118. end
  119.  
  120. def h264(filename, location)
  121. system("HandBrakeCLI --preset \"Normal\" --two-pass --optimize --encoder x264 \
  122. --turbo --input \"#{$ROOT}/#{location}/#{filename}\" --output \
  123. \"#{$ROOT}/#{location}/output.mp4\"")
  124. end
  125.  
  126. def mobile(filename, location)
  127. system("HandBrakeCLI --preset \"Universal\" --two-pass --optimize --encoder x264 \
  128. --turbo --input \"#{$ROOT}/#{location}/#{filename}\" --output \
  129. \"#{$ROOT}/#{location}/mobile.mp4\"")
  130. end
  131.  
  132. def screenshot(filename, location, time)
  133. system("ffmpeg -itsoffset -#{time} -i \"#{$ROOT}/#{location}/#{filename}\" -y -vcodec mjpeg \
  134. -vframes 1 -an -f rawvideo \"#{$ROOT}/#{location}/screenshot.jpg\"")
  135. end
  136.  
  137. def thumbnails(filename, location, duration)
  138. time = duration / 10
  139.  
  140. for i in 1..10 do
  141. system("ffmpeg -itsoffset -#{time} -i \"#{$ROOT}/#{location}/#{filename}\" -y -vcodec mjpeg \
  142. -vframes 1 -an -f rawvideo -s 200x200 \"#{$ROOT}/#{location}/thumb#{i}.jpg\"")
  143. time = time + (time / i)
  144. end
  145. end
  146.  
  147. # An id of 12345 becomes “000/012/345”
  148. def id_to_folder(id)
  149. i = id
  150. while i.to_s.length <= 8 do
  151. i = "0" + i.to_s
  152. end
  153. return location = i.insert(3, '/').insert(7, '/')
  154. end
  155.  
  156. def hours_mins_secs_to_secs(hours, mins, secs)
  157. hours = hours * 60
  158. mins = hours + mins
  159. mins = mins * 60
  160. secs = secs + mins
  161. end
  162.  
  163. error do |exception|
  164. # ...
  165. end
Add Comment
Please, Sign In to add comment