Class: Hulu::Episode

Inherits:
Base
  • Object
show all
Defined in:
lib/hulu/show/episode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

prepare_name

Constructor Details

#initialize(show_title = '') {|_self| ... } ⇒ Episode

Returns a new instance of Episode.

Yields:

  • (_self)

Yield Parameters:

  • _self (Hulu::Episode)

    the object that the method was called on



15
16
17
18
19
20
21
22
# File 'lib/hulu/show/episode.rb', line 15

def initialize(show_title = '')
  self.show_title = show_title

  yield self if block_given?

  set_additional_attributes
  fetch_description
end

Instance Attribute Details

#air_dateObject

Returns the value of attribute air_date.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def air_date
  @air_date
end

#beaconidObject

Returns the value of attribute beaconid.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def beaconid
  @beaconid
end

#coming_soonObject

Returns the value of attribute coming_soon.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def coming_soon
  @coming_soon
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def description
  @description
end

#embed_htmlObject

Returns the value of attribute embed_html.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def embed_html
  @embed_html
end

#episodeObject

Returns the value of attribute episode.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def episode
  @episode
end

#running_timeObject

Returns the value of attribute running_time.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def running_time
  @running_time
end

#seasonObject

Returns the value of attribute season.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def season
  @season
end

#show_titleObject

Returns the value of attribute show_title.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def show_title
  @show_title
end

#thumbnail_urlObject

Returns the value of attribute thumbnail_url.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def thumbnail_url
  @thumbnail_url
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/hulu/show/episode.rb', line 2

def url
  @url
end

Instance Method Details

#additional_attributesObject



80
81
82
83
# File 'lib/hulu/show/episode.rb', line 80

def additional_attributes
  url = "http://www.hulu.com/api/oembed.json?url=http://www.hulu.com/watch/#{@beaconid}/#{Hulu::Base.prepare_name(@title)}"
  Hulu::Fetcher::Page.get(url).parsed_response
end

#fetch_descriptionObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/hulu/show/episode.rb', line 34

def fetch_description
  show_name = Hulu::Base.prepare_name(@show_title)
  title     = Hulu::Base.prepare_name(@title)
  url       = "http://www.hulu.com/watch/#{@beaconid}/#{show_name}-#{title}"
  info      = Hulu::Fetcher::Page.get(url).parsed_response

  d         = info.css('#description-contents').text.strip rescue ''

  @description = d.split('Hide Description').first if d
end

#parse_coming_soon(episode) ⇒ Object



68
69
70
71
# File 'lib/hulu/show/episode.rb', line 68

def parse_coming_soon(episode)
  cs = episode.css('td.c1 .vex-h a').first.css('img').attr('alt').value.strip rescue false
  cs ? true : false
end

#parse_coming_soon_dateObject



73
74
75
76
77
78
# File 'lib/hulu/show/episode.rb', line 73

def parse_coming_soon_date
  # In order to accomplish this, the episode will need access to
  # the entire html document
  # The following will get the available date on Hulu
  # ("#episode-container .coming-soon span").first.text
end

#parse_running_time(episode) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hulu/show/episode.rb', line 56

def parse_running_time(episode)
  run_time = episode.css('td.c3').text.strip

  if run_time.include?(':')
    @running_time = run_time
    @air_date     = episode.css('td.c4').text.strip rescue ''
  else
    @running_time = episode.css('td.c4').text.strip rescue ''
    @air_date     = episode.css('td.c5').text.strip rescue ''
  end
end

#process(season, episode) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/hulu/show/episode.rb', line 45

def process(season, episode)
  @season      = season.scan(/\d+/).first
  @episode     = episode.css('td.c0').text.strip rescue ''
  @title       = episode.css('td.c1 a').text.strip rescue ''
  @coming_soon = parse_coming_soon(episode)
  @url         = episode.css('td.c1 .vex-h a').last.attr('href').strip rescue ''
  @beaconid    = episode.css('td.c1 .vex-h a').last.attr('beaconid').strip rescue ''

  parse_running_time(episode)
end

#set_additional_attributesObject



24
25
26
27
28
29
30
31
32
# File 'lib/hulu/show/episode.rb', line 24

def set_additional_attributes
  info           = additional_attributes
  @embed_html    = info['html']
  @thumbnail_url = info['thumbnail_url']

  if @air_date && @air_date.empty?
    @air_date = Date.parse(info['air_date']).strftime("%m-%d-%Y")
  end
end

#to_paramObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/hulu/show/episode.rb', line 85

def to_param
  {
    show_title: show_title,
    title: title,
    episode: episode,
    running_time: running_time,
    air_date: air_date,
    season: season,
    url: url,
    beaconid: beaconid,
    thumbnail_url: thumbnail_url,
    embed_html: embed_html,
    description: description,
    coming_soon: coming_soon
  }
end