cinebase 5.7.0 → 5.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 633f0032bb5a5125614e1cbd9c8cc2bc3af6b85f14d044a91b7f6a8852267434
4
- data.tar.gz: cd99f85f54e48a7ec255d576de45fc3a41a7dab453de192982e42c3db42a37ea
3
+ metadata.gz: 7eff40769f29794d20f66b87e8d78a5295e6efb32acd0b59d7c2189456c1d98a
4
+ data.tar.gz: fabfa47d703f1aa2b4d8c6a06773a6435a36c974fd8775367ad844b7fec6f254
5
5
  SHA512:
6
- metadata.gz: ec6071a79582a6b476fa02cf1a96a3e5888f47c546ffd1250903099cf2469f2a8fd0ef8bd9dec69a8938b8ccaff86669b7a273b854166daac36ac265b0670a53
7
- data.tar.gz: 5d4971c4c9aed5182123eb52f554fb9edc16019ce18fcd24ead64dc1a22508cf52384abf1f3d98e93853603b366512bd8417f7c602d8d6ab3b7046ec2f578785
6
+ metadata.gz: 429d9f452ab938b0c1e8e353c18efcc52c374698a9c38d27e60d09ef3001d0ae1226aff4015f28b60ed1c915e2af59389701fd1ecb515f7e30d689b54bcbe1ca
7
+ data.tar.gz: b9c3e3a3834facd2f41448c3788c76a693d57081fa844266706415df4bfd4bbeb1a178aeb3e159da1d6b44d19bd6524d6d06094b383e686f6a05de750e46c983
data/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
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.9.0] - 2026-11-03
6
+ ### Added
7
+ - `Cinebase::Event` for opera, ballet, theatre and exhibition screenings. `Performance#event` names the series from the `film_name` prefix the title sanitizer gives, such as `Met Opera: `, and `Performance#film_name` leaves it out.
8
+ - `Cinebase::Audience` reads relaxed, kids, baby, dog-friendly, members and preview labels from a raw title.
9
+ - `Performance` takes the raw `title:`. With it, `#variant` adds audience variants and `#festival` falls back to one named in the title.
10
+ - Festival prefixes for Cinecity, FFF, French Film Fest UK, IFF, Into Film Festival, JFF, LDNDOCS, London Palestine Film Festival, LPFF, NFF, Queer East, RFF, SLA and Women and the World Festival, with or without a year, which may have two digits.
11
+ - Bengali, Gujarati, Japanese, Romanian and Vietnamese language versions.
12
+
13
+ ### Changed
14
+ - `COMMON_REPLACE` names every spelling of a Met Opera, Royal Ballet and Opera, National Theatre Live, Exhibition on Screen or Bolshoi season with one prefix, including Met operas listed in an RBO season.
15
+ - `COMMON_REMOVE` also strips audience labels, festival gala labels, bracketed 3D and 4K, `4K Restoration`, restorations after an anniversary, square-bracketed anniversaries, bracketed encores, `(Recorded)`, `(English Dubbed)`, `- Live On Stage`, and `+ ScreenTalk`, `+ Intro` and `+ Short Film` add-ons.
16
+ - Titles listed in capitals are title cased.
17
+
18
+ ## [5.8.0] - 2026-11-02
19
+ ### Added
20
+ - `Cinebase::Http` for chain gems' requests: `get`, and `post` with a form or JSON body, over HTTPS. It retries dropped connections twice, never follows redirects, raises errors that name the status and host but leave out the body, and returns bodies as UTF-8. `keep_alive: true` reuses one connection per host until `close`. Tests stub `Cinebase::Http.pause` to skip the waits between attempts.
21
+ - `Cinebase::London` for London dates and times: `today`, `utc` for a listed wall-clock time (the hour repeated when clocks go back is read as BST) and `date` for a time's London date.
22
+
23
+ ### Changed
24
+ - The A1Web and Boxoffice clients, and `Performance#starting_at`, use them. `Performance#starting_at` no longer raises for a local time in the repeated hour when clocks go back.
25
+
5
26
  ## [5.7.0] - 2026-11-01
6
27
  ### Added
7
28
  - `cinebase/a1web`, loaded only on request, for chains whose websites run on Admit One's A1Web, such as Arc, Reel and Movie House
data/README.md CHANGED
@@ -53,7 +53,8 @@ module CinemaChainName
53
53
  def self.at(cinema_id)
54
54
  # parse webpages or apis to get performances for a cinema, built with
55
55
  # booking_url:, cinema_id:, cinema_name:, dimension:, festival:,
56
- # film_name:, film_year:, language:, starting_at: and variant:
56
+ # film_name:, film_year:, language:, starting_at:, title: (the raw
57
+ # title) and variant:
57
58
  end
58
59
  end
59
60
  end
@@ -93,6 +94,38 @@ Cinebase::Festival.from_title('UKJFF - From Cable Street To Brick Lane', year: 2
93
94
 
94
95
  `COMMON_REMOVE` strips the same prefixes from titles.
95
96
 
97
+ ### Stage shows
98
+
99
+ The common rules name opera, ballet, theatre and exhibition screenings with
100
+ one prefix per series, such as `Met Opera: Tosca`. A performance strips it
101
+ from `film_name` and names the series as its `event`, with an `arts` variant:
102
+
103
+ ```ruby
104
+ performance = CinemaChainName::Performance.new(film_name: 'Met Opera: Tosca', ...)
105
+ performance.film_name #=> "Tosca"
106
+ performance.event #=> #<data Cinebase::Event name="Met Opera">
107
+ ```
108
+
109
+ A chain's own `replace` rules should produce the same prefixes.
110
+
111
+ ### Audiences
112
+
113
+ Some chains name relaxed, toddler, parent and baby, dog-friendly, members'
114
+ or preview screenings in the title. `COMMON_REMOVE` strips the label, and a
115
+ performance given `title:` adds the variant:
116
+
117
+ ```ruby
118
+ Cinebase::Audience.variants('Relaxed Screening: Wicked') #=> ["relaxed"]
119
+ ```
120
+
121
+ A performance given `title:` also finds its festival when not given one.
122
+
123
+ ### Titles in capitals
124
+
125
+ A title listed in capitals is title cased, keeping acronyms without vowels,
126
+ Roman numerals and words with digits: `ROCKY IV` reads `Rocky IV`, and
127
+ `BTS 'ARIRANG'` reads `BTS 'Arirang'`.
128
+
96
129
  ### Film years
97
130
 
98
131
  Titles often end with the film's year. `COMMON_REMOVE` strips it, and
data/cinebase.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'base64'
22
22
  spec.add_development_dependency 'bundler', '>= 2.0'
23
+ spec.add_development_dependency 'minitest-mock'
23
24
  spec.add_development_dependency 'minitest-reporters'
24
25
  spec.add_development_dependency 'rake', '>= 13.0'
25
26
  spec.add_development_dependency 'simplecov', '~> 0.22'
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'cgi/escape'
4
- require 'net/http'
5
4
 
6
5
  module Cinebase
7
6
  module A1web
@@ -14,16 +13,13 @@ module Cinebase
14
13
  SITE_CODE = /var sitecode\s*=\s*'([^']+)'/
15
14
  # Pages claim ISO-8859-1 but send Windows-1252 dashes and quotes
16
15
  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
16
 
22
17
  attr_reader :base_url
23
18
 
24
19
  # @param [String] base_url the chain website, e.g. 'https://www.arccinema.co.uk'
25
20
  def initialize(base_url:)
26
21
  @base_url = base_url.delete_suffix('/')
22
+ @http = Http.new
27
23
  end
28
24
 
29
25
  # Venues in the home page's cinema menu, with the site codes the home
@@ -52,29 +48,12 @@ module Cinebase
52
48
  private
53
49
 
54
50
  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)
51
+ decode(@http.get(url))
72
52
  end
73
53
 
74
54
  def decode(body)
75
- utf8 = body.dup.force_encoding(Encoding::UTF_8)
76
- if utf8.valid_encoding?
77
- utf8
55
+ if body.valid_encoding?
56
+ body
78
57
  else
79
58
  body.dup.force_encoding(LEGACY_ENCODING).encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
80
59
  end
@@ -96,12 +96,12 @@ module Cinebase
96
96
  end
97
97
 
98
98
  def local_date(timestamp)
99
- TZInfo::Timezone.get(TIME_ZONE).to_local(Time.at(timestamp).utc).to_date
99
+ London.date(Time.at(timestamp))
100
100
  end
101
101
 
102
102
  def starting_at(date, time)
103
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
104
+ London.utc(local)
105
105
  end
106
106
 
107
107
  # Movie House links leave out the venue's path, and only work with it
@@ -47,7 +47,7 @@ module Cinebase
47
47
  # @return [Array<Cinebase::A1web::Performance>] instances of the subclass
48
48
  def self.at(
49
49
  cinema_id,
50
- from: TZInfo::Timezone.get(TIME_ZONE).now.to_date,
50
+ from: London.today,
51
51
  to: from + 13
52
52
  )
53
53
  raise ArgumentError, 'to must not precede from' if to < from
@@ -56,7 +56,7 @@ module Cinebase
56
56
  if cinema.url.empty?
57
57
  []
58
58
  else
59
- today = TZInfo::Timezone.get(TIME_ZONE).now.to_date
59
+ today = London.today
60
60
  html = cinema_class.client.whats_on(cinema.url)
61
61
  showings = Listings.new(html, venue_url: cinema.url, today: today).showings
62
62
  performances = showings.select { |showing| (from..to).cover?(showing.date) }.map do |showing|
@@ -76,6 +76,7 @@ module Cinebase
76
76
  film_year: TitleSanitizer.film_year(title),
77
77
  language: title[LANGUAGE, 1],
78
78
  starting_at: showing.starting_at,
79
+ title: title,
79
80
  variant: variant(showing)
80
81
  }
81
82
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinebase
4
+ # Screenings for a particular audience, which some chains name in the title
5
+ module Audience
6
+ SEPARATOR = /\s*[-–:]?\s*/
7
+
8
+ # Title labels, keyed by the variant they mark
9
+ LABELS = {
10
+ 'kids' => [/\A(?:Toddler (?:Club|Kino)|Kids'? Club)\s*:\s*/i],
11
+ 'relaxed' => [/\ARelaxed(?: Screening)?\s*:\s*/i, /#{SEPARATOR}(?:Sensory|Autism) Friendly Screening\z/i],
12
+ 'dog_friendly' => [/\ADog-Friendly Screening\s*:\s*/i],
13
+ 'baby' => [/\s*\(Parent (?:&|and) Baby(?: Only Show)?\)/i],
14
+ 'members' => [/#{SEPARATOR}(?:Unlimited|MyOmnipass Member) Screening\z/i],
15
+ 'preview' => [/\s*[-–]\s*(?:Special )?Preview\z/i]
16
+ }.freeze
17
+
18
+ PATTERNS = LABELS.values.flatten.freeze
19
+
20
+ # @param [String] title raw film title
21
+ # @return [Array<String>] variants the title's labels mark
22
+ def self.variants(title)
23
+ LABELS.select { |_, patterns| patterns.any? { |pattern| title.match?(pattern) } }.keys
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require 'net/http'
5
4
 
6
5
  module Cinebase
7
6
  module Boxoffice
@@ -16,16 +15,13 @@ module Cinebase
16
15
  MOVIES_PER_REQUEST = 50
17
16
  # Listings days run from 3am to 3am, like the website's
18
17
  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
18
 
24
19
  attr_reader :base_url
25
20
 
26
21
  # @param [String] base_url the chain website, e.g. 'https://www.everymancinema.com'
27
22
  def initialize(base_url:)
28
23
  @base_url = base_url.delete_suffix('/')
24
+ @http = Http.new
29
25
  end
30
26
 
31
27
  # @return [Array<Hash>] every theatre in the website's daily build
@@ -77,25 +73,7 @@ module Cinebase
77
73
  end
78
74
 
79
75
  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
76
+ @http.get(url, headers: { 'Accept' => accept })
99
77
  end
100
78
  end
101
79
  end
@@ -28,7 +28,7 @@ module Cinebase
28
28
  # @return [Array<Cinebase::Boxoffice::Performance>] instances of the subclass
29
29
  def self.at(
30
30
  cinema_id,
31
- from: TZInfo::Timezone.get('Europe/London').now.to_date,
31
+ from: London.today,
32
32
  to: from + 13
33
33
  )
34
34
  raise ArgumentError, 'to must not precede from' if to < from
@@ -62,6 +62,7 @@ module Cinebase
62
62
  film_year: TitleSanitizer.film_year(title),
63
63
  language: showtime.language || title[/\((#{TitleSanitizer::LANGUAGES.join('|')})\)/i, 1],
64
64
  starting_at: starting_at,
65
+ title: title,
65
66
  variant: showtime.variant
66
67
  }
67
68
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinebase
4
+ Event = Data.define(:name)
5
+
6
+ # A stage show or exhibition screened in cinemas rather than a film
7
+ class Event
8
+ # Prefixes title sanitizers give these shows, keyed by the series
9
+ PREFIXES = {
10
+ 'Met Opera' => /\AMet Opera: /,
11
+ 'Royal Ballet and Opera' => /\A(?:Royal Ballet and Opera|The Royal Ballet|The Royal Opera): /,
12
+ 'National Theatre Live' => /\A(?:National Theatre Live|National Theatre|NT Live): /,
13
+ 'Exhibition on Screen' => /\AExhibition on Screen: /,
14
+ 'Bolshoi Ballet' => /\ABolshoi(?: Ballet)?: /
15
+ }.freeze
16
+
17
+ PREFIX = Regexp.union(PREFIXES.values)
18
+
19
+ # @param [String] film_name sanitized film name, e.g. "Met Opera: Tosca"
20
+ # @return [Cinebase::Event, nil]
21
+ def self.from_name(film_name)
22
+ name, = PREFIXES.find { |_, prefix| film_name.match?(prefix) }
23
+ new(name: name) if name
24
+ end
25
+
26
+ # @param [String] film_name sanitized film name, e.g. "Met Opera: Tosca"
27
+ # @return [String] the show's own name, e.g. "Tosca"
28
+ def self.strip(film_name)
29
+ film_name.sub(PREFIX, '')
30
+ end
31
+ end
32
+ end
@@ -5,15 +5,22 @@ module Cinebase
5
5
 
6
6
  # An annual festival edition a film is screened in
7
7
  class Festival
8
+ NAMES = [
9
+ 'CFF', 'Cinecity', 'FFF', 'French Film Fest UK', 'IFF', 'Into Film Festival', 'JFF', 'LDNDOCS',
10
+ 'London Palestine Film Festival', 'LPFF', 'NFF', 'Queer East', 'RFF', 'SLA', 'UKJFF',
11
+ 'Women and the World Festival'
12
+ ].freeze
13
+
8
14
  # Title prefixes naming a festival: the name, then the year when given
9
15
  PREFIXES = [
10
16
  /\A(Cine-Excess) (20\d{2}): /,
11
17
  /\A(Cinemagic) (\d{4}) -/,
12
- /\A(UKJFF) -/,
13
- /\A(CFF): /,
14
- /\A(Horror Season) (20\d{2}) /
18
+ /\A(Horror Season) (20\d{2}) /,
19
+ /\A(#{NAMES.map { |name| Regexp.escape(name) }.join('|')})(?: ((?:20)?\d{2}))?\s*[:–-]\s*/
15
20
  ].freeze
16
21
 
22
+ CENTURY = 2000
23
+
17
24
  # @param [String] title raw film title
18
25
  # @param [Integer] year the edition when the title gives none, usually the
19
26
  # screening's year
@@ -21,9 +28,18 @@ module Cinebase
21
28
  def self.from_title(title, year:)
22
29
  PREFIXES.each do |prefix|
23
30
  match = title.match(prefix)
24
- return new(name: match[1], year: Integer(match[2] || year)) if match
31
+ return new(name: match[1], year: edition(match[2]) || year) if match
25
32
  end
26
33
  nil
27
34
  end
35
+
36
+ # "26" in "Queer East 26:" is 2026
37
+ def self.edition(year)
38
+ return unless year
39
+
40
+ year = Integer(year, 10)
41
+ year < 100 ? CENTURY + year : year
42
+ end
43
+ private_class_method :edition
28
44
  end
29
45
  end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ module Cinebase
7
+ # HTTPS requests for chain gems. Retries dropped connections, never
8
+ # follows redirects and leaves response bodies out of errors, which can
9
+ # be whole HTML pages.
10
+ class Http
11
+ OPEN_TIMEOUT = 10
12
+ READ_TIMEOUT = 30
13
+ RETRIES = 2
14
+ TRANSIENT_ERRORS = [
15
+ EOFError, Errno::ECONNRESET, Errno::ECONNREFUSED, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError
16
+ ].freeze
17
+
18
+ # Waits between attempts. Tests stub it.
19
+ # @param [Integer] seconds
20
+ def self.pause(seconds)
21
+ sleep(seconds)
22
+ end
23
+
24
+ # @param [Integer] read_timeout seconds to wait for a response
25
+ # @param [Hash] headers sent with every request, e.g. a User-Agent
26
+ # @param [Boolean] keep_alive reuse one connection per host until
27
+ # {#close}, for chains that need many requests to one slow site
28
+ def initialize(read_timeout: READ_TIMEOUT, headers: {}, keep_alive: false)
29
+ @read_timeout = read_timeout
30
+ @headers = headers
31
+ @keep_alive = keep_alive
32
+ @connections = {}
33
+ end
34
+
35
+ # @param [String] url
36
+ # @param [Hash] headers
37
+ # @return [String] the response body as UTF-8
38
+ def get(url, headers: {})
39
+ perform(Net::HTTP::Get.new(URI(url), @headers.merge(headers)))
40
+ end
41
+
42
+ # @param [String] url
43
+ # @param [Hash] form fields sent form-encoded
44
+ # @param [Hash, Array] json a body sent as JSON
45
+ # @param [Hash] headers
46
+ # @return [String] the response body as UTF-8
47
+ def post(url, form: nil, json: nil, headers: {})
48
+ request = Net::HTTP::Post.new(URI(url), @headers.merge(headers))
49
+ if json
50
+ request['Content-Type'] = 'application/json'
51
+ request.body = JSON.generate(json)
52
+ else
53
+ request.set_form_data(form || {})
54
+ end
55
+ perform(request)
56
+ end
57
+
58
+ # Close kept-alive connections
59
+ # @return [nil]
60
+ def close
61
+ @connections.each_value { |connection| connection.finish if connection.started? }
62
+ @connections.clear
63
+ nil
64
+ end
65
+
66
+ private
67
+
68
+ def perform(request)
69
+ uri = request.uri
70
+ attempts = 0
71
+ begin
72
+ response = send_request(uri, request)
73
+ rescue *TRANSIENT_ERRORS
74
+ drop(uri)
75
+ attempts += 1
76
+ raise if attempts > RETRIES
77
+
78
+ self.class.pause(attempts)
79
+ retry
80
+ end
81
+
82
+ if response.is_a?(Net::HTTPSuccess)
83
+ String.new(response.body.to_s, encoding: Encoding::UTF_8)
84
+ else
85
+ raise "HTTP error #{response.code} from #{uri.host}"
86
+ end
87
+ end
88
+
89
+ def send_request(uri, request)
90
+ if @keep_alive
91
+ connection(uri).request(request)
92
+ else
93
+ start(uri) { |http| http.request(request) }
94
+ end
95
+ end
96
+
97
+ # Net::HTTP's own retries would repeat requests behind ours
98
+ def start(uri, &block)
99
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', open_timeout: OPEN_TIMEOUT,
100
+ read_timeout: @read_timeout, max_retries: 0, &block)
101
+ end
102
+
103
+ def connection(uri)
104
+ @connections[[uri.host, uri.port]] ||= start(uri)
105
+ end
106
+
107
+ def drop(uri)
108
+ connection = @connections.delete([uri.host, uri.port])
109
+ connection.finish if connection&.started?
110
+ rescue IOError
111
+ nil
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinebase
4
+ # Dates and times in London, where chain websites list showtimes
5
+ module London
6
+ ZONE = 'Europe/London'
7
+
8
+ # @return [Date] today's date in London
9
+ def self.today
10
+ zone.now.to_date
11
+ end
12
+
13
+ # @param [Time] local a London wall-clock time whose fields are read as
14
+ # is, whatever its offset
15
+ # @return [Time] the UTC time. A time in the hour repeated when clocks go
16
+ # back is read as British Summer Time.
17
+ def self.utc(local)
18
+ zone.local_to_utc(local) { |periods| periods.first }.utc
19
+ end
20
+
21
+ # @param [Time] time
22
+ # @return [Date] its date in London
23
+ def self.date(time)
24
+ zone.to_local(time).to_date
25
+ end
26
+
27
+ # @return [TZInfo::Timezone]
28
+ def self.zone
29
+ TZInfo::Timezone.get(ZONE)
30
+ end
31
+ end
32
+ end
@@ -7,10 +7,9 @@ module Cinebase
7
7
  attr_reader :dimension
8
8
  attr_reader :cinema_id
9
9
  attr_reader :cinema_name
10
- attr_reader :festival
11
- attr_reader :film_name
12
10
  attr_reader :film_year
13
11
  attr_reader :language
12
+ attr_reader :title
14
13
 
15
14
  def initialize(options)
16
15
  @booking_url = options.fetch(:booking_url, nil)
@@ -22,6 +21,7 @@ module Cinebase
22
21
  @film_year = options.fetch(:film_year, nil)
23
22
  @language = options.fetch(:language, nil)
24
23
  @time = options.fetch(:starting_at)
24
+ @title = options.fetch(:title, nil)
25
25
  @variant = options.fetch(:variant, [])
26
26
  end
27
27
 
@@ -35,7 +35,7 @@ module Cinebase
35
35
  if @time.utc?
36
36
  @time
37
37
  else
38
- TZInfo::Timezone.get('Europe/London').local_to_utc(@time)
38
+ London.utc(@time)
39
39
  end
40
40
  end
41
41
 
@@ -43,14 +43,36 @@ module Cinebase
43
43
  starting_at.to_date
44
44
  end
45
45
 
46
+ # Given, or named by the raw title
47
+ def festival
48
+ @festival || (title && Festival.from_title(title, year: starting_at.year))
49
+ end
50
+
51
+ # The show's own name when it is an Event, e.g. "Tosca"
52
+ def film_name
53
+ Event.strip(@film_name)
54
+ end
55
+
56
+ # A stage show or exhibition, which title sanitizers name as a prefix
57
+ def event
58
+ Event.from_name(@film_name)
59
+ end
60
+
46
61
  def variant
47
62
  @variant = @variant.split(' ') if @variant.is_a?(String)
48
- @variant.map(&:downcase).sort.uniq
63
+ (@variant + title_variants).map(&:downcase).sort.uniq
49
64
  end
50
65
 
51
66
  # English subtitles or open captions
52
67
  def subtitled?
53
68
  variant.include?('subtitled')
54
69
  end
70
+
71
+ private
72
+
73
+ def title_variants
74
+ audiences = title ? Audience.variants(title) : []
75
+ event ? audiences + %w(arts) : audiences
76
+ end
55
77
  end
56
78
  end
@@ -12,7 +12,9 @@ module Cinebase
12
12
  replace.each do |pattern, prefix|
13
13
  sanitized.gsub!(pattern) { |_| prefix + $1 }
14
14
  end
15
- sanitized.squeeze(' ').strip
15
+ sanitized = sanitized.squeeze(' ').strip
16
+ series = sanitized[Event::PREFIX].to_s
17
+ series + title_case(sanitized.delete_prefix(series))
16
18
  end
17
19
  end
18
20
 
@@ -32,25 +34,33 @@ module Cinebase
32
34
  # Rules every chain can share; subclasses opt in after their own patterns,
33
35
  # e.g. `[...] + COMMON_REMOVE` in #remove
34
36
  class TitleSanitizer
35
- LANGUAGES = %w(Arabic Cantonese French Hindi Kannada Korean Lithuanian
36
- Malayalam Mandarin Marathi Polish Punjabi Tamil Telugu
37
- Turkish).freeze
37
+ LANGUAGES = %w(Arabic Bengali Cantonese French Gujarati Hindi Japanese
38
+ Kannada Korean Lithuanian Malayalam Mandarin Marathi Polish
39
+ Punjabi Romanian Tamil Telugu Turkish Vietnamese).freeze
38
40
 
39
41
  # A trailing "(1996)", allowing other bracketed markers after it
40
42
  FILM_YEAR = /\s*\((1[89]\d{2}|20\d{2})\)(?=(?:\s*\([^)]*\))*\s*\z)/
41
43
 
42
44
  COMMON_REMOVE = [
43
45
  *Festival::PREFIXES, # festival prefix
46
+ *Audience::PATTERNS, # audience label
47
+ /\A(?:Opening|Closing|Centrepiece|Documentary)(?: Night)? Gala:\s*/i, # festival gala
44
48
  /\s+[23]d\b/i, # dimension
49
+ /\s*\([23]D\)/i, # bracketed dimension
45
50
  /\((#{LANGUAGES.join('|')})\)/i, # language version
46
- /\((Dubbed|Subbed|English Dub|[^)]*subtitles)\)/i, # dub or subtitle version
47
- /\(\d+(st|nd|rd|th) Anniversary\)/i, # anniversary re-release
51
+ /\((Dubbed|Subbed|English Dub(?:bed)?|[^)]*subtitles)\)/i, # dub or subtitle version
52
+ /\s*[(\[]\d+(st|nd|rd|th) Anniversary(?: 4K)?(?: Restoration)?[)\]]/i, # anniversary re-release
53
+ /\s*\(4K(?: Restoration)?\)/i, # bracketed 4K restoration
54
+ /\s*\((?:20\d{2} )?Encore\)/i, # bracketed encore
55
+ /\s*\(Recorded\)/i, # recorded, not live
56
+ /\s+-\s+Live On Stage\z/i, # filmed stage show
48
57
  /\(Re-release\)/i, # re-release
49
58
  FILM_YEAR, # film year, see .film_year
50
59
  /\s*\+\s*(?:[\w-]+\s+)*Q(?:&|\+)A\z/i, # Q&A add-on
51
60
  /\s*\+\s*Discussion\z/i, # discussion add-on
61
+ /\s*\+\s*(?:ScreenTalk|Intro(?:duction)?|Short Film)\z/i, # talk or short add-on
52
62
  /\s*\((35|70)mm\)/i, # film gauge
53
- /\s+4K\b/, # 4K restoration
63
+ /\s+4K(?: Restoration)?\b/i, # 4K restoration
54
64
  /:\s*Encore\z/i, # encore
55
65
  /\bsing-?a-?long\z/i, # singalong
56
66
  'amp;' # html ampersands
@@ -62,10 +72,54 @@ module Cinebase
62
72
  title[FILM_YEAR, 1]&.to_i
63
73
  end
64
74
 
75
+ ARTS_SEASON = %r{\s*(?:(?:20)?\d{2}[-/]\d{2})?}
76
+ ARTS_SEPARATOR = %r{(?:\s*[:/]\s*|\s+[-–]\s+)}
77
+
78
+ # Arts series named the way Event::PREFIXES expects; Met Opera first, as
79
+ # some chains list it inside an RBO season
65
80
  COMMON_REPLACE = {
66
- /Met Opera (?:Encore )?20\d{2}-\d{2}: (.*)/ => 'Met Opera: ',
67
- /RBO (?:Cinema Season )?20\d{2}-\d{2}: (.*)/ => 'Royal Ballet and Opera: ',
68
- /WORLD TOUR(.*)/ => 'World Tour'
81
+ /\A(?:RBO[^:]*:\s*)?(?:The )?Met\.?(?: Opera)?(?:\s+(?:Live|Encore))?#{ARTS_SEASON}#{ARTS_SEPARATOR}(.*)/i =>
82
+ 'Met Opera: ',
83
+ /\A(?:RBO|Royal Ballet (?:and|&) Opera|(?:The )?Royal (?:Ballet|Opera))(?:\s+(?:Live|Encore|Cinema Season))?#{ARTS_SEASON}#{ARTS_SEPARATOR}(?:The Royal (?:Ballet|Opera)\s+[-–]\s+)?(.*)/i =>
84
+ 'Royal Ballet and Opera: ',
85
+ /\A(?:NT (?:Live|Encore)(?: Encore)?|NTL|National Theatre(?: Live)?)#{ARTS_SEPARATOR}(.*)/i => 'National Theatre Live: ',
86
+ /\AExhibition on Screen#{ARTS_SEPARATOR}(.*)/i => 'Exhibition on Screen: ',
87
+ /\ABolshoi(?: Ballet)?#{ARTS_SEPARATOR}(.*)/i => 'Bolshoi Ballet: ',
88
+ /WORLD TOUR(.*)/ => 'World Tour'
69
89
  }.freeze
90
+
91
+ SMALL_WORDS = %w(a an and as at but by for from in into nor of on or the to v vs with).freeze
92
+ HONORIFICS = %w(dr mr mrs ms st).freeze
93
+ ROMAN_NUMERAL = /\A(?=[IVX])X{0,3}(?:IX|IV|V?I{0,3})\z/
94
+ VOWEL = /[AEIOUYÀ-Ý]/
95
+ OPENS_PHRASE = /[:\-–]\z/
96
+
97
+ private
98
+
99
+ # A title listed in capitals, such as "ROCKY IV", reads "Rocky IV"
100
+ def title_case(text)
101
+ if text.match?(/\p{Ll}/)
102
+ text
103
+ else
104
+ words = text.split(' ')
105
+ words.each_with_index.map do |word, index|
106
+ title_case_word(word, opens_phrase: index.zero? || words[index - 1].match?(OPENS_PHRASE))
107
+ end.join(' ')
108
+ end
109
+ end
110
+
111
+ # Acronyms such as "BTS", numerals and words with digits keep capitals
112
+ def title_case_word(word, opens_phrase:)
113
+ letters = word.gsub(/\P{L}/, '').downcase
114
+ if word.match?(/\d/) || word.match?(ROMAN_NUMERAL)
115
+ word
116
+ elsif !opens_phrase && SMALL_WORDS.include?(letters)
117
+ word.downcase
118
+ elsif !word.match?(VOWEL) && !HONORIFICS.include?(letters)
119
+ word
120
+ else
121
+ word.split('-').map { |part| part.downcase.sub(/\p{L}/, &:upcase) }.join('-')
122
+ end
123
+ end
70
124
  end
71
125
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Cinebase version
4
4
  module Cinebase
5
- VERSION = '5.7.0'
5
+ VERSION = '5.9.0'
6
6
  end
data/lib/cinebase.rb CHANGED
@@ -5,7 +5,11 @@ require 'tzinfo/data'
5
5
 
6
6
  require 'cinebase/version'
7
7
 
8
+ require 'cinebase/audience'
8
9
  require 'cinebase/cinema'
10
+ require 'cinebase/event'
9
11
  require 'cinebase/festival'
12
+ require 'cinebase/http'
13
+ require 'cinebase/london'
10
14
  require 'cinebase/performance'
11
15
  require 'cinebase/title_sanitizer'
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.7.0
4
+ version: 5.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Croll
@@ -37,6 +37,20 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest-mock
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: minitest-reporters
42
56
  requirement: !ruby/object:Gem::Requirement
@@ -149,13 +163,17 @@ files:
149
163
  - lib/cinebase/a1web/listings.rb
150
164
  - lib/cinebase/a1web/performance.rb
151
165
  - lib/cinebase/a1web/showing.rb
166
+ - lib/cinebase/audience.rb
152
167
  - lib/cinebase/boxoffice.rb
153
168
  - lib/cinebase/boxoffice/cinema.rb
154
169
  - lib/cinebase/boxoffice/client.rb
155
170
  - lib/cinebase/boxoffice/performance.rb
156
171
  - lib/cinebase/boxoffice/showtime.rb
157
172
  - lib/cinebase/cinema.rb
173
+ - lib/cinebase/event.rb
158
174
  - lib/cinebase/festival.rb
175
+ - lib/cinebase/http.rb
176
+ - lib/cinebase/london.rb
159
177
  - lib/cinebase/performance.rb
160
178
  - lib/cinebase/title_sanitizer.rb
161
179
  - lib/cinebase/version.rb