9
10
11
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
|
# File 'lib/clean.rb', line 9
def self.run played_date
puts "#{DateTime.now.strftime('%m-%d-%Y %H:%M:%S')}|"\
"Cleanup Starting"
played_date = (played_date == 'true') ? true : false
@appleScript = Henchman::AppleScript.new
@cache = Henchman::Cache.new
begin
@config = YAML.load_file(File.expand_path('~/.henchman/config'))
@cache.config @config
@appleScript.setup @config
rescue StandardError => err
puts "#{DateTime.now.strftime('%m-%d-%Y %H:%M:%S')}|"\
"Error opening config file. Try rerunning `henchman configure`"
return
end
cutoff = DateTime.now - 1
tracks = @appleScript.get_tracks_with_location
tracks.each do |track|
cache_time = @cache.get_time_last_downloaded track
if track[:date] < cutoff && ((cache_time < cutoff) || played_date)
cleanup track
end
end
@cache.flush
puts "#{DateTime.now.strftime('%m-%d-%Y %H:%M:%S')}|"\
"Cleanup Finished"
end
|