Class: Epodder::Download
Instance Method Summary
collapse
Methods inherited from Verb
#add_command, #each_argument, #lookup_args, #verb_struct
Methods inherited from Eclass
#initialize
Instance Method Details
permalink
#download(args) ⇒ Object
[View source]
5
6
7
8
9
|
# File 'lib/verb/download.rb', line 5
def download(args)
each_argument(args) do |podcast|
look_for_episodes podcast
end
end
|
permalink
#download_episode(episode) ⇒ Object
[View source]
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/verb/download.rb', line 22
def download_episode(episode)
begin
Downspout::Config.max_redirects = 100
Downspout::Config.enable_curb! if Downspout::Config.curb_available?
download = Downspout.download_url_to_path(episode.url, "download/#{episode.podcast.title.strip}/#{episode.url.to_s.match('((?!\/).)*$')}")
puts download
episode.mark_as_downloaded
rescue StandardError => e
puts "#{episode.url} generated #{e}"
end
end
|
permalink
#look_for_episodes(podcast) ⇒ Object
[View source]
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/verb/download.rb', line 11
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
|