Class: Epodder::Download

Inherits:
Verb show all
Defined in:
lib/verb/download.rb

Instance Method Summary collapse

Methods inherited from Verb

#add_command, #each_argument, #lookup_args, #verb_struct

Constructor Details

#initializeDownload

Returns a new instance of Download.



5
6
# File 'lib/verb/download.rb', line 5

def initialize
end

Instance Method Details

#download(args) ⇒ Object



8
9
10
11
12
# File 'lib/verb/download.rb', line 8

def download args
    each_argument(args) do |podcast|
        look_for_episodes podcast
    end
end

#download_episode(episode) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/verb/download.rb', line 25

def download_episode episode
    begin
        Downspout::Config.max_redirects = 100
        Downspout.download_url_to_path(episode.url, "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



14
15
16
17
18
19
20
21
22
23
# File 'lib/verb/download.rb', line 14

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