shin 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/shin/data/dfi.rb +4 -4
- data/lib/shin/data/previewnetworks.rb +64 -0
- data/lib/shin/data/sfi.rb +6 -6
- data/lib/shin/data.rb +11 -0
- data/lib/shin/hash.rb +63 -0
- data/lib/shin/httparty_icebox.rb +1 -1
- data/lib/shin/play/apple.rb +52 -0
- data/lib/shin/play/hbonordic.rb +42 -0
- data/lib/shin/play/viasat.rb +1 -1
- data/lib/shin/play.rb +16 -1
- data/lib/shin/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c016c0787c6b653275ff7617bc9c91e1fe63bbc
|
4
|
+
data.tar.gz: f2a6b501aa0e7db1dd6e03b2f42fa5d46b82b8d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6e61a9e6bae07ae46fdda9192500ad2092ab24643eaa51656417a86c61b6e1ca1bafcc2edd19753d88059fde25a72ecb6e88d1dbe170b5cc26ef7e60b086a97
|
7
|
+
data.tar.gz: 2f15aa1623a2f07946e890de499ae577ead857c431d309ec0ca2215b68d8bff0832b3f8e645b4d333fb0b324fb75ee90d6c2cc3013f81117827ff54bd193c4e0
|
data/lib/shin/data/dfi.rb
CHANGED
@@ -12,11 +12,11 @@ module Shin
|
|
12
12
|
# Search (on title)
|
13
13
|
def search(params={})
|
14
14
|
raise MissingArgument, "You are missing the argument 'title' which is required to use this source." unless params[:title] != ""
|
15
|
-
|
15
|
+
params[:year] ||= nil
|
16
16
|
|
17
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)
|
18
|
+
if params[:year] != nil
|
19
|
+
response = Base.get('http://nationalfilmografien.service.dfi.dk/movie.svc/list?titlecontains=' + URI.encode(params[:title]) + '&startyear='+(params[:year] - 1).to_s+'&endyear='+(params[:year] + 1).to_s)
|
20
20
|
else
|
21
21
|
response = Base.get('http://nationalfilmografien.service.dfi.dk/movie.svc/list?titlecontains=' + URI.encode(params[:title]))
|
22
22
|
end
|
@@ -34,7 +34,7 @@ module Shin
|
|
34
34
|
doc.xpath("//MovieListItems/MovieListItem").each do |item|
|
35
35
|
|
36
36
|
# If year is nil then return all
|
37
|
-
if year != nil
|
37
|
+
if params[:year] != nil
|
38
38
|
return {id: item.xpath('./ID').text.to_i, name: item.xpath('./Name').text, url: item.xpath('./Url').text}.to_hashugar
|
39
39
|
else
|
40
40
|
@array << {id: item.xpath('./ID').text.to_i, name: item.xpath('./Name').text, url: item.xpath('./Url').text}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# DFI provides an OPEN API
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Shin
|
5
|
+
module Data
|
6
|
+
class Previewnetworks
|
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 'previewnetworks_key' which is required to use this source." unless Shin.get[:previewnetworks_key] != nil
|
15
|
+
|
16
|
+
# Timestamp
|
17
|
+
Shin.get[:previewnetworks_country] ||= "se"
|
18
|
+
|
19
|
+
"http://" + Shin.get[:previewnetworks_country] + ".feed.previewnetworks.com"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Search (on title)
|
23
|
+
def search(params={})
|
24
|
+
url = before()
|
25
|
+
|
26
|
+
# Response
|
27
|
+
response = Base.get(url + '/v3.1/all/search-2/' + Shin.get[:previewnetworks_key] + '/?' + URI.encode_www_form(params))
|
28
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
29
|
+
|
30
|
+
# Data, it can be multiple reviews for a single movie from different reviewers
|
31
|
+
doc = Nokogiri::XML(response.body)
|
32
|
+
|
33
|
+
doc.remove_namespaces!
|
34
|
+
data = []
|
35
|
+
doc.xpath("//previewnetworks/movies/movie").each do |d|
|
36
|
+
data << Hash.from_xml(d.to_xml)[:movie]
|
37
|
+
end
|
38
|
+
|
39
|
+
data.to_hashugar
|
40
|
+
end
|
41
|
+
|
42
|
+
# Info
|
43
|
+
def info(params={})
|
44
|
+
url = before()
|
45
|
+
|
46
|
+
# Response
|
47
|
+
response = Base.get(url + '/v3.1/all/' + params[:id].to_s + '/' + Shin.get[:previewnetworks_key] + '/?' + URI.encode_www_form(params))
|
48
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
49
|
+
|
50
|
+
# Data, it can be multiple reviews for a single movie from different reviewers
|
51
|
+
doc = Nokogiri::XML(response.body)
|
52
|
+
|
53
|
+
doc.remove_namespaces!
|
54
|
+
data = {}
|
55
|
+
doc.xpath("//previewnetworks/movies/movie").each do |d|
|
56
|
+
data = Hash.from_xml(d.to_xml)[:movie]
|
57
|
+
end
|
58
|
+
|
59
|
+
data.to_hashugar
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/shin/data/sfi.rb
CHANGED
@@ -13,12 +13,12 @@ module Shin
|
|
13
13
|
def search(params={})
|
14
14
|
raise MissingArgument, "You are missing the argument 'title' which is required to use this source." unless params[:title] != ""
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
params[:type] ||= "MovieTitle"
|
17
|
+
params[:match] ||= "Begin"
|
18
|
+
params[:year] ||= nil
|
19
19
|
|
20
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')
|
21
|
+
response = Base.get('http://www.sfi.se/sv/svensk-filmdatabas/sokresultat/?searchword=' + URI.encode(params[:title]) + '&type=' + params[:type] + '&match=' + params[:match] + '&prom=False')
|
22
22
|
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
23
23
|
|
24
24
|
# Nokogiri parse
|
@@ -36,9 +36,9 @@ module Shin
|
|
36
36
|
@country = e.text[/\((\d+), (.*)\)/, 2].to_s rescue nil
|
37
37
|
|
38
38
|
# Find one or get all? (Allow years to be one less or one more aswell)
|
39
|
-
if year == nil
|
39
|
+
if params[:year] == nil
|
40
40
|
@array << {id: @id.to_i, title: @title, year: @year, country: @country}
|
41
|
-
elsif @year == year or (@year - 1) == year or (@year + 1) == year
|
41
|
+
elsif @year == params[:year] or (@year - 1) == params[:year] or (@year + 1) == params[:year]
|
42
42
|
# It should only return a single one if you have specified a year
|
43
43
|
return {id: @id.to_i, title: @title, year: @year, country: @country}.to_hashugar
|
44
44
|
end
|
data/lib/shin/data.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative 'data/sfi'
|
2
2
|
require_relative 'data/dfi'
|
3
3
|
require_relative 'data/viasat'
|
4
|
+
require_relative 'data/previewnetworks'
|
5
|
+
require_relative 'hash'
|
4
6
|
|
5
7
|
module Shin
|
6
8
|
module Data
|
@@ -10,17 +12,26 @@ module Shin
|
|
10
12
|
self
|
11
13
|
end
|
12
14
|
|
15
|
+
# SFI HTML
|
13
16
|
def sfi
|
14
17
|
@sfi ||= Sfi.new
|
15
18
|
end
|
16
19
|
|
20
|
+
# DFI API
|
17
21
|
def dfi
|
18
22
|
@dfi ||= Dfi.new
|
19
23
|
end
|
20
24
|
|
25
|
+
# Viasat API (Images only atm)
|
21
26
|
def viasat
|
22
27
|
@viasat ||= Viasat.new
|
23
28
|
end
|
29
|
+
|
30
|
+
# Previewnetworks API
|
31
|
+
def previewnetworks
|
32
|
+
@previewnetworks ||= Previewnetworks.new
|
33
|
+
end
|
34
|
+
|
24
35
|
end
|
25
36
|
end
|
26
37
|
end
|
data/lib/shin/hash.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
|
2
|
+
require 'nokogiri'
|
3
|
+
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
|
4
|
+
|
5
|
+
class Hash
|
6
|
+
class << self
|
7
|
+
def from_xml(xml_io)
|
8
|
+
begin
|
9
|
+
result = Nokogiri::XML(xml_io)
|
10
|
+
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
|
11
|
+
rescue Exception => e
|
12
|
+
# raise your custom exception here
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def xml_node_to_hash(node)
|
17
|
+
# If we are at the root of the document, start the hash
|
18
|
+
if node.element?
|
19
|
+
result_hash = {}
|
20
|
+
if node.attributes != {}
|
21
|
+
result_hash[:attributes] = {}
|
22
|
+
node.attributes.keys.each do |key|
|
23
|
+
result_hash[:attributes][node.attributes[key].name.to_sym] = prepare(node.attributes[key].value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
if node.children.size > 0
|
27
|
+
node.children.each do |child|
|
28
|
+
result = xml_node_to_hash(child)
|
29
|
+
|
30
|
+
if child.name == "text"
|
31
|
+
unless child.next_sibling || child.previous_sibling
|
32
|
+
return prepare(result)
|
33
|
+
end
|
34
|
+
elsif result_hash[child.name.to_sym]
|
35
|
+
if result_hash[child.name.to_sym].is_a?(Object::Array)
|
36
|
+
result_hash[child.name.to_sym] << prepare(result)
|
37
|
+
else
|
38
|
+
result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << prepare(result)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
result_hash[child.name.to_sym] = prepare(result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return result_hash
|
46
|
+
else
|
47
|
+
return result_hash
|
48
|
+
end
|
49
|
+
else
|
50
|
+
return prepare(node.content.to_s)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def prepare(data)
|
55
|
+
(data.class == String && data.to_i.to_s == data) ? data.to_i : data
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_struct(struct_name)
|
60
|
+
Struct.new(struct_name,*keys).new(*values)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/shin/httparty_icebox.rb
CHANGED
@@ -168,7 +168,7 @@ module HTTParty #:nodoc:
|
|
168
168
|
|
169
169
|
# ===== Store objects in memory
|
170
170
|
#
|
171
|
-
Struct.new("
|
171
|
+
Struct.new("ShinResponse", :code, :body, :headers) { def to_s; self.body; end }
|
172
172
|
class MemoryStore < AbstractStore
|
173
173
|
def initialize(options={})
|
174
174
|
super; @store = {}; self
|
@@ -0,0 +1,52 @@
|
|
1
|
+
## Apple Provides a OPEN API
|
2
|
+
## Docs: https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
|
3
|
+
module Shin
|
4
|
+
module Play
|
5
|
+
class Apple
|
6
|
+
|
7
|
+
def new
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
# Search
|
12
|
+
def search(params={})
|
13
|
+
# Response
|
14
|
+
response = Base.get('https://itunes.apple.com/search?' + URI.encode_www_form(params))
|
15
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
16
|
+
|
17
|
+
# Data
|
18
|
+
data = Oj.load(response.body) rescue nil
|
19
|
+
d2 = data['results'] rescue nil
|
20
|
+
|
21
|
+
if d2 != nil
|
22
|
+
d2.to_hashugar
|
23
|
+
else
|
24
|
+
raise NotValid, "Couldn't find any responses/results please check again."
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# Find
|
30
|
+
def find(params={})
|
31
|
+
# Response
|
32
|
+
response = Base.get('https://itunes.apple.com/lookup?' + URI.encode_www_form(params))
|
33
|
+
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
34
|
+
|
35
|
+
# Data
|
36
|
+
data = Oj.load(response.body) rescue nil
|
37
|
+
d2 = data['results'] rescue nil
|
38
|
+
|
39
|
+
if d2 != nil
|
40
|
+
d2.first.to_hashugar
|
41
|
+
else
|
42
|
+
raise NotValid, "Couldn't find any responses/results please check again."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Errors
|
47
|
+
class NotValid < StandardError; end
|
48
|
+
class MissingArgument < StandardError; end
|
49
|
+
class HTTPError < StandardError; end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
## HBO Nordic have a REST API but isn't for public use
|
2
|
+
module Shin
|
3
|
+
module Play
|
4
|
+
class Hbonordic
|
5
|
+
|
6
|
+
def new
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
# Category
|
11
|
+
def all(params={})
|
12
|
+
raise NotValid, "Not a valid category. Please check again." unless ["movies", "series"].include?(params[:category])
|
13
|
+
|
14
|
+
# Response
|
15
|
+
response = Base.get('http://hbonordic.se/rest-services-hook/' + params[:category])
|
16
|
+
|
17
|
+
# They place movies in a "entry" tag somehow
|
18
|
+
if params[:category] == "movies"
|
19
|
+
response.parsed_response['entry'].to_hashugar
|
20
|
+
else
|
21
|
+
response.parsed_response.to_hashugar
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Info
|
26
|
+
def info(params={})
|
27
|
+
raise NotValid, "Not a valid category. Please check again." unless ["movies", "series"].include?(params[:category])
|
28
|
+
|
29
|
+
# Response
|
30
|
+
response = Base.get('http://hbonordic.se/rest-services-hook/' + params[:category] + '/' + params[:id])
|
31
|
+
|
32
|
+
# Data
|
33
|
+
response.parsed_response.to_hashugar
|
34
|
+
end
|
35
|
+
|
36
|
+
# Errors
|
37
|
+
class NotValid < StandardError; end
|
38
|
+
class MissingArgument < StandardError; end
|
39
|
+
class HTTPError < StandardError; end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/shin/play/viasat.rb
CHANGED
data/lib/shin/play.rb
CHANGED
@@ -10,7 +10,12 @@ require_relative 'play/viasat'
|
|
10
10
|
#require_relative 'play/headweb'
|
11
11
|
#require_relative 'play/film2home'
|
12
12
|
#require_relative 'play/plejmo'
|
13
|
-
#require_relative 'play/
|
13
|
+
#require_relative 'play/sfanytime'
|
14
|
+
require_relative 'play/apple'
|
15
|
+
#require_relative 'play/cmore'
|
16
|
+
#require_relative 'play/filmnet'
|
17
|
+
#require_relative 'play/discshop'
|
18
|
+
require_relative 'play/hbonordic'
|
14
19
|
|
15
20
|
module Shin
|
16
21
|
module Play
|
@@ -55,6 +60,16 @@ module Shin
|
|
55
60
|
@viasat ||= Viasat.new
|
56
61
|
end
|
57
62
|
|
63
|
+
# HBO Nordic (NORDIC CONTENT)
|
64
|
+
def hbonordic
|
65
|
+
@hbonordic ||= Hbonordic.new
|
66
|
+
end
|
67
|
+
|
68
|
+
# Apple iTunes (WORLDWIDE CONTENT)
|
69
|
+
def apple
|
70
|
+
@apple ||= Apple.new
|
71
|
+
end
|
72
|
+
|
58
73
|
end
|
59
74
|
end
|
60
75
|
end
|
data/lib/shin/version.rb
CHANGED
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:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joakim Nylen
|
@@ -96,10 +96,14 @@ files:
|
|
96
96
|
- lib/shin/base.rb
|
97
97
|
- lib/shin/data.rb
|
98
98
|
- lib/shin/data/dfi.rb
|
99
|
+
- lib/shin/data/previewnetworks.rb
|
99
100
|
- lib/shin/data/sfi.rb
|
100
101
|
- lib/shin/data/viasat.rb
|
102
|
+
- lib/shin/hash.rb
|
101
103
|
- lib/shin/httparty_icebox.rb
|
102
104
|
- lib/shin/play.rb
|
105
|
+
- lib/shin/play/apple.rb
|
106
|
+
- lib/shin/play/hbonordic.rb
|
103
107
|
- lib/shin/play/oppetarkiv.rb
|
104
108
|
- lib/shin/play/sbstv.rb
|
105
109
|
- lib/shin/play/svtplay.rb
|