Class: MiniSubler::Command
- Inherits:
-
Object
- Object
- MiniSubler::Command
- Defined in:
- lib/mini_subler/command.rb
Instance Attribute Summary collapse
-
#command_path ⇒ Object
Returns the value of attribute command_path.
Class Method Summary collapse
Instance Method Summary collapse
- #escape(s) ⇒ Object
- #get_metadata(file_path) ⇒ Object
- #hash_to_subler_hash(h) ⇒ Object
- #set_metadata(file_path, hash) ⇒ Object
- #subler_hash_to_argument(h) ⇒ Object
- #subler_hash_to_hash(h) ⇒ Object
Instance Attribute Details
#command_path ⇒ Object
Returns the value of attribute command_path.
14 15 16 |
# File 'lib/mini_subler/command.rb', line 14 def command_path @command_path end |
Class Method Details
.vendored ⇒ Object
7 8 9 10 11 12 |
# File 'lib/mini_subler/command.rb', line 7 def self.vendored gem_root = File. '../../..', __FILE__ s = Command.new s.command_path = File.join gem_root, "vendor", "SublerCLI" s end |
Instance Method Details
#escape(s) ⇒ Object
63 64 65 |
# File 'lib/mini_subler/command.rb', line 63 def escape(s) s.to_s.gsub("{", "{").gsub("{", "}").gsub(":", ":") end |
#get_metadata(file_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mini_subler/command.rb', line 16 def (file_path) file_path = File. file_path = Cocaine::CommandLine.new(self.command_path, "-source :source -listmetadata", source: file_path).run hash = {} .each_line do |line| if line.include?(self.command_path) # Do nothing else split = line.split ": " hash[split[0].parameterize("_").to_sym] = split[1].chomp end end hash rescue nil end |
#hash_to_subler_hash(h) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mini_subler/command.rb', line 39 def hash_to_subler_hash(h) n = {} h.each do |key, value| n[key.to_s.titleize.gsub("Tv", "TV").gsub("Id", "ID").gsub("Hd", "HD").gsub("Number", "#")] = value end n end |
#set_metadata(file_path, hash) ⇒ Object
33 34 35 36 37 |
# File 'lib/mini_subler/command.rb', line 33 def (file_path, hash) file_path = File. file_path line = Cocaine::CommandLine.new(self.command_path, "-dest :source -metadata :metadata", source: file_path, metadata: subler_hash_to_argument(hash_to_subler_hash(hash))) puts line.run end |
#subler_hash_to_argument(h) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mini_subler/command.rb', line 55 def subler_hash_to_argument(h) s = "" h.each do |key, value| s << "{#{escape key}:#{escape value}}" end s end |
#subler_hash_to_hash(h) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/mini_subler/command.rb', line 47 def subler_hash_to_hash(h) n = {} h.each do |tag_name, tag_value| n[tag_name.gsub("#", "Number").parameterize("_").to_sym] = tag_value end n end |