Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'cherrypicker'
- require 'rvideo'
- require 'pg'
- $ROOT = "/home/admin/vidso/shared/video"
- #$ROOT = "/Volumes/Storage/Dropbox/Uni/vidso/video"
- #db = PGconn.open(:dbname => 'vidso_production')
- #db = PGconn.open(:dbname => 'vidso_development')
- db = PGconn.connect("localhost", 5432, '', '', "vidso_production", "vidso", '')
- #db = PGconn.connect("localhost", 5432, '', '', "vidso_development", "postgres", 'password')
- job "video.webm" do |args|
- db.exec("INSERT INTO statuses(status, video_id) VALUES(9, #{args["id"]})")
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- location = id_to_folder(args["id"])
- webm(filename, location)
- db.exec("INSERT INTO statuses(status, video_id) VALUES(8, #{args["id"]})")
- end
- job "video.h264" do |args|
- db.exec("INSERT INTO statuses(status, video_id) VALUES(7, #{args["id"]})")
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- location = id_to_folder(args["id"])
- h264(filename, location)
- db.exec("INSERT INTO statuses(status, video_id) VALUES(6, #{args["id"]})")
- end
- job "video.mobile" do |args|
- db.exec("INSERT INTO statuses(status, video_id) VALUES(5, #{args["id"]})")
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- location = id_to_folder(args["id"])
- mobile(filename, location)
- db.exec("INSERT INTO statuses(status, video_id) VALUES(4, #{args["id"]})")
- end
- job "video.screenshot" do |args|
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- duration = res[0]['duration'].to_i
- location = id_to_folder(args["id"])
- screenshot(filename, location, (duration / 2))
- db.exec("INSERT INTO statuses(status, video_id) VALUES(3, #{args["id"]})")
- end
- job "video.thumbnails" do |args|
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- location = id_to_folder(args["id"])
- file = RVideo::Inspector.new(:file => "\"#{$ROOT}/#{location}/#{filename}\"")
- file.raw_response[/Duration: (\d{2}):(\d{2}):(\d{2})/]
- hours = Regexp.last_match(1).to_i
- mins = Regexp.last_match(2).to_i
- secs = Regexp.last_match(3).to_i
- filename = res[0]['clip_file_name']
- duration = res[0]['duration'].to_i
- location = id_to_folder(args["id"])
- thumbnails(filename, location, duration)
- db.exec("INSERT INTO statuses(status, video_id) VALUES(2, #{args["id"]})")
- end
- job "video.duration" do |args|
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- location = id_to_folder(args["id"])
- file = RVideo::Inspector.new(:file => "\"#{$ROOT}/#{location}/#{filename}\"")
- file.raw_response[/Duration: (\d{2}):(\d{2}):(\d{2})/]
- hours = Regexp.last_match(1).to_i
- mins = Regexp.last_match(2).to_i
- secs = Regexp.last_match(3).to_i
- db.exec("update videos set duration=#{hours_mins_secs_to_secs(hours, mins, secs)} where id=#{args["id"]}")
- db.exec("INSERT INTO statuses(status, video_id) VALUES(1, #{args["id"]})")
- end
- job "video.cleanup" do |args|
- res = db.exec("select * from videos where id=#{args["id"]}")
- filename = res[0]['clip_file_name']
- location = id_to_folder(args["id"])
- system("rm -rf \"#{$ROOT}/#{location}/#{filename}\"")
- end
- job "video.download" do |args|
- db.results_as_hash = true
- db.execute("select * from host_downloads where id=?", args["id"]) do |row|
- @url = row['urls']
- @username = row['host_username']
- @password = row['host_password']
- end
- check = @url.split(/\r\n/)
- result = LinkChecker.new(check).status
- if result["Dead"]
- # db.execute("update host_downloads set status=? where id=?", "false", args["id"])
- else
- result["Alive"].each do |link|
- Rapidshare.new("#{link[0]}", "#{@username}", "#{@password}", link[1]).download
- end
- #db.execute("update host_downloads set status=? where id=?", "true", args["id"])
- end
- system("unrarall")
- end
- def webm(filename, location)
- system("ffmpeg -pass 1 -passlogfile \"#{$ROOT}/#{location}/#{filename}\" -threads 16 -keyint_min 0 -g 250 \
- -b 614400 -skip_threshold 0 -qmin 10 -qmax 51 -i \"#{$ROOT}/#{location}/#{filename}\" -vcodec libvpx \
- -an -y \"#{$ROOT}/#{location}/output.webm\"")
- system("ffmpeg -pass 2 -passlogfile \"#{$ROOT}/#{location}/#{filename}\" -threads 16 -keyint_min 0 -g 250 \
- -b 614400 -skip_threshold 0 -qmin 10 -qmax 51 -i \"#{$ROOT}/#{location}/#{filename}\" -vcodec libvpx \
- -acodec libvorbis -y \"#{$ROOT}/#{location}/output.webm\"")
- end
- def h264(filename, location)
- system("HandBrakeCLI --preset \"Normal\" --two-pass --optimize --encoder x264 \
- --turbo --input \"#{$ROOT}/#{location}/#{filename}\" --output \
- \"#{$ROOT}/#{location}/output.mp4\"")
- end
- def mobile(filename, location)
- system("HandBrakeCLI --preset \"Universal\" --two-pass --optimize --encoder x264 \
- --turbo --input \"#{$ROOT}/#{location}/#{filename}\" --output \
- \"#{$ROOT}/#{location}/mobile.mp4\"")
- end
- def screenshot(filename, location, time)
- system("ffmpeg -itsoffset -#{time} -i \"#{$ROOT}/#{location}/#{filename}\" -y -vcodec mjpeg \
- -vframes 1 -an -f rawvideo \"#{$ROOT}/#{location}/screenshot.jpg\"")
- end
- def thumbnails(filename, location, duration)
- time = duration / 10
- for i in 1..10 do
- system("ffmpeg -itsoffset -#{time} -i \"#{$ROOT}/#{location}/#{filename}\" -y -vcodec mjpeg \
- -vframes 1 -an -f rawvideo -s 200x200 \"#{$ROOT}/#{location}/thumb#{i}.jpg\"")
- time = time + (time / i)
- end
- end
- # An id of 12345 becomes “000/012/345”
- def id_to_folder(id)
- i = id
- while i.to_s.length <= 8 do
- i = "0" + i.to_s
- end
- return location = i.insert(3, '/').insert(7, '/')
- end
- def hours_mins_secs_to_secs(hours, mins, secs)
- hours = hours * 60
- mins = hours + mins
- mins = mins * 60
- secs = secs + mins
- end
- error do |exception|
- # ...
- end
Add Comment
Please, Sign In to add comment