shin 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shin/data/dfi.rb +77 -0
- data/lib/shin/data/sfi.rb +117 -0
- data/lib/shin/data/viasat.rb +52 -0
- data/lib/shin/data.rb +26 -0
- data/lib/shin/play/oppetarkiv.rb +100 -0
- data/lib/shin/play/sbstv.rb +84 -0
- data/lib/shin/play/tv4play.rb +78 -0
- data/lib/shin/play/urplay.rb +42 -0
- data/lib/shin/play/viasat.rb +87 -0
- data/lib/shin/play.rb +34 -3
- data/lib/shin/version.rb +1 -1
- data/lib/shin.rb +5 -0
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75593124b977e12576cd7cc859216eb6d3d5d3dc
|
4
|
+
data.tar.gz: d2940ba29adeff8c32faf158bf268a54deb3d6a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6340c7d4d97b5e22a1c9153df2d21babec9fb502fdc912977ce287eb3d42f2224110dab61594dbcf4900f1dda55c01ba895ba6a1deba5ac5e2359ca58e0a4cbc
|
7
|
+
data.tar.gz: 6020e9a25cc8da2d2d1d480f9a58a58418c4af5600d0f8f25480a62a84f18d54c4514e5c6e939dc46228eb3fd5c842dd7bf8b2733c8d67c94b2ba3b8a351ee46
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# DFI provides an OPEN API
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Shin
|
5
|
+
module Data
|
6
|
+
class Dfi
|
7
|
+
|
8
|
+
def new
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
# Search (on title)
|
13
|
+
def search(params={})
|
14
|
+
raise MissingArgument, "You are missing the argument 'title' which is required to use this source." unless params[:title] != ""
|
15
|
+
year = params[:year] != "" ? params[:year] : nil
|
16
|
+
|
17
|
+
# Response
|
18
|
+
if year != nil
|
19
|
+
response = Base.get('http://nationalfilmografien.service.dfi.dk/movie.svc/list?titlecontains=' + URI.encode(params[:title]) + '&startyear='+(year - 1).to_s+'&endyear='+(year + 1).to_s)
|
20
|
+
else
|
21
|
+
response = Base.get('http://nationalfilmografien.service.dfi.dk/movie.svc/list?titlecontains=' + URI.encode(params[:title]))
|
22
|
+
end
|
23
|
+
|
24
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
25
|
+
|
26
|
+
# Nokogiri parse
|
27
|
+
doc = Nokogiri::XML(response.body) rescue nil
|
28
|
+
|
29
|
+
# Can't be nil
|
30
|
+
if doc != nil
|
31
|
+
doc.remove_namespaces!
|
32
|
+
|
33
|
+
@array = []
|
34
|
+
doc.xpath("//MovieListItems/MovieListItem").each do |item|
|
35
|
+
|
36
|
+
# If year is nil then return all
|
37
|
+
if year != nil
|
38
|
+
return {id: item.xpath('./ID').text.to_i, name: item.xpath('./Name').text, url: item.xpath('./Url').text}.to_hashugar
|
39
|
+
else
|
40
|
+
@array << {id: item.xpath('./ID').text.to_i, name: item.xpath('./Name').text, url: item.xpath('./Url').text}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
@array.to_hashugar
|
46
|
+
else
|
47
|
+
raise NotValid, "Nokogiri failed to parse the XML."
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# Info
|
53
|
+
def info(params={})
|
54
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
55
|
+
|
56
|
+
# Response
|
57
|
+
response = Base.get('http://nationalfilmografien.service.dfi.dk/movie.svc/' + params[:id].to_s)
|
58
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
59
|
+
|
60
|
+
# Nokogiri parse
|
61
|
+
data = response.parsed_response['MovieItem'] rescue nil
|
62
|
+
|
63
|
+
if data != nil
|
64
|
+
{id: data['ID'].to_i, title: data['Title'], original_title: data['OriginalTitle'].strip, age_limit: data['Censorship'], url: data['Url'], description: data['Description']}.to_hashugar
|
65
|
+
else
|
66
|
+
raise NotValid, "Nokogiri failed to parse the XML."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Errors
|
71
|
+
class NotValid < StandardError; end
|
72
|
+
class HTTPError < StandardError; end
|
73
|
+
class MissingArgument < StandardError; end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
## SFI doesn't have a public API but uses a very easy to import HTML.
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Shin
|
5
|
+
module Data
|
6
|
+
class Sfi
|
7
|
+
|
8
|
+
def new
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
# Search (on title)
|
13
|
+
def search(params={})
|
14
|
+
raise MissingArgument, "You are missing the argument 'title' which is required to use this source." unless params[:title] != ""
|
15
|
+
|
16
|
+
type = params[:type] == "" ? params[:type] : "MovieTitle"
|
17
|
+
match = params[:match] == "" ? params[:match] : "Begin"
|
18
|
+
year = params[:year] != "" ? params[:year] : nil
|
19
|
+
|
20
|
+
# Response
|
21
|
+
response = Base.get('http://www.sfi.se/sv/svensk-filmdatabas/sokresultat/?searchword=' + URI.encode(params[:title]) + '&type=' + type + '&match=' + match + '&prom=False')
|
22
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
23
|
+
|
24
|
+
# Nokogiri parse
|
25
|
+
@main_noko = Nokogiri::HTML response.body rescue nil
|
26
|
+
|
27
|
+
# Can't be nil
|
28
|
+
if @main_noko != nil
|
29
|
+
@array = []
|
30
|
+
|
31
|
+
@main_noko.css('div.search_result > div.search_heading').map do |e|
|
32
|
+
@id = e.css('a')[0]['href'][/itemid\=(\d+)/, 1].to_i rescue nil
|
33
|
+
|
34
|
+
@title = e.css('a').text.strip rescue nil
|
35
|
+
@year = e.text[/\((\d+)/, 1].to_i rescue nil
|
36
|
+
@country = e.text[/\((\d+), (.*)\)/, 2].to_s rescue nil
|
37
|
+
|
38
|
+
# Find one or get all? (Allow years to be one less or one more aswell)
|
39
|
+
if year == nil
|
40
|
+
@array << {id: @id.to_i, title: @title, year: @year, country: @country}
|
41
|
+
elsif @year == year or (@year - 1) == year or (@year + 1) == year
|
42
|
+
# It should only return a single one if you have specified a year
|
43
|
+
return {id: @id.to_i, title: @title, year: @year, country: @country}.to_hashugar
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return
|
49
|
+
@array.to_hashugar
|
50
|
+
else
|
51
|
+
raise NotValid, "Nokogiri failed to parse the HTML."
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
# Info
|
58
|
+
def info(params={})
|
59
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
60
|
+
|
61
|
+
# Response
|
62
|
+
response = Base.get('http://www.sfi.se/sv/svensk-filmdatabas/Item/?type=MOVIE&itemid=' + params[:id].to_s)
|
63
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
64
|
+
|
65
|
+
# Nokogiri parse
|
66
|
+
@main_noko = Nokogiri::HTML response.body rescue nil
|
67
|
+
|
68
|
+
# Can't be nil
|
69
|
+
if @main_noko != nil
|
70
|
+
# Data
|
71
|
+
@swedish_title = @main_noko.css('td#ctl00_Full_Main_ctl00_SwedishTitleCell').text.gsub(/Mer$/, "").strip rescue nil
|
72
|
+
@description = @main_noko.css('div#ctl00_Full_Main_ctl00_StorySummary').text.strip rescue nil
|
73
|
+
@swedish_premiere = @main_noko.css('td#ctl00_Full_Main_ctl00_SwedishPremiereCell').text rescue nil
|
74
|
+
@age_limit = @main_noko.css('span#ctl00_Full_Main_ctl00_AgeLimitContent').text.strip rescue nil
|
75
|
+
|
76
|
+
{id: params[:id].to_i, swedish_title: @swedish_title, swedish_premiere: @swedish_premiere, description: @description, age_limit: @age_limit}.to_hashugar
|
77
|
+
else
|
78
|
+
raise NotValid, "Nokogiri failed to parse the HTML."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Titles
|
83
|
+
def titles(params={})
|
84
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
85
|
+
|
86
|
+
# Response
|
87
|
+
response = Base.get('http://www.sfi.se/en-GB/svensk-filmdatabas/Item/?type=MOVIE&iv=Titles&itemid=' + params[:id].to_s)
|
88
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
89
|
+
|
90
|
+
# Nokogiri parse
|
91
|
+
@main_noko = Nokogiri::HTML response.body rescue nil
|
92
|
+
|
93
|
+
# Can't be nil
|
94
|
+
if @main_noko != nil
|
95
|
+
@array = []
|
96
|
+
|
97
|
+
@main_noko.css('table#ctl00_Full_Main_ctl00_TitlesTable > tr').map do |e|
|
98
|
+
@type = e.css('th').text.strip.gsub(/\:$/, "") rescue nil
|
99
|
+
@title = e.css('td').text.strip rescue nil
|
100
|
+
|
101
|
+
@array << {type: @type, title: @title}
|
102
|
+
end
|
103
|
+
|
104
|
+
@array.to_hashugar
|
105
|
+
else
|
106
|
+
raise NotValid, "Nokogiri failed to parse the HTML."
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Errors
|
112
|
+
class NotValid < StandardError; end
|
113
|
+
class HTTPError < StandardError; end
|
114
|
+
class MissingArgument < StandardError; end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
## Viasat provide an API to fetch images for the programmes in their TV Guide
|
2
|
+
|
3
|
+
module Shin
|
4
|
+
module Data
|
5
|
+
class Viasat
|
6
|
+
|
7
|
+
def new
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
def images(params={})
|
13
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
14
|
+
|
15
|
+
# Response
|
16
|
+
response = Base.get('http://se.press.viasat.tv/export?id=' + params[:id].to_s + '&enhancedinfo=true')
|
17
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
18
|
+
|
19
|
+
# Its splitted by newlines
|
20
|
+
data = response.body.split( /\r?\n/ ) rescue nil
|
21
|
+
|
22
|
+
# Just check to be sure
|
23
|
+
if data != nil and data != "" and data.kind_of?(Array)
|
24
|
+
# For each do this
|
25
|
+
array = {portrait: nil, landscape: nil, all: []}
|
26
|
+
|
27
|
+
data.each do |d|
|
28
|
+
url, width, height, image_type, removed = d.split(",")
|
29
|
+
# Just return one
|
30
|
+
if image_type == 'portrait' and array[:portrait] == nil
|
31
|
+
array[:portrait] = url
|
32
|
+
elsif image_type == 'landscape' and array[:landscape] == nil
|
33
|
+
array[:landscape] = url
|
34
|
+
else
|
35
|
+
# We don't add the ones already specified above.
|
36
|
+
array[:all] << {url: url, width: width, height: height, type: image_type}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
array.to_hashugar
|
41
|
+
else
|
42
|
+
raise NotValid, "We failed to parse the document."
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# Error
|
48
|
+
class NotValid < StandardError; end
|
49
|
+
class HTTPError < StandardError; end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/shin/data.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'data/sfi'
|
2
|
+
require_relative 'data/dfi'
|
3
|
+
require_relative 'data/viasat'
|
4
|
+
|
5
|
+
module Shin
|
6
|
+
module Data
|
7
|
+
class << self
|
8
|
+
# I don't know why I need this
|
9
|
+
def new
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def sfi
|
14
|
+
@sfi ||= Sfi.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def dfi
|
18
|
+
@dfi ||= Dfi.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def viasat
|
22
|
+
@viasat ||= Viasat.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
## OppetArkiv doesn't have an open API so let's parse their HTML
|
2
|
+
require 'date'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Shin
|
6
|
+
module Play
|
7
|
+
class Oppetarkiv
|
8
|
+
|
9
|
+
def new
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
# Episodes
|
14
|
+
def episodes(params={})
|
15
|
+
raise MissingArgument, "You are missing the argument 'slug' which is required to use this source." unless params[:slug] != ""
|
16
|
+
|
17
|
+
# What to return
|
18
|
+
array = {title: nil, episodes: []}
|
19
|
+
|
20
|
+
total_pages = 999
|
21
|
+
(1..total_pages).each do |page_num|
|
22
|
+
# Response
|
23
|
+
response = Base.get('http://www.oppetarkiv.se/etikett/titel/' + params[:slug].to_s + '/?sida=' + page_num.to_s + '&sort=tid_stigande')
|
24
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
25
|
+
|
26
|
+
# Nokogiri parse
|
27
|
+
@main_noko = Nokogiri::HTML response.body rescue nil
|
28
|
+
|
29
|
+
# Can't be nil
|
30
|
+
if @main_noko != nil
|
31
|
+
# Title
|
32
|
+
array[:title] = @main_noko.css('span.svt-heading-l').text.strip rescue nil
|
33
|
+
|
34
|
+
# Episodes
|
35
|
+
@main_noko.css('div.svtoa-js-searchlist > article').map do |e|
|
36
|
+
@video_id = e.css('a')[0]['href'][/\/video\/(\d+)\//, 1].to_i rescue nil
|
37
|
+
@url = e.css('a')[0]['href'] rescue nil
|
38
|
+
@season = e.css('h2.svt-text-margin-small').text[/S.song\s+(\d+)/, 1].to_i rescue nil
|
39
|
+
@episode = e.css('h3.svt-heading-xs.svt-text-margin-medium').text[/Avsnitt\s+(\d+)/, 1].to_i rescue nil
|
40
|
+
@of_episode = e.css('h3.svt-heading-xs.svt-text-margin-medium').text[/Avsnitt\s+(\d+)\s+av\s+(\d+)/, 2].to_i rescue nil
|
41
|
+
@image = e.css('img.svtHide-No-Js')[0]['data-imagename'].gsub("ALTERNATES/medium", "ALTERNATES/extralarge") rescue nil
|
42
|
+
|
43
|
+
# Parse published_to
|
44
|
+
if e.css('time') != nil and e.css('time') != "" and pat = e.css('time')[0]['datetime']
|
45
|
+
@published_on = Time.parse(pat) rescue nil
|
46
|
+
end
|
47
|
+
|
48
|
+
# No episode info? Possible a subtitle
|
49
|
+
if @season < 1 and @episode < 1
|
50
|
+
@subtitle = e.css('h3.svt-heading-xs.svt-text-margin-medium > a')[0]['title'].strip
|
51
|
+
else
|
52
|
+
@subtitle = e.css('h3.svt-heading-xs.svt-text-margin-medium > a')[0]['title'].gsub("Avsnitt " + @episode.to_s + ' av ' + @of_episode.to_s + ':', '').gsub("Avsnitt " + @episode.to_s + ' av ' + @of_episode.to_s, '').strip
|
53
|
+
end
|
54
|
+
|
55
|
+
array[:episodes] << {id: @video_id, subtitle: @subtitle, image: @image, season: @season, episode: @episode, of_episodes: @of_episode, url: @url, published_on: @published_on}
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# No more pages, break.
|
60
|
+
if @main_noko.css('a.svtoa-js-search-step-button').to_s == ""
|
61
|
+
break
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise NotValid, "Nokogiri failed to parse the HTML."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
array.to_hashugar
|
69
|
+
end
|
70
|
+
|
71
|
+
# Programs
|
72
|
+
def programs
|
73
|
+
# Response
|
74
|
+
response = Base.get('http://www.oppetarkiv.se/kategori/titel')
|
75
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
76
|
+
|
77
|
+
# Nokogiri parse
|
78
|
+
@main_noko = Nokogiri::HTML response.body rescue nil
|
79
|
+
|
80
|
+
# Foreach programs
|
81
|
+
@array = []
|
82
|
+
if @main_noko != nil
|
83
|
+
@main_noko.css('ul.svtoa-anchor-list.svtColumns-1-2-3-4 > li').map do |p|
|
84
|
+
sluge = p.css('a')[0]['href'].strip[/titel\/(.*)\//, 1]
|
85
|
+
titlee = p.css('a').text
|
86
|
+
@array << {slug: sluge, title: titlee}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
@array.to_hashugar
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# Errors
|
95
|
+
class MissingArgument < StandardError; end
|
96
|
+
class HTTPError < StandardError; end
|
97
|
+
class NotValid < StandardError; end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
## SBSTV have an API but it isn't for public use
|
2
|
+
## - Requires an domainname as they limit the programs for some
|
3
|
+
## Docs: http://www.kanal5play.se/api
|
4
|
+
module Shin
|
5
|
+
module Play
|
6
|
+
class Sbstv
|
7
|
+
|
8
|
+
def new
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
# Fix these before running
|
13
|
+
def before(params={})
|
14
|
+
raise MissingArgument, "You are missing the argument 'sbstv_domain' which is required to use this source." unless Shin.get[:sbstv_domain] != nil
|
15
|
+
|
16
|
+
"http://www." + Shin.get[:sbstv_domain]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Programs
|
20
|
+
def programs
|
21
|
+
domain = before()
|
22
|
+
|
23
|
+
# Response
|
24
|
+
response = Base.get(domain + '/api/listPrograms?format=FLASH')
|
25
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
26
|
+
|
27
|
+
# Data
|
28
|
+
data = Oj.load(response.body) rescue nil
|
29
|
+
|
30
|
+
# Multiple
|
31
|
+
if data != nil
|
32
|
+
data.to_hashugar
|
33
|
+
else
|
34
|
+
raise NotValid, "Couldn't parse the JSON"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Videos
|
39
|
+
def videos(params={})
|
40
|
+
domain = before(params)
|
41
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
42
|
+
|
43
|
+
# Response
|
44
|
+
response = Base.get(domain + '/api/listVideos?format=FLASH&programId=' + params[:id].to_s )
|
45
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
46
|
+
|
47
|
+
# Data
|
48
|
+
data = Oj.load(response.body) rescue nil
|
49
|
+
|
50
|
+
# Multiple
|
51
|
+
if data != nil
|
52
|
+
data.to_hashugar
|
53
|
+
else
|
54
|
+
raise NotValid, "Couldn't parse the JSON"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Video
|
59
|
+
def video(params={})
|
60
|
+
domain = before(params)
|
61
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
62
|
+
|
63
|
+
# Response
|
64
|
+
response = Base.get(domain + '/api/getVideo?format=FLASH&videoId=' + params[:id].to_s )
|
65
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
66
|
+
|
67
|
+
# Data
|
68
|
+
data = Oj.load(response.body) rescue nil
|
69
|
+
|
70
|
+
# Can't be nil
|
71
|
+
if data != nil
|
72
|
+
data.to_hashugar
|
73
|
+
else
|
74
|
+
raise NotValid, "Couldn't parse the JSON"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Errors
|
79
|
+
class NotValid < StandardError; end
|
80
|
+
class MissingArgument < StandardError; end
|
81
|
+
class HTTPError < StandardError; end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
## TV4 Play have an API but it isn't for public use
|
2
|
+
module Shin
|
3
|
+
module Play
|
4
|
+
class Tv4play
|
5
|
+
|
6
|
+
def new
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
# Programs
|
11
|
+
def programs
|
12
|
+
# Response
|
13
|
+
response = Base.get('http://webapi.tv4play.se/play/programs?per_page=900&page=1')
|
14
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
15
|
+
|
16
|
+
# Data
|
17
|
+
data = Oj.load(response.body) rescue nil
|
18
|
+
|
19
|
+
# Can't be nil
|
20
|
+
if data != nil
|
21
|
+
data['results'].to_hashugar
|
22
|
+
else
|
23
|
+
raise NotValid, "Couldn't parse the JSON"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# Videos
|
29
|
+
def videos(params={})
|
30
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
31
|
+
|
32
|
+
# Response
|
33
|
+
response = Base.get('http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&per_page=99999&node_nids=' + params[:id].to_s)
|
34
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
35
|
+
|
36
|
+
# Data
|
37
|
+
data = Oj.load(response.body) rescue nil
|
38
|
+
|
39
|
+
# Can't be nil
|
40
|
+
if data != nil
|
41
|
+
data['results'].to_hashugar
|
42
|
+
else
|
43
|
+
raise NotValid, "Couldn't parse the JSON"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# Video
|
49
|
+
def video(params={})
|
50
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
51
|
+
|
52
|
+
# Response
|
53
|
+
response = Base.get('http://webapi.tv4play.se/play/video_assets?id=' + params[:id].to_s)
|
54
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
55
|
+
|
56
|
+
# Data
|
57
|
+
data = Oj.load(response.body) rescue nil
|
58
|
+
|
59
|
+
# Can't be nil
|
60
|
+
if data != nil
|
61
|
+
if data['total_hits'] == 0
|
62
|
+
raise NotValid, "No results"
|
63
|
+
else
|
64
|
+
data['results'].first.to_hashugar
|
65
|
+
end
|
66
|
+
|
67
|
+
else
|
68
|
+
raise NotValid, "Couldn't parse the JSON"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Errors
|
73
|
+
class NotValid < StandardError; end
|
74
|
+
class MissingArgument < StandardError; end
|
75
|
+
class HTTPError < StandardError; end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
## UR Play doesn't have an open API so let's parse their HTML
|
2
|
+
|
3
|
+
module Shin
|
4
|
+
module Play
|
5
|
+
class Urplay
|
6
|
+
|
7
|
+
def new
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
# Programs
|
12
|
+
def programs
|
13
|
+
# Response
|
14
|
+
response = Base.get('http://www.urplay.se/A-O')
|
15
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
16
|
+
|
17
|
+
# Nokogiri parse
|
18
|
+
@main_noko = Nokogiri::HTML response.body rescue nil
|
19
|
+
|
20
|
+
if @main_noko != nil
|
21
|
+
@array = []
|
22
|
+
@main_noko.css('section#alphabet > ul > li').map do |p|
|
23
|
+
sluge = p.css('a')[0]['href'].strip.gsub("/Produkter/", '')
|
24
|
+
p.css('a > span').remove
|
25
|
+
titlee = p.css('a').text.strip
|
26
|
+
ide = sluge[/^(\d+)/, 1]
|
27
|
+
@array << {id: ide.to_i, slug: sluge, title: titlee}
|
28
|
+
end
|
29
|
+
|
30
|
+
@array.to_hashugar
|
31
|
+
else
|
32
|
+
raise NotValid, "Nokogiri failed to parse the HTML."
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# Errors
|
38
|
+
class NotValid < StandardError; end
|
39
|
+
class HTTPError < StandardError; end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
## Viasat (Play) have an API but it isn't for public use
|
2
|
+
module Shin
|
3
|
+
module Play
|
4
|
+
class Viasat
|
5
|
+
|
6
|
+
def new
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
# Videos
|
11
|
+
def videos(params={})
|
12
|
+
# Response
|
13
|
+
response = Base.get('http://playapi.mtgx.tv/v3/videos?' + URI.encode_www_form(params))
|
14
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
15
|
+
|
16
|
+
# Return this
|
17
|
+
ret = {page: nil, total_pages: nil, results: []}
|
18
|
+
|
19
|
+
# Data
|
20
|
+
data = Oj.load(response.body) rescue nil
|
21
|
+
|
22
|
+
# Can't be nil
|
23
|
+
if data != nil
|
24
|
+
ret[:page] = data['count']['page'].to_i
|
25
|
+
ret[:total_pages] = data['count']['total_pages'].to_i
|
26
|
+
ret[:results] = data["_embedded"]['videos']
|
27
|
+
|
28
|
+
ret.to_hashugar
|
29
|
+
else
|
30
|
+
raise NotValid, "Couldn't parse the JSON"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# Channels
|
36
|
+
def channels(params={})
|
37
|
+
page = params[:page] == "" ? params[:type] : 1
|
38
|
+
|
39
|
+
# Response
|
40
|
+
response = Base.get('http://playapi.mtgx.tv/v3/channels?' + URI.encode_www_form(params))
|
41
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
42
|
+
|
43
|
+
# Return this
|
44
|
+
ret = {page: nil, total_pages: nil, results: []}
|
45
|
+
|
46
|
+
# Data
|
47
|
+
data = Oj.load(response.body) rescue nil
|
48
|
+
|
49
|
+
# Can't be nil
|
50
|
+
if data != nil
|
51
|
+
ret[:page] = data['count']['page'].to_i
|
52
|
+
ret[:total_pages] = data['count']['total_pages'].to_i
|
53
|
+
ret[:results] = data["_embedded"]['channels']
|
54
|
+
|
55
|
+
ret.to_hashugar
|
56
|
+
else
|
57
|
+
raise NotValid, "Couldn't parse the JSON"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# Video
|
63
|
+
def video(params={})
|
64
|
+
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
|
65
|
+
|
66
|
+
# Response
|
67
|
+
response = Base.get('http://playapi.mtgx.tv/v3/videos/' + params[:id].to_s)
|
68
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
69
|
+
|
70
|
+
# Data
|
71
|
+
data = Oj.load(response.body) rescue nil
|
72
|
+
|
73
|
+
# Can't be nil
|
74
|
+
if data != nil
|
75
|
+
data.to_hashugar
|
76
|
+
else
|
77
|
+
raise NotValid, "Couldn't parse the JSON"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Errors
|
82
|
+
class NotValid < StandardError; end
|
83
|
+
class MissingArgument < StandardError; end
|
84
|
+
class HTTPError < StandardError; end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/shin/play.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require_relative 'play/svtplay'
|
2
2
|
require_relative 'play/viki'
|
3
|
-
|
4
|
-
|
3
|
+
require_relative 'play/oppetarkiv'
|
4
|
+
require_relative 'play/tv4play'
|
5
|
+
require_relative 'play/urplay'
|
6
|
+
require_relative 'play/sbstv'
|
5
7
|
#require_relative 'play/viaplay'
|
6
8
|
#require_relative 'play/netflix'
|
7
|
-
|
9
|
+
require_relative 'play/viasat'
|
8
10
|
#require_relative 'play/headweb'
|
9
11
|
#require_relative 'play/film2home'
|
10
12
|
#require_relative 'play/plejmo'
|
13
|
+
#require_relative 'play/hbonordic'
|
11
14
|
|
12
15
|
module Shin
|
13
16
|
module Play
|
@@ -17,13 +20,41 @@ module Shin
|
|
17
20
|
self
|
18
21
|
end
|
19
22
|
|
23
|
+
# SVTPLAY.SE (SWEDISH CONTENT)
|
20
24
|
def svtplay
|
21
25
|
@svtplay ||= Svtplay.new
|
22
26
|
end
|
23
27
|
|
28
|
+
# VIKI.COM (ASIAN CONTENT)
|
24
29
|
def viki
|
25
30
|
@viki ||= Viki.new
|
26
31
|
end
|
32
|
+
|
33
|
+
# OPPETARKIV.SE (SWEDISH CONTENT)
|
34
|
+
def oppetarkiv
|
35
|
+
@oppetarkiv ||= Oppetarkiv.new
|
36
|
+
end
|
37
|
+
|
38
|
+
# URPLAY.SE (SWEDISH CONTENT)
|
39
|
+
def urplay
|
40
|
+
@urplay ||= Urplay.new
|
41
|
+
end
|
42
|
+
|
43
|
+
# TV4PLAY.SE (SWEDISH CONTENT)
|
44
|
+
def tv4play
|
45
|
+
@tv4play ||= Tv4play.new
|
46
|
+
end
|
47
|
+
|
48
|
+
# SBSTV (K5, K9, K11) (SWEDISH CONTENT)
|
49
|
+
def sbstv
|
50
|
+
@sbstv ||= Sbstv.new
|
51
|
+
end
|
52
|
+
|
53
|
+
# Viasat (TV3 etc) (NORDIC CONTENT)
|
54
|
+
def viasat
|
55
|
+
@viasat ||= Viasat.new
|
56
|
+
end
|
57
|
+
|
27
58
|
end
|
28
59
|
end
|
29
60
|
end
|
data/lib/shin/version.rb
CHANGED
data/lib/shin.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'shin/httparty_icebox'
|
|
8
8
|
require_relative 'shin/base'
|
9
9
|
require_relative 'shin/reviews'
|
10
10
|
require_relative 'shin/play'
|
11
|
+
require_relative 'shin/data'
|
11
12
|
|
12
13
|
module Shin
|
13
14
|
class Error < RuntimeError
|
@@ -39,5 +40,9 @@ module Shin
|
|
39
40
|
def reviews
|
40
41
|
@reviews ||= Reviews.new
|
41
42
|
end
|
43
|
+
|
44
|
+
def data
|
45
|
+
@data ||= Data.new
|
46
|
+
end
|
42
47
|
end
|
43
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joakim Nylen
|
@@ -94,9 +94,18 @@ files:
|
|
94
94
|
- README.textile
|
95
95
|
- lib/shin.rb
|
96
96
|
- lib/shin/base.rb
|
97
|
+
- lib/shin/data.rb
|
98
|
+
- lib/shin/data/dfi.rb
|
99
|
+
- lib/shin/data/sfi.rb
|
100
|
+
- lib/shin/data/viasat.rb
|
97
101
|
- lib/shin/httparty_icebox.rb
|
98
102
|
- lib/shin/play.rb
|
103
|
+
- lib/shin/play/oppetarkiv.rb
|
104
|
+
- lib/shin/play/sbstv.rb
|
99
105
|
- lib/shin/play/svtplay.rb
|
106
|
+
- lib/shin/play/tv4play.rb
|
107
|
+
- lib/shin/play/urplay.rb
|
108
|
+
- lib/shin/play/viasat.rb
|
100
109
|
- lib/shin/play/viki.rb
|
101
110
|
- lib/shin/reviews.rb
|
102
111
|
- lib/shin/reviews/kritiker.rb
|