viddl-rb 0.4.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ __viddl-rb:__
2
+ Created by Marc Seeger (@rb2k)
3
+ Repo: http://github.com/rb2k/viddl-rb
4
+
5
+
6
+
7
+ __Installation:__
8
+ gem install viddl-rb
9
+
10
+ __Usage:__
11
+
12
+ Download a video:
13
+ viddl-rb http://www.youtube.com/watch?v=QH2-TGUlwu4
14
+
15
+ Download a video and extract the audio:
16
+ viddl-rb http://www.youtube.com/watch?v=QH2-TGUlwu4 --extract-audio
17
+
18
+ In both cases we'll name the output file according to the video title.
19
+
20
+
21
+ __Requirements:__
22
+
23
+ * curl/wget or the [progress bar](http://github.com/nex3/ruby-progressbar/) gem
24
+ * [Nokogiri](http://nokogiri.org/)
25
+ * ffmpeg if you want to extract audio tracks from the videos
26
+
27
+
28
+ __Contributors:__
29
+
30
+ * [kl](https://github.com/kl): Windows support (who knew!) and bug fixes
31
+ * [divout](https://github.com/divout) aka Ivan K: blip.tv plugin, bugfixes
32
+ * Sniper: bugfixes
33
+ * [Serabe](https://github.com/Serabe) aka Sergio Arbeo: packaging viddl as a binary
data/bin/viddl-rb CHANGED
@@ -5,11 +5,12 @@ require "rubygems"
5
5
  require "nokogiri"
6
6
  require "cgi"
7
7
  require "open-uri"
8
+ require "open3"
8
9
  require "download-helper.rb"
9
10
  require "plugin-helper.rb"
10
11
 
11
- if ARGV.first.nil?
12
- puts "Usage: viddl-rb [URL]!"
12
+ if ARGV[0].nil?
13
+ puts "Usage: viddl-rb URL [--extract-audio]"
13
14
  exit
14
15
  end
15
16
 
@@ -20,26 +21,75 @@ end
20
21
 
21
22
  puts "Plugins loaded: #{PluginBase.registered_plugins.inspect}"
22
23
 
24
+ url = ARGV[0]
25
+ extract_audio = ARGV.include?('--extract-audio')
26
+ puts "Will try to extract audio: #{extract_audio}."
27
+
28
+ unless url.match(/^http/)
29
+ puts "Please include 'http' with your URL e.g. http://www.youtube.com/watch?v=QH2-TGUlwu4"
30
+ exit(1)
31
+ end
23
32
 
24
- url = ARGV.first
25
33
  puts "Analyzing URL: #{url}"
34
+ #Check all plugins for a match
26
35
  PluginBase.registered_plugins.each do |plugin|
27
36
  if plugin.matches_provider?(url)
28
37
  puts "#{plugin}: true"
29
38
  begin
39
+ #we'll end up with an array of hashes with they keys :url and :name
30
40
  download_queue = plugin.get_urls_and_filenames(url)
31
41
  rescue StandardError => e
32
42
  puts "Error while running the #{plugin.name.inspect} plugin. Maybe it has to be updated? Error: #{e.message}."
33
- exit
43
+ exit(1)
34
44
  end
35
45
  download_queue.each do |url_name|
36
46
  result = DownloadHelper.save_file(url_name[:url], url_name[:name])
37
47
  if result
38
48
  puts "Download for #{url_name[:name]} successful."
49
+ if extract_audio
50
+ puts "Extracting audio for #{url_name[:name]}"
51
+ if DownloadHelper.os_has?('ffmpeg')
52
+ no_ext_filename = url_name[:name].split('.')[0..-1][0]
53
+ #capture stderr because ffmpeg expects an output param and will error out
54
+ file_info = Open3.popen3("ffmpeg -i #{url_name[:name]}") {|stdin, stdout, stderr, wait_thr| stderr.read }
55
+
56
+ if !file_info.to_s.empty?
57
+ audio_format_matches = file_info.match(/Audio: (\w*)/)
58
+ if audio_format_matches
59
+ audio_format = audio_format_matches[1]
60
+ else
61
+ puts "Couldn't find any audio:\n#{file_info.inspect}"
62
+ next
63
+ end
64
+
65
+ extension_mapper = {
66
+ 'aac' => 'm4a',
67
+ 'mp3' => 'mp3',
68
+ 'vorbis' => 'ogg'
69
+ }
70
+
71
+ if extension_mapper.key?(audio_format)
72
+ output_extension = extension_mapper[audio_format]
73
+ else
74
+ #lame fallback
75
+ puts "Unknown audio format: #{audio_format}, using name as extension: '.#{audio_format}'."
76
+ output_extension = audio_format
77
+ end
78
+ output_filename = "#{no_ext_filename}.#{output_extension}"
79
+ Open3.popen3("ffmpeg -i #{url_name[:name]} -vn -acodec copy #{output_filename}") {|stdin, stdout, stderr, wait_thr| stdout.read }
80
+ puts "Done extracting audio to #{output_filename}"
81
+ else
82
+ puts "Error while checking audio track of #{url_name[:name]}"
83
+ end
84
+ else
85
+ puts "Didn't detect ffmpeg on your system, can't extract audio."
86
+ end
87
+ end
39
88
  else
40
89
  puts "Download for #{url_name[:name]} failed."
41
90
  end
42
91
  end
92
+ #plugin matched and downloaded, we're done
43
93
  exit
44
94
  else
45
95
  puts "#{plugin}: false"
@@ -24,11 +24,10 @@ class DownloadHelper
24
24
  def self.save_file(file_uri, file_name)
25
25
  unescaped_uri = CGI::unescape(file_uri)
26
26
  result = false
27
- windows = ENV['OS'] =~ /windows/i
28
- if os_has?("wget", windows)
27
+ if os_has?("wget")
29
28
  puts "using wget"
30
29
  result = system("wget \"#{unescaped_uri}\" -O #{file_name}")
31
- elsif os_has?("curl", windows)
30
+ elsif os_has?("curl")
32
31
  puts "using curl"
33
32
  #-L means: follow redirects, We set an agent because Vimeo seems to want one
34
33
  result = system("curl -A 'Mozilla/2.02 (OS/2; U)' -L \"#{unescaped_uri}\" -o #{file_name}")
@@ -42,7 +41,7 @@ class DownloadHelper
42
41
  end
43
42
 
44
43
  #checks to see whether the os has a certain utility like wget or curl
45
- def self.os_has?(utility, windows)
44
+ def self.os_has?(utility, windows = (ENV['OS'] =~ /windows/i))
46
45
  unless windows # if os is something else than Windows
47
46
  return `which #{utility}`.include?(utility)
48
47
  else
metadata CHANGED
@@ -1,45 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: viddl-rb
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 9
10
- version: 0.4.9
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Marc Seeger
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-19 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70340043318900 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- description: An extendable commandline video downloader for flash video sites. Includes plugins for vimeo, youtube and megavideo
23
+ prerelease: false
24
+ version_requirements: *70340043318900
25
+ description: An extendable commandline video downloader for flash video sites. Includes
26
+ plugins for vimeo, youtube and megavideo
35
27
  email: mail@marc-seeger.de
36
- executables:
28
+ executables:
37
29
  - viddl-rb
38
30
  extensions: []
39
-
40
31
  extra_rdoc_files: []
41
-
42
- files:
32
+ files:
43
33
  - bin/viddl-rb
44
34
  - helper/download-helper.rb
45
35
  - helper/plugin-helper.rb
@@ -48,41 +38,29 @@ files:
48
38
  - plugins/vimeo.rb
49
39
  - plugins/youtube.rb
50
40
  - CHANGELOG.txt
51
- - README.txt
41
+ - README.md
52
42
  homepage: https://github.com/rb2k/viddl-rb
53
43
  licenses: []
54
-
55
44
  post_install_message:
56
45
  rdoc_options: []
57
-
58
- require_paths:
46
+ require_paths:
59
47
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
61
49
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
55
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 19
75
- segments:
76
- - 1
77
- - 3
78
- - 4
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
79
59
  version: 1.3.4
80
60
  requirements: []
81
-
82
61
  rubyforge_project: viddl-rb
83
- rubygems_version: 1.8.6
62
+ rubygems_version: 1.8.10
84
63
  signing_key:
85
64
  specification_version: 3
86
65
  summary: An extendable commandline video downloader for flash video sites.
87
66
  test_files: []
88
-
data/README.txt DELETED
@@ -1,17 +0,0 @@
1
- = viddl-rb
2
-
3
- * http://github.com/rb2k/viddl-rb
4
-
5
- == Installation:
6
- gem install viddl-rb
7
-
8
-
9
- == Gems needed so far:
10
-
11
- Progressbar
12
- gem install progressbar
13
- homepage: http://github.com/nex3/ruby-progressbar/
14
-
15
- Nokogiri
16
- gem install nokogiri
17
- homepage: http://nokogiri.org/