cinebase 5.6.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 +7 -0
- data/README.md +59 -0
- 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/version.rb +1 -1
- metadata +7 -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,13 @@
|
|
|
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
|
+
|
|
5
12
|
## [5.6.0] - 2026-10-31
|
|
6
13
|
### Added
|
|
7
14
|
- `Cinema#latitude` and `Cinema#longitude`, `nil` by default. Chain gems return Floats in decimal degrees when they know where a cinema is.
|
data/README.md
CHANGED
|
@@ -220,6 +220,65 @@ CinemaChainName::Performance.at('X0712', from: Date.today, to: Date.today + 365)
|
|
|
220
220
|
request per 50 films. `Cinebase::Boxoffice::Client.new(base_url:)` is the
|
|
221
221
|
underlying client, with `theaters`, `schedule` and `movies`.
|
|
222
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
|
+
|
|
223
282
|
## Contributing
|
|
224
283
|
|
|
225
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'
|
data/lib/cinebase/version.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,12 @@ 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
|
|
146
152
|
- lib/cinebase/boxoffice.rb
|
|
147
153
|
- lib/cinebase/boxoffice/cinema.rb
|
|
148
154
|
- lib/cinebase/boxoffice/client.rb
|