YoutubeTools 0.0.2 → 0.0.3
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.
- data/VERSION +1 -1
- data/YoutubeTools.gemspec +1 -1
- data/lib/youtube_tools/converter.rb +18 -6
- metadata +2 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.3
|
data/YoutubeTools.gemspec
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
module YoutubeTools
|
|
2
2
|
class Converter
|
|
3
|
-
attr_accessor :file, :folder, :file_name
|
|
3
|
+
attr_accessor :file, :folder, :file_name, :format
|
|
4
4
|
|
|
5
|
-
def initialize(file,
|
|
6
|
-
@folder = path.nil? ? FOLDER_PATH : path
|
|
5
|
+
def initialize(file, options={})
|
|
6
|
+
@folder = options[:path].nil? ? FOLDER_PATH : options[:path]
|
|
7
|
+
@format = options[:format].nil? ? :mp3 : options[:format]
|
|
7
8
|
|
|
8
9
|
@file = "#{@folder}/#{file}"
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
converter_to(@format)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
protected
|
|
13
15
|
def converter_to(format=:mp3)
|
|
14
|
-
@file_name = "#{@file}.#{format}"
|
|
15
|
-
|
|
16
|
+
@file_name = "#{@file}.#{format}"
|
|
17
|
+
|
|
18
|
+
case format
|
|
19
|
+
when :avi
|
|
20
|
+
system "ffmpeg -i #{@file} -ab 56 -ar 22050 -b 500 -s 320x240 -vcodec xvid -acodec mp3 #{@file_name}"
|
|
21
|
+
when :mp4
|
|
22
|
+
system "ffmpeg -i #{@file} -ar 22050 #{@file_name}"
|
|
23
|
+
when :mpg
|
|
24
|
+
system "ffmpeg -i #{@file} -ab 56 -ar 22050 -b 500 -s 320x240 #{@file_name}"
|
|
25
|
+
else
|
|
26
|
+
system "ffmpeg -i #{@file} -ab 128k -ac 2 -acodec libmp3lame -vn -y #{@file_name}"
|
|
27
|
+
end
|
|
16
28
|
system "rm -Rf #{@file}" if File.exist? @file
|
|
17
29
|
end
|
|
18
30
|
end
|