Class: Epodder::Download
Instance Method Summary
collapse
Methods inherited from Verb
#add_command, #each_argument, #lookup_args, #verb_struct
Constructor Details
Returns a new instance of Download.
7
8
9
|
# File 'lib/verb/download.rb', line 7
def initialize
@mechanize = Mechanize.new
end
|
Instance Method Details
#download(args) ⇒ Object
11
12
13
14
15
|
# File 'lib/verb/download.rb', line 11
def download args
each_argument(args) do |podcast|
look_for_episodes podcast
end
end
|
#download_episode(episode) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/verb/download.rb', line 28
def download_episode episode
begin
@mechanize.get(episode.url).save_as("download/#{episode.podcast.title.strip}/#{episode.url.to_s.match('((?!\/).)*$')}")
episode.mark_as_downloaded
rescue StandardError => e
puts e
end
end
|
#look_for_episodes(podcast) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/verb/download.rb', line 17
def look_for_episodes podcast
episodes = Episode.all(:downloaded => false, :podcast => podcast)
episodes.select{|ep| !ep.nil?}.each do |episode|
puts episode.podcast.title
title = (episode.podcast.title).strip
Dir.mkdir "download/#{title}" unless Dir.exists? "download/#{title}"
puts "Downloading #{title} - #{episode.title || episode.id}"
download_episode episode
end
end
|