taifu 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eadfaff239772633fc2471d38d2312631115736a
4
- data.tar.gz: e1ea4e6985a13f861930e5e47f808be99144f702
3
+ metadata.gz: 687e080038b7ca8e3b794a76d5a2eef0eef6ea19
4
+ data.tar.gz: b4b3377605241443b5d7327bb17c03c388122ef1
5
5
  SHA512:
6
- metadata.gz: 1e69a23a889681856423d3e4fa5ab60bfec847d4a94abe219e2f51998fc6e13ce344596200d3fd8701c01ab2776ffcffe816e4e4e3dc0e4d999d01ac7b95250e
7
- data.tar.gz: a8457c3a5704680cb154f2c0d7f4a90807b0ccdf3ac7a3099a05d627ea375bad57f4f8c1d938041d0f913fcad3acdbd9dd0473bf218a956eae03768f975ad252
6
+ metadata.gz: 8e8619e306cdbea2e3edd8b8dea1d3347aaffd89a771b04f1725a5750737e8563f8582293dba9aed78143d6698aeccdab13c89282120f646571a8bdd27edd53a
7
+ data.tar.gz: bff38a8313cc3f0fc37ee0c47d2eb3e5c2843132beec88430165b8e76724523e8e1b986a66ae738a8e2cb9d3b7ae0840cef8d7d68afa9863bb6fc723a2bb5223
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .coveralls.yml
5
6
  coverage
6
7
  InstalledFiles
7
8
  lib/bundler/man
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # taifu [![Build Status](https://travis-ci.org/katsuma/taifu.png?branch=master)](https://travis-ci.org/katsuma/taifu)
1
+ # taifu [![Build Status](https://travis-ci.org/katsuma/taifu.png?branch=master)](https://travis-ci.org/katsuma/taifu) [![Coverage Status](https://coveralls.io/repos/katsuma/taifu/badge.png?branch=master)](https://coveralls.io/r/katsuma/taifu)
2
2
  taifu brings YouTube sound to your iTunes library silently.
3
3
 
4
4
  ## Usage
@@ -6,7 +6,7 @@ taifu brings YouTube sound to your iTunes library silently.
6
6
  Try
7
7
 
8
8
  ```
9
- taifu http://www.youtube.com/watch?v=I1X6MrBfjrk
9
+ taifu http://www.youtube.com/watch?v=your-video-id
10
10
  ```
11
11
 
12
12
  After that type `taifu` at search box on your iTunes.
@@ -32,5 +32,9 @@ gem install taifu
32
32
 
33
33
  You can install these tools by homebrew.
34
34
 
35
+ ## Warning
36
+ You can use this tool for only contents you have copyrights.
37
+
38
+
35
39
  ## Licence
36
40
  taifu is released under the MIT License.
@@ -1,16 +1,17 @@
1
1
  # coding: utf-8
2
2
  require 'fileutils'
3
3
  require 'logger'
4
+ require 'itunes-client'
4
5
  require 'taifu/app'
6
+ require 'taifu/util'
5
7
  require 'taifu/version'
6
8
 
7
9
  module Taifu
8
10
  def hit
9
11
  url = ARGV.first
10
12
  if url.nil?
11
- raise ArgumentError.new 'You need to specify URL. Try "taifu http://www.youtube.com/watch?v=I1X6MrBfjrk"'
13
+ raise ArgumentError.new 'You need to specify URL. Try "taifu http://www.youtube.com/watch?v=your-video-id"'
12
14
  end
13
-
14
15
  taifu = App.new
15
16
  wav_path = taifu.save_as_wav_with(url)
16
17
  taifu.add_track(wav_path)
@@ -10,15 +10,18 @@ module Taifu
10
10
 
11
11
  def save_as_wav_with(youtube_url)
12
12
  url = youtube_url.split('&').first
13
+ flv_path = "#{working_dir}/taifu.flv"
13
14
  wav_file = 'taifu.wav'
14
15
  wav_path = "#{working_dir}/#{wav_file}"
15
16
 
17
+ FileUtils.rm_f(wav_path) if File.exist?(wav_path)
18
+
16
19
  @logger.info 'Download data'
17
- download_from url
20
+ Util.save_flv_from_url(url, flv_path)
18
21
 
19
22
  @logger.info 'Save wav file'
20
- convert_flv_to wav_path
21
- remove_flv
23
+ Util.convert_flv_to_wav(flv_path, wav_path)
24
+ FileUtils.rm_f(flv_path)
22
25
 
23
26
  wav_path
24
27
  end
@@ -30,12 +33,11 @@ module Taifu
30
33
  raise ArgumentError.new 'Not found wav file'
31
34
  end
32
35
 
33
- script_path = File.expand_path("#{File.dirname(__FILE__)}/../../scripts/add_track.scpt")
34
- expand_wav_path = File.expand_path(wav_path)
35
- execute_script(script_path, expand_wav_path)
36
-
37
- FileUtils.rm_f(wav_path) if clean_up
38
-
36
+ track = Itunes::Application.instance.add(wav_path)
37
+ converted_track = track.convert
38
+ converted_track.update_attributes(name: 'Taifu')
39
+ track.delete! if clean_up
40
+ FileUtils.rm_f(wav_path)
39
41
  @logger.info "Done. Type 'taifu' on your iTunes"
40
42
  end
41
43
 
@@ -56,7 +58,7 @@ module Taifu
56
58
  private :check_env
57
59
 
58
60
  def installed?(app)
59
- !`which #{app}`.empty?
61
+ !!(system "which #{app}")
60
62
  end
61
63
  private :installed?
62
64
 
@@ -72,25 +74,5 @@ module Taifu
72
74
  end
73
75
  end
74
76
  private :init_working_dir
75
-
76
- def download_from(url)
77
- system "youtube-dl -q #{url} -o #{working_dir}/taifu.flv"
78
- end
79
- private :download_from
80
-
81
- def convert_flv_to(wav)
82
- system "ffmpeg -i #{working_dir}/taifu.flv #{wav} 2>/dev/null"
83
- end
84
- private :convert_flv_to
85
-
86
- def remove_flv
87
- system "rm -f #{working_dir}/taifu.flv"
88
- end
89
- private :remove_flv
90
-
91
- def execute_script(script, args)
92
- `osascript #{script} #{args}`
93
- end
94
- private :execute_script
95
77
  end
96
78
  end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+ module Taifu
3
+ class Util
4
+ def self.save_flv_from_url(url, flv_path)
5
+ system "youtube-dl -q #{url} -o #{flv_path}"
6
+ end
7
+
8
+ def self.convert_flv_to_wav(flv_path, wav_path)
9
+ system "ffmpeg -i #{flv_path} #{wav_path} 2>/dev/null"
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,4 @@
1
1
  # coding: utf-8
2
2
  module Taifu
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'bundler'
4
4
  require 'fakefs/spec_helpers'
5
+ require 'simplecov'
6
+ require 'coveralls'
5
7
 
6
8
  Bundler.setup(:default, :development)
7
9
 
@@ -11,3 +13,11 @@ RSpec.configure do |config|
11
13
  #config.formatter = :documentation
12
14
  config.include FakeFS::SpecHelpers, fakefs: true
13
15
  end
16
+
17
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
18
+ SimpleCov::Formatter::HTMLFormatter,
19
+ Coveralls::SimpleCov::Formatter
20
+ ]
21
+ SimpleCov.start do
22
+ add_filter '/spec/'
23
+ end
@@ -5,6 +5,7 @@ require 'taifu'
5
5
  describe Taifu do
6
6
  let(:url) { 'http://www.youtube.com/watch?v=I1X6MrBfjrk' }
7
7
  let(:working_dir) { '/tmp/.taifu' }
8
+ let(:util) { Taifu::Util }
8
9
 
9
10
  describe '#hit' do
10
11
  context 'with no arguments' do
@@ -34,7 +35,6 @@ describe Taifu do
34
35
  end
35
36
 
36
37
  describe Taifu::App do
37
-
38
38
  describe '.new' do
39
39
  subject { Taifu::App.new }
40
40
 
@@ -55,12 +55,12 @@ describe Taifu do
55
55
 
56
56
  before do
57
57
  taifu.should_receive(:installed?).at_least(:twice).and_return(true)
58
+ FileUtils.rm_rf(working_dir)
58
59
  end
59
60
 
60
61
  it 'makes a working directory', fakefs: true do
61
62
  taifu.should_receive(:working_dir).at_least(:twice).and_return(working_dir)
62
- subject
63
- File.should exist(working_dir)
63
+ expect { subject }.to change { File.exist?(working_dir) }.from(false).to(true)
64
64
  end
65
65
  end
66
66
  end
@@ -74,18 +74,18 @@ describe Taifu do
74
74
  let(:load_url) { "#{url}&fature=endscreen" }
75
75
  let(:taifu) { Taifu::App.any_instance }
76
76
 
77
- before { stub_constructor }
77
+ before { stub_app_installed }
78
78
 
79
79
  it 'saves file as wav' do
80
- taifu.should_receive(:download_from).with(url)
81
- taifu.should_receive(:convert_flv_to).with("#{working_dir}/taifu.wav")
82
- taifu.should_receive(:remove_flv)
80
+ util.should_receive(:save_flv_from_url)
81
+ util.should_receive(:convert_flv_to_wav)
82
+
83
83
  subject
84
84
  end
85
85
  end
86
86
 
87
87
  describe '#add_track' do
88
- subject do
88
+ subject(:add_track) do
89
89
  taifu = Taifu::App.new
90
90
  taifu.add_track(wav_path)
91
91
  end
@@ -93,7 +93,7 @@ describe Taifu do
93
93
  let(:taifu) { Taifu::App.any_instance }
94
94
  let(:wav_path) { '/tmp/.taifu.wav' }
95
95
 
96
- before { stub_constructor }
96
+ before { stub_app_installed }
97
97
 
98
98
  context 'if wav file is not found' do
99
99
  before do
@@ -101,7 +101,7 @@ describe Taifu do
101
101
  end
102
102
 
103
103
  it 'raises ArgumentError', fakefs: true do
104
- expect { subject }.to raise_error(ArgumentError)
104
+ expect { add_track }.to raise_error(ArgumentError)
105
105
  end
106
106
  end
107
107
 
@@ -110,19 +110,22 @@ describe Taifu do
110
110
  FileUtils.touch(wav_path)
111
111
  end
112
112
 
113
- it 'converts wav file', fakefs: true do
114
- taifu.should_receive(:execute_script)
113
+ let(:track) { Itunes::Track.new }
114
+ let(:converted_track) { Itunes::Track.new }
115
+
116
+ it 'calls Itunes util methods', fakefs: true do
117
+ Itunes::Application.any_instance.stub(:add).with(wav_path).and_return(track)
118
+ track.should_receive(:convert).and_return(converted_track)
119
+ converted_track.should_receive(:update_attributes)
120
+ track.should_receive(:delete!)
115
121
 
116
- File.should exist(wav_path)
117
- subject
118
- File.should_not exist(wav_path)
122
+ add_track
119
123
  end
120
124
  end
121
125
  end
122
126
 
123
- def stub_constructor
124
- taifu.should_receive(:installed?).exactly(2).times.and_return(true)
125
- taifu.should_receive(:working_dir).at_least(:once).and_return(working_dir)
127
+ def stub_app_installed
128
+ taifu.should_receive(:system).with(/^which/).exactly(2).times.and_return(true)
126
129
  end
127
130
  end
128
131
  end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+ require 'taifu'
4
+
5
+ describe Taifu::Util do
6
+ let(:util) { Taifu::Util }
7
+
8
+ describe '.save_flv_from_url' do
9
+ subject(:save_flv_from_url) { util.save_flv_from_url(url, flv_path) }
10
+ let(:url) { 'http://www.youtube.com/watch?v=foo' }
11
+ let(:flv_path) { '/tmp/foo.flv' }
12
+ it 'executes youtube_dl command' do
13
+ util.should_receive(:system).with("youtube-dl -q #{url} -o #{flv_path}")
14
+ save_flv_from_url
15
+ end
16
+ end
17
+
18
+ describe '.convert_flv_to_wav' do
19
+ subject(:convert_flv_to_wav) { util.convert_flv_to_wav(flv_path, wav_path) }
20
+ let(:flv_path) { '/tmp/foo.flv' }
21
+ let(:wav_path) { '/tmp/foo.wav' }
22
+
23
+ it 'executes ffmpeg command' do
24
+ util.should_receive(:system).with("ffmpeg -i #{flv_path} #{wav_path} 2>/dev/null")
25
+ convert_flv_to_wav
26
+ end
27
+ end
28
+ end
@@ -19,11 +19,15 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
  s.licenses = ["MIT"]
21
21
 
22
- s.add_development_dependency "rake"
23
- s.add_development_dependency "rspec"
24
- s.add_development_dependency "rb-fsevent"
25
- s.add_development_dependency "guard"
26
- s.add_development_dependency "guard-rspec"
27
- s.add_development_dependency "growl"
28
- s.add_development_dependency "fakefs"
22
+ s.add_development_dependency "rake", "~> 10.0.3"
23
+ s.add_development_dependency "rspec", "~> 2.13.0"
24
+ s.add_development_dependency "rb-fsevent", "~> 0.9.3"
25
+ s.add_development_dependency "guard", "~> 1.8.1"
26
+ s.add_development_dependency "guard-rspec", "~> 3.0.2"
27
+ s.add_development_dependency "growl", "~> 1.0.3"
28
+ s.add_development_dependency "fakefs", "~> 0.4.2"
29
+ s.add_development_dependency "coveralls", "~> 0.6.6"
30
+ s.add_development_dependency "simplecov", "~> 0.7.1"
31
+ s.add_development_dependency "pry", "~> 0.9.12.2"
32
+ s.add_dependency "itunes-client", "~> 0.0.6"
29
33
  end
metadata CHANGED
@@ -1,113 +1,169 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taifu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Katsuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-03 00:00:00.000000000 Z
11
+ date: 2013-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 10.0.3
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 10.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.13.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rb-fsevent
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.9.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.9.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.8.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.8.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 3.0.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 3.0.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: growl
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.0.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 1.0.3
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: fakefs
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 0.4.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 0.4.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.6
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.6.6
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.7.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 0.7.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 0.9.12.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 0.9.12.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: itunes-client
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: 0.0.6
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 0.0.6
111
167
  description: taifu brings YouTube sound to your iTunes library silently
112
168
  email:
113
169
  - katsuma@gmail.com
@@ -116,7 +172,9 @@ executables:
116
172
  extensions: []
117
173
  extra_rdoc_files: []
118
174
  files:
175
+ - .coveralls.yml
119
176
  - .gitignore
177
+ - .ruby-version
120
178
  - .travis.yml
121
179
  - Gemfile
122
180
  - Guardfile
@@ -126,10 +184,12 @@ files:
126
184
  - bin/taifu
127
185
  - lib/taifu.rb
128
186
  - lib/taifu/app.rb
187
+ - lib/taifu/util.rb
129
188
  - lib/taifu/version.rb
130
189
  - scripts/add_track.scpt
131
190
  - spec/spec_helper.rb
132
191
  - spec/taifu_spec.rb
192
+ - spec/util_spec.rb
133
193
  - taifu.gemspec
134
194
  homepage: http://github.com/katsuma/taifu
135
195
  licenses:
@@ -151,10 +211,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
211
  version: '0'
152
212
  requirements: []
153
213
  rubyforge_project: taifu
154
- rubygems_version: 2.0.0
214
+ rubygems_version: 2.0.3
155
215
  signing_key:
156
216
  specification_version: 4
157
217
  summary: YouTube sound converter for iTunes
158
218
  test_files:
159
219
  - spec/spec_helper.rb
160
220
  - spec/taifu_spec.rb
221
+ - spec/util_spec.rb