1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 53 54 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
#--
# Copyright (c) 2005 Robert Aman
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
module FeedTools
# Represents a feed/feed item's category
class Category
# The category term value
attr_accessor :term
# The categorization scheme
attr_accessor :scheme
# A human-readable description of the category
attr_accessor :label
alias_method :value, :term
alias_method :category, :term
alias_method :domain, :scheme
end
# Represents a feed/feed item's author
class Author
# The author's real name
attr_accessor :name
# The author's email address
attr_accessor :email
# The url of the author's homepage
attr_accessor :href
# The raw value of the author tag if present
attr_accessor :raw
alias_method :url, :href
alias_method :url=, :href=
alias_method :uri, :href
alias_method :uri=, :href=
end
# Represents a feed's image
class Image
# The image's title
attr_accessor :title
# The image's description
attr_accessor :description
# The url of the image that is being linked to
attr_accessor :href
# The url to link the image to
attr_accessor :link
# The width of the image
attr_accessor :width
# The height of the image
attr_accessor :height
# The style of the image
# Possible values are "icon", "image", or "image-wide"
attr_accessor :style
alias_method :url, :href
alias_method :url=, :href=
end
# Represents a feed's text input element.
# Be aware that this will be ignored for feed generation. It's a
# pointless element that aggregators usually ignore and it doesn't have an
# equivalent in all feeds types.
class TextInput
# The label of the Submit button in the text input area.
attr_accessor :title
# The description explains the text input area.
attr_accessor :description
# The URL of the CGI script that processes text input requests.
attr_accessor :link
# The name of the text object in the text input area.
attr_accessor :name
end
# Represents a feed's cloud.
# Be aware that this will be ignored for feed generation.
class Cloud
# The domain of the cloud.
attr_accessor :domain
# The path for the cloud.
attr_accessor :path
# The port the cloud is listening on.
attr_accessor :port
# The web services protocol the cloud uses.
# Possible values are either "xml-rpc" or "soap".
attr_accessor :protocol
# The procedure to use to request notification.
attr_accessor :register_procedure
end
# Represents a simple hyperlink
class Link
# The url that is being linked to
attr_accessor :href
# The language of the resource being linked to
attr_accessor :hreflang
# The relation type of the link
attr_accessor :rel
# The mime type of the link
attr_accessor :type
# The title of the hyperlink
attr_accessor :title
# The length of the resource being linked to in bytes
attr_accessor :length
alias_method :url, :href
alias_method :url=, :href=
end
# This class stores information about a feed item's file enclosures.
class Enclosure
# The url for the enclosure
attr_accessor :href
# The MIME type of the file referenced by the enclosure
attr_accessor :type
# The size of the file referenced by the enclosure
attr_accessor :file_size
# The total play time of the file referenced by the enclosure
attr_accessor :duration
# The height in pixels of the enclosed media
attr_accessor :height
# The width in pixels of the enclosed media
attr_accessor :width
# The bitrate of the enclosed media
attr_accessor :bitrate
# The framerate of the enclosed media
attr_accessor :framerate
# The thumbnail for this enclosure
attr_accessor :thumbnail
# The categories for this enclosure
attr_accessor :categories
# A hash of the enclosed file
attr_accessor :hash
# A website containing some kind of media player instead of a direct
# link to the media file.
attr_accessor :player
# A list of credits for the enclosed media
attr_accessor :credits
# A text rendition of the enclosed media
attr_accessor :text
# A list of alternate version of the enclosed media file
attr_accessor :versions
# The default version of the enclosed media file
attr_accessor :default_version
alias_method :url, :href
alias_method :url=, :href=
alias_method :link, :href
alias_method :link=, :href=
def initialize
@expression = 'full'
end
# Returns true if this is the default enclosure
def is_default?
return @is_default
end
# Sets whether this is the default enclosure for the media group
def is_default=(new_is_default)
@is_default = new_is_default
end
# Returns true if the enclosure contains explicit material
def explicit?
return @explicit
end
# Sets the explicit attribute on the enclosure
def explicit=(new_explicit)
@explicit = new_explicit
end
# Determines if the object is a sample, or the full version of the
# object, or if it is a stream.
# Possible values are 'sample', 'full', 'nonstop'.
def expression
return @expression
end
# Sets the expression attribute on the enclosure.
# Allowed values are 'sample', 'full', 'nonstop'.
def expression=(new_expression)
unless ['sample', 'full', 'nonstop'].include? new_expression.downcase
return @expression
end
@expression = new_expression.downcase
end
# Returns true if this enclosure contains audio content
def audio?
unless self.type.nil?
return true if (self.type =~ /^audio/) != nil
end
# TODO: create a more complete list
# =================================
audio_extensions = ['mp3', 'm4a', 'm4p', 'wav', 'ogg', 'wma']
audio_extensions.each do |extension|
if (url =~ /#{extension}$/) != nil
return true
end
end
return false
end
# Returns true if this enclosure contains video content
def video?
unless self.type.nil?
return true if (self.type =~ /^video/) != nil
return true if self.type == "image/mov"
end
# TODO: create a more complete list
# =================================
video_extensions = ['mov', 'mp4', 'avi', 'wmv', 'asf']
video_extensions.each do |extension|
if (url =~ /#{extension}$/) != nil
return true
end
end
return false
end
end
# TODO: Make these actual classes instead of structs
# ==================================================
EnclosureHash = Struct.new( "EnclosureHash", :hash, :type )
EnclosurePlayer = Struct.new( "EnclosurePlayer", :url, :height, :width )
EnclosureCredit = Struct.new( "EnclosureCredit", :name, :role )
EnclosureThumbnail = Struct.new( "EnclosureThumbnail", :url, :height,
:width )
end
|