class Shin::Play::Viaplay

Public Instance Methods

before(params={}) click to toggle source

Fix these before running

# File lib/shin/play/viaplay.rb, line 11
def before(params={})
  raise MissingArgument, "You are missing the argument 'viaplay_country' which is required to use this source." unless Shin.get[:viaplay_country] != nil

  "https://content.viaplay."  + Shin.get[:viaplay_country] + "/pcdash-" + Shin.get[:viaplay_country] + "/"
end
movies(params={}) click to toggle source

Movies

# File lib/shin/play/viaplay.rb, line 67
def movies(params={})
  # domain
  domain = before()
  country = Shin.get[:viaplay_country]

  # Translated shit
  type = "kaikki"    if country == "fi"
  type = "alle"      if country == "dk" or country == "no"
  type = "samtliga"  if country == "se"

  if params[:page] != nil
    id = type + "?pageNumber=" + params[:page].to_s + "&sort=recently_added"
  elsif params[:id] != nil
    id = params[:id].to_s
  else
    id = type + "?sort=recently_added"
  end



  # Response
  if country == "fi"
    response = Base.get(domain + 'leffat/' + id)
  elsif country == "no"
    response = Base.get(domain + 'filmer/' + id)
  else
    response = Base.get(domain + 'film/' + id)
  end


  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200

  # Data
  data = Oj.load(response.body) rescue nil

  # Can't be nil
  if data != nil
    data['_embedded']['viaplay:blocks'].to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end
end
new() click to toggle source
# File lib/shin/play/viaplay.rb, line 6
def new
  self
end
rental_movies(params={}) click to toggle source

Rental movies

# File lib/shin/play/viaplay.rb, line 111
def rental_movies(params={})
  # domain
  domain = before()
  country = Shin.get[:viaplay_country]

  # Translated shit
  type = "kaikki"    if country == "fi"
  type = "alle"      if country == "dk" or country == "no"
  type = "samtliga"  if country == "se"

  if params[:page] != nil
    id = type + "?pageNumber=" + params[:page].to_s + "&sort=recently_added"
  elsif params[:id] != nil
    id = params[:id].to_s
  else
    id = type + "?sort=recently_added"
  end

  # Response
  if country == "fi"
    response = Base.get(domain + 'vuokraamo/' + id)
  elsif country == "dk"
    response = Base.get(domain + 'lejebutik/' + id)
  elsif country == "no"
    response = Base.get(domain + 'leiebutikk/' + id)
  else
    response = Base.get(domain + 'hyrbutik/' + id)
  end


  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200

  # Data
  data = Oj.load(response.body) rescue nil

  # Can't be nil
  if data != nil
    data['_embedded']['viaplay:blocks'].to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end
end
series(params={}) click to toggle source

Series

# File lib/shin/play/viaplay.rb, line 18
def series(params={})
  # domain
  domain = before()
  country = Shin.get[:viaplay_country]

  # Translated shit
  type = "kaikki"    if country == "fi"
  type = "alle"      if country == "dk" or country == "no"
  type = "samtliga"  if country == "se"

  # URLs
  if params[:page] != nil
    id = type + "?pageNumber=" + params[:page].to_s + "&sort=recently_added"
  elsif params[:season] != nil
    id = params[:id] + "?seasonNumber=" + params[:season].to_s + "&partial=1&block=2"
  elsif params[:id] != nil
    id = params[:id].to_s
  else
    id = type + "?sort=recently_added"
  end

  # Response
  if country == "fi"
    response = Base.get(domain + 'sarjat/' + id)
  else
    response = Base.get(domain + 'serier/' + id)
  end


  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200

  # Data
  data = Oj.load(response.body) rescue nil

  # Can't be nil
  if data != nil
    # Episodes for a seaosn is in products, not blocks.
    if params[:season] != nil
      data['_embedded']['viaplay:products'].to_hashugar
    else
      data['_embedded']['viaplay:blocks'].to_hashugar
    end
  else
    raise NotValid, "Couldn't parse the JSON"
  end

end