Module: SVT::Recorder

Defined in:
lib/svt/recorder.rb,
lib/svt/recorder/base.rb,
lib/svt/recorder/play.rb,
lib/svt/recorder/rapport.rb

Overview

Summary

This library will give you the URL:s for recording files from SVT Play and Play rapport.

Read the documentation for the Play class for how to use those classes directly.

Defined Under Namespace

Classes: Base, Play, Rapport

Constant Summary collapse

VERSION =
'1.0.2'

Class Method Summary collapse

Class Method Details

.fetch_playlist(url, css_path) ⇒ Object

Given an URL to a HTML document and a CSS search path find the ‘data-json-href’ attribute that will give the URL for a videos playlist. This playlist will then be used to fetch all parts/chunks of a video.

Args:

url      :: Any valid URL
css_path :: A CSS expression to search, ex. Play have used '#player'

Yields:

url :: The URL from data-json-href, Play have to add modify the URL
       to make it absolute. So the caller makes any modifications
       before the JSON-file gets fetched.
       Not required to work.

Returns:

A hash with these keys:
  :title :: The title of the video
  :url   :: The URL to the playlist


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/svt/recorder/base.rb', line 26

def self.fetch_playlist(url, css_path)
  doc = Nokogiri::HTML(open(url).read)
  player = doc.at_css(css_path)
  stream = CGI.unescape(player['data-json-href'])
  stream = yield stream if block_given?

  js = JSON.parse(open(stream).read)
  if not js['video']['availableOnMobile']
    raise ArgumentError, "The passed in URL is not available for mobile"
  end

  title = js['context']['title']
  v = js['video']['videoReferences'].find({}) {|v| v['playerType'] == 'ios' }

  return({:title => title, :url => CGI.unescape(v['url'])}) if not v.empty?
end

.record(url) ⇒ Object

To facilitate easy recordings you can use this method to easily instantiate the right class depending on the URL passed in.

If the URL matches playrapport.se it will use the Rapport class, else the Play class.

Returns an array consisting of: [base_url, [parts], bitrate, video_title]



28
29
30
31
32
33
34
# File 'lib/svt/recorder.rb', line 28

def self.record(url)
  if url.match(/svtplay.se/)
    SVT::Recorder::Play.record(url)
  else
    SVT::Recorder::Rapport.record(url)
  end
end