Class: Mediaman::LibraryDocument

Inherits:
Document
  • Object
show all
Defined in:
lib/mediaman/library_document.rb

Overview

Represents an on-disk folder or file representation of some kind of media.

This type is part of a “library” folder strucure.

Instance Attribute Summary collapse

Attributes inherited from Document

#path

Instance Method Summary collapse

Methods inherited from Document

#add_metadata_to_file!, #add_to_itunes!, #artwork_path, #download_image!, #ext, #extra_path, #extra_paths, #extras_path, #extras_paths, #filename, #filename_metadata, from_path, #junk_files, #library_extras_path, #local_metadata, #local_metadata_fetched?, #metadata, #primary_video_file, #rebase!, #remote_metadata, #save_and_apply_metadata!, #save_sidecar!, #secondary_video_files, #sidecar_metadata, #standalone_extras_path, #supports_embedding_video_metadata?, #video_files, #video_metadata

Instance Attribute Details

#library_pathObject

Returns the value of attribute library_path.



10
11
12
# File 'lib/mediaman/library_document.rb', line 10

def library_path
  @library_path
end

Instance Method Details

#desired_library_extras_pathObject



72
73
74
# File 'lib/mediaman/library_document.rb', line 72

def desired_library_extras_path
  File.join File.dirname(library_file_path), "Extras", File.basename(library_file_path, '.*')
end

#desired_library_junk_pathObject



76
77
78
# File 'lib/mediaman/library_document.rb', line 76

def desired_library_junk_path
  File.join desired_library_extras_path, "Junk"
end

#files_to_moveObject



21
22
23
24
25
26
27
28
# File 'lib/mediaman/library_document.rb', line 21

def files_to_move
  files = {}
  files[primary_video_file] = library_file_path if primary_video_file
  for file in junk_files + secondary_video_files
    files[file] = File.join desired_library_junk_path, File.basename(file)
  end
  files
end

#library_file_pathObject



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

def library_file_path
  @library_file_path ||= begin
    base_path = File.join File.expand_path(library_path), .library_category
    i = 1
    dup = true
    while dup == true
      path = File.join base_path, library_versioned_filename(i)
      if File.exists?(path) || File.directory?(path)
        i = i + 1
        dup = true
      else
        dup = false
      end
    end
    path
  end
end

#library_filenameObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mediaman/library_document.rb', line 30

def library_filename
  if .tv? && .canonical_show_name
    s = "#{.canonical_show_name}/Season #{.season_number}/#{.episode_id}"
    s << " - #{.canonical_episode_name}" if .canonical_episode_name.present?
    s
  elsif .year.present?
    "#{.canonical_movie_title.gsub(":", " - ")} (#{.year})"
  else
    .name
  end
end

#library_versioned_filename(n = 1) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mediaman/library_document.rb', line 42

def library_versioned_filename(n = 1)
  extension = File.extname(primary_video_file)[1..-1]
  old_filename  = File.basename(primary_video_file, '.*')
  v = ""
  v = " v#{n}" if n > 1
  if library_filename.present?
    "#{library_filename}#{v}.#{extension}"
  else
    "#{old_filename}#{v}.#{extension}"
  end
end

#move_to_library!Object



12
13
14
15
16
17
18
19
# File 'lib/mediaman/library_document.rb', line 12

def move_to_library!
  files_to_move.each do |original_file, new_file|
    FileUtils.mkdir_p(File.dirname(new_file))
    FileUtils.move(original_file, new_file)
  end
  rebase! library_file_path
  FileUtils.mkdir_p library_extras_path
end