cinebase 5.5.0 → 5.7.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/CHANGELOG.md +17 -0
- data/README.md +139 -1
- data/lib/cinebase/a1web/cinema.rb +94 -0
- data/lib/cinebase/a1web/client.rb +84 -0
- data/lib/cinebase/a1web/listings.rb +127 -0
- data/lib/cinebase/a1web/performance.rb +92 -0
- data/lib/cinebase/a1web/showing.rb +20 -0
- data/lib/cinebase/a1web.rb +17 -0
- data/lib/cinebase/boxoffice/cinema.rb +94 -0
- data/lib/cinebase/boxoffice/client.rb +102 -0
- data/lib/cinebase/boxoffice/performance.rb +71 -0
- data/lib/cinebase/boxoffice/showtime.rb +81 -0
- data/lib/cinebase/boxoffice.rb +16 -0
- data/lib/cinebase/cinema.rb +8 -0
- data/lib/cinebase/version.rb +1 -1
- data/lib/cinebase/vista/guest_token.rb +14 -3
- data/lib/cinebase/vista/token_holder.rb +57 -0
- data/lib/cinebase/vista.rb +1 -0
- metadata +13 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 633f0032bb5a5125614e1cbd9c8cc2bc3af6b85f14d044a91b7f6a8852267434
|
|
4
|
+
data.tar.gz: cd99f85f54e48a7ec255d576de45fc3a41a7dab453de192982e42c3db42a37ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec6071a79582a6b476fa02cf1a96a3e5888f47c546ffd1250903099cf2469f2a8fd0ef8bd9dec69a8938b8ccaff86669b7a273b854166daac36ac265b0670a53
|
|
7
|
+
data.tar.gz: 5d4971c4c9aed5182123eb52f554fb9edc16019ce18fcd24ead64dc1a22508cf52384abf1f3d98e93853603b366512bd8417f7c602d8d6ab3b7046ec2f578785
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
+
## [5.7.0] - 2026-11-01
|
|
6
|
+
### Added
|
|
7
|
+
- `cinebase/a1web`, loaded only on request, for chains whose websites run on Admit One's A1Web, such as Arc, Reel and Movie House
|
|
8
|
+
- `A1web::Client` reads venues from the website's cinema menu and site codes from `GlobalSiteData`, or from a venue's own page when the home page lists none. It reads a venue's `/whatson` page, which holds every advertised date, as UTF-8 although A1Web sends Windows-1252. It retries dropped connections.
|
|
9
|
+
- `A1web::Listings` reads each showtime's date, start, absolute booking link and tags (icon names, `a1-event-*` icon classes and group headings). It handles date panels keyed by timestamp, tabs carrying a timestamp, and tabs with only a label such as `Tue 03 Nov`, reads repeated mobile copies once, and adds the venue path that Movie House booking links leave out.
|
|
10
|
+
- `A1web::Cinema` and `A1web::Performance` base classes. A chain defines `Cinema.website` and `#brand`, optionally `Cinema.locations` with addresses and coordinates, and `Performance.cinema_class`, `.title_sanitizer` and optionally `.variants`. 3D and IMAX also come from titles.
|
|
11
|
+
|
|
12
|
+
## [5.6.0] - 2026-10-31
|
|
13
|
+
### Added
|
|
14
|
+
- `Cinema#latitude` and `Cinema#longitude`, `nil` by default. Chain gems return Floats in decimal degrees when they know where a cinema is.
|
|
15
|
+
- `Vista::TokenHolder` for chain modules: `token`, `acquire_token!`, `ensure_token!` (fetches only when there is no token or it expires within `RENEWAL_MARGIN`, an hour), `token_expires_at` and `reject_token!`
|
|
16
|
+
- `Vista::GuestToken.expires_at(token)` reads a JWT's `exp` claim
|
|
17
|
+
- `cinebase/boxoffice`, loaded only on request, for chains whose websites run on Webedia's "Movies Pro" theme and sell tickets through Boxoffice, such as Everyman and Showcase. Extracted from `everyman_uk`.
|
|
18
|
+
- `Boxoffice::Client` reads theatres from the website's daily static build and showtimes and films from its `/api/gatsby-source-boxofficeapi/` routes, with no token. It retries dropped connections, and a whole year of one theatre's showtimes is one request.
|
|
19
|
+
- `Boxoffice::Showtime` reads a showtime's start in the theatre's time zone, booking link (the chain's `default` provider first, then any other), dimension (`3d` or `RealD3D` tags), language and variants. `VARIANTS` maps Boxoffice's own tags; chains pass `variants:` with their own tags merged in.
|
|
20
|
+
- `Boxoffice::Cinema` and `Boxoffice::Performance` base classes. A chain defines `Cinema.website` and `#brand`, and `Performance.cinema_class`, `.title_sanitizer` and optionally `.variants`.
|
|
21
|
+
|
|
5
22
|
## [5.5.0] - 2026-10-22
|
|
6
23
|
### Changed
|
|
7
24
|
- `Vista::Client` keeps one connection open for all its requests instead of opening a new TLS connection each time, which cost over ten times the request itself. Requests on one client are serialised, so a client can be shared between threads.
|
data/README.md
CHANGED
|
@@ -37,6 +37,14 @@ module CinemaChainName
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# define address methods
|
|
40
|
+
|
|
41
|
+
def latitude
|
|
42
|
+
# Float in decimal degrees, or nil when unknown (the default)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def longitude
|
|
46
|
+
# Float in decimal degrees, or nil when unknown (the default)
|
|
47
|
+
end
|
|
40
48
|
end
|
|
41
49
|
end
|
|
42
50
|
|
|
@@ -132,7 +140,32 @@ end
|
|
|
132
140
|
|
|
133
141
|
`GuestToken#fetch` runs `curl-impersonate` with a Chrome profile, checks the
|
|
134
142
|
token's declared expiry and raises `Cinebase::Vista::AuthenticationError` when
|
|
135
|
-
it cannot get a current token.
|
|
143
|
+
it cannot get a current token. `GuestToken.expires_at(token)` reads a token's
|
|
144
|
+
`exp` claim as a `Time`, or `nil` when it cannot.
|
|
145
|
+
|
|
146
|
+
A chain module keeps its token by extending `TokenHolder`:
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
module CinemaChainName
|
|
150
|
+
extend Cinebase::Vista::TokenHolder
|
|
151
|
+
|
|
152
|
+
def self.guest_token_class
|
|
153
|
+
Internal::GuestToken
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
CinemaChainName.token = guest_jwt # set one you already have
|
|
158
|
+
CinemaChainName.acquire_token! # always fetches a new token
|
|
159
|
+
CinemaChainName.ensure_token! # fetches only when there is no token
|
|
160
|
+
# or it expires within an hour
|
|
161
|
+
CinemaChainName.token_expires_at #=> 2026-10-30 18:00:00 +0000
|
|
162
|
+
CinemaChainName.reject_token!(rejected) # forgets a token the API rejected
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
API calls never fetch a token themselves. When the API rejects a token, the
|
|
166
|
+
chain gem calls `reject_token!` and re-raises, so the next `ensure_token!`
|
|
167
|
+
fetches a fresh one. `reject_token!` keeps a token set since the rejected
|
|
168
|
+
request. To ship curl-impersonate inside platform gems,
|
|
136
169
|
add this to the chain gem's Rakefile:
|
|
137
170
|
|
|
138
171
|
```ruby
|
|
@@ -141,6 +174,111 @@ Cinebase::Vista::PackageTask.new('chain_name.gemspec')
|
|
|
141
174
|
# rake 'package:native[arm64-darwin]' or rake package:all
|
|
142
175
|
```
|
|
143
176
|
|
|
177
|
+
### Boxoffice chains
|
|
178
|
+
|
|
179
|
+
Chains whose websites run on Webedia's "Movies Pro" theme and sell tickets
|
|
180
|
+
through Boxoffice (Everyman, Showcase) share a client and base classes. These
|
|
181
|
+
are not loaded by `require 'cinebase'`:
|
|
182
|
+
|
|
183
|
+
```ruby
|
|
184
|
+
require 'cinebase/boxoffice'
|
|
185
|
+
|
|
186
|
+
module CinemaChainName
|
|
187
|
+
class Cinema < Cinebase::Boxoffice::Cinema
|
|
188
|
+
def self.website
|
|
189
|
+
'https://www.example.co.uk'
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def brand
|
|
193
|
+
'Example'
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
class Performance < Cinebase::Boxoffice::Performance
|
|
198
|
+
def self.cinema_class
|
|
199
|
+
Cinema
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def self.title_sanitizer
|
|
203
|
+
Internal::TitleSanitizer
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Optional: the chain's own tags, e.g. screen brands
|
|
207
|
+
def self.variants
|
|
208
|
+
super.merge('Internal.Brand.XPlus' => 'xplus')
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
CinemaChainName::Cinema.all # open UK theatres, cached for an hour
|
|
214
|
+
CinemaChainName::Performance.at('X0712', from: Date.today, to: Date.today + 365)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`Cinema` gives `adr`, `name`, `url`, `latitude`, `longitude` and
|
|
218
|
+
`time_zone` from the theatre list in the website's daily build.
|
|
219
|
+
`Performance.at` makes one schedule request for the whole range and one
|
|
220
|
+
request per 50 films. `Cinebase::Boxoffice::Client.new(base_url:)` is the
|
|
221
|
+
underlying client, with `theaters`, `schedule` and `movies`.
|
|
222
|
+
|
|
223
|
+
### A1Web chains
|
|
224
|
+
|
|
225
|
+
Chains whose websites run on Admit One's A1Web (Arc, Reel, Movie House)
|
|
226
|
+
share a client, a what's on page parser and base classes. These are not
|
|
227
|
+
loaded by `require 'cinebase'`:
|
|
228
|
+
|
|
229
|
+
```ruby
|
|
230
|
+
require 'cinebase/a1web'
|
|
231
|
+
|
|
232
|
+
module CinemaChainName
|
|
233
|
+
class Cinema < Cinebase::A1web::Cinema
|
|
234
|
+
def self.website
|
|
235
|
+
'https://www.example.co.uk'
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Optional: A1Web sites publish no structured addresses
|
|
239
|
+
def self.locations
|
|
240
|
+
{
|
|
241
|
+
'EX_HIGH' => {
|
|
242
|
+
street_address: '1 High Street', locality: 'Exampleton', postal_code: 'EX1 1AA',
|
|
243
|
+
latitude: 52.5, longitude: -1.25
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def brand
|
|
249
|
+
'Example'
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
class Performance < Cinebase::A1web::Performance
|
|
254
|
+
def self.cinema_class
|
|
255
|
+
Cinema
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def self.title_sanitizer
|
|
259
|
+
Internal::TitleSanitizer
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# Optional: the chain's own showtime icons and headings
|
|
263
|
+
def self.variants
|
|
264
|
+
super.merge('Hypersense' => 'hypersense')
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
CinemaChainName::Cinema.all # venues in the cinema menu, cached for an hour
|
|
270
|
+
CinemaChainName::Performance.at('EX_HIGH', from: Date.today, to: Date.today + 365)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Cinema ids are A1Web site codes such as `ARC_BEE`. The home page's
|
|
274
|
+
`GlobalSiteData` lists them, and where it does not, each venue's own page
|
|
275
|
+
sets one. `Performance.at` makes one request: the venue's `/whatson` page
|
|
276
|
+
holds every advertised date. `Cinebase::A1web::Listings` reads all three
|
|
277
|
+
known templates, whose date panels are keyed by timestamp (Arc), have a
|
|
278
|
+
timestamp on their tab (Movie House) or have only a label such as
|
|
279
|
+
`Tue 03 Nov` (Reel). Showtime tags are icon names, `a1-event-*` icon
|
|
280
|
+
classes and group headings; `Performance::VARIANTS` maps the shared ones.
|
|
281
|
+
|
|
144
282
|
## Contributing
|
|
145
283
|
|
|
146
284
|
1. [Fork it](https://github.com/andycroll/cinebase/fork)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module A1web
|
|
5
|
+
# Cinema base class for an A1Web chain. Subclasses define `.website` and
|
|
6
|
+
# `#brand`, and may define `.locations` with addresses and coordinates,
|
|
7
|
+
# which A1Web sites do not publish in a structured form.
|
|
8
|
+
class Cinema < Cinebase::Cinema
|
|
9
|
+
# Worker processes outlive a day's listings, so refetch the venue list
|
|
10
|
+
CACHE_SECONDS = 3600
|
|
11
|
+
ADDRESS_PARTS = %i(street_address extended_address locality region postal_code).freeze
|
|
12
|
+
|
|
13
|
+
# @return [String] the chain website, e.g. 'https://www.arccinema.co.uk'
|
|
14
|
+
def self.website
|
|
15
|
+
raise NotImplementedError, "#{self} must define .website"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [Cinebase::A1web::Client]
|
|
19
|
+
def self.client
|
|
20
|
+
Client.new(base_url: website)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Hash{String => Hash}] by site code: :street_address,
|
|
24
|
+
# :extended_address, :locality, :region, :postal_code, :latitude and
|
|
25
|
+
# :longitude, each optional
|
|
26
|
+
def self.locations
|
|
27
|
+
{}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Every venue in the website's cinema menu
|
|
31
|
+
# @return [Array<Cinebase::A1web::Cinema>] instances of the subclass
|
|
32
|
+
def self.all
|
|
33
|
+
venues_hash.keys.map { |id| new(id) }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @param [String] id the A1Web site code, e.g. 'ARC_BEE' or 'arc_bee'
|
|
37
|
+
def initialize(id)
|
|
38
|
+
@id = id.to_s.upcase
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [Hash] contains :street_address, :extended_address,
|
|
42
|
+
# :locality, :region, :postal_code, :country_name
|
|
43
|
+
def adr
|
|
44
|
+
ADDRESS_PARTS.to_h { |part| [part, location[part]] }.merge(country_name: 'United Kingdom')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @return [Float, nil]
|
|
48
|
+
def latitude
|
|
49
|
+
location[:latitude]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [Float, nil]
|
|
53
|
+
def longitude
|
|
54
|
+
location[:longitude]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @return [String] e.g. 'Beeston'
|
|
58
|
+
def name
|
|
59
|
+
venue[:name].to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @return [String] the venue's own site, e.g. 'https://beeston.arccinema.co.uk'
|
|
63
|
+
def url
|
|
64
|
+
venue[:url].to_s
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Chains that list no site codes on their home page set one on each
|
|
68
|
+
# venue's own page
|
|
69
|
+
def self.venues_hash
|
|
70
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
71
|
+
if @venues_hash.nil? || now - @fetched_at > CACHE_SECONDS
|
|
72
|
+
@fetched_at = now
|
|
73
|
+
api = client
|
|
74
|
+
@venues_hash = api.venues.filter_map do |venue|
|
|
75
|
+
code = venue[:code] || api.site_code(venue[:url])
|
|
76
|
+
[code.upcase, venue] if code
|
|
77
|
+
end.to_h
|
|
78
|
+
end
|
|
79
|
+
@venues_hash
|
|
80
|
+
end
|
|
81
|
+
private_class_method :venues_hash
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def location
|
|
86
|
+
self.class.locations.fetch(id, {})
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def venue
|
|
90
|
+
self.class.send(:venues_hash).fetch(id, {})
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cgi/escape'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
|
|
6
|
+
module Cinebase
|
|
7
|
+
module A1web
|
|
8
|
+
# Reads venues and listings pages from an A1Web chain website. No token
|
|
9
|
+
# is needed.
|
|
10
|
+
class Client
|
|
11
|
+
# The cinema menu on every page links each venue's own site
|
|
12
|
+
VENUE = %r{<option[^>]*value="(https?://[^"]+)"[^>]*>([^<]*)</option>}
|
|
13
|
+
SITE_CODES = /GlobalSiteData\['([^']+)'\]\s*=\s*'([^']+)'/
|
|
14
|
+
SITE_CODE = /var sitecode\s*=\s*'([^']+)'/
|
|
15
|
+
# Pages claim ISO-8859-1 but send Windows-1252 dashes and quotes
|
|
16
|
+
LEGACY_ENCODING = Encoding::Windows_1252
|
|
17
|
+
RETRIES = 2
|
|
18
|
+
TRANSIENT_ERRORS = [
|
|
19
|
+
EOFError, Errno::ECONNRESET, Errno::ECONNREFUSED, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
attr_reader :base_url
|
|
23
|
+
|
|
24
|
+
# @param [String] base_url the chain website, e.g. 'https://www.arccinema.co.uk'
|
|
25
|
+
def initialize(base_url:)
|
|
26
|
+
@base_url = base_url.delete_suffix('/')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Venues in the home page's cinema menu, with the site codes the home
|
|
30
|
+
# page lists. Some chains list none.
|
|
31
|
+
# @return [Array<Hash>] with :url, :name and :code (nil when unlisted)
|
|
32
|
+
def venues
|
|
33
|
+
html = get(@base_url + '/')
|
|
34
|
+
codes = html.scan(SITE_CODES).to_h { |url, code| [url.delete_suffix('/'), code] }
|
|
35
|
+
html.scan(VENUE).map { |url, name| [url.delete_suffix('/'), name] }.uniq(&:first).map do |url, name|
|
|
36
|
+
{ url: url, name: CGI.unescapeHTML(name).strip, code: codes[url] }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @param [String] venue_url e.g. 'https://moviehouse.co.uk/coleraine'
|
|
41
|
+
# @return [String, nil] the site code the venue's home page sets, e.g. 'MH_COLE'
|
|
42
|
+
def site_code(venue_url)
|
|
43
|
+
get(venue_url)[SITE_CODE, 1]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @param [String] venue_url e.g. 'https://beeston.arccinema.co.uk'
|
|
47
|
+
# @return [String] the venue's what's on page, with every advertised date
|
|
48
|
+
def whats_on(venue_url)
|
|
49
|
+
get("#{venue_url.delete_suffix('/')}/whatson")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def get(url)
|
|
55
|
+
uri = URI(url)
|
|
56
|
+
attempts = 0
|
|
57
|
+
begin
|
|
58
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 10, read_timeout: 30) do |http|
|
|
59
|
+
http.request(Net::HTTP::Get.new(uri))
|
|
60
|
+
end
|
|
61
|
+
rescue *TRANSIENT_ERRORS
|
|
62
|
+
attempts += 1
|
|
63
|
+
raise if attempts > RETRIES
|
|
64
|
+
|
|
65
|
+
sleep(attempts)
|
|
66
|
+
retry
|
|
67
|
+
end
|
|
68
|
+
# Omit response bodies from errors, and never follow redirects.
|
|
69
|
+
raise "HTTP error #{response.code} from #{uri.host}" unless response.is_a?(Net::HTTPSuccess)
|
|
70
|
+
|
|
71
|
+
decode(response.body)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def decode(body)
|
|
75
|
+
utf8 = body.dup.force_encoding(Encoding::UTF_8)
|
|
76
|
+
if utf8.valid_encoding?
|
|
77
|
+
utf8
|
|
78
|
+
else
|
|
79
|
+
body.dup.force_encoding(LEGACY_ENCODING).encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cgi/escape'
|
|
4
|
+
require 'date'
|
|
5
|
+
|
|
6
|
+
module Cinebase
|
|
7
|
+
module A1web
|
|
8
|
+
# Reads every showtime from a venue's what's on page. Templates differ in
|
|
9
|
+
# how they date their panels: Arc keys each panel by its local midnight,
|
|
10
|
+
# Movie House gives that timestamp on the panel's tab, and Reel's tabs
|
|
11
|
+
# give only a label such as 'Today' or 'Tue 03 Nov'.
|
|
12
|
+
class Listings
|
|
13
|
+
PANEL = /<div id="panel_?(\d+)"[^>]*tab-content/
|
|
14
|
+
TAB = %r{<button data-target="(\d+)"([^>]*)>(.*?)</button>}m
|
|
15
|
+
TAB_TIMESTAMP = /value="(\d+)"/
|
|
16
|
+
FILM = %r{<h2[^>]*>\s*<a[^>]*href="[^"]*/event/(\d+)[^"]*"[^>]*>(.*?)</a>}m
|
|
17
|
+
# Group headings, such as 'Subtitled', come before the showtimes they label
|
|
18
|
+
HEADING_OR_SHOWTIME = %r{
|
|
19
|
+
<p\sclass="[^"]*font-semibold[^"]*">([^<]*)</p>
|
|
20
|
+
|
|
|
21
|
+
<a\sclass="[^"]*perfButton[^"]*"\shref="([^"]*)"[^>]*>(.*?)</a>
|
|
22
|
+
}mx
|
|
23
|
+
ICON = /alt="([^"]*)"/
|
|
24
|
+
ICON_SUFFIX = /(?:\A|\s+)icon\z/i
|
|
25
|
+
EVENT_ICON = /class="a1-event-([\w-]+)/
|
|
26
|
+
TIME = /(\d{1,2}):(\d{2})/
|
|
27
|
+
DAY_MONTH = /(\d{1,2}) (#{Date::ABBR_MONTHNAMES.compact.join('|')})/
|
|
28
|
+
# Panel keys this long are timestamps rather than tab numbers
|
|
29
|
+
TIMESTAMP_DIGITS = 9
|
|
30
|
+
TIME_ZONE = 'Europe/London'
|
|
31
|
+
|
|
32
|
+
# @param [String] html a what's on page
|
|
33
|
+
# @param [String] venue_url the venue's own site, e.g. 'https://beeston.arccinema.co.uk'
|
|
34
|
+
# @param [Date] today the date in London when the page was fetched
|
|
35
|
+
def initialize(html, venue_url:, today:)
|
|
36
|
+
@html = html
|
|
37
|
+
@venue_url = venue_url
|
|
38
|
+
@today = today
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Each showtime once, as Reel and Movie House repeat them for small screens
|
|
42
|
+
# @return [Array<Cinebase::A1web::Showing>]
|
|
43
|
+
def showings
|
|
44
|
+
all = @html.split(PANEL).drop(1).each_slice(2).flat_map do |key, panel|
|
|
45
|
+
date = panel_date(key)
|
|
46
|
+
date ? panel_showings(panel, date) : []
|
|
47
|
+
end
|
|
48
|
+
all.uniq(&:booking_url)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def panel_showings(panel, date)
|
|
54
|
+
panel.split(FILM).drop(1).each_slice(3).flat_map do |film_id, title, markup|
|
|
55
|
+
heading = nil
|
|
56
|
+
markup.to_s.scan(HEADING_OR_SHOWTIME).filter_map do |label, href, button|
|
|
57
|
+
if label
|
|
58
|
+
heading = text(label)
|
|
59
|
+
nil
|
|
60
|
+
elsif (time = text(button).match(TIME))
|
|
61
|
+
Showing.new(film_id: film_id, title: text(title), date: date, starting_at: starting_at(date, time),
|
|
62
|
+
booking_url: booking_url(href), tags: tags(button, heading))
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def panel_date(key)
|
|
69
|
+
if key.length >= TIMESTAMP_DIGITS
|
|
70
|
+
local_date(key.to_i)
|
|
71
|
+
else
|
|
72
|
+
tab_dates[key]
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def tab_dates
|
|
77
|
+
@tab_dates ||= @html.scan(TAB).to_h do |key, attributes, label|
|
|
78
|
+
timestamp = attributes[TAB_TIMESTAMP, 1]
|
|
79
|
+
[key, timestamp ? local_date(timestamp.to_i) : label_date(text(label))]
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def label_date(label)
|
|
84
|
+
case label
|
|
85
|
+
when /\AToday\z/i then @today
|
|
86
|
+
when /\ATomorrow\z/i then @today + 1
|
|
87
|
+
when DAY_MONTH then next_date(Regexp.last_match(1).to_i, Date::ABBR_MONTHNAMES.index(Regexp.last_match(2)))
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Labels have no year, so the first such date from today
|
|
92
|
+
def next_date(day, month)
|
|
93
|
+
years = [@today.year, @today.year + 1]
|
|
94
|
+
dates = years.filter_map { |year| Date.new(year, month, day) if Date.valid_date?(year, month, day) }
|
|
95
|
+
dates.find { |date| date >= @today }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def local_date(timestamp)
|
|
99
|
+
TZInfo::Timezone.get(TIME_ZONE).to_local(Time.at(timestamp).utc).to_date
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def starting_at(date, time)
|
|
103
|
+
local = Time.utc(date.year, date.month, date.day, time[1].to_i, time[2].to_i)
|
|
104
|
+
TZInfo::Timezone.get(TIME_ZONE).local_to_utc(local) { |periods| periods.first }.utc
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Movie House links leave out the venue's path, and only work with it
|
|
108
|
+
def booking_url(href)
|
|
109
|
+
href = CGI.unescapeHTML(href)
|
|
110
|
+
venue_path = URI(@venue_url).path.delete_suffix('/')
|
|
111
|
+
if href.start_with?('/') && !href.start_with?("#{venue_path}/")
|
|
112
|
+
href = venue_path + href
|
|
113
|
+
end
|
|
114
|
+
URI.join(@venue_url, href).to_s
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def tags(button, heading)
|
|
118
|
+
icons = button.scan(ICON).map { |(alt)| text(alt).sub(ICON_SUFFIX, '') }
|
|
119
|
+
(icons + button.scan(EVENT_ICON).flatten + [heading]).compact.reject(&:empty?)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def text(html)
|
|
123
|
+
CGI.unescapeHTML(html.gsub(/<[^>]*>/, ' ')).gsub(/\s+/, ' ').strip
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module A1web
|
|
5
|
+
# Performance base class for an A1Web chain. Subclasses define
|
|
6
|
+
# `.cinema_class` and `.title_sanitizer`, and may override `.variants`.
|
|
7
|
+
class Performance < Cinebase::Performance
|
|
8
|
+
# Showtime icons and group headings shared by A1Web chains, and the
|
|
9
|
+
# variants they mean. Chains merge in their own, such as screen brands.
|
|
10
|
+
VARIANTS = {
|
|
11
|
+
'Event Cinema' => 'arts',
|
|
12
|
+
'IMAX' => 'imax',
|
|
13
|
+
'Kids Club' => 'kids',
|
|
14
|
+
'Parent & Baby' => 'baby',
|
|
15
|
+
'Sensory Screening' => 'relaxed',
|
|
16
|
+
'Silver Screen' => 'senior',
|
|
17
|
+
'Subtitled' => 'subtitled',
|
|
18
|
+
'subtitles' => 'subtitled'
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
# A tag, or the title, as some chains list 3D and IMAX copies as films
|
|
22
|
+
THREE_D = /\b3D\b/i
|
|
23
|
+
IMAX = /\bIMAX\b/i
|
|
24
|
+
LANGUAGE = /\((#{TitleSanitizer::LANGUAGES.join('|')})(?: language)?\)/i
|
|
25
|
+
TIME_ZONE = 'Europe/London'
|
|
26
|
+
|
|
27
|
+
# @return [Class] the chain's Cinebase::A1web::Cinema subclass
|
|
28
|
+
def self.cinema_class
|
|
29
|
+
raise NotImplementedError, "#{self} must define .cinema_class"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @return [Class] the chain's Cinebase::TitleSanitizer subclass
|
|
33
|
+
def self.title_sanitizer
|
|
34
|
+
raise NotImplementedError, "#{self} must define .title_sanitizer"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @return [Hash{String => String}] tags and the variants they mean
|
|
38
|
+
def self.variants
|
|
39
|
+
VARIANTS
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Performances within an inclusive range of listings days, from the
|
|
43
|
+
# venue's what's on page, which holds every advertised date.
|
|
44
|
+
# @param [String] cinema_id e.g. 'ARC_BEE'
|
|
45
|
+
# @param [Date] from first date (defaults to today in London)
|
|
46
|
+
# @param [Date] to last date (defaults to 13 days after from)
|
|
47
|
+
# @return [Array<Cinebase::A1web::Performance>] instances of the subclass
|
|
48
|
+
def self.at(
|
|
49
|
+
cinema_id,
|
|
50
|
+
from: TZInfo::Timezone.get(TIME_ZONE).now.to_date,
|
|
51
|
+
to: from + 13
|
|
52
|
+
)
|
|
53
|
+
raise ArgumentError, 'to must not precede from' if to < from
|
|
54
|
+
|
|
55
|
+
cinema = cinema_class.new(cinema_id)
|
|
56
|
+
if cinema.url.empty?
|
|
57
|
+
[]
|
|
58
|
+
else
|
|
59
|
+
today = TZInfo::Timezone.get(TIME_ZONE).now.to_date
|
|
60
|
+
html = cinema_class.client.whats_on(cinema.url)
|
|
61
|
+
showings = Listings.new(html, venue_url: cinema.url, today: today).showings
|
|
62
|
+
performances = showings.select { |showing| (from..to).cover?(showing.date) }.map do |showing|
|
|
63
|
+
new(attributes(showing).merge(cinema_id: cinema.id, cinema_name: cinema.name))
|
|
64
|
+
end
|
|
65
|
+
performances.sort_by(&:starting_at)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.attributes(showing)
|
|
70
|
+
title = showing.title
|
|
71
|
+
{
|
|
72
|
+
booking_url: showing.booking_url,
|
|
73
|
+
dimension: [title, *showing.tags].any? { |text| text.match?(THREE_D) } ? '3d' : '2d',
|
|
74
|
+
festival: Festival.from_title(title, year: showing.date.year),
|
|
75
|
+
film_name: title_sanitizer.new(title).sanitized,
|
|
76
|
+
film_year: TitleSanitizer.film_year(title),
|
|
77
|
+
language: title[LANGUAGE, 1],
|
|
78
|
+
starting_at: showing.starting_at,
|
|
79
|
+
variant: variant(showing)
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
private_class_method :attributes
|
|
83
|
+
|
|
84
|
+
def self.variant(showing)
|
|
85
|
+
variant = showing.tags.filter_map { |tag| variants[tag] }
|
|
86
|
+
variant << 'imax' if showing.title.match?(IMAX)
|
|
87
|
+
variant.uniq
|
|
88
|
+
end
|
|
89
|
+
private_class_method :variant
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module A1web
|
|
5
|
+
# One showtime on a what's on page.
|
|
6
|
+
# @!attribute [r] film_id
|
|
7
|
+
# @return [String] the website's event id, e.g. '110406'
|
|
8
|
+
# @!attribute [r] title
|
|
9
|
+
# @return [String] the film title as listed
|
|
10
|
+
# @!attribute [r] date
|
|
11
|
+
# @return [Date] the listings date
|
|
12
|
+
# @!attribute [r] starting_at
|
|
13
|
+
# @return [Time] UTC
|
|
14
|
+
# @!attribute [r] booking_url
|
|
15
|
+
# @return [String]
|
|
16
|
+
# @!attribute [r] tags
|
|
17
|
+
# @return [Array<String>] icon names and group headings, e.g. 'IMAX', 'Subtitled'
|
|
18
|
+
Showing = Data.define(:film_id, :title, :date, :starting_at, :booking_url, :tags)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cinebase'
|
|
4
|
+
|
|
5
|
+
module Cinebase
|
|
6
|
+
# Shared support for chains whose websites run on Admit One's A1Web, such
|
|
7
|
+
# as Arc, Reel and Movie House. Not loaded by `require 'cinebase'`; these
|
|
8
|
+
# gems `require 'cinebase/a1web'`.
|
|
9
|
+
module A1web
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require 'cinebase/a1web/client'
|
|
14
|
+
require 'cinebase/a1web/showing'
|
|
15
|
+
require 'cinebase/a1web/listings'
|
|
16
|
+
require 'cinebase/a1web/cinema'
|
|
17
|
+
require 'cinebase/a1web/performance'
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module Boxoffice
|
|
5
|
+
# Cinema base class for a Boxoffice chain. Subclasses define `.website`
|
|
6
|
+
# and `#brand`.
|
|
7
|
+
class Cinema < Cinebase::Cinema
|
|
8
|
+
# Worker processes outlive a day's listings, so refetch the theatre list
|
|
9
|
+
CACHE_SECONDS = 3600
|
|
10
|
+
|
|
11
|
+
# @return [String] the chain website, e.g. 'https://www.everymancinema.com'
|
|
12
|
+
def self.website
|
|
13
|
+
raise NotImplementedError, "#{self} must define .website"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [Cinebase::Boxoffice::Client]
|
|
17
|
+
def self.client
|
|
18
|
+
Client.new(base_url: website)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Every open UK cinema
|
|
22
|
+
# @return [Array<Cinebase::Boxoffice::Cinema>] instances of the subclass
|
|
23
|
+
def self.all
|
|
24
|
+
theaters_hash.keys.map { |id| new(id) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @param [String] id the Boxoffice theatre id, e.g. 'X0712' or 'x0712'
|
|
28
|
+
def initialize(id)
|
|
29
|
+
@id = id.to_s.upcase
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @return [Hash] contains :street_address, :extended_address,
|
|
33
|
+
# :locality, :region, :postal_code, :country_name
|
|
34
|
+
def adr
|
|
35
|
+
location = theater.dig('practicalInfo', 'location') || {}
|
|
36
|
+
{
|
|
37
|
+
street_address: location['address'],
|
|
38
|
+
extended_address: nil,
|
|
39
|
+
locality: location['city'],
|
|
40
|
+
region: nil,
|
|
41
|
+
postal_code: location['zip']&.squeeze(' ')&.upcase,
|
|
42
|
+
country_name: 'United Kingdom'
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Float, nil]
|
|
47
|
+
def latitude
|
|
48
|
+
theater.dig('practicalInfo', 'coordinates', 'latitude')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @return [Float, nil]
|
|
52
|
+
def longitude
|
|
53
|
+
theater.dig('practicalInfo', 'coordinates', 'longitude')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @return [String] e.g. 'Baker Street'
|
|
57
|
+
def name
|
|
58
|
+
theater['name'].to_s
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @return [String] e.g. 'Europe/London'
|
|
62
|
+
def time_zone
|
|
63
|
+
theater.fetch('timeZone', 'Europe/London')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @return [String] the cinema's page on the chain website
|
|
67
|
+
def url
|
|
68
|
+
self.class.website + theater['path'].to_s
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.theaters_hash
|
|
72
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
73
|
+
if @theaters_hash.nil? || now - @fetched_at > CACHE_SECONDS
|
|
74
|
+
@fetched_at = now
|
|
75
|
+
@theaters_hash = client.theaters.select { |theater| open_in_uk?(theater) }
|
|
76
|
+
.to_h { |theater| [theater.fetch('id'), theater] }
|
|
77
|
+
end
|
|
78
|
+
@theaters_hash
|
|
79
|
+
end
|
|
80
|
+
private_class_method :theaters_hash
|
|
81
|
+
|
|
82
|
+
def self.open_in_uk?(theater)
|
|
83
|
+
theater.dig('country', 'iso31661A2') == 'GB' && !theater.dig('practicalInfo', 'closed')
|
|
84
|
+
end
|
|
85
|
+
private_class_method :open_in_uk?
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def theater
|
|
90
|
+
self.class.send(:theaters_hash).fetch(id, {})
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
|
|
6
|
+
module Cinebase
|
|
7
|
+
module Boxoffice
|
|
8
|
+
# Reads theatres from a chain website's static build and listings from
|
|
9
|
+
# the website's own Boxoffice API routes. No token is needed.
|
|
10
|
+
class Client
|
|
11
|
+
API_PATH = '/api/gatsby-source-boxofficeapi/'
|
|
12
|
+
BUILD_URL = %r{https://cms-assets\.webediamovies\.pro/prod/[\w-]+/\d{4}-\d{2}-\d{2}/public/}
|
|
13
|
+
# The theme's theatre list query, tried before the home page's others
|
|
14
|
+
THEATERS_QUERY = '2506275789'
|
|
15
|
+
# The website asks for the same number of films at once
|
|
16
|
+
MOVIES_PER_REQUEST = 50
|
|
17
|
+
# Listings days run from 3am to 3am, like the website's
|
|
18
|
+
DAY_STARTS_AT = 'T03:00:00'
|
|
19
|
+
RETRIES = 2
|
|
20
|
+
TRANSIENT_ERRORS = [
|
|
21
|
+
EOFError, Errno::ECONNRESET, Errno::ECONNREFUSED, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError
|
|
22
|
+
].freeze
|
|
23
|
+
|
|
24
|
+
attr_reader :base_url
|
|
25
|
+
|
|
26
|
+
# @param [String] base_url the chain website, e.g. 'https://www.everymancinema.com'
|
|
27
|
+
def initialize(base_url:)
|
|
28
|
+
@base_url = base_url.delete_suffix('/')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [Array<Hash>] every theatre in the website's daily build
|
|
32
|
+
def theaters
|
|
33
|
+
build_url = current_build_url
|
|
34
|
+
hashes = page_data(build_url, 'page-data/index/page-data.json').fetch('staticQueryHashes')
|
|
35
|
+
hashes.sort_by { |hash| hash == THEATERS_QUERY ? 0 : 1 }.each do |hash|
|
|
36
|
+
theaters = page_data(build_url, "page-data/sq/d/#{hash}.json").dig('data', 'allTheater', 'nodes')
|
|
37
|
+
return theaters if theaters
|
|
38
|
+
end
|
|
39
|
+
raise "No theatre list in #{build_url}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @param [String] theater_id e.g. 'X0712'
|
|
43
|
+
# @param [String] time_zone the theatre's, e.g. 'Europe/London'
|
|
44
|
+
# @param [Date] from first listings day
|
|
45
|
+
# @param [Date] to last listings day
|
|
46
|
+
# @return [Hash{String => Hash{String => Array<Hash>}}] showtimes by
|
|
47
|
+
# movie id, then by day
|
|
48
|
+
def schedule(theater_id, time_zone:, from:, to:)
|
|
49
|
+
query = {
|
|
50
|
+
'from' => from.iso8601 + DAY_STARTS_AT,
|
|
51
|
+
'to' => (to + 1).iso8601 + DAY_STARTS_AT,
|
|
52
|
+
'theaters' => JSON.generate('id' => theater_id, 'timeZone' => time_zone)
|
|
53
|
+
}
|
|
54
|
+
api('schedule', query).dig(theater_id, 'schedule') || {}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @param [Array<String>] ids movie ids
|
|
58
|
+
# @return [Array<Hash>] movies
|
|
59
|
+
def movies(ids)
|
|
60
|
+
ids.uniq.each_slice(MOVIES_PER_REQUEST).flat_map { |slice| api('movies', 'ids' => slice) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def api(path, query)
|
|
66
|
+
JSON.parse(get("#{@base_url}#{API_PATH}#{path}?#{URI.encode_www_form(query)}", accept: 'application/json'))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The build moves to a new dated path every day, and the home page can
|
|
70
|
+
# still link images from an older one
|
|
71
|
+
def current_build_url
|
|
72
|
+
get(@base_url + '/', accept: 'text/html').scan(BUILD_URL).max || raise("No build path on #{@base_url}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def page_data(build_url, path)
|
|
76
|
+
JSON.parse(get(build_url + path, accept: 'application/json'))
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def get(url, accept:)
|
|
80
|
+
uri = URI(url)
|
|
81
|
+
request = Net::HTTP::Get.new(uri)
|
|
82
|
+
request['Accept'] = accept
|
|
83
|
+
attempts = 0
|
|
84
|
+
begin
|
|
85
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 10, read_timeout: 30) do |http|
|
|
86
|
+
http.request(request)
|
|
87
|
+
end
|
|
88
|
+
rescue *TRANSIENT_ERRORS
|
|
89
|
+
attempts += 1
|
|
90
|
+
raise if attempts > RETRIES
|
|
91
|
+
|
|
92
|
+
sleep(attempts)
|
|
93
|
+
retry
|
|
94
|
+
end
|
|
95
|
+
# Omit response bodies from errors, and never follow redirects.
|
|
96
|
+
raise "HTTP error #{response.code} from #{uri.host}" unless response.is_a?(Net::HTTPSuccess)
|
|
97
|
+
|
|
98
|
+
response.body
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module Boxoffice
|
|
5
|
+
# Performance base class for a Boxoffice chain. Subclasses define
|
|
6
|
+
# `.cinema_class` and `.title_sanitizer`, and may override `.variants`.
|
|
7
|
+
class Performance < Cinebase::Performance
|
|
8
|
+
# @return [Class] the chain's Cinebase::Boxoffice::Cinema subclass
|
|
9
|
+
def self.cinema_class
|
|
10
|
+
raise NotImplementedError, "#{self} must define .cinema_class"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [Class] the chain's Cinebase::TitleSanitizer subclass
|
|
14
|
+
def self.title_sanitizer
|
|
15
|
+
raise NotImplementedError, "#{self} must define .title_sanitizer"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [Hash{String => String}] Boxoffice tags and the variants they mean
|
|
19
|
+
def self.variants
|
|
20
|
+
Showtime::VARIANTS
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Performances within an inclusive range of listings days, from one
|
|
24
|
+
# schedule request for the whole range and one request per 50 films.
|
|
25
|
+
# @param [String] cinema_id e.g. 'X0712'
|
|
26
|
+
# @param [Date] from first date (defaults to today in London)
|
|
27
|
+
# @param [Date] to last date (defaults to 13 days after from)
|
|
28
|
+
# @return [Array<Cinebase::Boxoffice::Performance>] instances of the subclass
|
|
29
|
+
def self.at(
|
|
30
|
+
cinema_id,
|
|
31
|
+
from: TZInfo::Timezone.get('Europe/London').now.to_date,
|
|
32
|
+
to: from + 13
|
|
33
|
+
)
|
|
34
|
+
raise ArgumentError, 'to must not precede from' if to < from
|
|
35
|
+
|
|
36
|
+
cinema = cinema_class.new(cinema_id)
|
|
37
|
+
client = cinema_class.client
|
|
38
|
+
schedule = client.schedule(cinema.id, time_zone: cinema.time_zone, from: from, to: to)
|
|
39
|
+
movies = client.movies(schedule.keys).to_h { |movie| [movie.fetch('id').to_s, movie] }
|
|
40
|
+
|
|
41
|
+
performances = schedule.flat_map do |movie_id, days|
|
|
42
|
+
title = movies.dig(movie_id.to_s, 'title')
|
|
43
|
+
next [] unless title
|
|
44
|
+
|
|
45
|
+
days.values.flatten.map do |showtime|
|
|
46
|
+
parsed = Showtime.new(showtime, time_zone: cinema.time_zone, variants: variants)
|
|
47
|
+
new(attributes(parsed, title).merge(cinema_id: cinema.id, cinema_name: cinema.name))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
performances.sort_by(&:starting_at)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Release dates are UK releases, so re-releases would get the wrong year;
|
|
54
|
+
# only a year in the title counts.
|
|
55
|
+
def self.attributes(showtime, title)
|
|
56
|
+
starting_at = showtime.starting_at
|
|
57
|
+
{
|
|
58
|
+
booking_url: showtime.booking_url,
|
|
59
|
+
dimension: showtime.dimension,
|
|
60
|
+
festival: Festival.from_title(title, year: starting_at.year),
|
|
61
|
+
film_name: title_sanitizer.new(title).sanitized,
|
|
62
|
+
film_year: TitleSanitizer.film_year(title),
|
|
63
|
+
language: showtime.language || title[/\((#{TitleSanitizer::LANGUAGES.join('|')})\)/i, 1],
|
|
64
|
+
starting_at: starting_at,
|
|
65
|
+
variant: showtime.variant
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
private_class_method :attributes
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module Boxoffice
|
|
5
|
+
# Reads one Boxoffice showtime: its start, booking link and tags
|
|
6
|
+
class Showtime
|
|
7
|
+
# Boxoffice's own tags and the variants they mean. Chains label them
|
|
8
|
+
# differently, e.g. KidsFriendly is Everyman's Toddler Club. Chains
|
|
9
|
+
# merge in their own tags, such as screen brands.
|
|
10
|
+
VARIANTS = {
|
|
11
|
+
'Format.Projection.35mm' => '35mm',
|
|
12
|
+
'Showtime.Accessibility.AudioDescription' => 'audio_described',
|
|
13
|
+
'Showtime.Accessibility.AutismFriendly' => 'relaxed',
|
|
14
|
+
'Showtime.Accessibility.ClosedCaption' => 'subtitled',
|
|
15
|
+
'Showtime.Accessibility.SensoryFriendly' => 'relaxed',
|
|
16
|
+
'Showtime.Accessibility.Subtitled' => 'subtitled',
|
|
17
|
+
'Showtime.Event.QandAEvent' => 'q&a',
|
|
18
|
+
'Showtime.Event.QandARecorded' => 'q&a',
|
|
19
|
+
'Showtime.Experience.EncoreShow' => 'arts',
|
|
20
|
+
'Showtime.Experience.FamilyFriendly' => 'kids',
|
|
21
|
+
'Showtime.Experience.LiveSatellite' => 'arts',
|
|
22
|
+
'Showtime.Experience.LiveShow' => 'arts',
|
|
23
|
+
'Showtime.Restriction.BabyClub' => 'baby',
|
|
24
|
+
'Showtime.Restriction.KidsFriendly' => 'kids',
|
|
25
|
+
'Showtime.Restriction.LoyaltyOnly' => 'members',
|
|
26
|
+
'Showtime.Restriction.Senior' => 'senior',
|
|
27
|
+
'Showtime.Restriction.SilverScreen' => 'senior'
|
|
28
|
+
}.freeze
|
|
29
|
+
|
|
30
|
+
# Format.Projection.3d, or RealD3D alone on Showcase's XPlus RealD 3D
|
|
31
|
+
THREE_D = /\.(RealD)?3d\z/i
|
|
32
|
+
LANGUAGE = /\ALocalization\.Language\.(\w+)\z/
|
|
33
|
+
|
|
34
|
+
# @param [Hash] showtime one showtime from the schedule
|
|
35
|
+
# @param [String] time_zone the theatre's, e.g. 'Europe/London'
|
|
36
|
+
# @param [Hash{String => String}] variants tags and the variants they mean
|
|
37
|
+
def initialize(showtime, time_zone:, variants: VARIANTS)
|
|
38
|
+
@showtime = showtime
|
|
39
|
+
@time_zone = time_zone
|
|
40
|
+
@variants = variants
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Showcase also lists a 'relay' provider, so the chain's own 'default'
|
|
44
|
+
# comes first
|
|
45
|
+
# @return [String, nil] the chain's own booking page
|
|
46
|
+
def booking_url
|
|
47
|
+
ticketing = @showtime.dig('data', 'ticketing') || []
|
|
48
|
+
link = ticketing.find { |entry| entry['provider'] == 'default' } || ticketing.first
|
|
49
|
+
link&.fetch('urls', [])&.first
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [String] '2d' or '3d'
|
|
53
|
+
def dimension
|
|
54
|
+
tags.any? { |tag| tag.match?(THREE_D) } ? '3d' : '2d'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @return [String, nil] audio language, e.g. 'Korean'
|
|
58
|
+
def language
|
|
59
|
+
tags.filter_map { |tag| tag[LANGUAGE, 1] }.first
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# startsAt is the theatre's local time, without an offset
|
|
63
|
+
# @return [Time] UTC
|
|
64
|
+
def starting_at
|
|
65
|
+
local = Time.utc(*@showtime.fetch('startsAt').scan(/\d+/).map(&:to_i))
|
|
66
|
+
TZInfo::Timezone.get(@time_zone).local_to_utc(local) { |periods| periods.first }.utc
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @return [Array<String>]
|
|
70
|
+
def variant
|
|
71
|
+
tags.filter_map { |tag| @variants[tag] }.uniq
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def tags
|
|
77
|
+
@showtime.fetch('tags', [])
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cinebase'
|
|
4
|
+
|
|
5
|
+
module Cinebase
|
|
6
|
+
# Shared support for chains whose websites run on Webedia's "Movies Pro"
|
|
7
|
+
# Gatsby theme and sell tickets through Boxoffice. Not loaded by
|
|
8
|
+
# `require 'cinebase'`; these gems `require 'cinebase/boxoffice'`.
|
|
9
|
+
module Boxoffice
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require 'cinebase/boxoffice/client'
|
|
14
|
+
require 'cinebase/boxoffice/showtime'
|
|
15
|
+
require 'cinebase/boxoffice/cinema'
|
|
16
|
+
require 'cinebase/boxoffice/performance'
|
data/lib/cinebase/cinema.rb
CHANGED
data/lib/cinebase/version.rb
CHANGED
|
@@ -15,6 +15,16 @@ module Cinebase
|
|
|
15
15
|
@curl = curl || default_curl
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
# @param [String] token a JWT
|
|
19
|
+
# @return [Time, nil] from the token's exp claim; nil when it has none or
|
|
20
|
+
# cannot be read
|
|
21
|
+
def self.expires_at(token)
|
|
22
|
+
payload = token.split('.').fetch(1).tr('-_', '+/').unpack1('m')
|
|
23
|
+
Time.at(Integer(JSON.parse(payload).fetch('exp')))
|
|
24
|
+
rescue JSON::ParserError, ArgumentError, IndexError, TypeError, NoMethodError
|
|
25
|
+
nil
|
|
26
|
+
end
|
|
27
|
+
|
|
18
28
|
# @return [String] the guest JWT
|
|
19
29
|
# @raise [Cinebase::Vista::AuthenticationError]
|
|
20
30
|
def fetch
|
|
@@ -66,9 +76,10 @@ module Cinebase
|
|
|
66
76
|
end
|
|
67
77
|
|
|
68
78
|
def validate_expiry!(token)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
expires_at = self.class.expires_at(token)
|
|
80
|
+
if expires_at.nil?
|
|
81
|
+
raise AuthenticationError, 'Guest token page data is missing or invalid'
|
|
82
|
+
elsif expires_at <= Time.now
|
|
72
83
|
raise AuthenticationError, 'Guest token supplied by the page has expired'
|
|
73
84
|
end
|
|
74
85
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cinebase
|
|
4
|
+
module Vista
|
|
5
|
+
# Keeps a chain's guest token. A chain module extends it and defines
|
|
6
|
+
# .guest_token_class. API calls never fetch a token; callers do, with
|
|
7
|
+
# #acquire_token! or #ensure_token!.
|
|
8
|
+
module TokenHolder
|
|
9
|
+
# A token this close to expiry is renewed, so it outlasts a long import
|
|
10
|
+
RENEWAL_MARGIN = 3600
|
|
11
|
+
|
|
12
|
+
# @return [String, nil] raw guest JWT, without the "Bearer " prefix.
|
|
13
|
+
# Never persisted.
|
|
14
|
+
attr_accessor :token
|
|
15
|
+
|
|
16
|
+
# Fetches a new guest token, whatever the current one
|
|
17
|
+
# @param [String, nil] curl curl-impersonate executable
|
|
18
|
+
# @return [String] the guest JWT
|
|
19
|
+
# @raise [Cinebase::Vista::AuthenticationError]
|
|
20
|
+
def acquire_token!(curl: nil)
|
|
21
|
+
self.token = guest_token_class.new(curl: curl).fetch
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Fetches a guest token only when there is none, or the current one is
|
|
25
|
+
# unreadable or expires within RENEWAL_MARGIN
|
|
26
|
+
# @param [String, nil] curl curl-impersonate executable
|
|
27
|
+
# @return [String] the guest JWT
|
|
28
|
+
# @raise [Cinebase::Vista::AuthenticationError]
|
|
29
|
+
def ensure_token!(curl: nil)
|
|
30
|
+
expires_at = token_expires_at
|
|
31
|
+
if expires_at.nil? || expires_at - Time.now <= RENEWAL_MARGIN
|
|
32
|
+
acquire_token!(curl: curl)
|
|
33
|
+
else
|
|
34
|
+
token
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Forgets a token the API rejected, so the next #ensure_token! fetches
|
|
39
|
+
# one. A token set since the rejected request is kept.
|
|
40
|
+
# @param [String, nil] rejected the token the API rejected
|
|
41
|
+
def reject_token!(rejected = token)
|
|
42
|
+
self.token = nil if token == rejected
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @return [Time, nil] from the token's exp claim; nil without a
|
|
46
|
+
# readable token
|
|
47
|
+
def token_expires_at
|
|
48
|
+
GuestToken.expires_at(token) if token
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @return [Class] the chain's Cinebase::Vista::GuestToken subclass
|
|
52
|
+
def guest_token_class
|
|
53
|
+
raise NotImplementedError, "#{self} must define guest_token_class"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/cinebase/vista.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cinebase
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Croll
|
|
@@ -143,6 +143,17 @@ files:
|
|
|
143
143
|
- bin/setup
|
|
144
144
|
- cinebase.gemspec
|
|
145
145
|
- lib/cinebase.rb
|
|
146
|
+
- lib/cinebase/a1web.rb
|
|
147
|
+
- lib/cinebase/a1web/cinema.rb
|
|
148
|
+
- lib/cinebase/a1web/client.rb
|
|
149
|
+
- lib/cinebase/a1web/listings.rb
|
|
150
|
+
- lib/cinebase/a1web/performance.rb
|
|
151
|
+
- lib/cinebase/a1web/showing.rb
|
|
152
|
+
- lib/cinebase/boxoffice.rb
|
|
153
|
+
- lib/cinebase/boxoffice/cinema.rb
|
|
154
|
+
- lib/cinebase/boxoffice/client.rb
|
|
155
|
+
- lib/cinebase/boxoffice/performance.rb
|
|
156
|
+
- lib/cinebase/boxoffice/showtime.rb
|
|
146
157
|
- lib/cinebase/cinema.rb
|
|
147
158
|
- lib/cinebase/festival.rb
|
|
148
159
|
- lib/cinebase/performance.rb
|
|
@@ -152,6 +163,7 @@ files:
|
|
|
152
163
|
- lib/cinebase/vista/client.rb
|
|
153
164
|
- lib/cinebase/vista/guest_token.rb
|
|
154
165
|
- lib/cinebase/vista/package_task.rb
|
|
166
|
+
- lib/cinebase/vista/token_holder.rb
|
|
155
167
|
homepage: http://github.com/andycroll/cinebase
|
|
156
168
|
licenses:
|
|
157
169
|
- MIT
|