copycasts 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bin/copycasts-start-crawl +6 -0
- data/copycasts.gemspec +24 -0
- data/lib/copycasts.rb +69 -0
- data/lib/markdown +122 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ccd505ccc5e8c553f3baee43a252ca5d513e899e
|
4
|
+
data.tar.gz: d0cd9c67bfb26bc7adc92c4ed73493897920bc9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: adec6cd79686ec8c470e33e0356768490d8340e5c0a19eb562f0fc2c27472da884a756bf8456ae6b1a7a2c54843c9aa07958b3f079fd850cc509b7ecbc0cd7ee
|
7
|
+
data.tar.gz: 176088b17dcc0bd3bb90a3479617610cdfdaba572f961e1780dcb2bea4f2202683ae10ae64a128aec7e6bfa0078144c1d4e4e5f1dcc4b601cb43c691fe226227
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nicholas
|
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,31 @@
|
|
1
|
+
# Copycasts
|
2
|
+
|
3
|
+
Crawling railcast video and download to your local
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'copycasts'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install copycasts
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Run using this command in your terminal:
|
22
|
+
|
23
|
+
copycasts-start-crawl
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/copycasts.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path File.join(File.dirname(__FILE__), 'lib')
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "copycasts"
|
7
|
+
spec.version = File.read('VERSION').strip
|
8
|
+
spec.authors = ["Nicholas"]
|
9
|
+
spec.email = ["secret@live.com.my"]
|
10
|
+
spec.description = %q{Offline watch free episode of railscast videos for personal usage.}
|
11
|
+
spec.summary = %q{Download videos from video source}
|
12
|
+
spec.homepage = "https://github.com/nichthinkof30/copycasts"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = ["copycasts-start-crawl"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "nokogiri", "~> 1.5", ">= 1.5.6"
|
23
|
+
spec.add_development_dependency "open-uri", "~> 1.5", ">= 1.5.6"
|
24
|
+
end
|
data/lib/copycasts.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Copycasts
|
6
|
+
|
7
|
+
class Crawling
|
8
|
+
TARGET_URL = 'http://railscasts.com'
|
9
|
+
attr_accessor :page
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@pages = options[:page] || maximum_page
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_links
|
16
|
+
casts_list = []
|
17
|
+
puts "Start crawling..."
|
18
|
+
for index in 1..@pages
|
19
|
+
puts "Page :#{index}"
|
20
|
+
target_page = Nokogiri::HTML(open(TARGET_URL + "/?type=free&page=#{index}"))
|
21
|
+
target_page.css('.watch a:first').each do |link|
|
22
|
+
link_without_autoplay = link['href'].to_s.sub('?autoplay=true','')
|
23
|
+
casts_list << link_without_autoplay
|
24
|
+
end
|
25
|
+
end
|
26
|
+
puts "Finish crawling."
|
27
|
+
casts_list
|
28
|
+
end
|
29
|
+
|
30
|
+
def maximum_page
|
31
|
+
target_page = Nokogiri::HTML(open(TARGET_URL + "/?type=free"))
|
32
|
+
ret = 0
|
33
|
+
target_page.css('.pagination a').each do |a|
|
34
|
+
if !(a.content.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil) #not number
|
35
|
+
if a.content.to_i > 0
|
36
|
+
ret = a.content.to_i
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
ret
|
41
|
+
end
|
42
|
+
|
43
|
+
def mp4_video_links
|
44
|
+
mp4_links = []
|
45
|
+
get_links.each do |video_link|
|
46
|
+
video_page = Nokogiri::HTML(open(TARGET_URL + "/" + video_link))
|
47
|
+
link = video_page.css('.downloads li[3] a').first
|
48
|
+
mp4_links << link.values.first
|
49
|
+
end
|
50
|
+
mp4_links
|
51
|
+
end
|
52
|
+
|
53
|
+
def download_videos
|
54
|
+
mp4_video_links.each do |video_link|
|
55
|
+
uri = URI.parse(video_link)
|
56
|
+
file_name = video_link.split("/").last
|
57
|
+
|
58
|
+
Net::HTTP.start(uri.host) do |http|
|
59
|
+
puts "Start downloading #{file_name}..."
|
60
|
+
response = http.get(uri.request_uri)
|
61
|
+
open(file_name, "wb") do |file|
|
62
|
+
file.write(response.body)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
puts "Downloaded successfully!"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/markdown
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
gem uninstall copycasts
|
2
|
+
gem build copycasts.gemspec
|
3
|
+
gem install copycasts
|
4
|
+
|
5
|
+
require 'copycasts'
|
6
|
+
a = CopyCasts.new({page: 1})
|
7
|
+
a.download_videos
|
8
|
+
|
9
|
+
types = {}
|
10
|
+
file_links = []
|
11
|
+
|
12
|
+
types[:zip] = 2 if options[:zip]
|
13
|
+
types[:mp4] = 3 if options[:mp4]
|
14
|
+
types[:m4v] = 4 if options[:m4v]
|
15
|
+
types[:webm] = 5 if options[:webm]
|
16
|
+
types[:ogv] = 6 if options[:ogv]
|
17
|
+
|
18
|
+
types = { zip: 2, mp4: 3, m4v: 4, webm: 5, ogv: 6 } if options[:all]
|
19
|
+
|
20
|
+
types.each_pair do |key, value|
|
21
|
+
puts "Crawling "
|
22
|
+
get_links.each do |link|
|
23
|
+
file_link = Nokogiri::HTML(open(TARGET_URL + "/" + link))
|
24
|
+
url = url.css('.downloads li[#{value}] a').first
|
25
|
+
file_links << url.values.first
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
file_links
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
Gem::Specification.new do |s|
|
34
|
+
s.name = "copycasts"
|
35
|
+
s.version = "0.0.2"
|
36
|
+
s.authors = ["Nicholas Ng"]
|
37
|
+
s.email = ["secret@live.com.my"]
|
38
|
+
s.homepage = ""
|
39
|
+
s.summary = %q{Offline watch free episode of railscast videos for personal usage.}
|
40
|
+
s.description = %q{Download videos from video source}
|
41
|
+
|
42
|
+
s.add_development_dependency "nokogiri", "~> 1.5", ">= 1.5.6"
|
43
|
+
s.add_development_dependency "open-uri", "~> 1.5", ">= 1.5.6"
|
44
|
+
s.add_development_dependency "rake", "~> 10.1", ">= 10.1.0"
|
45
|
+
|
46
|
+
s.files = [
|
47
|
+
"lib/copycasts.rb"
|
48
|
+
]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
require 'nokogiri'
|
57
|
+
require 'open-uri'
|
58
|
+
require 'net/http'
|
59
|
+
|
60
|
+
class CopyCasts
|
61
|
+
TARGET_URL = 'http://railscasts.com'
|
62
|
+
attr_accessor :page
|
63
|
+
|
64
|
+
def initialize(options = {})
|
65
|
+
@pages = options[:page] || maximum_page
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_links
|
70
|
+
casts_list = []
|
71
|
+
puts "Crawling casts list..."
|
72
|
+
for index in 1..@pages
|
73
|
+
target_page = Nokogiri::HTML(open(TARGET_URL + "/?type=free&page=#{index}"))
|
74
|
+
target_page.css('.watch a:first').each do |link|
|
75
|
+
link_without_autoplay = link['href'].to_s.sub('?autoplay=true','')
|
76
|
+
casts_list << link_without_autoplay
|
77
|
+
end
|
78
|
+
end
|
79
|
+
puts "Finish crawling."
|
80
|
+
casts_list
|
81
|
+
end
|
82
|
+
|
83
|
+
def maximum_page
|
84
|
+
target_page = Nokogiri::HTML(open(TARGET_URL + "/?type=free"))
|
85
|
+
ret = 0
|
86
|
+
target_page.css('.pagination a').each do |a|
|
87
|
+
if !(a.content.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil) #not number
|
88
|
+
if a.content.to_i > 0
|
89
|
+
ret = a.content.to_i
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
ret
|
94
|
+
end
|
95
|
+
|
96
|
+
def file_links
|
97
|
+
mp4_links = []
|
98
|
+
get_links.each do |video_link|
|
99
|
+
video_page = Nokogiri::HTML(open(TARGET_URL + "/" + video_link))
|
100
|
+
link = video_page.css('.downloads li[3] a').first
|
101
|
+
mp4_links << link.values.first
|
102
|
+
end
|
103
|
+
mp4_links
|
104
|
+
end
|
105
|
+
|
106
|
+
def download_videos
|
107
|
+
mp4_video_links.each do |video_link|
|
108
|
+
uri = URI.parse(video_link)
|
109
|
+
file_name = video_link.split("/").last
|
110
|
+
|
111
|
+
Net::HTTP.start(uri.host) do |http|
|
112
|
+
puts "Start downloading #{file_name}..."
|
113
|
+
response = http.get(uri.request_uri)
|
114
|
+
open(file_name, "wb") do |file|
|
115
|
+
file.write(response.body)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
puts "Downloaded successfully!"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: copycasts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicholas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.5.6
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.5'
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.5.6
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: open-uri
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.5'
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.5.6
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.5'
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.5.6
|
81
|
+
description: Offline watch free episode of railscast videos for personal usage.
|
82
|
+
email:
|
83
|
+
- secret@live.com.my
|
84
|
+
executables:
|
85
|
+
- copycasts-start-crawl
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- .gitignore
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- VERSION
|
95
|
+
- bin/copycasts-start-crawl
|
96
|
+
- copycasts.gemspec
|
97
|
+
- lib/copycasts.rb
|
98
|
+
- lib/markdown
|
99
|
+
homepage: https://github.com/nichthinkof30/copycasts
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.3
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Download videos from video source
|
123
|
+
test_files: []
|