Module: Fc2Get
- Defined in:
- lib/fc2_get.rb,
lib/fc2_get/version.rb
Defined Under Namespace
Classes: FileExists
Constant Summary collapse
- VERSION =
"1.0.4"
Class Method Summary collapse
- .decode_params(params_str) ⇒ Object
- .download(video_id, path = '.') ⇒ Object
- .download_uri(video_id) ⇒ Object
- .mimi(video_id) ⇒ Object
- .params_uri(video_id) ⇒ Object
Class Method Details
.decode_params(params_str) ⇒ Object
23 24 25 |
# File 'lib/fc2_get.rb', line 23 def decode_params params_str Hash[params_str.scan(/([^=]+)=([^&]*)&?/)] end |
.download(video_id, path = '.') ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fc2_get.rb', line 32 def download video_id, path = '.' video_uri = download_uri(video_id) file_path = File.directory?(path) ? File.(File.basename(video_uri.path), path) : path raise FileExists.new "path: #{file_path}", file_path if File.exist? file_path Net::HTTP.get_response(video_uri) do |res| size, total = 0, res.header['Content-Length'].to_i open file_path, 'w' do |io| res.read_body do |chunk| io.write chunk size += chunk.size print "%d%% done (%d of %d)\r" % [(size * 100) / total, size, total] end end end end |
.download_uri(video_id) ⇒ Object
27 28 29 30 |
# File 'lib/fc2_get.rb', line 27 def download_uri video_id params = decode_params(open(params_uri(video_id)).read) URI("#{params['filepath']}?mid=#{params['mid']}") end |
.mimi(video_id) ⇒ Object
15 16 17 |
# File 'lib/fc2_get.rb', line 15 def mimi(video_id) Digest::MD5.hexdigest(video_id + '_gGddgPfeaf_gzyr') end |
.params_uri(video_id) ⇒ Object
19 20 21 |
# File 'lib/fc2_get.rb', line 19 def params_uri video_id URI("http://video.fc2.com/ginfo.php?mimi=#{mimi(video_id)}&upid=#{video_id}") end |