Last active
December 14, 2015 04:28
-
-
Save mcmoyer/5027882 to your computer and use it in GitHub Desktop.
Thumbnail videos that don't have imdb info in mythTV. This takes into consideration storage groups in the mythTV system.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sequel' | |
CONFIG = { | |
db_host_name: 'localhost', | |
db_user_name: 'mythtv', | |
db_name: 'mythconverg', | |
db_password: '*********', | |
out_path: "/tmp", | |
cover_path: "/var/lib/mythtv/coverart/", | |
frame: '0000000002.jpg', | |
skip_offset: 35 | |
} | |
DB = Sequel.mysql(host: CONFIG[:db_host_name], user: CONFIG[:db_user_name], | |
password: CONFIG[:db_password], database: CONFIG[:db_name]) | |
storage_paths = DB[:storagegroup].select(:dirname).where(groupname: 'Videos') | |
videos = DB[:videometadata].select(:intid, :filename).where(coverfile: '') | |
videos.each do |video| | |
puts "#{video[:intid]} #{video[:filename]}" | |
storage_path = storage_paths.detect {|sp| File.exists?(File.join(sp[:dirname],video[:filename])) } | |
relative_file_path = File.join(storage_path[:dirname], video[:filename]) | |
length_command = %Q!avconv -i "#{relative_file_path}" -vcodec copy -acodec copy -f null /dev/null 2>&1 | grep 'frame=' | awk '/frame=[ .]/{print $2}'! | |
length = `#{length_command}` | |
puts "video length command #{length_command}" | |
puts "video length is #{length}" | |
skip = ((length.to_i * CONFIG[:skip_offset]) / 100) / 30 | |
puts "calculated skip is #{skip}" | |
`avconv -i "#{relative_file_path}" -ss #{skip} -vframes 1 #{CONFIG[:out_path]}/test.bmp` | |
`convert -quality 80 #{CONFIG[:out_path]}/test.bmp #{CONFIG[:out_path]}/#{CONFIG[:frame]}` | |
`rm #{CONFIG[:out_path]}/test.bmp` | |
destination = File.join(CONFIG[:cover_path], "initid.#{video[:intid]}.jpg") | |
move_cmd = "mv #{CONFIG[:out_path]}/#{CONFIG[:frame]} #{destination}" | |
`#{move_cmd}` | |
if File.exists? destination | |
DB[:videometadata].where(intid: video[:intid]).update(coverfile: destination) | |
else | |
puts "unable to move file! will not update videometadata table" | |
`rm #{CONFIG[:out_path]}/#{CONFIG[:frame]}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment