Class: BBCNet::MetaInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/bbcnet.rb

Overview


get stream metadata episode url => pid => xml playlist => version pid (vpid aka. identifier)

=> xml stream metadata => wma

Defined Under Namespace

Classes: StreamInfo

Constant Summary collapse

Keys =
[ :duration, :vpid, :group, :media, :onAirDate, :channel, :title, :summary, :aacLow, :aacStd, :real, :wma, :streams ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid) ⇒ MetaInfo

Returns a new instance of MetaInfo.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bbcnet.rb', line 59

def initialize(pid)
    @pid = pid
    Keys.each do |k|
        s = ('@' + k.to_s).to_sym
        self.instance_variable_set(s, nil)
        self.class.class_eval %Q{
            def #{k}
                #{s}
            end
        }
    end

    @streams = []
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



57
58
59
# File 'lib/bbcnet.rb', line 57

def pid
  @pid
end

Class Method Details

.get(url) ⇒ Object



52
53
54
55
# File 'lib/bbcnet.rb', line 52

def self.get(url)
    pid = BBCNet.extractPid(url)
    self.new(pid)
end

Instance Method Details

#readXmlPlaylistObject

read duration, vpid, group, media, onAirDate, channel

from XmlPlaylist


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/bbcnet.rb', line 78

def readXmlPlaylist
    return self if @vpid

    res = BBCNet.read("http://www.bbc.co.uk/iplayer/playlist/#{@pid}")
#             res = IO.read("../tmp/iplayer-playlist-me.xml")

    doc = Nokogiri::XML(res)
    item = doc.at_css("noItems")
    raise "No Playlist " + item[:reason] if item

    item = doc.at_css("item")
    @media = item[:kind].gsub(/programme/i, '')
    @duration = item[:duration].to_i
    @vpid = item[:identifier]
    @group = item[:group]
    @onAirDate = BBCNet.getTime(item.at_css("broadcast").content.to_s)
    @channel = item.at_css("service").content.to_s
    @title = item.at_css("title").content.to_s
    @summary = doc.at_css("summary").content.to_s
    self
end

#readXmlStreamMetaObject Also known as: update



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/bbcnet.rb', line 111

def readXmlStreamMeta
    readXmlPlaylist unless @vpid

    res = BBCNet.read("http://www.bbc.co.uk/mediaselector/4/mtis/stream/#{vpid}")
#             res = IO.read("../tmp/iplayer-stream-meta-me.xml")

    doc = Nokogiri::XML(res)
    me = doc.css("media")
    me.each do |m|
        stmInf = StreamInfo.new
        stmInf.encoding = m[:encoding]  # wma
        stmInf.bitrate = m[:bitrate].to_i    # 48
        expiresStr = m[:expires]
        stmInf.expires = BBCNet.getTime(expiresStr)  if expiresStr
        stmInf.type = m[:kind]          # audio

        con = m.at_css("connection")
        stmInf.indirectUrl = con[:href]
        @streams <<= stmInf

        case stmInf.encoding
        when /\bwma\b/i
            @wma = stmInf
        when /\baac\b/i
            if stmInf.bitrate < 64
                @aacLow = stmInf
            else
                @aacStd = stmInf
            end
        when /\breal\b/i
            @real = stmInf
        end
    end
    self
end