Class: MixcloudParser::Parser
- Inherits:
-
Object
- Object
- MixcloudParser::Parser
- Defined in:
- lib/mixcloud_parser/parser.rb
Instance Method Summary collapse
-
#initialize(url, path) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
Main parser method.
Constructor Details
#initialize(url, path) ⇒ Parser
Returns a new instance of Parser.
3 4 5 6 |
# File 'lib/mixcloud_parser/parser.rb', line 3 def initialize(url, path) @url = url @path = path end |
Instance Method Details
#parse ⇒ Object
Main parser method
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 |
# File 'lib/mixcloud_parser/parser.rb', line 9 def parse # Try parse file begin # Open browser window for getting file name and URL (Mixcloud gives link only after starting a podcast) browser = Watir::Browser.new browser.goto @url # Parse the resulted page through nokogiri page = Nokogiri::HTML(browser.html) # Close browser browser.close # Get file name filename = page.search('cloudcast-title', '//h1').last.content puts "Downloading '#{ filename }'..." # Get file URL url = page.css('audio') url = URI.extract(url.to_s).first # Check the download check_file(url, filename) # Return error message and retry rescue puts 'Error. Retrying...' browser.close retry end end |