musicapp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +126 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/exe/musicapp +3 -0
- data/lib/musicapp.rb +9 -0
- data/lib/musicapp/cli.rb +83 -0
- data/lib/musicapp/script.rb +240 -0
- data/lib/musicapp/version.rb +3 -0
- data/musicapp.gemspec +30 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5502b9d74f1058162f63e3d699eba347382f2c5e68e6b882c26b0c221425bd0d
|
4
|
+
data.tar.gz: e2377983af7cf564251f262971a1569e1bdf8b998845018a319c069a2d9b43ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d319affe2f460b17d875d7cd879471b0ed377e1a5d45470a1938f378f138a69e5b798dab296b5fe3b8d5484e03196c1a5144c89a431ca82473a456d005cc85a9
|
7
|
+
data.tar.gz: efd5a73da7d492945352c7255864de9d9538894dcf8f68f5273762459a5d0db405a429a8d4bd5161aeb155a7ba337ee4fc6d64cfd6ebbb3196bf77a08880593f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- bin/*
|
4
|
+
- node_modules/**/*
|
5
|
+
|
6
|
+
Layout/CaseIndentation:
|
7
|
+
EnforcedStyle: end
|
8
|
+
|
9
|
+
Layout/EndAlignment:
|
10
|
+
EnforcedStyleAlignWith: variable
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Layout/EmptyLinesAroundAccessModifier:
|
16
|
+
EnforcedStyle: only_before
|
17
|
+
|
18
|
+
Layout/SpaceInLambdaLiteral:
|
19
|
+
EnforcedStyle: require_space
|
20
|
+
|
21
|
+
Layout/SpaceInsideBlockBraces:
|
22
|
+
SpaceBeforeBlockParameters: false
|
23
|
+
|
24
|
+
Layout/SpaceInsideHashLiteralBraces:
|
25
|
+
EnforcedStyle: no_space
|
26
|
+
|
27
|
+
Metrics/AbcSize:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Metrics/BlockLength:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Metrics/ClassLength:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Metrics/CyclomaticComplexity:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Metrics/ModuleLength:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Metrics/PerceivedComplexity:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Naming/HeredocDelimiterNaming:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Naming/MethodParameterName:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Naming/PredicateName:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/Alias:
|
58
|
+
EnforcedStyle: prefer_alias_method
|
59
|
+
|
60
|
+
Style/AsciiComments:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/BlockDelimiters:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/Documentation:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Style/EmptyCaseCondition:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/EmptyMethod:
|
73
|
+
EnforcedStyle: expanded
|
74
|
+
|
75
|
+
Style/FrozenStringLiteralComment:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/HashSyntax:
|
79
|
+
Exclude:
|
80
|
+
- Rakefile
|
81
|
+
- "**/*.rake"
|
82
|
+
|
83
|
+
Style/Lambda:
|
84
|
+
EnforcedStyle: literal
|
85
|
+
|
86
|
+
Style/IfUnlessModifier:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Style/MultilineBlockChain:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/NumericLiterals:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/NumericPredicate:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
Style/PercentLiteralDelimiters:
|
99
|
+
PreferredDelimiters:
|
100
|
+
'%i': '()'
|
101
|
+
'%w': '()'
|
102
|
+
'%r': '()'
|
103
|
+
|
104
|
+
Style/SpecialGlobalVars:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
Style/StringLiterals:
|
108
|
+
EnforcedStyle: double_quotes
|
109
|
+
|
110
|
+
Style/StringLiteralsInInterpolation:
|
111
|
+
EnforcedStyle: double_quotes
|
112
|
+
|
113
|
+
Style/SymbolArray:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
Style/TrailingCommaInArguments:
|
117
|
+
EnforcedStyleForMultiline: consistent_comma
|
118
|
+
|
119
|
+
Style/TrailingCommaInArrayLiteral:
|
120
|
+
EnforcedStyleForMultiline: consistent_comma
|
121
|
+
|
122
|
+
Style/TrailingCommaInHashLiteral:
|
123
|
+
EnforcedStyleForMultiline: consistent_comma
|
124
|
+
|
125
|
+
Style/ZeroLengthPredicate:
|
126
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Unreleased
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
musicapp (0.1.0)
|
5
|
+
pastel (~> 0.7.4)
|
6
|
+
thor (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
equatable (0.6.1)
|
14
|
+
parallel (1.19.1)
|
15
|
+
parser (2.7.1.3)
|
16
|
+
ast (~> 2.4.0)
|
17
|
+
pastel (0.7.4)
|
18
|
+
equatable (~> 0.6)
|
19
|
+
tty-color (~> 0.5)
|
20
|
+
rainbow (3.0.0)
|
21
|
+
rake (12.3.3)
|
22
|
+
regexp_parser (1.7.0)
|
23
|
+
rexml (3.2.4)
|
24
|
+
rspec (3.9.0)
|
25
|
+
rspec-core (~> 3.9.0)
|
26
|
+
rspec-expectations (~> 3.9.0)
|
27
|
+
rspec-mocks (~> 3.9.0)
|
28
|
+
rspec-core (3.9.2)
|
29
|
+
rspec-support (~> 3.9.3)
|
30
|
+
rspec-expectations (3.9.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-mocks (3.9.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-support (3.9.3)
|
37
|
+
rubocop (0.85.0)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.7.0.1)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.7)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 0.0.3)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
46
|
+
rubocop-ast (0.0.3)
|
47
|
+
parser (>= 2.7.0.1)
|
48
|
+
ruby-progressbar (1.10.1)
|
49
|
+
thor (1.0.1)
|
50
|
+
tty-color (0.5.1)
|
51
|
+
unicode-display_width (1.7.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
musicapp!
|
58
|
+
rake (~> 12.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
rubocop (~> 0.85.0)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 labocho
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# musicapp
|
2
|
+
|
3
|
+
`musicapp` is a command to control Apple's Music.app.
|
4
|
+
Now, this supports following.
|
5
|
+
|
6
|
+
* Get metadata of selected tracks as JSON.
|
7
|
+
* Set metadata of selected tracks by JSON.
|
8
|
+
* Play, Pause, and skip to next track.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
$ gem install musicapp
|
13
|
+
|
14
|
+
Or
|
15
|
+
|
16
|
+
$ git clone https://github.com/labocho/musicapp.git
|
17
|
+
$ cd musicapp
|
18
|
+
$ bundle install
|
19
|
+
$ bundle exec rake install
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
# Show help
|
24
|
+
$ musicapp help
|
25
|
+
|
26
|
+
# Play, Pause, Skip to next track
|
27
|
+
$ musicapp play
|
28
|
+
$ musicapp stop
|
29
|
+
$ musicapp skip
|
30
|
+
|
31
|
+
# Get metadata of selected tracks
|
32
|
+
$ musicapp get --field name,trackNumber
|
33
|
+
{"name":"Hello, World!","trackNumber":12}
|
34
|
+
{"name":"foobar","trackNumber":13}
|
35
|
+
|
36
|
+
# Set metadata of selected tracks
|
37
|
+
$ cat <<EOS | musicapp set
|
38
|
+
{"name":"Hello, World!!!","trackNumber":11}
|
39
|
+
{"name":"foobar!!","trackNumber":12}
|
40
|
+
EOS
|
41
|
+
|
42
|
+
# List available metadata fields
|
43
|
+
$ musicapp fields
|
44
|
+
album
|
45
|
+
albumArtist
|
46
|
+
albumDisliked
|
47
|
+
...
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/musicapp.
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "musicapp"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rubocop
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/setup
ADDED
data/exe/musicapp
ADDED
data/lib/musicapp.rb
ADDED
data/lib/musicapp/cli.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "pastel"
|
3
|
+
|
4
|
+
module Musicapp
|
5
|
+
class Cli < Thor
|
6
|
+
desc "get", "Get and print metadata"
|
7
|
+
option :field, aliases: :f, type: :string
|
8
|
+
def get
|
9
|
+
fields = case options[:field]
|
10
|
+
when "all"
|
11
|
+
:all
|
12
|
+
when nil
|
13
|
+
:default
|
14
|
+
else
|
15
|
+
options[:field].split(",")
|
16
|
+
end
|
17
|
+
|
18
|
+
Script.get_metadata(fields).each do |track|
|
19
|
+
puts track.to_json
|
20
|
+
end
|
21
|
+
rescue ::Musicapp::Error => e
|
22
|
+
color_warn e.message
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "set", "Set metadata"
|
27
|
+
def set
|
28
|
+
new_metadata = $stdin.read.each_line.map {|l| JSON.parse(l) }
|
29
|
+
properties = new_metadata.flat_map(&:keys).uniq.sort
|
30
|
+
current_metadata = Script.get_metadata(properties | %w(name))
|
31
|
+
|
32
|
+
current_metadata.zip(new_metadata).each do |(current_value, new_value)|
|
33
|
+
puts current_value["name"]
|
34
|
+
new_value.each do |k, v|
|
35
|
+
puts " #{k}:"
|
36
|
+
puts " #{current_value[k]}"
|
37
|
+
puts " -> #{v}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
print "Update?: "
|
42
|
+
exit 1 unless $stdin.gets.chomp =~ /^y(es)?/i
|
43
|
+
|
44
|
+
Script.set_metadata(new_metadata)
|
45
|
+
puts "Complete!"
|
46
|
+
rescue ::Musicapp::Error => e
|
47
|
+
color_warn e.message
|
48
|
+
exit 1
|
49
|
+
rescue ::JSON::ParserError => e
|
50
|
+
color_warn e.message
|
51
|
+
exit 2
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "fields", "List available fields"
|
55
|
+
def fields
|
56
|
+
Script::FULL_PROPERTIES.sort.each do |f|
|
57
|
+
puts f
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "play", "Play"
|
62
|
+
def play
|
63
|
+
Script.play
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "pause", "Pause"
|
67
|
+
def pause
|
68
|
+
Script.pause
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "next", "Advance to the next track"
|
72
|
+
def next
|
73
|
+
Script.next_track
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def color_warn(message)
|
78
|
+
pastel = Pastel.new
|
79
|
+
message = pastel.red(message) if pastel.enabled?
|
80
|
+
warn message
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# rubocop:disable Naming/AccessorMethodName
|
2
|
+
require "shellwords"
|
3
|
+
require "open3"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Musicapp
|
7
|
+
module Script
|
8
|
+
class ScriptError < ::Musicapp::Error; end
|
9
|
+
|
10
|
+
ITEM_PROPERTIES = %w(
|
11
|
+
name
|
12
|
+
).map(&:freeze).freeze
|
13
|
+
TRACK_PROPERTIES = %w(
|
14
|
+
album
|
15
|
+
albumArtist
|
16
|
+
albumDisliked
|
17
|
+
albumLoved
|
18
|
+
albumRating
|
19
|
+
albumRatingKind
|
20
|
+
artist
|
21
|
+
bitRate
|
22
|
+
bookmark
|
23
|
+
bookmarkable
|
24
|
+
bpm
|
25
|
+
category
|
26
|
+
cloudStatus
|
27
|
+
comment
|
28
|
+
compilation
|
29
|
+
composer
|
30
|
+
databaseID
|
31
|
+
dateAdded
|
32
|
+
description
|
33
|
+
discCount
|
34
|
+
discNumber
|
35
|
+
disliked
|
36
|
+
downloaderAppleID
|
37
|
+
downloaderName
|
38
|
+
duration
|
39
|
+
enabled
|
40
|
+
episodeID
|
41
|
+
episodeNumber
|
42
|
+
eq
|
43
|
+
finish
|
44
|
+
gapless
|
45
|
+
genre
|
46
|
+
grouping
|
47
|
+
kind
|
48
|
+
longDescription
|
49
|
+
loved
|
50
|
+
lyrics
|
51
|
+
mediaKind
|
52
|
+
modificationDate
|
53
|
+
movement
|
54
|
+
movementCount
|
55
|
+
movementNumber
|
56
|
+
playedCount
|
57
|
+
playedDate
|
58
|
+
purchaserAppleID
|
59
|
+
purchaserName
|
60
|
+
rating
|
61
|
+
ratingKind
|
62
|
+
releaseDate
|
63
|
+
sampleRate
|
64
|
+
seasonNumber
|
65
|
+
shufflable
|
66
|
+
skippedCount
|
67
|
+
skippedDate
|
68
|
+
show
|
69
|
+
sortAlbum
|
70
|
+
sortArtist
|
71
|
+
sortAlbumArtist
|
72
|
+
sortName
|
73
|
+
sortComposer
|
74
|
+
sortShow
|
75
|
+
size
|
76
|
+
start
|
77
|
+
time
|
78
|
+
trackCount
|
79
|
+
trackNumber
|
80
|
+
unplayed
|
81
|
+
volumeAdjustment
|
82
|
+
work
|
83
|
+
year
|
84
|
+
).map(&:freeze).freeze
|
85
|
+
FILE_TRACK_PROPERTIES = %w(
|
86
|
+
location
|
87
|
+
).map(&:freeze).freeze
|
88
|
+
FULL_PROPERTIES = (ITEM_PROPERTIES + TRACK_PROPERTIES + FILE_TRACK_PROPERTIES).freeze
|
89
|
+
DEFAULT_PROPERTIES = %w(album albumArtist artist discCount discNumber name trackCount trackNumber location).map(&:freeze).freeze
|
90
|
+
READONLY_PROPERTIES = %w(
|
91
|
+
albumRatingKind
|
92
|
+
bitRate
|
93
|
+
cloudStatus
|
94
|
+
databaseID
|
95
|
+
dateAdded
|
96
|
+
downloaderAppleID
|
97
|
+
downloaderName
|
98
|
+
duration
|
99
|
+
kind
|
100
|
+
modificationDate
|
101
|
+
purchaserAppleID
|
102
|
+
purchaserName
|
103
|
+
ratingKind
|
104
|
+
releaseDate
|
105
|
+
sampleRate
|
106
|
+
size
|
107
|
+
time
|
108
|
+
).map(&:freeze).freeze
|
109
|
+
WRITABLE_PROPERTIES = (FULL_PROPERTIES - READONLY_PROPERTIES).freeze
|
110
|
+
|
111
|
+
module_function
|
112
|
+
|
113
|
+
def osascript(script, *args)
|
114
|
+
out, err, status = Open3.capture3("osascript", "-l", "JavaScript", "-e", script, *args)
|
115
|
+
unless status.success?
|
116
|
+
raise ScriptError, err
|
117
|
+
end
|
118
|
+
|
119
|
+
[out, err, status]
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_metadata(properties)
|
123
|
+
properties = case properties
|
124
|
+
when :all
|
125
|
+
FULL_PROPERTIES
|
126
|
+
when :default
|
127
|
+
DEFAULT_PROPERTIES
|
128
|
+
else
|
129
|
+
invalid = properties - FULL_PROPERTIES
|
130
|
+
unless invalid.empty?
|
131
|
+
raise ::Musicapp::Error, "Unknown properties: #{invalid.inspect}"
|
132
|
+
end
|
133
|
+
|
134
|
+
properties
|
135
|
+
end
|
136
|
+
|
137
|
+
script = <<~JS
|
138
|
+
function run(argv) {
|
139
|
+
var itunes = Application("Music");
|
140
|
+
var selection = itunes.browserWindows[0].selection();
|
141
|
+
var trackProperties = JSON.parse(argv[0]);
|
142
|
+
var tracks = [];
|
143
|
+
|
144
|
+
for (var i in selection) {
|
145
|
+
var props = {};
|
146
|
+
var track = selection[i];
|
147
|
+
|
148
|
+
for (var j in trackProperties) {
|
149
|
+
var prop = trackProperties[j];
|
150
|
+
switch(prop) {
|
151
|
+
case "location":
|
152
|
+
if (track.class() != "fileTrack") continue;
|
153
|
+
props.location = track.location().toString();
|
154
|
+
break;
|
155
|
+
default:
|
156
|
+
props[prop] = track[prop]();
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
tracks.push(props);
|
161
|
+
}
|
162
|
+
|
163
|
+
return JSON.stringify(tracks);
|
164
|
+
}
|
165
|
+
JS
|
166
|
+
|
167
|
+
out, _err, _status = osascript(script, properties.to_json)
|
168
|
+
JSON.parse(out)
|
169
|
+
end
|
170
|
+
|
171
|
+
def set_metadata(metadata)
|
172
|
+
script = <<~JS
|
173
|
+
function run(argv) {
|
174
|
+
var itunes = Application("Music");
|
175
|
+
var selection = itunes.browserWindows[0].selection();
|
176
|
+
var metadata = JSON.parse(argv[0]);
|
177
|
+
var track = null;
|
178
|
+
|
179
|
+
for (var i in selection) {
|
180
|
+
track = metadata[i]
|
181
|
+
if (!track) continue;
|
182
|
+
|
183
|
+
for (var j in track) {
|
184
|
+
var prop = track[j];
|
185
|
+
selection[i][j] = prop;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
JS
|
190
|
+
|
191
|
+
invalid = metadata.flat_map do |track|
|
192
|
+
track.keys - WRITABLE_PROPERTIES
|
193
|
+
end
|
194
|
+
|
195
|
+
unless invalid.empty?
|
196
|
+
raise ::Musicapp::Error, "Unknown or readonly properties: #{invalid.inspect}"
|
197
|
+
end
|
198
|
+
|
199
|
+
out, _err, _status = osascript(script, metadata.to_json)
|
200
|
+
out
|
201
|
+
end
|
202
|
+
|
203
|
+
def play
|
204
|
+
script = <<~JS
|
205
|
+
function run(argv) {
|
206
|
+
var itunes = Application("Music");
|
207
|
+
itunes.play();
|
208
|
+
}
|
209
|
+
JS
|
210
|
+
|
211
|
+
out, _err, _status = osascript(script)
|
212
|
+
out
|
213
|
+
end
|
214
|
+
|
215
|
+
def pause
|
216
|
+
script = <<~JS
|
217
|
+
function run(argv) {
|
218
|
+
var itunes = Application("Music");
|
219
|
+
itunes.pause();
|
220
|
+
}
|
221
|
+
JS
|
222
|
+
|
223
|
+
out, _err, _status = osascript(script)
|
224
|
+
out
|
225
|
+
end
|
226
|
+
|
227
|
+
def next_track
|
228
|
+
script = <<~JS
|
229
|
+
function run(argv) {
|
230
|
+
var itunes = Application("Music");
|
231
|
+
itunes.nextTrack();
|
232
|
+
}
|
233
|
+
JS
|
234
|
+
|
235
|
+
out, _err, _status = osascript(script)
|
236
|
+
out
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
# rubocop:enable Naming/AccessorMethodName
|
data/musicapp.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "lib/musicapp/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "musicapp"
|
5
|
+
spec.version = Musicapp::VERSION
|
6
|
+
spec.authors = ["labocho"]
|
7
|
+
spec.email = ["labocho@penguinlab.jp"]
|
8
|
+
|
9
|
+
spec.summary = "CLI for Apple's Music.app"
|
10
|
+
spec.description = "CLI for Apple's Music.app"
|
11
|
+
spec.homepage = "https://github.com/labocho/musicapp"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/labocho/musicapp"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/labocho/musicapp/master/CHANGELOG.md"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r(^exe/)) {|f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "pastel", "~> 0.7.4"
|
29
|
+
spec.add_dependency "thor", "~> 1.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: musicapp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- labocho
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pastel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
description: CLI for Apple's Music.app
|
42
|
+
email:
|
43
|
+
- labocho@penguinlab.jp
|
44
|
+
executables:
|
45
|
+
- musicapp
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".rubocop.yml"
|
52
|
+
- ".travis.yml"
|
53
|
+
- CHANGELOG.md
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/console
|
60
|
+
- bin/rubocop
|
61
|
+
- bin/setup
|
62
|
+
- exe/musicapp
|
63
|
+
- lib/musicapp.rb
|
64
|
+
- lib/musicapp/cli.rb
|
65
|
+
- lib/musicapp/script.rb
|
66
|
+
- lib/musicapp/version.rb
|
67
|
+
- musicapp.gemspec
|
68
|
+
homepage: https://github.com/labocho/musicapp
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://github.com/labocho/musicapp
|
73
|
+
source_code_uri: https://github.com/labocho/musicapp
|
74
|
+
changelog_uri: https://github.com/labocho/musicapp/master/CHANGELOG.md
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.3.0
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.1.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: CLI for Apple's Music.app
|
94
|
+
test_files: []
|