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
#download(args) ⇒ Object
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
|
#download_episode(episode) ⇒ Object
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
|
# 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?
podcast_title = episode.podcast.title.strip
episode_title = episode.url.to_s.match('((?!\/).)*$').to_s
source_path = episode.url
destination_path = "download/" + podcast_title + "/" + episode_title
begin
download = Downspout.download_url_to_path(source_path, destination_path)
rescue NoMethodError
puts "Error"
end
puts download
episode.downloaded = true
if !episode.save
errors.each do |e|
puts e
end
end
rescue StandardError => e
puts "#{episode.url} generated #{e}"
puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
end
end
|
#look_for_episodes(podcast) ⇒ Object
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
|