# # # = Jeeves # # == Video CLI # # Author:: Robert Sharp # Copyright:: Copyright (c) 2014 Robert Sharp # License:: Open Software Licence v3.0 # # This software is licensed for use under the Open Software Licence v. 3.0 # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php # and in the file copyright.txt. Under the terms of this licence, all derivative works # must themselves be licensed under the Open Software Licence v. 3.0 # # # require 'optplus/nested' class VideosCLI < Optplus::NestedParser include Jeni::IO usage "videos []" description "Do things with videos, such as load them into Jeeves." def before_actions @jeeves_config = @_parent.jeeves_config @logger = @_parent.logger end describe :show, 'show information about a Jeeves-ready video' def show file = next_argument_or_error "Need to provide a file to show" unless FileTest.exists?(file) exit_on_error "File does not exist: #{file}" end vid = Jeeves::Video.new(file, @logger, @jeeves_config) tags = vid.get_tags strs = Array.new %w{programme subtitle category}.each do |key| strs << [key.capitalize, tags.delete(key)] if tags.has_tag?(key) end unless tags.has_tag?('description') exit_on_error "This file has not been tagged for Jeeves" end width = 80 descs = [tags.delete('description')] if descs[0].length > width then descs = descs[0].scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/) end first = true descs.each do |desc| strs << [first ? 'Description' : '', desc] first = false end strs << ['',''] strs << ['Start', Time.at(tags.delete('start').to_i).strftime('%a %-d %b %y, %H:%M')] strs << ['Duration', Jeeves.hrs_mins(tags.delete('duration').to_i)] tags.each_tag do |key, value| strs << [key, value] end Jeeves.tabulate(%w{* 80}, %w{Key Contents}, strs) end describe :load, 'load an existing video into Jeeves' help :load, 'Use load for a file that already has the tags relevant to Jeeves', 'and just needs to be added to the database.' def load file = next_argument_or_error "Need to provide a file to load" unless FileTest.exists?(file) exit_on_error "File does not exist: #{file}" end vid = Jeeves::Video.new(file, @logger, @jeeves_config) response = vid.upload_to_jeeves vid.clean_up if response.to_i == 0 then puts "Jeeves OK".green else exit_on_error "Jeeves returned unexpected response: #{response}" end rescue Jeeves::JeevesError => e exit_on_error "Error while loading video: #{e}" end describe :wrangle, 'tag and load a video into Jeeves' help :load, 'Obtain metadata from Jeeves and tag a video with it', 'before loading into Jeeves.' def wrangle file = next_argument_or_error "Need to provide a file to wrangle" unless FileTest.exists?(file) exit_on_error "File does not exist: #{file}" end pid = next_argument_or_error "Need to provide a programme id to wrangle" vid = Jeeves::Video.new(file, @logger, @jeeves_config) vid.tag_from_prog_id(pid) response = vid.upload_to_jeeves vid.clean_up if response.to_i == 0 then puts "Jeeves OK" else exit_on_error "Jeeves returned unexpected response: #{response}" end rescue Jeeves::JeevesError => e exit_on_error "Error while wrangling video: #{e}" end describe :orphans, 'find files that have no entry in Jeeves' def orphans end end