Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby -Ku
- # -*- encoding: UTF-8 -*-
- $KCODE = 'UTF8'
- require 'kconv'
- require 'open-uri'
- require 'rexml/document'
- require 'date'
- $is_windows = RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|cygwin|bccwin/
- $script_dir = File.dirname( File.expand_path( __FILE__ ) )
- if $is_windows
- $script_dir = $script_dir.kconv( Kconv::UTF8, Kconv::SJIS )
- $null = "nul"
- else
- $null = "/dev/null"
- end
- $cgi_uri = 'http://www50.atpages.jp/streamer/enews/enews.cgi'
- $flv_prefix = 'rtmp://flv9.nhk.or.jp/flv9/_definst_/e-news/data/'
- def to_native( string )
- return $is_windows ? string.kconv( Kconv::SJIS, Kconv::UTF8 ) : string
- end
- def main
- open( $cgi_uri ) { |f|
- doc = REXML::Document.new( f )
- prefix = doc.elements["enews/prefix/@video"].to_s
- doc.elements.each( 'enews/flv' ) { |element|
- flv = element.attributes['video']
- out_file = to_native( "ニュースで英会話_#{flv[0, 4]}_#{flv[4, 2]}_#{flv[7, 2]}.flv" )
- out_dir = to_native( File.join( $script_dir, "ニュースで英会話" ) )
- Dir.mkdir( out_dir ) unless File.exist?( out_dir )
- out_dir += File::Separator
- command = "flvstreamer -m 0 -r \"#{prefix}#{flv}\" -o \"#{out_dir}#{out_file}\" > #{$null} 2>&1"
- if File.exist?( out_dir + out_file )
- puts( 'skip : ' + out_file )
- else
- puts( 'download: ' + out_file )
- system( command )
- if $?.to_i == 0x7f00
- puts( 'Failed to execute flvstreamer' )
- exit
- end
- end
- }
- }
- end
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement