lib/uencode/elements.rb in uencode-3.0.0 vs lib/uencode/elements.rb in uencode-3.1.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2011, uEncode, Cassio Marques
+# Copyright (c) 2011, uEncode, Cássio Marques
module UEncode
module SizeBase
ATTRIBUTES = [:width, :height]
@@ -74,11 +74,67 @@
include Transfer
private
def root_name; "source"; end
end
+
+ class OverlayUrl
+ include Transfer
+
+ private
+ def root_name; "url"; end
+ end
+
+ class Position
+ ATTRIBUTES = [:x, :y]
+
+ include AttrSetting
+ def to_xml
+ %Q{
+ <position>
+ <#{x.nil? ? '<x>' + x.to_s + '</x>' : ""}
+ <#{y.nil? ? '<y>' + y.to_s + '</y>' : ""}
+ </position>
+ }
+ end
+ end
+
+ class Overlay
+ ATTRIBUTES = [:quadrant]
+
+ include AttrSetting
+
+ def position=(_position)
+ _position = Position.new(_position) unless _position.instance_of?(Position) || _position.nil?
+ instance_variable_set :@position, _position
+ end
+
+ def position
+ @position
+ end
+
+ def source_image=(_source)
+ _source = OverlayUrl.new(_source) unless _source.instance_of?(OverlayUrl) || _source.nil?
+ instance_variable_set :@source_image, _source
+ end
+
+ def source_image
+ @source_image
+ end
+
+ def to_xml
+ %Q{
+ <overlay>
+ #{!source_image.nil? ? source_image.to_xml : ""}
+ #{!@position.nil? ? @position.to_xml : ""}
+ #{!quadrant.nil? ? '<quadrant>' + quadrant.to_s + '</quadrant>' : ""}
+ </overlay>
+ }
+ end
+ end
+
class CaptureOutput
ATTRIBUTES = [:rate, :stretch, :crop, :zip, :prefix]
def initialize(options)
@destinations = []
@@ -105,11 +161,19 @@
def max_size
@max_size
end
+ def overlay=(_overlay)
+ _overlay = Overlay.new(_overlay) unless _overlay.instance_of?(Overlay) || _overlay.nil?
+ instance_variable_set :@overlay, _overlay
+ end
+ def overlay
+ @overlay
+ end
+
def to_xml
%Q{
<capture>
<rate>#{rate}</rate>
#{!zip.nil? ? '<zip>' + zip.to_s + '</zip>' : ""}
@@ -117,23 +181,97 @@
<destinations>
#{@destinations.inject("") { |s, dest| s << dest.to_xml}}
</destinations>
#{@size ? @size.to_xml : ""}
#{@max_size ? @max_size.to_xml : ""}
+ #{@overlay ? @overlay.to_xml : ""}
</capture>
}
end
end
+ class Metadata
+ ATTRIBUTES = [:title, :author, :composer, :album, :year, :track, :comment, :genre, :copyright, :description, :synopsis, :show, :episode_id, :network]
+
+ include AttrSetting
+
+ def to_xml
+ %Q{
+ <meta>
+ #{!title.nil? ? '<title>' + title.to_s + '</title>' : ""}
+ #{!author.nil? ? '<author>' + author.to_s + '</author>' : ""}
+ #{!composer.nil? ? '<composer>' + composer.to_s + '</composer>' : ""}
+ #{!album.nil? ? '<album>' + album.to_s + '</album>' : ""}
+ #{!year.nil? ? '<year>' + year.to_s + '</year>' : ""}
+ #{!track.nil? ? '<track>' + track.to_s + '</track>' : ""}
+ #{!comment.nil? ? '<comment>' + comment.to_s + '</comment>' : ""}
+ #{!genre.nil? ? '<genre>' + genre.to_s + '</genre>' : ""}
+ #{!copyright.nil? ? '<copyright>' + copyright.to_s + '</copyright>' : ""}
+ #{!description.nil? ? '<description>' + description.to_s + '</description>' : ""}
+ #{!synopsis.nil? ? '<synopsis>' + synopsis.to_s + '</synopsis>' : ""}
+ #{!show.nil? ? '<show>' + show.to_s + '</show>' : ""}
+ #{!episode_id.nil? ? '<episode_id>' + episode_id.to_s + '</episode_id>' : ""}
+ #{!network.nil? ? '<network>' + network.to_s + '</network>' : ""}
+ </meta>
+ }
+ end
+ end
+
+ class Clip
+ ATTRIBUTES = [:start, :duration]
+
+ include AttrSetting
+
+ def to_xml
+ %Q{
+ <clip>
+ #{!start.nil? ? '<start>' + start.to_s + '</start>' : ""}
+ #{!duration.nil? ? '<duration>' + duration.to_s + '</duration>' : ""}
+ </clip>
+ }
+ end
+ end
+
class VideoOutput
ATTRIBUTES = [:destination, :container]
+ include AttrSetting
+
include Enumerable
attr_writer :container
attr_accessor :streams
+
+ def overlay=(_overlay)
+ _overlay = Overlay.new(_overlay) unless _overlay.instance_of?(Overlay) || _overlay.nil?
+ instance_variable_set :@overlay, _overlay
+ end
+
+ def overlay
+ @overlay
+ end
+
+ def clip=(_clip)
+ _clip = Clip.new(_clip) unless _clip.instance_of?(Clip) || _clip.nil?
+ instance_variable_set :@clip, _clip
+ end
+
+ def clip
+ @clip
+ end
+
+ def metadata=(_metadata)
+ _metadata = Metadata.new(_metadata) unless _metadata.instance_of?(Metadata) || _metadata.nil?
+ instance_variable_set :@metadata, _metadata
+ end
+
+ def metadata
+ @metadata
+ end
+
+
def initialize(options)
@streams = VideoStreams.new
@destinations = []
super
end
@@ -148,12 +286,15 @@
def to_xml
%Q{
<video>
<destinations>
- #{@destinations.inject("") { |s, dest| s << dest.to_xml}}
+ #{@destinations.inject("") { |s, dest| s << dest.to_xml}}
</destinations>
+ #{metadata.nil? ? "" : metadata.to_xml}
+ #{clip.nil? ? "" : clip.to_xml}
+ #{overlay.nil? ? "" : overlay.to_xml}
<container>#{container}</container>
#{@streams.to_xml}
</video>
}
end
@@ -161,10 +302,11 @@
# VideoStreams represents the audio and video streams for a single output
class VideoStreams
attr_reader :video_config, :audio_config
+
def initialize
@video_config = VideoConfig.new
@audio_config = AudioConfig.new
end
@@ -178,21 +320,21 @@
#
# The keys for the :audio hash can be any of the following:
# codec, bitrate, channels, samplerate.
#
def configure(hash)
- video = hash[:video]
- audio = hash[:audio]
- if !video.nil?
+ vid = hash[:video]
+ aud = hash[:audio]
+ if !vid.nil?
configure_video do |c|
- video.each_pair { |key, value| c.send("#{key}=", value) }
+ vid.each_pair { |key, value| c.send("#{key}=", value)}
end
end
- if !audio.nil?
+ if !aud.nil?
configure_audio do |c|
- audio.each_pair { |key, value| c.send("#{key}=", value) }
+ aud.each_pair { |key, value| c.send("#{key}=", value) }
end
end
end
def configure_video
@@ -239,16 +381,10 @@
# The video configs for each VideoStream
class VideoConfig
attr_accessor :bitrate, :codec, :profile, :quality, :framerate, :passes, :deinterlace, :fix_rotation, :force_square_pixels
- def initialize
- @deinterlace = false
- @profile = "main"
- @passes = 1
- end
-
def size=(_size)
_size = Size.new(_size) unless _size.instance_of?(Size) || _size.nil?
instance_variable_set :@size, _size
end
@@ -267,10 +403,11 @@
end
# The audio configs for each VideoStream
class AudioConfig
attr_accessor :codec, :bitrate, :channels, :samplerate, :quality
+
end
class JobStatus
ATTRIBUTES = [:key, :userdata, :customerkey]
@@ -288,11 +425,11 @@
end
def source_video
@source_video
end
-
+
def initialize(options)
@video_outputs = []
@captures = []
source_video = options[:source_video]
super
@@ -309,10 +446,10 @@
def to_xml
xml = %Q{
<job>
#{source_video.nil? ? "" : source_video.to_xml}
#{userdata.nil? ? "" : '<userdata>' + userdata + '</userdata>'}
- #{callback.nil? ? "" : '<callback>' + callback + '</callback>'}
+ #{callback.nil? ? "" : '<callback>' + callback + '</callback>'}
<outputs>
#{@video_outputs.inject("") { |s, vid| s << vid.to_xml}}
#{@captures.inject("") { |s, cap| s << cap.to_xml }}
</outputs>
</job>