Module: Crunchyroll
- Defined in:
- lib/crunchyroll/utils.rb,
lib/crunchyroll/version.rb,
lib/crunchyroll/crunchyroll.rb
Overview
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Defined Under Namespace
Modules: Utils
Class Method Summary collapse
- .find(series, time_zone = 'Rome', proxy = nil, use_proxy = true) ⇒ Object (also: get)
- .get_page(url, proxy, use_proxy) ⇒ Object
- .today(time_zone = 'Rome') ⇒ Object
- .version ⇒ Object
Class Method Details
.find(series, time_zone = 'Rome', proxy = nil, use_proxy = true) ⇒ Object Also known as: get
20 21 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 50 51 52 |
# File 'lib/crunchyroll/crunchyroll.rb', line 20 def find(series, time_zone = 'Rome', proxy = nil, use_proxy = true) proxy ||= { host: '136.0.16.217', port: '7808' } cr = 'http://www.crunchyroll.com/lineup' title, url = [''] * 2 Nokogiri::HTML(get_page(cr, proxy, use_proxy)).xpath('//a[@class="portrait-element block-link titlefix element-lineup-anime"]').each do |r| if r['title'].downcase.include? series.downcase title = r['title'] url = r['href' ] break end end return false if title.empty? || url.empty? air = Nokogiri::HTML(get_page(url, proxy, use_proxy)).xpath('//ul[@id="sidebar_elements"]/li').select { |e| e.at_xpath('.//p[@class="strong"]') }[0] return false unless air air = air.text day_literal = air.split('Simulcast on ')[1].split[0][0..-2] date = Time.parse(Utils.format_cr_date(air)) date = Chronic.parse("this #{day_literal} at #{date.hour}:#{date.min}").in_time_zone time_zone date += 3600 unless Time.now.dst? { :title => title, :where => 'Crunchyroll', :day => day_literal, :hour => date.hour <= 9 ? "0#{date.hour}" : date.hour, :min => date.min <= 9 ? "0#{date.min}" : date.min, :left => Utils.time_left(Time.now, date) } end |
.get_page(url, proxy, use_proxy) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/crunchyroll/crunchyroll.rb', line 89 def get_page(url, proxy, use_proxy) if use_proxy url = URI(url) Net::HTTP::Proxy(proxy[:host], proxy[:port]).start(url.host, url.port) { |r| r.request(Net::HTTP::Get.new(url.path)) }.body else open(url).read end end |
.today(time_zone = 'Rome') ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/crunchyroll/crunchyroll.rb', line 55 def today(time_zone = 'Rome') url = 'http://horriblesubs.info/release-schedule/' tomorrow = Date.tomorrow today = Time.now [].tap do |releases| Nokogiri::HTML(open(url)).xpath('//table[@class="schedule-table"]/tr').each { |r| title = r.at_xpath('.//td[@class="schedule-widget-show"]').text time = r.at_xpath('.//td[@class="schedule-time"]').text date = Chronic.parse("today at #{time}").in_time_zone(time_zone) date += 3600 unless today.dst? time_diff = TimeDifference.between(today, date).in_general airs = if date.day == tomorrow.day && time_diff[:days] == 0 :tomorrow else time_diff[:days] == 0 ? :today : :aired end releases << { :title => title, :where => 'Crunchyroll', :date => date, :airs => airs, :day => date.strftime("%A"), :hour => date.hour, :min => date.min, :left => Utils.time_left(today, date) } } end.sort_by { |h| h[:date] } end |
.version ⇒ Object
16 17 18 |
# File 'lib/crunchyroll/version.rb', line 16 def self.version '0.9.9' end |