class Getvideo::Sina

Attributes

ipad_vid[RW]
page[RW]

Public Class Methods

new(url) click to toggle source
Calls superclass method
# File lib/getvideo/sina.rb, line 15
def initialize(url)
  super
  parse_page if !(is_flash_url? || is_subject_url?)
end

Public Instance Methods

cover() click to toggle source
# File lib/getvideo/sina.rb, line 26
def cover
  return "" if is_flash_url? || is_subject_url?
  page.match(/pic[\s]*:[\s]*["|']?[\s]*([^'|"]+)?/).to_a[1]
end
flash() click to toggle source
# File lib/getvideo/sina.rb, line 40
def flash
  return url if is_flash_url?
  return "" if is_subject_url?
  return "" if !page
  page.match(/swfOutsideUrl[\s]*:[\s]*["|']?[\s]*([^'|"]+)/).to_a[1]
end
html_url() click to toggle source
# File lib/getvideo/sina.rb, line 31
def html_url
  return "" if is_flash_url?
  url
end
id() click to toggle source
# File lib/getvideo/sina.rb, line 20
def id
  return url.match(/vid=(\d+)/).to_a[1] if is_flash_url?
  return url.match(/#(\d+)/).to_a[1] if is_subject_url?
  page.match(/vid[\s]*:[\s]*["|']?[\s]*(\d+)[\s]*["|']?/).to_a[1]
end
ipad_response() click to toggle source
# File lib/getvideo/sina.rb, line 11
def ipad_response
  @ipad_response ||= ipad_connection
end
m3u8() click to toggle source
# File lib/getvideo/sina.rb, line 47
def m3u8
  if !(is_flash_url? || is_subject_url?)
    ipad_response["video"]["durl"]["url"]
  else
    ""
  end
end
media() click to toggle source
# File lib/getvideo/sina.rb, line 55
def media
  video_list = {}
  if !(is_flash_url? || is_subject_url?)
    video_list["mp4"] = []
    video_list["mp4"] << ipad_response["video"]["durl"]["url"]
  end
  video_list["hlv"] = []
  video_list["hlv"] << response["video"]["durl"]["url"]
  return video_list
end
title() click to toggle source
# File lib/getvideo/sina.rb, line 36
def title
  response["video"]["vname"]
end

Private Instance Methods

get_k(vid, rand) click to toggle source
# File lib/getvideo/sina.rb, line 73
def get_k(vid, rand)
  t = Time.now.to_i.to_s(2)[0..-7].to_i(2)
  Digest::MD5.hexdigest("#{vid.to_s}Z6prk18aWxP278cVAH#{t.to_s}#{rand.to_s}".encode('utf-8'))[0..15] + t.to_s
end
ipad_connection() click to toggle source
# File lib/getvideo/sina.rb, line 68
def ipad_connection
  rand = "0.#{rand(10000..10000000)}#{rand(10000..10000000)}"
  Response.new(Faraday.get("http://v.iask.com/v_play.php?vid=#{ipad_vid}&ran=#{rand}&p=i&k=#{get_k(ipad_vid, rand)}")).parsed
end
is_flash_url?() click to toggle source
# File lib/getvideo/sina.rb, line 78
def is_flash_url?
  url =~ /\.swf/ 
end
is_subject_url?() click to toggle source
# File lib/getvideo/sina.rb, line 82
def is_subject_url?
  url =~ /#\d+/
end
parse_page() click to toggle source
# File lib/getvideo/sina.rb, line 86
def parse_page
  page_res = Faraday.get(url)
  @page = page_res.body
  @ipad_vid = page.match(/ipad_vid[\s]*:[\s]*["|']?[\s]*(\d+)[\s]*["|']?/).to_a[1]
end