-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathruby-tapas-downloader.rb
More file actions
80 lines (65 loc) · 1.84 KB
/
ruby-tapas-downloader.rb
File metadata and controls
80 lines (65 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'watir'
require 'fileutils'
require 'open-uri'
require 'pry'
require 'net/https'
require_relative './constants'
require_relative './lib/pages/login_page'
require_relative './lib/pages/episode_page'
require_relative './lib/pages/episodes_page'
require_relative './lib/extractors/save_content_html'
require_relative './lib/extractors/save_page_source'
require_relative './lib/extractors/save_video'
BROWSER = LoggedBrowser.new.call
class RubyTapasDownloader
def call
create_save_dir { log_status_update('SETUP DIRECTORY') }
get_episode_links { log_status_update('LISTING ALL EPISODES IN CATALOG') }
download_missing_episodes { log_status_update('DOWNLOADING MISSING EPISODES') }
rescue => e
log_status_update('ERROR check log file')
errors = e.backtrace.push(BROWSER.html)
File.open('error.log', 'w+') do |f|
errors.each do |line|
f << line
f << "\n"
end
end
ensure
BROWSER.close
end
private
def create_save_dir
FileUtils::mkdir_p SAVE_DIRECTORY
end
def get_episode_links
yield if block_given?
@get_episode_links ||= EpisodesPage.new(BROWSER).get_episode_links
end
def download_missing_episodes
yield if block_given?
get_episode_links.map{|x| [x.href, x.text]}.each do |info|
log_status_update(info[0])
EpisodeLink.new(info[0], info[1]).call
end
end
end
def log_status_update(update)
puts "--- #{update} ---"
end
unless (CA_FILE.nil? || CA_FILE.empty?) then
module Net
class HTTP
alias_method :original_use_ssl=, :use_ssl=
def use_ssl=(flag)
self.ca_file = CA_FILE
self.verify_mode = OpenSSL::SSL::VERIFY_PEER
self.original_use_ssl = flag
end
end
end
end
if defined?(SKIP_SSL_VERIFY) && SKIP_SSL_VERIFY
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
end
RubyTapasDownloader.new.call