Class: PinoyFilter::Episode

Inherits:
Object
  • Object
show all
Defined in:
lib/PinoyFilter/Classes/Episode.rb

Overview

The episode class holds basic data about a episode, like @title and @url It is also able to find the direct stream URL suing nokogiri.

Instance Method Summary collapse

Constructor Details

#initialize(link, status = nil, parent = nil) ⇒ Episode

Pinoy::EpisodeClass.streamURL call-seq:

streamURL(Nokogiri::element) => void

Workings

This function requires a 'a' element from nokogiri usually done throught a page.css('a') call or similar.

Accepts

This function accepts two kind of HTML elements. Either links or table-rows. The table rows are used when you parse anime webpage, links are used when parsing latest.

If you parse from link, the status will be set to :aired by default

Raises:

  • (ArgumentError)

19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/PinoyFilter/Classes/Episode.rb', line 19

def initialize(link, status = nil, parent=nil)
  raise ArgumentError.new("This is not a valid Nokogiri::XML::Element") unless link.class == Nokogiri::XML::Element
  raise PinoyFilter::WrongTagTypeException.new("Can not parse episode from this tag") unless ['a', 'tr'].include? link.name

  case link.name
  when 'a'
    @title, @url, @parent = extract_a link, status, parent 
    
  when 'tr'
    extract_tr link, status, parent
  end
end

Instance Method Details

#inspectObject

Custom Inspect Message


80
81
82
# File 'lib/PinoyFilter/Classes/Episode.rb', line 80

def inspect
  return "<#{self}, #{@title}>"
end

#pageURLObject

Returns the page url as string. The page URL is where this episode can be found. this link is used by streamURL to get the direct stream link


53
54
55
# File 'lib/PinoyFilter/Classes/Episode.rb', line 53

def pageURL
  return @url
end

#parentNokogiri::XML::Element?

Returns:

  • (Nokogiri::XML::Element)

    Parent object

  • (nil)

    If it has no parent


46
47
48
# File 'lib/PinoyFilter/Classes/Episode.rb', line 46

def parent
  return @parent
end

#statusObject

Returns status The status can either be :aired, :not-aired, :unknown :unknown is used to filter bad episodes.


40
41
42
# File 'lib/PinoyFilter/Classes/Episode.rb', line 40

def status
  return @status
end

#streamURLObject

Pinoy::EpisodeClass.streamURL call-seq:

streamURL(void) => string
streamURL(void) => nil

Workings

This function finds the episodes random id assigned by pinoyanime.

Then loads a play.pinoyanime.tv link using that ID. then parses the jwplayer javascript to find the direct link to the video.

Returns

The function returns an url if it can find one, or nil if the link is missing. This is not uncommon for older series linked on the site


74
75
76
77
# File 'lib/PinoyFilter/Classes/Episode.rb', line 74

def streamURL
  @streamurl ||= PinoyFilter::SiteHandler.GetEpisodeStreamURL(@url)
  return @streamurl
end

#titleObject

Returns episode title as string


33
34
35
# File 'lib/PinoyFilter/Classes/Episode.rb', line 33

def title
  return @title
end