aric 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 +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +100 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/aric.gemspec +24 -0
- data/bin/aric +5 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/aric.rb +5 -0
- data/lib/aric/command.rb +54 -0
- data/lib/aric/job.rb +9 -0
- data/lib/aric/job/base.rb +49 -0
- data/lib/aric/job/finder.rb +62 -0
- data/lib/aric/job/player.rb +77 -0
- data/lib/aric/job/util.rb +28 -0
- data/lib/aric/job/volume.rb +23 -0
- data/lib/aric/job_handler.rb +46 -0
- data/lib/aric/resource/base.rb +58 -0
- data/lib/aric/resource/playlist.rb +30 -0
- data/lib/aric/resource/track.rb +45 -0
- data/lib/aric/script_runner.rb +35 -0
- data/lib/aric/version.rb +3 -0
- data/scripts/activate.js +2 -0
- data/scripts/back_track.js +2 -0
- data/scripts/current_playlist.js +12 -0
- data/scripts/current_playlist_tracks.js +14 -0
- data/scripts/current_track.js +12 -0
- data/scripts/down.js +5 -0
- data/scripts/fast_forward.js +2 -0
- data/scripts/finder/find_all_playlists.js +15 -0
- data/scripts/finder/find_all_tracks.js +15 -0
- data/scripts/finder/find_loved_playlists.js +16 -0
- data/scripts/finder/find_loved_tracks.js +16 -0
- data/scripts/finder/find_playlist_by_id.js +16 -0
- data/scripts/finder/find_playlists.js +18 -0
- data/scripts/finder/find_track_by_id.js +16 -0
- data/scripts/finder/find_tracks.js +18 -0
- data/scripts/finder/find_tracks_by.js +19 -0
- data/scripts/love.js +2 -0
- data/scripts/love_playlist.js +2 -0
- data/scripts/mute.js +2 -0
- data/scripts/next_track.js +2 -0
- data/scripts/pause.js +2 -0
- data/scripts/play.js +13 -0
- data/scripts/player_position.js +2 -0
- data/scripts/player_state.js +2 -0
- data/scripts/previous_track.js +2 -0
- data/scripts/resume.js +2 -0
- data/scripts/set_player_position.js +4 -0
- data/scripts/unlove.js +2 -0
- data/scripts/unlove_playlist.js +2 -0
- data/scripts/unmute.js +2 -0
- data/scripts/up.js +5 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 83716dff105d773cb4fda838e9c412a5948750ad
|
4
|
+
data.tar.gz: a9bcf7b61e4d53ab16a374aae185c1f22c31775a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8926293e242e2efa94ac452e9fc6ca1cd74f703eacc74cfac566cec539840ebbda0ed6e19dc4f867676e11e9ec52639b68864a222d6e6a14cbd723ee1506f05a
|
7
|
+
data.tar.gz: de6c5e80d54124c0103fc57f35ca10e8838d30a4a0a80a1781887f9d8cc8105c8c1c3973d3b870a452d1a4c551e9c6265f59ea96000108e7d591769ab0801e06
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "vendor/**/*"
|
4
|
+
- "db/schema.rb"
|
5
|
+
DisplayCopNames: true
|
6
|
+
|
7
|
+
Style/AndOr:
|
8
|
+
EnforcedStyle: conditionals
|
9
|
+
|
10
|
+
Style/AsciiComments:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/BracesAroundHashParameters:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/CollectionMethods:
|
17
|
+
PreferredMethods:
|
18
|
+
detect: "detect"
|
19
|
+
find: "detect"
|
20
|
+
|
21
|
+
Style/DeprecatedHashMethods:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/DoubleNegation:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/DotPosition:
|
31
|
+
EnforcedStyle: trailing
|
32
|
+
|
33
|
+
Style/EmptyElse:
|
34
|
+
EnforcedStyle: empty
|
35
|
+
|
36
|
+
Style/FormatString:
|
37
|
+
EnforcedStyle: percent
|
38
|
+
|
39
|
+
Style/GuardClause:
|
40
|
+
MinBodyLength: 5
|
41
|
+
|
42
|
+
Style/IfUnlessModifier:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/IndentHash:
|
46
|
+
EnforcedStyle: consistent
|
47
|
+
|
48
|
+
Style/Lambda:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Style/NumericLiterals:
|
52
|
+
MinDigits: 7
|
53
|
+
|
54
|
+
Style/PredicateName:
|
55
|
+
NamePrefixBlacklist:
|
56
|
+
- "is_"
|
57
|
+
- "have_"
|
58
|
+
NamePrefix:
|
59
|
+
- "is_"
|
60
|
+
- "have_"
|
61
|
+
|
62
|
+
Style/RedundantReturn:
|
63
|
+
AllowMultipleReturnValues: true
|
64
|
+
|
65
|
+
Style/SignalException:
|
66
|
+
EnforcedStyle: only_raise
|
67
|
+
|
68
|
+
Style/SpaceAroundOperators:
|
69
|
+
MultiSpaceAllowedForOperators:
|
70
|
+
- "="
|
71
|
+
- "=>"
|
72
|
+
- "||"
|
73
|
+
|
74
|
+
Style/SingleLineBlockParams:
|
75
|
+
Enabled: false
|
76
|
+
|
77
|
+
Style/TrailingComma:
|
78
|
+
EnforcedStyleForMultiline: comma
|
79
|
+
|
80
|
+
Lint/UnderscorePrefixedVariableName:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Lint/UnusedMethodArgument:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Metrics/AbcSize:
|
87
|
+
Max: 30
|
88
|
+
|
89
|
+
Metrics/CyclomaticComplexity:
|
90
|
+
Max: 10
|
91
|
+
|
92
|
+
Metrics/LineLength:
|
93
|
+
Max: 120
|
94
|
+
|
95
|
+
Metrics/PerceivedComplexity:
|
96
|
+
Max: 8
|
97
|
+
|
98
|
+
Metrics/MethodLength:
|
99
|
+
CountComments: false
|
100
|
+
Max: 15
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Aric
|
2
|
+
|
3
|
+
<a href="https://codeclimate.com/github/ganmacs/aric"><img src="https://codeclimate.com/github/ganmacs/aric/badges/gpa.svg" /></a>
|
4
|
+
[![Build Status](https://travis-ci.org/ganmacs/aric.svg)](https://travis-ci.org/ganmacs/aric)
|
5
|
+
|
6
|
+
Awesome Ruby Itunes Client
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'aric'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install aric
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/[my-github-username]/aric/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/aric.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aric/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'aric'
|
8
|
+
spec.version = Aric::VERSION
|
9
|
+
spec.authors = ['ganmacs']
|
10
|
+
spec.email = ['ganmacs@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Awesome Ruby Ituens Client'
|
13
|
+
spec.homepage = 'https://github.com/ganmacs/arci'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'bin'
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
spec.add_dependency 'hashie', '~> 3.4.0'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
end
|
data/bin/aric
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'aric'
|
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
|
data/bin/setup
ADDED
data/lib/aric.rb
ADDED
data/lib/aric/command.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'aric/job_handler'
|
3
|
+
|
4
|
+
module Aric
|
5
|
+
class Command
|
6
|
+
class JobNameRequired < StandardError; end
|
7
|
+
|
8
|
+
def initialize(args = ARGV)
|
9
|
+
@args = args
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
case
|
14
|
+
when list?
|
15
|
+
puts JobHandler.jobs
|
16
|
+
else
|
17
|
+
puts handler.run(*values)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def values
|
24
|
+
@values ||= @args.drop(1)
|
25
|
+
end
|
26
|
+
|
27
|
+
def job
|
28
|
+
@job ||= (@args.first or raise JobNameRequired)
|
29
|
+
end
|
30
|
+
|
31
|
+
def handler
|
32
|
+
@handler ||= JobHandler.new(job)
|
33
|
+
end
|
34
|
+
|
35
|
+
def list?
|
36
|
+
options['list']
|
37
|
+
end
|
38
|
+
|
39
|
+
def options
|
40
|
+
@options ||= option_parser.getopts(@argv)
|
41
|
+
end
|
42
|
+
|
43
|
+
def option_parser
|
44
|
+
@optin_parser ||= OptionParser.new do |opt|
|
45
|
+
opt.version = Aric::VERSION
|
46
|
+
opt.banner = 'Usage: aric [options]'
|
47
|
+
|
48
|
+
opt.separator 'Options:'
|
49
|
+
opt.on('-l', '--list', 'show available methods')
|
50
|
+
opt.on('-d', 'demonize')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/aric/job.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'singleton'
|
3
|
+
require 'aric/script_runner'
|
4
|
+
require 'aric/resource/track'
|
5
|
+
require 'aric/resource/playlist'
|
6
|
+
|
7
|
+
module Aric
|
8
|
+
module Job
|
9
|
+
class Base
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def run(job_name, *args)
|
14
|
+
instance.send(job_name, *args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def run(job_name, *opt)
|
21
|
+
ScriptRunner.run(job_name.to_s, *opt)
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_track(json)
|
25
|
+
::Aric::Resource::Track.new(json)
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_tracks(json)
|
29
|
+
json.map do |e|
|
30
|
+
build_track(e)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_playlist(json)
|
35
|
+
::Aric::Resource::Playlist.new(json)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_playlists(json)
|
39
|
+
json.map do |e|
|
40
|
+
build_playlist(e)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def jsonify(body)
|
45
|
+
JSON.parse(body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'aric/job/base'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
module Job
|
5
|
+
class Finder < Base
|
6
|
+
def find_tracks(v)
|
7
|
+
ts = run(:find_tracks, v)
|
8
|
+
build_tracks(jsonify(ts))
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_track_by_id(id)
|
12
|
+
t = run(:find_track_by_id, id)
|
13
|
+
build_track(jsonify(t))
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_loved_tracks
|
17
|
+
ts = run(:find_loved_tracks)
|
18
|
+
build_tracks(jsonify(ts))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Too Slow Command
|
22
|
+
def find_all_tracks
|
23
|
+
ts = run(:find_all_tracks)
|
24
|
+
build_tracks(jsonify(ts))
|
25
|
+
end
|
26
|
+
|
27
|
+
%w(albums all artists composers displayed songs).each do |n|
|
28
|
+
name = "find_tracks_by_#{n}"
|
29
|
+
define_method(name) do |v|
|
30
|
+
t = run('find_tracks_by', n, v)
|
31
|
+
build_tracks(jsonify(t))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_playlists(name)
|
36
|
+
pls = run(:find_playlists, name)
|
37
|
+
build_playlists(jsonify(pls))
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_playlist_by_id(id)
|
41
|
+
pl = run(:find_playlist_by_id, id)
|
42
|
+
build_playlist(jsonify(pl))
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_loved_playlists
|
46
|
+
pls = run(:find_loved_playlists)
|
47
|
+
build_playlists(jsonify(pls))
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_all_playlists
|
51
|
+
pls = run(:find_all_playlists)
|
52
|
+
build_playlists(jsonify(pls))
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def run(job_name, *opt)
|
58
|
+
ScriptRunner.run("finder/#{job_name}", opt)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'aric/job/base'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
module Job
|
5
|
+
class Player < Base
|
6
|
+
def play(id = nil)
|
7
|
+
run(:play, id)
|
8
|
+
end
|
9
|
+
alias_method :start, :play
|
10
|
+
|
11
|
+
def pause
|
12
|
+
run(:pause)
|
13
|
+
end
|
14
|
+
alias_method :stop, :pause
|
15
|
+
|
16
|
+
def resume
|
17
|
+
run(:resume)
|
18
|
+
end
|
19
|
+
|
20
|
+
def back_track
|
21
|
+
run(:back_track)
|
22
|
+
end
|
23
|
+
alias_method :back, :back_track
|
24
|
+
|
25
|
+
def previous_track
|
26
|
+
run(:previous_track)
|
27
|
+
end
|
28
|
+
|
29
|
+
def next_track
|
30
|
+
run(:next_track)
|
31
|
+
end
|
32
|
+
alias_method :next, :next_track
|
33
|
+
|
34
|
+
def fast_forward
|
35
|
+
run(:fast_forward)
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_track
|
39
|
+
t = run(:current_track)
|
40
|
+
build_track(jsonify(t))
|
41
|
+
end
|
42
|
+
alias_method :track, :current_track
|
43
|
+
|
44
|
+
def current_playlist
|
45
|
+
pl = run(:current_playlist)
|
46
|
+
build_playlist(jsonify(pl))
|
47
|
+
end
|
48
|
+
alias_method :playlist, :current_playlist
|
49
|
+
|
50
|
+
def current_playlist_tracks
|
51
|
+
ts = run(:current_playlist_tracks)
|
52
|
+
build_tracks(jsonify(ts))
|
53
|
+
end
|
54
|
+
|
55
|
+
def player_state(v = [])
|
56
|
+
run(:player_state)
|
57
|
+
end
|
58
|
+
alias_method :state, :player_state
|
59
|
+
|
60
|
+
%w(playing paused stopped).each do |name|
|
61
|
+
define_method("#{name}?") do
|
62
|
+
player_state == name
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def player_position
|
67
|
+
run(:player_position)
|
68
|
+
end
|
69
|
+
alias_method :position, :player_position
|
70
|
+
|
71
|
+
def set_player_position(pos)
|
72
|
+
run(:set_player_position, pos)
|
73
|
+
end
|
74
|
+
alias_method :set_position, :set_player_position
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'aric/job/base'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
module Job
|
5
|
+
class Util < Base
|
6
|
+
def activate
|
7
|
+
run(:activate)
|
8
|
+
end
|
9
|
+
alias_method :open, :activate
|
10
|
+
|
11
|
+
def love
|
12
|
+
run(:love)
|
13
|
+
end
|
14
|
+
|
15
|
+
def unlove
|
16
|
+
run(:unlove)
|
17
|
+
end
|
18
|
+
|
19
|
+
def love_playlist
|
20
|
+
run(:love_playlist)
|
21
|
+
end
|
22
|
+
|
23
|
+
def playlist_unlove
|
24
|
+
run(:unlove_playlist)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'aric/job/base'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
module Job
|
5
|
+
class Volume < Base
|
6
|
+
def up(v = 5)
|
7
|
+
run(:up, v)
|
8
|
+
end
|
9
|
+
|
10
|
+
def down(v = 5)
|
11
|
+
run(:down, v)
|
12
|
+
end
|
13
|
+
|
14
|
+
def mute
|
15
|
+
run(:mute)
|
16
|
+
end
|
17
|
+
|
18
|
+
def unmute
|
19
|
+
run(:unmute)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'aric/job'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
class JobHandler
|
5
|
+
class JobNotFound < StandardError; end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def jobs
|
9
|
+
@jobs ||= job_class_hash.values.flat_map(&:itself)
|
10
|
+
end
|
11
|
+
|
12
|
+
def job_class_hash
|
13
|
+
@job_class_hash ||= job_classes.each_with_object({}) do |c, a|
|
14
|
+
a[c] = c.public_instance_methods(false)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def job_classes
|
21
|
+
@job_class ||= Job.constants.map { |e| Job.const_get(e) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(job_name)
|
26
|
+
@job_name = job_name.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def run(*args)
|
30
|
+
# check argument number
|
31
|
+
job_class.run(@job_name, *args)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Return Job class that has job_name method
|
37
|
+
def job_class
|
38
|
+
raise JobNotFound if job_not_found?
|
39
|
+
JobHandler.job_class_hash.find { |_, v| v.include?(@job_name) }.first
|
40
|
+
end
|
41
|
+
|
42
|
+
def job_not_found?
|
43
|
+
!JobHandler.jobs.include?(@job_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'aric/job'
|
3
|
+
|
4
|
+
module Aric
|
5
|
+
module Resource
|
6
|
+
class Base
|
7
|
+
class << self
|
8
|
+
def find_by(cond)
|
9
|
+
raise ArgumentError if cond.nil?
|
10
|
+
if cond.is_a?(Hash)
|
11
|
+
find_with_condition(cond)
|
12
|
+
elsif cond == :all
|
13
|
+
find_all
|
14
|
+
else
|
15
|
+
raise ArgumentError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def all
|
20
|
+
find_by(:all)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def find_all
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_with_condition(cond)
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
def finder
|
34
|
+
@finder ||= Aric::Job::Finder.instance
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(resource)
|
39
|
+
properties = resource.delete('properties') || {}
|
40
|
+
@resource = Hashie::Mash.new(resource.merge(properties))
|
41
|
+
|
42
|
+
@resource.select { |_, v| [TrueClass, FalseClass].include?(v.class) }.each do |k, v|
|
43
|
+
self.class.class_eval do
|
44
|
+
define_method("#{k}?") { v }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(method_name, *args, &block)
|
50
|
+
if @resource.respond_to?(method_name)
|
51
|
+
@resource.send(method_name, *args, &block)
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'aric/resource/base'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
module Resource
|
5
|
+
class Playlist < Base
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
|
9
|
+
def find_with_condition(cond)
|
10
|
+
case
|
11
|
+
when cond[:id]
|
12
|
+
finder.find_playlist_by_id(cond[:id]).first
|
13
|
+
when cond[:name]
|
14
|
+
finder.find_playlists(cond[:name]).first
|
15
|
+
when cond[:loved]
|
16
|
+
finder.find_loved_playlists(cond[:loved])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_all
|
21
|
+
finder.find_all_playlists
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'aric/resource/base'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
module Resource
|
5
|
+
class Track < Base
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
|
9
|
+
def find_with_condition(cond)
|
10
|
+
case
|
11
|
+
when cond[:id]
|
12
|
+
finder.find_track_by_id(cond[:id])
|
13
|
+
when cond[:loved]
|
14
|
+
finder.find_loved_tracks(cond[:loved])
|
15
|
+
when cond[:name]
|
16
|
+
finder.find_tracks_by_songs(cond[:name]).first
|
17
|
+
when cond[:album]
|
18
|
+
finder.find_tracks_by_albums(cond[:album]).first
|
19
|
+
when cond[:artists]
|
20
|
+
finder.find_tracks_by_artists(cond[:artists]).first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Maybe Too Slow
|
25
|
+
def find_all
|
26
|
+
finder.finder_all_tracks
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def play
|
31
|
+
player.play(persistentID)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
'%s / %s / %s' % [name, artist, album]
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def player
|
41
|
+
@player ||= Aric::Job::Player.instance
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Aric
|
4
|
+
class ScriptRunner
|
5
|
+
class << self
|
6
|
+
def run(file_name, args = [])
|
7
|
+
new(file_name).run(args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(file_name)
|
12
|
+
@file_name = file_name.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(args = [])
|
16
|
+
args = Array(args).join(' ')
|
17
|
+
stdout, stderr, status = Open3.capture3("osascript -l JavaScript #{script_file_path} #{args}")
|
18
|
+
puts nil, '<============================================================ DEBUG OUTPUT START HERE'
|
19
|
+
p stdout, stderr, status
|
20
|
+
puts '<============================================================ DEBUG OUTPUT CLOSE HERE', nil
|
21
|
+
raise stderr unless status.success?
|
22
|
+
stdout.strip
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def script_file_path
|
28
|
+
"#{script_base_dir}/#{@file_name}.js"
|
29
|
+
end
|
30
|
+
|
31
|
+
def script_base_dir
|
32
|
+
@script_base_dir ||= File.expand_path('../../../scripts', __FILE__)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/aric/version.rb
ADDED
data/scripts/activate.js
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
var app = Application("iTunes");
|
2
|
+
var playlist = app.currentPlaylist();
|
3
|
+
|
4
|
+
JSON.stringify({
|
5
|
+
class: playlist.class(),
|
6
|
+
container: playlist.container(),
|
7
|
+
id: playlist.id(),
|
8
|
+
index: playlist.index(),
|
9
|
+
name: playlist.name(),
|
10
|
+
persistentID: playlist.persistentID(),
|
11
|
+
properties: playlist.properties()
|
12
|
+
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
var app = Application("iTunes");
|
2
|
+
var tracks_in_playlist = app.currentPlaylist().tracks().map(function(track){
|
3
|
+
var tmp = {
|
4
|
+
class: track.class(),
|
5
|
+
container: track.container(),
|
6
|
+
id: track.id(),
|
7
|
+
index: track.index(),
|
8
|
+
name: track.name(),
|
9
|
+
persistentID: track.persistentID(),
|
10
|
+
properties: track.properties()
|
11
|
+
};
|
12
|
+
return tmp;
|
13
|
+
});
|
14
|
+
JSON.stringify(tracks_in_playlist);
|
@@ -0,0 +1,12 @@
|
|
1
|
+
var app = Application("iTunes");
|
2
|
+
var track = app.currentTrack();
|
3
|
+
|
4
|
+
JSON.stringify({
|
5
|
+
class: track.class(),
|
6
|
+
container: track.container(),
|
7
|
+
id: track.id(),
|
8
|
+
index: track.index(),
|
9
|
+
name: track.name(),
|
10
|
+
persistentID: track.persistentID(),
|
11
|
+
properties: track.properties()
|
12
|
+
});
|
data/scripts/down.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var pls = app.playlists().map(function(playlist){
|
4
|
+
return {
|
5
|
+
class: playlist.class(),
|
6
|
+
container: playlist.container(),
|
7
|
+
id: playlist.id(),
|
8
|
+
index: playlist.index(),
|
9
|
+
name: playlist.name(),
|
10
|
+
persistentID: playlist.persistentID(),
|
11
|
+
properties: playlist.properties()
|
12
|
+
};
|
13
|
+
});
|
14
|
+
return JSON.stringify(pls);
|
15
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var tracks = app.tracks().map(function(track){
|
4
|
+
return {
|
5
|
+
class: track.class(),
|
6
|
+
container: track.container(),
|
7
|
+
id: track.id(),
|
8
|
+
index: track.index(),
|
9
|
+
name: track.name(),
|
10
|
+
persistentID: track.persistentID(),
|
11
|
+
properties: track.properties()
|
12
|
+
};
|
13
|
+
});
|
14
|
+
return JSON.stringify(tracks);
|
15
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var playlists = app.playlists().filter(function(x){ return x.loved(); }).map(function(playlist){
|
4
|
+
return {
|
5
|
+
class: playlist.class(),
|
6
|
+
container: playlist.container(),
|
7
|
+
id: playlist.id(),
|
8
|
+
index: playlist.index(),
|
9
|
+
name: playlist.name(),
|
10
|
+
persistentID: playlist.persistentID(),
|
11
|
+
properties: playlist.properties()
|
12
|
+
};
|
13
|
+
});;
|
14
|
+
|
15
|
+
return JSON.stringify(playlists);
|
16
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var tracks = app.tracks().filter(function(x){ return x.loved(); }).map(function(track){
|
4
|
+
return {
|
5
|
+
class: track.class(),
|
6
|
+
container: track.container(),
|
7
|
+
id: track.id(),
|
8
|
+
index: track.index(),
|
9
|
+
name: track.name(),
|
10
|
+
persistentID: track.persistentID(),
|
11
|
+
properties: track.properties()
|
12
|
+
};
|
13
|
+
});;
|
14
|
+
|
15
|
+
return JSON.stringify(tracks);
|
16
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var playlist = app.playlists().find(function(x){
|
4
|
+
return x.persistentID() == argv[0];
|
5
|
+
});
|
6
|
+
|
7
|
+
return JSON.stringify({
|
8
|
+
class: playlist.class(),
|
9
|
+
container: playlist.container(),
|
10
|
+
id: playlist.id(),
|
11
|
+
index: playlist.index(),
|
12
|
+
name: playlist.name(),
|
13
|
+
persistentID: playlist.persistentID(),
|
14
|
+
properties: playlist.properties()
|
15
|
+
});
|
16
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var playlists = app.playlists().filter(function(x){
|
4
|
+
return x.name() == argv[0];
|
5
|
+
}).map(function(playlist){
|
6
|
+
return {
|
7
|
+
class: playlist.class(),
|
8
|
+
container: playlist.container(),
|
9
|
+
id: playlist.id(),
|
10
|
+
index: playlist.index(),
|
11
|
+
name: playlist.name(),
|
12
|
+
persistentID: playlist.persistentID(),
|
13
|
+
properties: playlist.properties()
|
14
|
+
};
|
15
|
+
});
|
16
|
+
|
17
|
+
return JSON.stringify(playlists);
|
18
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var track = app.tracks().find(function(x){
|
4
|
+
return x.persistentID() == argv[0];
|
5
|
+
});
|
6
|
+
|
7
|
+
return JSON.stringify({
|
8
|
+
class: track.class(),
|
9
|
+
container: track.container(),
|
10
|
+
id: track.id(),
|
11
|
+
index: track.index(),
|
12
|
+
name: track.name(),
|
13
|
+
persistentID: track.persistentID(),
|
14
|
+
properties: track.properties()
|
15
|
+
});
|
16
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var pl = app.playlists().find(function(x){
|
4
|
+
return x.name() == "ミュージック" || x.name() == "Music";
|
5
|
+
});
|
6
|
+
var tracks = app.search(pl, {for: argv[0]}).map(function(track){
|
7
|
+
return {
|
8
|
+
class: track.class(),
|
9
|
+
container: track.container(),
|
10
|
+
id: track.id(),
|
11
|
+
index: track.index(),
|
12
|
+
name: track.name(),
|
13
|
+
persistentID: track.persistentID(),
|
14
|
+
properties: track.properties()
|
15
|
+
};
|
16
|
+
});
|
17
|
+
return JSON.stringify(tracks);
|
18
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
function run(argv) {
|
2
|
+
var app = Application("iTunes");
|
3
|
+
var pl = app.playlists().find(function(x){
|
4
|
+
return x.name() == "ミュージック" || x.name() == "Music";
|
5
|
+
});
|
6
|
+
var tracks = app.search(pl, {for: argv[1], only: argv[0]}).map(function(track){
|
7
|
+
return {
|
8
|
+
class: track.class(),
|
9
|
+
container: track.container(),
|
10
|
+
id: track.id(),
|
11
|
+
index: track.index(),
|
12
|
+
name: track.name(),
|
13
|
+
persistentID: track.persistentID(),
|
14
|
+
properties: track.properties()
|
15
|
+
};
|
16
|
+
});
|
17
|
+
|
18
|
+
return JSON.stringify(tracks);
|
19
|
+
}
|
data/scripts/love.js
ADDED
data/scripts/mute.js
ADDED
data/scripts/pause.js
ADDED
data/scripts/play.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
function run(argv){
|
2
|
+
var app = Application("iTunes");
|
3
|
+
|
4
|
+
if (argv.length > 0) {
|
5
|
+
var persistentID = argv[0];
|
6
|
+
var t = app.tracks().find(function (x) {
|
7
|
+
return x.persistentID() == persistentID;
|
8
|
+
});
|
9
|
+
app.play(t);
|
10
|
+
} else {
|
11
|
+
app.play();
|
12
|
+
}
|
13
|
+
}
|
data/scripts/resume.js
ADDED
data/scripts/unlove.js
ADDED
data/scripts/unmute.js
ADDED
data/scripts/up.js
ADDED
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aric
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ganmacs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ganmacs@gmail.com
|
72
|
+
executables:
|
73
|
+
- aric
|
74
|
+
- console
|
75
|
+
- setup
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".rubocop.yml"
|
82
|
+
- ".travis.yml"
|
83
|
+
- Gemfile
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- aric.gemspec
|
87
|
+
- bin/aric
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- lib/aric.rb
|
91
|
+
- lib/aric/command.rb
|
92
|
+
- lib/aric/job.rb
|
93
|
+
- lib/aric/job/base.rb
|
94
|
+
- lib/aric/job/finder.rb
|
95
|
+
- lib/aric/job/player.rb
|
96
|
+
- lib/aric/job/util.rb
|
97
|
+
- lib/aric/job/volume.rb
|
98
|
+
- lib/aric/job_handler.rb
|
99
|
+
- lib/aric/resource/base.rb
|
100
|
+
- lib/aric/resource/playlist.rb
|
101
|
+
- lib/aric/resource/track.rb
|
102
|
+
- lib/aric/script_runner.rb
|
103
|
+
- lib/aric/version.rb
|
104
|
+
- scripts/activate.js
|
105
|
+
- scripts/back_track.js
|
106
|
+
- scripts/current_playlist.js
|
107
|
+
- scripts/current_playlist_tracks.js
|
108
|
+
- scripts/current_track.js
|
109
|
+
- scripts/down.js
|
110
|
+
- scripts/fast_forward.js
|
111
|
+
- scripts/finder/find_all_playlists.js
|
112
|
+
- scripts/finder/find_all_tracks.js
|
113
|
+
- scripts/finder/find_loved_playlists.js
|
114
|
+
- scripts/finder/find_loved_tracks.js
|
115
|
+
- scripts/finder/find_playlist_by_id.js
|
116
|
+
- scripts/finder/find_playlists.js
|
117
|
+
- scripts/finder/find_track_by_id.js
|
118
|
+
- scripts/finder/find_tracks.js
|
119
|
+
- scripts/finder/find_tracks_by.js
|
120
|
+
- scripts/love.js
|
121
|
+
- scripts/love_playlist.js
|
122
|
+
- scripts/mute.js
|
123
|
+
- scripts/next_track.js
|
124
|
+
- scripts/pause.js
|
125
|
+
- scripts/play.js
|
126
|
+
- scripts/player_position.js
|
127
|
+
- scripts/player_state.js
|
128
|
+
- scripts/previous_track.js
|
129
|
+
- scripts/resume.js
|
130
|
+
- scripts/set_player_position.js
|
131
|
+
- scripts/unlove.js
|
132
|
+
- scripts/unlove_playlist.js
|
133
|
+
- scripts/unmute.js
|
134
|
+
- scripts/up.js
|
135
|
+
homepage: https://github.com/ganmacs/arci
|
136
|
+
licenses: []
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.4.5.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Awesome Ruby Ituens Client
|
158
|
+
test_files: []
|