Class: Mediaman::CommandLine

Inherits:
Thor
  • Object
show all
Defined in:
lib/mediaman/command.rb

Instance Method Summary collapse

Instance Method Details

#add(input_path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mediaman/command.rb', line 12

def add(input_path)

  # Find files for batch.
  if options[:batch] && File.directory?(input_path)
    paths = []
    Dir.glob File.join(input_path, "*") do |searchfile|
      case File.extname(searchfile)[1..-1]
      when /mov|mp4|m4v|avi|wmv|mkv/i then
        paths << searchfile
      else
        if File.directory?(searchfile)
          paths << searchfile
        end
      end
    end
  else
    # Just try the path if it's not a directory.
    paths = [input_path]
  end

  if paths.length > 0
    puts "Found #{paths.length} supported file#{paths.length == 1 ? "" : "s"}.".yellow
  else
    puts "No directories or supported files found.".red
  end

  # Add each
  for path in paths
    puts "Adding #{File.basename File.expand_path(path)}".green
    library_document = LibraryDocument.from_path path
    library_document.library_path = File.expand_path options[:library]
    puts "  -> #{library_document.video_files.size} video files / #{library_document.junk_files.size} junk files."
    library_document.move_to_library!
    library_document.save_and_apply_metadata!
    puts "  -> Destination: #{library_document.path}"
    if options[:itunes]
      library_document.add_to_itunes!
      puts "  -> Added to iTunes"
    end
  end

end

#metadata(path) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mediaman/command.rb', line 56

def (path)
  path = File.expand_path path
  if !File.exists?(path) && !File.directory?(path)
    name = path
  end
  if name
    doc = Mediaman::TemporaryDocument.from_name(name)
    puts doc..stringify_keys.to_yaml
  else
    doc = Document.from_path(path)
    doc.save_and_apply_metadata!
    puts "Metadata and image saved to #{doc.extras_path}".green
  end
end