Module: Crunchyroll

Defined in:
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.

Class Method Summary collapse

Class Method Details

.find(series, time_zone = 'Rome', proxy = nil, use_proxy = true) ⇒ Object Also known as: get



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
53
54
55
# File 'lib/crunchyroll/crunchyroll.rb', line 23

def find(series, time_zone = 'Rome', proxy = nil, use_proxy = true)
  proxy ||= { host: '104.140.67.36', 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(air.format_cr_date)
  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  => Time.now.left(date)
  }
end

.get_page(url, proxy, use_proxy) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/crunchyroll/crunchyroll.rb', line 91

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



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
88
89
# File 'lib/crunchyroll/crunchyroll.rb', line 58

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('//div[@class="today-releases"]/div[@class="series-name"]').each { |r|
      title = r.at_xpath('.//child::text()').to_s.squeeze(' ')
      time  = r.at_xpath('.//span').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  => today.left(date)
      }
    }
  end.sort_by { |h| h[:date] }
end

.versionObject



16
17
18
# File 'lib/crunchyroll/version.rb', line 16

def self.version
  '0.9.8.1'
end