taifu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .bundle
20
+ Gemfile.lock
21
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in taifu.gemspec
4
+ gemspec
@@ -0,0 +1,31 @@
1
+ # taifu
2
+ taifu will bring YouTube sound to your iTunes library silently.
3
+
4
+ ## Usage
5
+
6
+ Try
7
+
8
+ ```
9
+ taifu http://www.youtube.com/watch?v=I1X6MrBfjrk
10
+ ```
11
+
12
+ And check type 'taifu' at search box on your iTunes.
13
+
14
+
15
+ ## Install
16
+
17
+ ```
18
+ gem install taifu
19
+ ```
20
+
21
+ # Supported OS
22
+ - OSX
23
+
24
+ ## Dependencies
25
+ - ffmpeg
26
+ - youtube-dl
27
+
28
+ You can install these tools by homebrew.
29
+
30
+ ## Licence
31
+ taifu is released into the public domain by the copyright holders.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'taifu'
3
+ include Taifu
4
+
5
+ Taifu.hit
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ require 'fileutils'
3
+ require 'appscript'
4
+
5
+ require "taifu/app"
6
+ require "taifu/version"
7
+
8
+ module Taifu
9
+ def hit
10
+ url = ARGV.first
11
+ if url.nil?
12
+ raise ArgumentError.new 'You need to specify URL. Try "taifu http://www.youtube.com/watch?v=I1X6MrBfjrk"'
13
+ end
14
+ App.new(url)
15
+ end
16
+ module_function :hit
17
+ end
@@ -0,0 +1,111 @@
1
+ # coding: utf-8
2
+ module Taifu
3
+ include Appscript
4
+
5
+ class App
6
+ REQUIRED_APPS = ['youtube-dl', 'ffmpeg']
7
+
8
+ def initialize(url)
9
+ return unless satisfied?
10
+
11
+ init_working_dir
12
+
13
+ save_wav_with(url)
14
+ add_track
15
+
16
+ logging "Done. Type 'taifu' on your iTunes", false
17
+ end
18
+
19
+ def init_working_dir
20
+ unless File.exist?(working_dir)
21
+ FileUtils.mkdir(working_dir)
22
+ end
23
+ end
24
+
25
+ def working_dir
26
+ home_dir = File.expand_path('~')
27
+ File.join(home_dir, '.taifu')
28
+ end
29
+
30
+ def add_track
31
+ logging 'Add wav file to iTunes'
32
+
33
+ script = create_script
34
+ `osascript #{script}`
35
+ delete_script
36
+
37
+ delete_wav
38
+ end
39
+
40
+ def delete_wav
41
+ FileUtils.rm "#{working_dir}/taifu.wav"
42
+ end
43
+
44
+ def delete_script
45
+ FileUtils.rm "#{working_dir}/track.scpt"
46
+ end
47
+
48
+ def create_script
49
+ file_path = MacTypes::FileURL.path(File.expand_path("#{working_dir}/taifu.wav")).hfs_path
50
+ script_path = "#{working_dir}/track.scpt"
51
+
52
+ script = script_base.gsub('$file_path', file_path)
53
+ open(script_path, 'w') do |f|
54
+ f.write script
55
+ end
56
+ script_path
57
+ end
58
+
59
+ def save_wav_with(youtube_url)
60
+ url = youtube_url.split('&').first
61
+ wav_file = 'taifu.wav'
62
+ wav_path = "#{working_dir}/#{wav_file}"
63
+
64
+ logging 'Download data'
65
+ system "youtube-dl -q #{url} -o #{working_dir}/taifu.flv"
66
+
67
+ logging 'Save wav file'
68
+ system "ffmpeg -i #{working_dir}/taifu.flv #{wav_path} 2>/dev/null"
69
+ system "rm -f #{working_dir}/taifu.flv"
70
+ end
71
+
72
+ def satisfied?
73
+ REQUIRED_APPS.each do |app|
74
+ if `which #{app}`.empty?
75
+ messages = []
76
+ messages << "'#{app}' is not installed."
77
+ messages << "Try this command to install '#{app}'."
78
+ messages << ""
79
+ messages << " brew install #{app}"
80
+ messages << ""
81
+ raise RuntimeError, messages.join("\n")
82
+ end
83
+ end
84
+ true
85
+ end
86
+
87
+ def logging(message, caption=true)
88
+ if caption
89
+ puts "[#{message}]..." if ENV['LOGGING']
90
+ else
91
+ puts message
92
+ end
93
+ end
94
+
95
+ def script_base
96
+ <<-SCRIPT
97
+ tell application "iTunes"
98
+ set added_track to add "$file_path"
99
+ set loc to (get location of added_track)
100
+ convert added_track
101
+ delete added_track
102
+
103
+ tell application "Finder"
104
+ delete loc
105
+ end tell
106
+ end tell
107
+ SCRIPT
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ module Taifu
3
+ VERSION = "0.0.1"
4
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "taifu/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "taifu"
7
+ s.version = Taifu::VERSION
8
+ s.authors = ["Ryo Katsuma"]
9
+ s.email = ["katsuma@gmail.com"]
10
+ s.homepage = "http://github.com/katsuma/taifu"
11
+ s.summary = %q{YouTube sound converter for iTunes}
12
+ s.description = %q{taifu will bring YouTube sound to your iTunes library silently}
13
+
14
+ s.rubyforge_project = "taifu"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rb-appscript"
23
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taifu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryo Katsuma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rb-appscript
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: taifu will bring YouTube sound to your iTunes library silently
31
+ email:
32
+ - katsuma@gmail.com
33
+ executables:
34
+ - taifu
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - README.md
41
+ - Rakefile
42
+ - bin/taifu
43
+ - lib/taifu.rb
44
+ - lib/taifu/app.rb
45
+ - lib/taifu/version.rb
46
+ - taifu.gemspec
47
+ homepage: http://github.com/katsuma/taifu
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project: taifu
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: YouTube sound converter for iTunes
71
+ test_files: []