henchman-sync 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00b0b426fe2f85ce317502bbfec6dbe6545f757d
4
- data.tar.gz: 0d62c14e6b5d9fe87241e4e94e31264f2b6f99a3
3
+ metadata.gz: 34113b7a846cd62928aa75e9698a466ee237357f
4
+ data.tar.gz: 2b0ca4b2d1bb0212c6072c399f5ed8db8278d7a5
5
5
  SHA512:
6
- metadata.gz: 0141c85238c432b3ed3a6441ecff9d5639626339e8f3ce6137ce600b2a3da28917a3ad176850cee3d3e1a5848aeb0788e71afa4bfcddacd1595f634851624d23
7
- data.tar.gz: 5d0d0d6a43f71ad8d0a01c83d42611880820a3f26442074f08b61c166914103076d5cfd7f1a14c903ada9e0b710cc4beacbaaf9f199c4914ea13139743473682
6
+ metadata.gz: 74ca677b0cffdcc6fb94947f1a248e53ef2ca074e8b41472b92fa53d33b11e3b1bff1ae4cc2783397a33b0b45fde5ea30f0328877515d91c4a5d68514f4f49f3
7
+ data.tar.gz: bab19023bb414a722b905540479d1297ddd9fa25983c239ca112b3eb8a9114316211332a0ec49aedb8b900198f1a99103062fcb422580a2f5afa27c835ef0667
data/lib/applescript.rb CHANGED
@@ -15,9 +15,20 @@ module Henchman
15
15
  "end tell"
16
16
  end
17
17
 
18
- def prompt_script prompt
18
+ def prompt_script buttons = []
19
+ buttons = buttons.slice(0..1).map { |b| "Download #{b.gsub(/'/){ %q('"'"') }}" }
19
20
  "tell application \"iTunes\"\n"\
20
- " display dialog \"Fetch #{prompt.gsub(/'/){ %q('"'"') }}?\"\n"\
21
+ " display dialog \"\""\
22
+ " buttons {"\
23
+ " \"Cancel\""\
24
+ " #{(buttons.length > 0) ? ",\"#{buttons.first}\"" : ''}"\
25
+ " #{(buttons.length > 1) ? ",\"#{buttons.last}\"" : ''}"\
26
+ " }"\
27
+ " with title \"Henchman 🏃\""\
28
+ " cancel button \"Cancel\""\
29
+ " default button \"#{(buttons.length > 0) ? buttons.last : 'Cancel'}\""\
30
+ " giving up after 60"\
31
+ " with icon note\n"\
21
32
  "end tell"
22
33
  end
23
34
 
@@ -254,8 +265,9 @@ module Henchman
254
265
  tracks
255
266
  end
256
267
 
257
- def fetch? prompt
258
- (%x(#{applescript_command(prompt_script prompt)}).chomp == "button returned:OK") ? true : false
268
+ def fetch? buttons = []
269
+ resp = %x(#{applescript_command(prompt_script buttons)}).chomp
270
+ resp.split(',').first.split(':').last.split('Download ').last rescue ''
259
271
  end
260
272
 
261
273
  def get_active_app
data/lib/core.rb CHANGED
@@ -36,7 +36,10 @@ module Henchman
36
36
  if (missing_track_selected? track) && !(@cache.ignore? :artist, track[:artist])
37
37
  update_cache = true
38
38
  @cache.update_ignore :artist, track[:artist]
39
- if @appleScript.fetch? "#{track[:album]} by #{track[:artist]}"
39
+
40
+ opts = ['Album', 'Track']
41
+ fetch = @appleScript.fetch? opts
42
+ if opts.include? fetch
40
43
  begin
41
44
  # first download the selected track
42
45
  dropbox_path = @dropbox.search_for track
@@ -53,10 +56,13 @@ module Henchman
53
56
  next
54
57
  end
55
58
 
56
- # now that we've gotten the selected track, spawn off another process
57
- # to download the rest of the tracks on the album - spatial locality FTW
58
- album_tracks = @appleScript.get_album_tracks_of track
59
- threads << Thread.new{ download_tracks album_tracks }
59
+ # now that we've gotten the selected track, if we're to also get the
60
+ # album, spawn off another process to download the rest of the tracks
61
+ # on the album - spatial locality FTW
62
+ if fetch == 'Album'
63
+ album_tracks = @appleScript.get_album_tracks_of track
64
+ threads << Thread.new{ download_tracks album_tracks }
65
+ end
60
66
  end
61
67
  rescue StandardError => err
62
68
  puts err
@@ -71,7 +77,7 @@ module Henchman
71
77
  if (!playlist_tracks.empty?) && !(@cache.ignore? :playlist, playlist)
72
78
  update_cache = true
73
79
  @cache.update_ignore :playlist, playlist
74
- if @appleScript.fetch? playlist
80
+ if @appleScript.fetch?([playlist]) == playlist
75
81
  threads << Thread.new{ download_tracks playlist_tracks }
76
82
  end
77
83
  end
@@ -1,3 +1,3 @@
1
1
  module Henchman
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
4
+ version: 0.3.1
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-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander