Created
March 17, 2011 16:48
-
-
Save basicxman/874658 to your computer and use it in GitHub Desktop.
Generates JSON for a webcast entry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class String | |
def initial_format! | |
gsub!("\n", "") | |
gsub!("\r", "") | |
gsub!('"', "'") | |
end | |
def chat_format! | |
gsub!(/\'[0-9]+\'/, "'99%'") | |
gsub!("type=", "wmode='transparent' type=") | |
end | |
def ustream_format! | |
gsub!(/<br\s+\/>.*$/, "") | |
gsub!(/\'[0-9]+\'/, "'99%'") | |
gsub!(/<param\s+name=\'flashvars/, "<param name='wmode' value='transparent'><param name='flashvars") | |
gsub!("<embed", "<embed wmode='transparent'") | |
end | |
def mms_format width, height | |
return <<-eof | |
<OBJECT id='mediaPlayer' width='#{width}' height='#{height}' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'><param name='fileName' value='#{self}'><param name='animationatStart' value='true'><param name='transparentatStart' value='true'><param name='autoStart' value='false'><param name='showControls' value='true'><param name='loop' value='true'><EMBED type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download' id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='#{width}' height='#{height}' src='#{self}' autostat='false' designtimesp='5311' loop='true'></EMBED></OBJECT> | |
eof | |
end | |
end | |
require 'slop' | |
opts = Slop.parse do | |
banner "Usage: generator.rb [options]" | |
on :c, :chat, 'ustream chat conversion', :optional => true | |
on :u, :ustream, 'ustream conversion', :optional => true | |
on :m, :mms, 'MMS generator', :optional => true | |
on :s, :small, 'Small MMS embed', :default => true | |
on :l, :large, 'Large MMS embed' | |
on :n, :name, 'Stream name', :optional => true | |
on :f, :format, 'Format', :optional => true | |
end | |
if opts.chat? | |
working_copy = opts[:chat].dup | |
working_copy.initial_format! | |
working_copy.chat_format! | |
working_copy = <<-eof | |
{ | |
"name": "#{opts[:name]}", | |
"markup": "#{working_copy}", | |
"active": "true" | |
} | |
eof | |
puts working_copy | |
end | |
if opts.ustream? | |
working_copy = opts[:ustream].dup | |
working_copy.initial_format! | |
working_copy.ustream_format! | |
working_copy = <<-eof | |
{ | |
"name": "#{opts[:name]}", | |
"markup": "#{working_copy}", | |
"active": "true" | |
} | |
eof | |
puts working_copy | |
end | |
if opts.mms? | |
working_copy = opts[:mms].dup | |
if opts.small? | |
working_copy = working_copy.mms_format 320, 240 | |
title = "[Small]" | |
elsif opts.large? | |
working_copy = working_copy.mms_format 640, 480 | |
title = "[Large]" | |
end | |
working_copy = <<-eof | |
{ | |
"name": "#{opts[:name]} #{title}", | |
"markup": "#{working_copy}", | |
"active": "true" | |
} | |
eof | |
puts working_copy | |
end | |
if opts.format? | |
working_copy = opts[:format].dup | |
working_copy.initial_format! | |
working_copy = <<-eof | |
{ | |
"name": "#{opts[:name]}", | |
"markup": "#{working_copy}", | |
"active": "true" | |
} | |
eof | |
puts working_copy | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment