Class: Videos::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/videos/update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(videos_package) ⇒ Update

Returns a new instance of Update.



5
6
7
8
9
10
11
12
13
14
# File 'lib/videos/update.rb', line 5

def initialize(videos_package)
  @videos_package = videos_package

  @files = videos_package.root_path.descendant_files.reject { |p| p.basename.to_s[0..0] == '.' }
  @videos = []
  #load_data
  process
  save_data
  puts "\nDone!"
end

Instance Attribute Details

#videosObject

Returns the value of attribute videos.



3
4
5
# File 'lib/videos/update.rb', line 3

def videos
  @videos
end

#videos_packageObject (readonly)

Returns the value of attribute videos_package.



2
3
4
# File 'lib/videos/update.rb', line 2

def videos_package
  @videos_package
end

Instance Method Details

#created(f) ⇒ Object



62
63
64
65
66
67
# File 'lib/videos/update.rb', line 62

def created(f)
  video = Videos::Video.new(videos_package, f)
  video.generate_thumbnail
  video.
  videos << video
end

#deletedObject



58
59
60
# File 'lib/videos/update.rb', line 58

def deleted
  #
end

#load_dataObject



16
17
18
# File 'lib/videos/update.rb', line 16

def load_data
  self.videos = (Videos::Videos.load_json(videos_package.videos_path + "data.json") || []).map { |b| Videos::Video.from_hash(videos_package, b) }
end

#processObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/videos/update.rb', line 32

def process
  puts "\nLoading videos"
  @files.each_with_index do |f, i|
    $stdout.write "\rProcessing #{i + 1} of #{@files.length} (#{(((i + 1) / @files.length.to_f) * 100.0).round}%)"
    $stdout.flush

    #video = videos.find { |v| v.path.to_s == f.to_s }

    #if video
    #  updated video
    #else
      created f
    #end
  end
  #handle deleted first
  #@directories.each do |d|
  #  puts "d: #{d.inspect}"
  #  video = videos.find { |b| b.path == d }
  #  if video
  #    updated(video)
  #  else
  #    created(d)
  #  end
  #end
end

#save_dataObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/videos/update.rb', line 20

def save_data
  puts "\nWriting out JSON file"
  videos_hashes = []
  videos.each_with_index do |b, i|
    $stdout.write "\rProcessing #{i + 1} of #{videos.length} (#{(((i + 1) / videos.length.to_f) * 100.0).round}%)"
    $stdout.flush

    videos_hashes << b.to_hash
  end
  Videos::Videos.save_json(videos_package.videos_path + "data.json", videos_hashes)
end

#updated(video) ⇒ Object



69
70
71
72
# File 'lib/videos/update.rb', line 69

def updated(video)
  video.generate_thumbnail
  video.
end