isrc 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmUyNDdhNjQ4OTQyNTBmY2U1NWI2OThiOWY0MjI2YmJmN2FlMmUwMQ==
4
+ Y2U0Mjk5N2YxYzk1MmRjOGNkMzBmNmQ0ZjZkNWFiZGZhNGQ3YjJjOA==
5
5
  data.tar.gz: !binary |-
6
- MWRkZDU1NTk4MWI1ZWVmZWJjZWM2NTQ4ZDhjOWQxOGU5MDI2YjI2Ng==
6
+ M2UzNTkxNzcxOWU5ZjhhOWM5Y2I3NDk1OGYyZWQ3YzA1ODNjYWI3Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWFmZDNhMmQ3NjNjODQ5YjRkMWE5ZWU3NWVlY2FkOWUyZjRjMGI5MjhmMjBm
10
- OGE1Y2ZkYzUxN2QxMDRhNWNlMGI4MGMyN2MyZmYzNWM1YTExNDE0Mjk4NDFi
11
- Mjg5MjZhZDQ3MTc1MDc0YmRmMDQwNzA1MGNlMzMyZTIwN2NkMjk=
9
+ ODU1OWQ5NzJjNjljYjBlYzQzNzI3MTNmMWQwMmY0MmE1ZDkzYmFjNjJiZjA5
10
+ NGJiMDJlNDNlN2RhYTdkZDU5NTU2NzgxNjlkOWRmZGUwY2NkOWI2NmZkZTdh
11
+ MTI0NTZjNzcwYjkwNzc5NmJmMGUwYWRlMDgyOTM0NTI3ZGQxNTg=
12
12
  data.tar.gz: !binary |-
13
- NGExMmMyMDRhZDc0OWYyNDljYTg3ZTI5MmIyMDYyZWE3ZjYxMWQ3ZDY3ZWJi
14
- MGQwOWQ1YzZlOGFhMDUwOWU5MzVlYjU3NzhkNmZmNWQ5ZjUwMGE5N2MxMzk1
15
- NTM0NjdjZjJmMjgyZTA2ZGQ3ZDE3MDRkYzNhN2VmZDQ0MWE3ODc=
13
+ MzgzYzc0OWMzZmUzZGI3ZDM4M2MwMTFiYzFiYTBiOWU5ZTk0ZWNjYzBmMmE1
14
+ YjY1MmEzNGY3NDI5OGExMDE0ZGI4MmRiYTQ5NTk3ZjdmZmI2YjQyYzdiYjA0
15
+ MTYzMzM4MTgwYzQ5NGM1NWU4YzgzNmEzMmQ3ZTNjNTNkZTUwNTk=
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in isrc.gemspec
4
2
  gemspec
5
3
 
4
+ gem 'mechanize', '2.7.0'
5
+
6
6
  group :test do
7
7
  gem 'guard-rspec'
8
8
  gem 'pry'
9
+ gem 'pry-nav'
9
10
 
10
11
  if RUBY_PLATFORM.downcase.include? "darwin"
11
12
  gem 'rb-fsevent'
@@ -17,7 +17,7 @@ Gem::Specification.new do |g|
17
17
 
18
18
  g.add_dependency 'httparty'
19
19
  g.add_dependency 'nokogiri'
20
- g.add_dependency 'mechanize'
20
+ g.add_dependency 'mechanize', '~> 2.7.0'
21
21
 
22
22
  g.add_development_dependency 'rspec'
23
23
  g.add_development_dependency 'guard'
@@ -6,8 +6,8 @@ require 'logger'
6
6
 
7
7
  module ISRC
8
8
  # NOTE the cont=A is crucial to getting the trick to work
9
- PPLUK_SESSION_GRAB_URL = 'http://repsearch.ppluk.com/ARSWeb/appmanager/ARS/main'
10
- PPLUK_AJAX_SEARCH_URL = 'http://repsearch.ppluk.com/ARSWeb/block/send-receive-updates'
9
+ PPLUK_SESSION_GRAB_URL = 'http://repsearch.ppluk.com/ars/faces/pages/audioSearch.jspx'
10
+ PPLUK_AJAX_SEARCH_URL = 'http://repsearch.ppluk.com/ars/faces/pages/audioSearch.jspx'
11
11
 
12
12
  def self.configure(&block)
13
13
  ISRC::Configuration.instance_eval(&block)
@@ -38,7 +38,7 @@ module ISRC
38
38
  title: shortened_title,
39
39
  artist: opts[:artist]
40
40
  })
41
- end while @matches.empty? && pieces[:all].size > pieces_count + 1
41
+ end while @matches.empty? && pieces[:all].size >= pieces_count + 1
42
42
 
43
43
  # given 'Surrender [Original Mix]' the above algorithm will submit the entire title
44
44
  # if that didn't work, strip out all meta elements and try greatest to least number of song pieces
@@ -118,12 +118,13 @@ module ISRC
118
118
  end
119
119
 
120
120
  def extract_view_state(body)
121
- body.match(/javax\.faces\.ViewState" value="([0-9])"/)[1]
121
+ # in the older PPL interface it was
122
+ # body.match(/javax\.faces\.ViewState" value="([0-9])"/)[1]
123
+ Nokogiri::HTML(body).css("span[id='f1::postscript'] input").first.attributes["value"].to_s
122
124
  end
123
125
 
124
- def extract_ice_session(body)
125
- session_info = body.match(/history-frame:([^:]+):([0-9]+)/)
126
- [session_info[1], session_info[2].to_i]
126
+ def extract_control_state(body)
127
+ body.match(/_adf\.ctrl-state=([^"]+)/)[1]
127
128
  end
128
129
 
129
130
  def timestring_to_integer(time_string)
@@ -135,26 +136,29 @@ module ISRC
135
136
  puts "Title: #{opts[:title]}\nArtist: #{opts[:artist]}"
136
137
 
137
138
  agent = Mechanize.new
139
+
138
140
  # TODO log path needs to be configurable
139
141
  agent.log = Logger.new "mech.log"
140
- agent.user_agent_alias = 'Mac Safari'
142
+ # agent.user_agent = "User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5"
141
143
 
142
144
  # grab the main page HTML to pull session vars to make the AJAX request
143
145
  isrc_session_init = agent.get(PPLUK_SESSION_GRAB_URL)
144
146
  view_state = self.extract_view_state(isrc_session_init.body)
145
- ice_session, ice_session_count = self.extract_ice_session(isrc_session_init.body)
147
+ control_state = self.extract_control_state(isrc_session_init.body)
148
+
149
+ # ice_session, ice_session_count = self.extract_ice_session(isrc_session_init.body)
146
150
 
147
151
  # add the ice_sessions cookie for the AJAX search request
148
- ice_cookie = Mechanize::Cookie.new('ice.sessions', "#{ice_session}##{ice_session_count}")
149
- ice_cookie.path = "/"
150
- ice_cookie.domain = "repsearch.ppluk.com"
151
- agent.cookie_jar.add!(ice_cookie)
152
+ # ice_cookie = Mechanize::Cookie.new('ice.sessions', "#{ice_session}##{ice_session_count}")
153
+ # ice_cookie.path = "/"
154
+ # ice_cookie.domain = "repsearch.ppluk.com"
155
+ # agent.cookie_jar.add!(ice_cookie)
152
156
 
153
157
  begin
154
- isrc_search = agent.post PPLUK_AJAX_SEARCH_URL, {
155
- 'ice.submit.partial' => 'false',
156
- # 'ice.event.target' => 'T400335881332330323192:ars_form:search_button',
157
- # 'ice.event.captured' => 'T400335881332330323192:ars_form:search_button',
158
+ isrc_search = agent.post PPLUK_AJAX_SEARCH_URL + "?_afrWindowMode=0&_afrLoop=4161608415822937&_adf.ctrl-state=#{control_state}", {
159
+ # 'ice.submit.partial' => 'false',
160
+ # 'ice.event.target' => 'T6400388221404841317247:ars_form:search_button',
161
+ # 'ice.event.captured' => 'T6400388221404841317247:ars_form:search_button',
158
162
  # 'ice.event.type' => 'onclick',
159
163
  # 'ice.event.alt' => 'false',
160
164
  # 'ice.event.ctrl' => 'false',
@@ -164,22 +168,28 @@ module ISRC
164
168
  # 'ice.event.y' => '65',
165
169
  # 'ice.event.left' => 'false',
166
170
  # 'ice.event.right' => 'false',
167
- 'T6400388221404841317247:ars_form:search_button' => 'Search',
168
- 'T6400388221404841317247:ars_form:isrc_code' => '',
169
- 'T6400388221404841317247:ars_form:rec_title_idx' => '',
170
- 'T6400388221404841317247:ars_form:rec_title' => opts[:title],
171
- 'T6400388221404841317247:ars_form:rec_band_artist_idx' => '',
172
- 'T6400388221404841317247:ars_form:rec_band_artist' => opts[:artist],
173
- 'javax.faces.RenderKitId' => 'ICEfacesRenderKit',
171
+ # 'T6400388221404841317247:ars_form:search_button' => 'Search',
172
+ # 'T6400388221404841317247:ars_form:isrc_code' => '',
173
+ # 'T6400388221404841317247:ars_form:rec_title_idx' => '',
174
+ 'pt1:rec_title' => opts[:title],
175
+ # 'T6400388221404841317247:ars_form:rec_band_artist_idx' => '',
176
+ "pt1:isrc_code" => "",
177
+ 'pt1:rec_band_artist' => opts[:artist],
178
+ # 'javax.faces.RenderKitId' => 'ICEfacesRenderKit',
174
179
  'javax.faces.ViewState' => view_state,
175
- 'icefacesCssUpdates' => '',
176
- 'T6400388221404841317247:ars_form' => '',
177
- 'ice.session' => ice_session,
178
- 'ice.view' => view_state,
179
- 'ice.focus' => '',
180
+ "org.apache.myfaces.trinidad.faces.FORM" => "f1",
181
+ "event" => "pt1:search_button",
182
+ # 'icefacesCssUpdates' => '',
183
+ # 'T6400388221404841317247:ars_form' => '',
184
+ # 'ice.session' => ice_session,
185
+ # 'ice.view' => view_state,
186
+ # 'ice.focus' => 'T6400388221404841317247:ars_form:search_button',
180
187
 
181
188
  # the rand is 19 characters long in the browser's HTTP requests
182
- 'rand' => sprintf('%1.17f', rand)
189
+ # 'rand' => sprintf('%1.17f', rand)
190
+
191
+ "oracle.adf.view.rich.DELTAS" => "{pt1:searchResultsTable={viewportSize=3,rows=2}}",
192
+ "event.pt1:search_button" => '<m xmlns="http://oracle.com/richClient/comm"><k v="type"><s>action</s></k></m>'
183
193
  }
184
194
  rescue Mechanize::ResponseCodeError => e
185
195
  agent.log.error "Error submitting AJAX request: #{e.page.body}"
@@ -188,7 +198,7 @@ module ISRC
188
198
  # creates an array representation of the table:
189
199
  # artist, title, isrc, rights holder, released, time
190
200
 
191
- isrc_table = Nokogiri::HTML(isrc_search.body).css("table[id='T6400388221404841317247:ars_form:searchResultsTable'] tbody tr")
201
+ isrc_table = Nokogiri::HTML(isrc_search.body).css("div[id='pt1:searchResultsTable::db'] table tr")
192
202
  isrc_table.map do |m|
193
203
  columns = m.css('td')
194
204
 
@@ -1,3 +1,3 @@
1
1
  module ISRC
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -8,6 +8,9 @@ describe ISRC do
8
8
  it "should correctly handle multiple search results" do
9
9
  isrc.retrieve artist: 'Coldplay', title: 'Clocks'
10
10
  isrc.match(time:'5:08')[:isrc].should == 'GBAYE0200771'
11
+
12
+ isrc.retrieve artist: 'Normalites', title: 'The Sun Rising'
13
+ isrc.match(time:'5:10')[:isrc].should == 'GBDEX1000302'
11
14
  end
12
15
 
13
16
  it "should correctly handle a single search result" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bianco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-06 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: mechanize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 2.7.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 2.7.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.1.11
123
+ rubygems_version: 2.4.6
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Pull ISRC codes from PPLK UK's database