henchman-sync 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/applescript.rb +37 -43
- data/lib/core.rb +36 -12
- data/lib/dropbox.rb +1 -1
- data/lib/henchman/version.rb +1 -1
- data/lib/templates.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba50beb7184c552a3a27c1c6c993a70d9eb53496
|
4
|
+
data.tar.gz: c1c5bb43fd8eb9dd21dd3e976ce22fd8efc8215a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c06ad0803566f62aa4ad348801409c2b7b0a061cbb4dfea5e1a840cb1597c51c152be9baf260d3d9d0941d26527bbbd875ec34854039aa4cb8832e8ff253d09
|
7
|
+
data.tar.gz: 4db7132de8baacbc36b82a3890e040742d0fd753e10126e29fa90a7dce3ce3b1ac3b5f6d2f31d4412bb428516fc4d27e0091b80fb0deb9a08238092c88b650aa
|
data/lib/applescript.rb
CHANGED
@@ -5,7 +5,8 @@ module Henchman
|
|
5
5
|
class AppleScript
|
6
6
|
|
7
7
|
def setup config
|
8
|
-
@delimiter
|
8
|
+
@delimiter = config[:delimiter]
|
9
|
+
@delimiter_major = config[:delimiter_major]
|
9
10
|
end
|
10
11
|
|
11
12
|
def get_active_app_script
|
@@ -88,7 +89,7 @@ module Henchman
|
|
88
89
|
" set str to str & data_artist & \"#{@delimiter}\" "\
|
89
90
|
" & data_album & \"#{@delimiter}\" "\
|
90
91
|
" & data_title & \"#{@delimiter}\" "\
|
91
|
-
" & data_id & \"#{@
|
92
|
+
" & data_id & \"#{@delimiter_major}\"\n"\
|
92
93
|
" end if\n"\
|
93
94
|
" end repeat\n"\
|
94
95
|
" return str\n"\
|
@@ -112,53 +113,46 @@ module Henchman
|
|
112
113
|
"end tell"\
|
113
114
|
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# " & data_title & \"#{@delimiter}\" "\
|
138
|
-
# " & data_id & \"#{@delimiter}\" "\
|
139
|
-
# " & data_location & \"#{@delimiter*2}\n"\
|
140
|
-
# " end repeat\n"\
|
141
|
-
# " on error\n"\
|
142
|
-
# " return 0\n"\
|
143
|
-
# " end try\n"\
|
144
|
-
# "end tell"
|
145
|
-
# end
|
146
|
-
def get_playlist_tracks_script playlist
|
116
|
+
def progress
|
117
|
+
"set progress description to \"A simple progress indicator\"\n"\
|
118
|
+
"set progress additional description to \"Preparing…\"\n"\
|
119
|
+
"set progress total steps to -1\n"\
|
120
|
+
"\n"\
|
121
|
+
"delay 5\n"\
|
122
|
+
"\n"\
|
123
|
+
"set progress total steps to 100\n"\
|
124
|
+
"repeat with i from 1 to 100\n"\
|
125
|
+
" try\n"\
|
126
|
+
" set progress additional description to \"I am on step \" & i\n"\
|
127
|
+
" set progress completed steps to i\n"\
|
128
|
+
" delay 0.2\n"\
|
129
|
+
" on error thisErr\n"\
|
130
|
+
" display alert thisErr\n"\
|
131
|
+
" exit repeat\n"\
|
132
|
+
" end try\n"\
|
133
|
+
"end repeat"
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_playlist_tracks_script playlist, skip = [], size = 100
|
137
|
+
"property counter : 0\n"\
|
147
138
|
"tell application \"iTunes\"\n"\
|
148
139
|
" try\n"\
|
149
140
|
" set playlist_tracks to every track in playlist \"#{playlist.gsub(/'/){ %q('"'"') }}\"\n"\
|
150
141
|
" set str to \"\"\n"\
|
151
142
|
" repeat with playlist_track in playlist_tracks\n"\
|
152
143
|
" set data_location to location of playlist_track as string\n"\
|
153
|
-
"
|
144
|
+
" set data_id to database ID of playlist_track as string\n"\
|
145
|
+
" if data_location is equal to \"missing value\" "\
|
146
|
+
" and data_id is not in [#{skip.map{|e| "\"#{e}\""}.join(',')}] then\n"\
|
154
147
|
" set data_artist to artist of playlist_track as string\n"\
|
155
148
|
" set data_album to album of playlist_track as string\n"\
|
156
149
|
" set data_title to name of playlist_track as string\n"\
|
157
|
-
" set data_id to database ID of playlist_track as string\n"\
|
158
150
|
" set str to str & data_artist & \"#{@delimiter}\""\
|
159
151
|
" & data_album & \"#{@delimiter}\""\
|
160
152
|
" & data_title & \"#{@delimiter}\""\
|
161
|
-
" & data_id & \"#{@
|
153
|
+
" & data_id & \"#{@delimiter_major}\"\n"\
|
154
|
+
" set counter to counter + 1\n"\
|
155
|
+
" if counter is equal to #{size} then exit repeat\n"\
|
162
156
|
" end if\n"\
|
163
157
|
" end repeat\n"\
|
164
158
|
" return str\n"\
|
@@ -180,7 +174,7 @@ module Henchman
|
|
180
174
|
" set data_date to played date of cur_track\n"\
|
181
175
|
" set str to str & data_id & \"#{@delimiter}\""\
|
182
176
|
" & data_date & \"#{@delimiter}\""\
|
183
|
-
" & (POSIX path of data_location as string) & \"#{@
|
177
|
+
" & (POSIX path of data_location as string) & \"#{@delimiter_major}\"\n"\
|
184
178
|
" end if\n"\
|
185
179
|
" end repeat\n"\
|
186
180
|
" return str\n"\
|
@@ -211,7 +205,7 @@ module Henchman
|
|
211
205
|
def get_tracks_with_location
|
212
206
|
tracks = Array.new
|
213
207
|
tmp_tracks = %x(#{applescript_command(get_tracks_with_location_script)}).chomp
|
214
|
-
tmp_tracks = tmp_tracks.split @
|
208
|
+
tmp_tracks = tmp_tracks.split @delimiter_major
|
215
209
|
tmp_tracks.each do |track|
|
216
210
|
next if track.empty?
|
217
211
|
tmp_track = track.split @delimiter
|
@@ -232,10 +226,10 @@ module Henchman
|
|
232
226
|
end
|
233
227
|
end
|
234
228
|
|
235
|
-
def get_playlist_tracks playlist
|
229
|
+
def get_playlist_tracks playlist, skip = []
|
236
230
|
tracks = Array.new
|
237
|
-
tmp_tracks = %x(#{applescript_command(get_playlist_tracks_script playlist)}).chomp
|
238
|
-
tmp_tracks = tmp_tracks.split @
|
231
|
+
tmp_tracks = %x(#{applescript_command(get_playlist_tracks_script playlist, skip)}).chomp
|
232
|
+
tmp_tracks = tmp_tracks.split @delimiter_major
|
239
233
|
tmp_tracks.each do |track|
|
240
234
|
next if track.empty?
|
241
235
|
tmp_track = track.split @delimiter
|
@@ -252,7 +246,7 @@ module Henchman
|
|
252
246
|
album = selection[:album]
|
253
247
|
tracks = Array.new
|
254
248
|
tmp_tracks = %x(#{applescript_command(get_album_tracks_script artist, album)}).chomp
|
255
|
-
tmp_tracks = tmp_tracks.split @
|
249
|
+
tmp_tracks = tmp_tracks.split @delimiter_major
|
256
250
|
tmp_tracks.each do |track|
|
257
251
|
next if track.empty?
|
258
252
|
tmp_track = track.split @delimiter
|
data/lib/core.rb
CHANGED
@@ -10,16 +10,24 @@ module Henchman
|
|
10
10
|
def self.run
|
11
11
|
@appleScript = Henchman::AppleScript.new
|
12
12
|
@cache = Henchman::Cache.new
|
13
|
+
@update_cache = false
|
13
14
|
threads = []
|
14
|
-
update_cache = false
|
15
15
|
|
16
16
|
while itunes_is_active?
|
17
17
|
begin
|
18
|
-
|
18
|
+
config_file = File.expand_path('~/.henchman/config')
|
19
|
+
@config = YAML.load_file(config_file)
|
20
|
+
|
21
|
+
# add this for backward compatability:
|
22
|
+
if !(@config.include? :delimiter_major)
|
23
|
+
@config[:delimiter_major] = Henchman::Templates.config[:delimiter_major]
|
24
|
+
File.open(config_file, "w") { |f| f.write( @config.to_yaml ) }
|
25
|
+
end
|
26
|
+
|
19
27
|
@cache.config @config
|
20
28
|
rescue StandardError => err
|
21
29
|
puts "#{DateTime.now.strftime('%m-%d-%Y %H:%M:%S')}|"\
|
22
|
-
"Error opening config file. Try rerunning `henchman configure
|
30
|
+
"Error opening config file. Try rerunning `henchman configure`. (#{err})"
|
23
31
|
return
|
24
32
|
end
|
25
33
|
|
@@ -36,7 +44,7 @@ module Henchman
|
|
36
44
|
|
37
45
|
if track_selected? track
|
38
46
|
if (missing_track_selected? track) && !(@cache.ignore? :artist, track[:artist])
|
39
|
-
update_cache = true
|
47
|
+
@update_cache = true
|
40
48
|
@cache.update_ignore :artist, track[:artist]
|
41
49
|
|
42
50
|
opts = ['Album', 'Track']
|
@@ -74,13 +82,13 @@ module Henchman
|
|
74
82
|
end
|
75
83
|
else
|
76
84
|
playlist = @appleScript.get_playlist
|
77
|
-
if playlist
|
85
|
+
if playlist && !(@cache.ignore? :playlist, playlist)
|
78
86
|
playlist_tracks = @appleScript.get_playlist_tracks playlist
|
79
|
-
if
|
80
|
-
update_cache = true
|
87
|
+
if !playlist_tracks.empty?
|
88
|
+
@update_cache = true
|
81
89
|
@cache.update_ignore :playlist, playlist
|
82
90
|
if @appleScript.fetch?([playlist]) == playlist
|
83
|
-
threads << Thread.new{
|
91
|
+
threads << Thread.new{ download_playlist playlist, playlist_tracks }
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
@@ -89,7 +97,7 @@ module Henchman
|
|
89
97
|
end
|
90
98
|
|
91
99
|
threads.each { |thr| thr.join }
|
92
|
-
@cache.flush if update_cache
|
100
|
+
@cache.flush if @update_cache
|
93
101
|
end
|
94
102
|
|
95
103
|
def self.track_selected? track
|
@@ -102,11 +110,26 @@ module Henchman
|
|
102
110
|
|
103
111
|
def self.itunes_is_active?
|
104
112
|
@appleScript.get_active_app == 'iTunes'
|
105
|
-
# true
|
106
113
|
end
|
107
114
|
|
108
|
-
def self.
|
109
|
-
|
115
|
+
def self.download_playlist playlist, playlist_tracks
|
116
|
+
puts "#{DateTime.now.strftime('%m-%d-%Y %H:%M:%S')}|Downloading Playlist \"#{playlist}\""
|
117
|
+
skip = Array.new
|
118
|
+
while true
|
119
|
+
download_tracks playlist_tracks, skip
|
120
|
+
playlist_tracks = @appleScript.get_playlist_tracks playlist, skip
|
121
|
+
break if playlist_tracks.empty?
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.download_tracks album_tracks, skip = []
|
126
|
+
album_tracks.each do |album_track|
|
127
|
+
begin
|
128
|
+
download_and_update album_track
|
129
|
+
rescue StandardError => bad_id
|
130
|
+
skip.push bad_id
|
131
|
+
end
|
132
|
+
end
|
110
133
|
end
|
111
134
|
|
112
135
|
def self.download_and_update track
|
@@ -125,6 +148,7 @@ module Henchman
|
|
125
148
|
end
|
126
149
|
rescue StandardError => err
|
127
150
|
puts "#{DateTime.now.strftime('%m-%d-%Y %H:%M:%S')}|#{err}"
|
151
|
+
raise track[:id]
|
128
152
|
end
|
129
153
|
end
|
130
154
|
|
data/lib/dropbox.rb
CHANGED
@@ -69,7 +69,7 @@ module Henchman
|
|
69
69
|
|
70
70
|
# if there were no results, raise err
|
71
71
|
if results.empty?
|
72
|
-
raise "Track not found in Dropbox: #{selection.
|
72
|
+
raise "Track not found in Dropbox: #{selection.reject{|k,v| k == :id}.values.join(':')}"
|
73
73
|
|
74
74
|
# if there's only one result, return it
|
75
75
|
elsif results.length == 1
|
data/lib/henchman/version.rb
CHANGED
data/lib/templates.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: henchman-sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Merritt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|