bulk_youtube 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bulk_youtube.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michael Zakany
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Youtube Bulk Video Downloader:
2
+ =======
3
+ ```
4
+ Uses mechanize (2.7.2) and nokogiri (1.6.1)
5
+
6
+ Purpose: when you need to download multiple youtube files, say a course or tutorial i.e. to watch offline.
7
+
8
+ Note: change the @max_downloads to increase the amount of mp4s can send.
9
+
10
+ ```
11
+
12
+
13
+ Variables:
14
+ ==========
15
+
16
+ ```
17
+ > search = 'https://www.youtube.com/playlist?list=PLV1-QgpUU7N2TVWS6gEVMqEfAFjAl-DV6'
18
+ > save = '/path/to/save'
19
+ > word = 'French'
20
+ ```
21
+
22
+ Send mp4's to your local folder:
23
+ ==========
24
+
25
+
26
+ ```
27
+ Without keyword search:
28
+ > find = Scrape.new(search,save)
29
+ > find.grab_links.links #show the link objects as is
30
+ > find.grab_links.show #show a more concise version
31
+ > find.grab_links.you_convert #send links to folder
32
+ ```
33
+ ```
34
+ With keyword search:
35
+ > find = Scrape.new(search,save)
36
+ > find.grab_links('French').links
37
+ > find.grab_links('French').you_convert
38
+ ```
39
+ ```
40
+ Set to download more
41
+ > Scrape.new(search,save,10).grab_links.you_convert
42
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bulk_youtube/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bulk_youtube"
8
+ spec.version = BulkYoutube::VERSION
9
+ spec.authors = ["Michael C. Zakany"]
10
+ spec.email = ["mzakany@gmail.com"]
11
+ spec.description = %q{Download batches of youtube videos}
12
+ spec.summary = %q{Download Batches of youtube videos}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nokogiri"
22
+ spec.add_dependency "mechanize"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,132 @@
1
+ require "bulk_youtube/version"
2
+ require "bulk_youtube/globals"
3
+ require 'mechanize'
4
+ require 'nokogiri'
5
+
6
+
7
+ module BulkYoutube
8
+ class Scrape
9
+ include Globals
10
+
11
+ attr_accessor :search_path, :save_destination, :max_retries
12
+
13
+ def initialize(search_path=nil, save_destination=nil, max_downloads=2, max_retries=10)
14
+ @search_path = search_path
15
+ @save_destination = save_destination
16
+ @max_downloads = max_downloads
17
+ @max_retries = max_retries
18
+ end
19
+
20
+
21
+ # def you_convert
22
+ # retry_count = 0
23
+ # begin
24
+ # send_files(@link_arr)
25
+ # rescue Net::HTTP::Persistent::Error => e
26
+ # raise unless e.message =~ /too man connection resets/
27
+ # if retry_count > @max_retries
28
+ # puts "**** WARN: Mechanize retried connection reset #{@max_retries} times"
29
+ # raise
30
+ # end
31
+ # retry_count +=1
32
+ # Mechanize::HTTP::Agent.http.shutdown
33
+ # retry
34
+ # end
35
+ # end
36
+
37
+ def you_convert
38
+ begin
39
+ send_files(@link_arr)
40
+ rescue StandardError
41
+ false
42
+ end
43
+ end
44
+
45
+ def grab_links(word=nil)
46
+ gather(word)
47
+ end
48
+
49
+ def show
50
+ arr = []
51
+ @link_arr.each do |link|
52
+ REPLACE.each do |r|
53
+ link.text.gsub!(r[0], r[1])
54
+ end
55
+ arr << link
56
+ end
57
+ arr
58
+ end
59
+
60
+ def links
61
+ @link_arr
62
+ end
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+ private
71
+
72
+ def noko(path)
73
+ Nokogiri::HTML(path)
74
+ end
75
+
76
+ def mec_get(path)
77
+ Mechanize.new.get(path)
78
+ end
79
+
80
+ # returns itself
81
+ def gather(word)
82
+ @link_arr = []
83
+ path = mec_get(@search_path)
84
+ count = 0
85
+
86
+ if word.nil?
87
+
88
+ path.links.each do |link|
89
+ break if count > @max_downloads
90
+ youtube = link.click.uri.to_s
91
+
92
+ # next if link.text.include?('Play')
93
+
94
+ if youtube.include?('watch?v=')
95
+ @link_arr << link
96
+ count += 1
97
+ end
98
+ end
99
+
100
+ else
101
+
102
+ path.links_with(:text => /#{word}/).each do |link|
103
+
104
+ break if count > @max_downloads
105
+
106
+ # next if link.text.include?('Play')
107
+
108
+ if link.text.include?(word) && link.click.uri.to_s.include?('watch?v=')
109
+ @link_arr << link
110
+ count += 1
111
+ end
112
+ end
113
+ end
114
+ self
115
+ end
116
+
117
+ # requires an array
118
+ def send_files(links)
119
+ you_convert = 'http://www.youtubeinmp4.com/'
120
+ links.each_with_index do |link, i|
121
+ clicked_link = link.click.uri.to_s
122
+ form = mec_get(you_convert).forms[0]
123
+ next if link.nil?
124
+ puts "printing link #{i}"
125
+ form.field_with(:class => 'c3').value = clicked_link
126
+ path = "#{@save_destination}/#{i}.mp4"
127
+ form.submit.links[1].click.save_as(path)
128
+ puts "link #{1} successful"
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,15 @@
1
+ module Globals
2
+
3
+ REPLACE = [
4
+ [/\r/, ''],
5
+ [/\n/, ''],
6
+ [/\s+/, ' '],
7
+ ['Play', ''],
8
+ ['Next', ''],
9
+ ['views', ''],
10
+ ['Next', ''],
11
+ ['next', ''],
12
+ ['now', ''],
13
+ ['of', '']
14
+ ]
15
+ end
@@ -0,0 +1,3 @@
1
+ module BulkYoutube
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,50 @@
1
+ # this file tests many different types of youtube urls and playlists
2
+ require 'spec_helper'
3
+
4
+ describe 'Playlist' do
5
+ before do
6
+ @temples = 'https://www.youtube.com/watch?v=mLPvEfB8F2I&list=UU3I2GFN_F8WudD_2jUZbojA'
7
+ @of_monsters = 'https://www.youtube.com/watch?v=8Dw8qdmT_aY&list=TLF8Mb1J2-C51c-0bwT31CLxHjPDNIDemE'
8
+ @shovels_rope = 'https://www.youtube.com/watch?v=SFzWiUeooEY&list=PLB88CA03885F74F2B'
9
+ @save_to = '/Users/mzakany/Desktop/folder'
10
+ end
11
+
12
+ context 'Grab the links with no parameters' do
13
+
14
+ it 'should get temples' do
15
+ # theres a ton of links so I commented out
16
+ found_links = BulkYoutube::Scrape.new(@temples, @save_to)
17
+ # found_links.grab_links.count
18
+ end
19
+
20
+ it 'should get of_monsters' do
21
+ found_links = BulkYoutube::Scrape.new(@of_monsters,@save_to)
22
+ # found_links.grab_links.count
23
+ end
24
+ end
25
+
26
+ context 'Grab the links with word search' do
27
+ it 'should get Monsters' do
28
+ found_links = BulkYoutube::Scrape.new(@of_monsters,@save_to)
29
+ # found_links.grab_links('Monsters').show
30
+ end
31
+ end
32
+
33
+ context 'Send files to folder' do
34
+ before do
35
+ @run = BulkYoutube::Scrape.new(@of_monsters, @save_to)
36
+ end
37
+
38
+ it 'should send no parameter to folder' do
39
+ # links = @run.grab_links.links
40
+ # @run.you_convert(links)
41
+ end
42
+
43
+ it 'should send with word search to folder' do
44
+ # links = @run.grab_links('Monsters')
45
+ # @run.you_convert(links)
46
+ end
47
+ end
48
+
49
+
50
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe 'Full Page Playlist' do
5
+ before do
6
+ @EEVlog = 'https://www.youtube.com/playlist?list=PL55857F4F6F2D36B1'
7
+ @french = 'https://www.youtube.com/playlist?list=PLV1-QgpUU7N2TVWS6gEVMqEfAFjAl-DV6'
8
+ @save_to = '/Users/mzakany/Desktop/folder'
9
+
10
+ @found = BulkYoutube::Scrape.new(@EEVlog, @save_to)
11
+ @found_french = BulkYoutube::Scrape.new(@french, @save_to)
12
+ end
13
+
14
+ context 'Grab Links with no parameters' do
15
+ it 'should get eevlog links' do
16
+ # @found.grab_links.class
17
+ # expect(@found_french.grab_links).to be_an_instance_of Array
18
+ end
19
+ end
20
+
21
+ context 'Grab with word search' do
22
+ it 'should get with word search ' do
23
+ # expect(@found.grab_links('EEVblog')).to be_an_instance_of Array
24
+ # @found_french.grab_links('French').show
25
+ end
26
+
27
+ it 'should grab this page' do
28
+ path = 'https://www.youtube.com/watch?v=z5pJvhd3lFQ'
29
+ save = '/Users/mzakany/Desktop/folder'
30
+ found = BulkYoutube::Scrape.new(path,save)
31
+ puts found.grab_links.show
32
+ end
33
+ end
34
+
35
+ context 'Send to folder' do
36
+
37
+ before do
38
+ @run_french = BulkYoutube::Scrape.new(@french, @save_to)
39
+ end
40
+
41
+ it 'should do no parameters' do
42
+ # @run_french.grab_links('French').you_convert
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -0,0 +1,11 @@
1
+ require 'bulk_youtube'
2
+ require 'bulk_youtube/globals'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulk_youtube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael C. Zakany
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Download batches of youtube videos
95
+ email:
96
+ - mzakany@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bulk_youtube.gemspec
108
+ - lib/bulk_youtube.rb
109
+ - lib/bulk_youtube/globals.rb
110
+ - lib/bulk_youtube/version.rb
111
+ - spec/embedded_playlists_spec.rb
112
+ - spec/full_page_playlist_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.23
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Download Batches of youtube videos
139
+ test_files:
140
+ - spec/embedded_playlists_spec.rb
141
+ - spec/full_page_playlist_spec.rb
142
+ - spec/spec_helper.rb
143
+ has_rdoc: