# Bens amazing 'folder of MP4 files -> folder of book cover images' convertor. # March, 2010 # # Freeware. Use it for the benefit of mankind (or not, it's up to you). # Credit Ben Dunham [www.toasta.com] if you feel like it. require 'ftools' require 'rubygems' require 'mp4info' require 'amazon/aws/search' require 'open-uri' include Amazon::AWS include Amazon::AWS::Search # Initialise the image file name counter i = 0 # Loop over the mp4 files in my NAS movies folder Dir.glob('/Volumes/media/Movies/*.mp4').each do |movie| # Extract the MP4 metadata info = MP4Info.open(movie) # If the file posseses a COVR field, write it to a JPG file on disk if info.COVR i += 1 File.open('../movies/' + i.to_s + '.jpg','w'){|f| f.write(info.COVR) } # Else look it up on Amazon else begin is = ItemSearch.new('DVD', { 'Title' => movie.split('/').last.split('.').first } ) rg = ResponseGroup.new( 'Large' ) req = Request.new # Restrict to Amazon UK req.locale = 'uk' # Do the serch resp = req.search( is, rg ) # If item was matched... if resp.item_search_response[0].items.any? i += 1 # Download the file, and write ite to disk image = open(resp.item_search_response[0].items[0].item[0].small_image.url) File.open('../movies/' + i.to_s + '.jpg','w'){|f| f.write(image.read) } image.close end rescue # No image found. Oh well! end end end