class AnimeDL::AnimeHeaven
Public Class Methods
new()
click to toggle source
# File lib/anime_dl.rb, line 8 def initialize @agent = Mechanize.new @agent.user_agent_alias = 'Windows Chrome' @anime_page = nil end
Public Instance Methods
getPageLinks(option, range)
click to toggle source
Return the required page links based on user input
# File lib/anime_dl/anime_heaven.rb, line 5 def getPageLinks(option, range) @anime_page = @agent.get(option.attributes['href'].value) unless (@anime_page) page_links = @anime_page.search(".infoepbox").search("a").reverse return page_links if range.empty? links_required = [] first, last = getTotal(option) range = AnimeDL.range_handle(range, first, last) range.each { |num| links_required << page_links[num - first] } return links_required end
getTotal(option = nil)
click to toggle source
Returns the total number of episodes
# File lib/anime_dl.rb, line 21 def getTotal(option = nil) @anime_page = @agent.get(option.attributes['href'].value) unless (@anime_page) episodes = @anime_page.search(".infoepbox").search("a") # New Episodes have a different class begin first = episodes.last.search(".infoept2")[0].content.to_i rescue first = episodes.last.search(".infoept2r")[0].content.to_i end begin last = episodes.first.search(".infoept2")[0].content.to_i rescue last = episodes.first.search(".infoept2r")[0].content.to_i end return first, last end
getVideoLinks(option, range = [], quiet = false, output = false)
click to toggle source
Video Links
# File lib/anime_dl/anime_heaven.rb, line 19 def getVideoLinks(option, range = [], quiet = false, output = false) episode_links = getPageLinks(option, range) episodes = [] unless (output) puts "Fetching Links..." progress_bar = ProgressBar.create(:progress_mark => "\*", :length => 80, :total => episode_links.length) end episode_links.each do |link| episode_page = @agent.get(link.attributes['href'].value) # Limit Check if (episode_page.search(".c").search("b").length != 0) episodes << Episode.new(nil, limit_exceeded(quiet)) puts limit_exceeded(quiet) if (output) break end # Video Link Retrieval episode_no = episode_page.uri.to_s[/e=.+/][2..-1] # (Regex for safety) video_src = parseURL(episode_page.search("script")[3]) episode = Episode.new(episode_no, video_src) episodes << episode # Progress Bar increment progress_bar.progress += 1 unless (output) rescue nil puts episode.details if (output) end # Progress bar finish unless output progress_bar.finish puts "\n" end return episodes end
limit_exceeded(quiet)
click to toggle source
# File lib/anime_dl.rb, line 47 def limit_exceeded(quiet) return "Unfortunately \"animeheaven.eu\" only allows a certain number of page views per day (>170, <350).\n" + "It seems you have exceeded that limit :(.\n" + "Please change networks or try again tomorrow." if (!quiet) return "(Limit exceeded)" end
parseURL(url)
click to toggle source
UTILITY
# File lib/anime_dl.rb, line 42 def parseURL(url) url = url.to_s[/luu1=rrl\(".*?"\)/][10...-2] return url.tr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm") end
search(query)
click to toggle source
Search
# File lib/anime_dl.rb, line 15 def search(query) results_page = @agent.get("http://animeheaven.eu/search.php?q=#{query}") return results_page.search(".iepcon").search(".cona") end