shin 1.3.3 → 1.4.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/play/dplay.rb +1 -1
- data/lib/shin/play/svtplay.rb +74 -32
- data/lib/shin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e1e6476cdee7290afe35c4cdea3a3c3d1958e9a
|
4
|
+
data.tar.gz: f71a0824dc344396812052551e8636eb5913fea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d50d60c231a7c44cdc9692e68dfeba2c88ec848e00fb34fc6a0695c7ae8b868fa3f46f704855ab0d8c315195b376f2b09fe02f0a4f557ee454186840110b1870
|
7
|
+
data.tar.gz: 0d06aec1c4f0800074f4df3410532c27e9a24906b1b088fd3f3cbf61933117351058b29ea05bfcc8497891f74e6eb88c1995b39c99a28394f2e35d64366d22ed
|
data/lib/shin/play/dplay.rb
CHANGED
@@ -59,7 +59,7 @@ module Shin
|
|
59
59
|
domain = before()
|
60
60
|
|
61
61
|
# Response
|
62
|
-
response = Base.get(domain + '/api/v2/ajax/shows/
|
62
|
+
response = Base.get(domain + '/api/v2/ajax/shows/' + params[:show_id] + '/seasons?' + URI.encode_www_form(params))
|
63
63
|
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
64
64
|
|
65
65
|
# Data
|
data/lib/shin/play/svtplay.rb
CHANGED
@@ -5,20 +5,20 @@ require 'time'
|
|
5
5
|
module Shin
|
6
6
|
module Play
|
7
7
|
class Svtplay
|
8
|
-
|
8
|
+
|
9
9
|
def new
|
10
10
|
self
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# Get a show
|
14
14
|
def show(params={})
|
15
15
|
# Response
|
16
16
|
response = Base.get('http://www.svtplay.se/' + params[:slug].to_s + '?' + URI.encode_www_form(params))
|
17
17
|
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
18
|
-
|
18
|
+
|
19
19
|
# Nokogiri parse
|
20
20
|
@main_noko = Nokogiri::HTML response.body rescue nil
|
21
|
-
|
21
|
+
|
22
22
|
# Can't be nil
|
23
23
|
if @main_noko != nil
|
24
24
|
# Title
|
@@ -26,8 +26,13 @@ module Shin
|
|
26
26
|
@image.scheme = 'http' if !@image.nil?
|
27
27
|
|
28
28
|
# Data
|
29
|
-
@array = {image: @image.to_s, episodes: []}
|
30
|
-
|
29
|
+
@array = {title: @main_noko.css('header.play_title-page-info__header > h1.play_title-page-info__header-title').text.strip, description: @main_noko.css('p.play_title-page-info__description').last.text.strip, image: @image.to_s, genres: [], episodes: []}
|
30
|
+
|
31
|
+
# Genres
|
32
|
+
@main_noko.css('header.play_title-page-info__header > ul.play_tag-list > li').map do |e|
|
33
|
+
@array[:genres] << e.text.strip
|
34
|
+
end
|
35
|
+
|
31
36
|
# Episodes
|
32
37
|
@main_noko.css('div#play_js-tabpanel-more-episodes > ul > li').map do |e|
|
33
38
|
@video_id = e.css('a.play_vertical-list__video-element-thumbnail')[0]['href'][/\/video\/(\d+)\//, 1].to_i rescue nil
|
@@ -35,6 +40,17 @@ module Shin
|
|
35
40
|
@desc = e.css('p.play_vertical-list__description-text').text.strip rescue nil
|
36
41
|
@season = e.css('h2.play_vertical-list__header > a').text.strip[/S.song\s+(\d+)/, 1].to_i rescue nil
|
37
42
|
@episode = e.css('h2.play_vertical-list__header > a').text.strip[/Avsnitt\s+(\d+)/, 1].to_i rescue nil
|
43
|
+
|
44
|
+
# Try to match in description
|
45
|
+
if @episode == 0 or @episode == nil or @episode == ""
|
46
|
+
@episode = @desc.strip[/^Del\s+(\d+)/, 1] rescue nil
|
47
|
+
|
48
|
+
# If that doesn't work try url
|
49
|
+
if @episode == 0 or @episode == nil or @episode == ""
|
50
|
+
@episode = @url.strip[/avsnitt-(\d+)/, 1] rescue nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
38
54
|
@image = URI(e.css('img.play_vertical-list__image')[0]['src'].gsub("ALTERNATES/small", "ALTERNATES/extralarge")) rescue nil
|
39
55
|
@image.scheme = 'http' if !@image.nil?
|
40
56
|
|
@@ -43,28 +59,28 @@ module Shin
|
|
43
59
|
else
|
44
60
|
raise NotValid, "Nokogiri failed to parse the HTML."
|
45
61
|
end
|
46
|
-
|
62
|
+
|
47
63
|
@array.to_hashugar
|
48
64
|
end
|
49
|
-
|
65
|
+
|
50
66
|
# Get episodes for a slug
|
51
67
|
def episodes(params={})
|
52
68
|
# Response
|
53
69
|
response = Base.get('http://www.svtplay.se/' + params[:slug].to_s + '/hela-program?' + URI.encode_www_form(params))
|
54
70
|
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
55
|
-
|
71
|
+
|
56
72
|
# Nokogiri parse
|
57
73
|
@main_noko = Nokogiri::HTML response.body rescue nil
|
58
|
-
|
74
|
+
|
59
75
|
# Can't be nil
|
60
76
|
if @main_noko != nil
|
61
77
|
# Title
|
62
78
|
@title = @main_noko.css('div.play_gridpage__header-wrapper > h1 > a.play_link.play_link--discreet').text.strip rescue nil
|
63
79
|
@next_page = @main_noko.css('div.play_gridpage__pagination').css('a')[0]['href'][/\?sida\=(\d+)/, 1].to_i rescue nil
|
64
|
-
|
80
|
+
|
65
81
|
# Data
|
66
82
|
@array = {next_page: @next_page, results: []}
|
67
|
-
|
83
|
+
|
68
84
|
# Multiple episodes
|
69
85
|
@main_noko.css('div#gridpage-content > article').map do |e|
|
70
86
|
@video_id = e.css('a')[0]['href'][/\/video\/(\d+)\//, 1].to_i rescue nil
|
@@ -84,36 +100,46 @@ module Shin
|
|
84
100
|
@published_to = nil
|
85
101
|
end
|
86
102
|
end
|
87
|
-
|
88
|
-
|
103
|
+
|
104
|
+
|
89
105
|
# subtitle
|
90
106
|
if @episode > 0
|
91
107
|
@subtitle = e['data-title'].gsub(@title + " - ", '').gsub("Avsnitt " + @episode.to_s + ':', '').gsub("Avsnitt " + @episode.to_s, '').strip
|
92
108
|
else
|
93
109
|
@subtitle = e['data-title'].gsub(@title + " - ", '').strip
|
94
110
|
end
|
95
|
-
|
111
|
+
|
112
|
+
# Try to match in description
|
113
|
+
if @episode == 0 or @episode == nil or @episode == ""
|
114
|
+
@episode = @desc.strip[/^Del\s+(\d+)/, 1] rescue nil
|
115
|
+
|
116
|
+
# If that doesn't work try url
|
117
|
+
if @episode == 0 or @episode == nil or @episode == ""
|
118
|
+
@episode = @url.strip[/avsnitt-(\d+)/, 1] rescue nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
96
122
|
@array[:results] << {id: @video_id, image: @image.to_s, season: @season, episode: @episode, subtitle: @subtitle, url: @url, description: @desc, published_to: @published_to}
|
97
123
|
end
|
98
124
|
else
|
99
125
|
raise NotValid, "Nokogiri failed to parse the HTML."
|
100
126
|
end
|
101
|
-
|
127
|
+
|
102
128
|
@array.to_hashugar
|
103
129
|
end
|
104
|
-
|
130
|
+
|
105
131
|
# Programs
|
106
132
|
def programs
|
107
133
|
# Response
|
108
134
|
response = Base.get('http://www.svtplay.se/program')
|
109
135
|
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
110
|
-
|
136
|
+
|
111
137
|
# Nokogiri parse
|
112
138
|
@main_noko = Nokogiri::HTML response.body rescue nil
|
113
|
-
|
139
|
+
|
114
140
|
# Foreach programs
|
115
141
|
@array = []
|
116
|
-
|
142
|
+
|
117
143
|
# Cant be nil
|
118
144
|
if @main_noko != nil
|
119
145
|
@main_noko.css('ul.play_alphabetic-list > li > ul > li').map do |p|
|
@@ -121,38 +147,44 @@ module Shin
|
|
121
147
|
titlee = p.css('a').text
|
122
148
|
@array << {slug: sluge, title: titlee}
|
123
149
|
end
|
124
|
-
|
150
|
+
|
125
151
|
else
|
126
152
|
raise NotValid, "Nokogiri failed to parse the HTML."
|
127
153
|
end
|
128
154
|
|
129
155
|
@array.to_hashugar
|
130
156
|
end
|
131
|
-
|
157
|
+
|
132
158
|
# Video
|
133
159
|
def video(params={})
|
134
160
|
# Response
|
135
161
|
response = Base.get('http://www.svtplay.se/video/' + params[:id].to_s)
|
136
162
|
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
|
137
|
-
|
163
|
+
|
138
164
|
# Nokogiri parse
|
139
165
|
@main_noko = Nokogiri::HTML response.body rescue nil
|
140
|
-
|
166
|
+
|
141
167
|
# Cant be nil
|
142
168
|
if @main_noko != nil
|
143
169
|
# Title
|
144
170
|
@title = @main_noko.css("a.play_video-area-aside__linked-title")[0].text.strip
|
145
|
-
|
171
|
+
|
146
172
|
# Subtitle data
|
147
173
|
submeta = @main_noko.css("h2.play_video-area-aside__sub-title")[0].text.strip.gsub("\n", ' ').squeeze(' ') rescue nil
|
148
174
|
if !submeta.nil?
|
149
175
|
@season = submeta[/S.song\s+(\d+)/, 1].to_i rescue nil
|
150
176
|
@episode = submeta[/Avsnitt\s+(\d+)/, 1].to_i rescue nil
|
151
177
|
end
|
152
|
-
|
178
|
+
|
153
179
|
# Desc
|
154
180
|
@desc = @main_noko.css('p.play_video-area-aside__info-text')[0].text.strip rescue nil
|
155
|
-
|
181
|
+
|
182
|
+
# Genres
|
183
|
+
@genres = []
|
184
|
+
@main_noko.css('div.play_video-area-aside__info > ul.play_tag-list > li').map do |e|
|
185
|
+
@genres << e.text.strip
|
186
|
+
end
|
187
|
+
|
156
188
|
# Player data
|
157
189
|
playerdata = @main_noko.css("a.play_js-svtplayer")[0]
|
158
190
|
@published_on = Time.at(playerdata['data-popularity-publish-date'].to_i/1000) rescue nil
|
@@ -171,20 +203,30 @@ module Shin
|
|
171
203
|
# Add subtitle from playerdata
|
172
204
|
if submeta != nil and @episode > 0
|
173
205
|
@subtitle = playerdata['data-title'].gsub(@title + " - ", '').gsub("Avsnitt " + @episode.to_s + ':', '').gsub("Avsnitt " + @episode.to_s, '').strip
|
174
|
-
|
206
|
+
|
175
207
|
@subtitle = nil if @subtitle == ""
|
176
208
|
else
|
177
209
|
@subtitle = playerdata['data-title'].gsub(@title + " - ", '').strip
|
178
210
|
@subtitle = nil if @subtitle == ""
|
179
211
|
end
|
180
|
-
|
181
|
-
|
212
|
+
|
213
|
+
# Try to match in description
|
214
|
+
if @episode == 0 or @episode == nil or @episode == ""
|
215
|
+
@episode = @desc.strip[/^Del\s+(\d+)/, 1] rescue nil
|
216
|
+
|
217
|
+
# If that doesn't work try url
|
218
|
+
if @episode == 0 or @episode == nil or @episode == ""
|
219
|
+
@episode = @url.strip[/avsnitt-(\d+)/, 1] rescue nil
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
{ id: params[:id].to_i, title: @title, image: @image.to_s, season: @season, episode: @episode, subtitle: @subtitle, length: @length, published_on: @published_on, published_to: @published_to, url: @url, description: @desc, genres: @genres }.to_hashugar
|
182
224
|
else
|
183
225
|
raise NotValid, "Nokogiri failed to parse the HTML."
|
184
226
|
end
|
185
227
|
end
|
186
|
-
|
187
|
-
|
228
|
+
|
229
|
+
|
188
230
|
# Errors
|
189
231
|
class NotValid < StandardError; end
|
190
232
|
class HTTPError < StandardError; end
|
data/lib/shin/version.rb
CHANGED