Class: UncleKryon::KryonAumYearParser
- Inherits:
-
Object
- Object
- UncleKryon::KryonAumYearParser
- Includes:
- Logging
- Defined in:
- lib/unclekryon/parsers/kryon_aum_year_parser.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#exclude_album ⇒ Object
Returns the value of attribute exclude_album.
-
#release ⇒ Object
Returns the value of attribute release.
-
#title ⇒ Object
Returns the value of attribute title.
-
#trainers ⇒ Object
Returns the value of attribute trainers.
-
#training ⇒ Object
(also: #training?)
Returns the value of attribute training.
-
#updated_on ⇒ Object
readonly
Returns the value of attribute updated_on.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .fix_kryon_year_title(year) ⇒ Object
- .get_kryon_year_mirrors(year) ⇒ Object
- .get_kryon_year_url(year, url_version = 2) ⇒ Object
- .parse_kryon_date(date, year = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(title = nil, url = nil, artist = ArtistDataData.new(), training: false, train_filepath: nil, updated_on: nil, **options) ⇒ KryonAumYearParser
constructor
A new instance of KryonAumYearParser.
- #parse_date_cell(cells, album) ⇒ Object
- #parse_language_cell(cells, album) ⇒ Object
- #parse_location_cell(cells, album) ⇒ Object
- #parse_site(title = nil, url = nil, artist = nil) ⇒ Object
- #parse_topic_cell(cells, album) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(title = nil, url = nil, artist = ArtistDataData.new(), training: false, train_filepath: nil, updated_on: nil, **options) ⇒ KryonAumYearParser
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 40 def initialize(title=nil,url=nil,artist=ArtistDataData.new(),training: false,train_filepath: nil, updated_on: nil,**) @artist = artist @exclude_album = false @title = title @trainers = Trainers.new(train_filepath) @training = training @updated_on = Util.format_datetime(DateTime.now) if Util.empty_s?(updated_on) @url = Util.empty_s?(url) ? self.class.get_kryon_year_url(title) : url end |
Instance Attribute Details
#artist ⇒ Object
Returns the value of attribute artist.
29 30 31 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 29 def artist @artist end |
#exclude_album ⇒ Object
Returns the value of attribute exclude_album.
30 31 32 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 30 def exclude_album @exclude_album end |
#release ⇒ Object
Returns the value of attribute release.
31 32 33 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 31 def release @release end |
#title ⇒ Object
Returns the value of attribute title.
32 33 34 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 32 def title @title end |
#trainers ⇒ Object
Returns the value of attribute trainers.
33 34 35 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 33 def trainers @trainers end |
#training ⇒ Object Also known as: training?
Returns the value of attribute training.
34 35 36 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 34 def training @training end |
#updated_on ⇒ Object (readonly)
Returns the value of attribute updated_on.
35 36 37 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 35 def updated_on @updated_on end |
#url ⇒ Object
Returns the value of attribute url.
36 37 38 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 36 def url @url end |
Class Method Details
.fix_kryon_year_title(year) ⇒ Object
386 387 388 389 390 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 386 def self.fix_kryon_year_title(year) year = '2002_05' if year == '2002-2005' return year end |
.get_kryon_year_mirrors(year) ⇒ Object
392 393 394 395 396 397 398 399 400 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 392 def self.get_kryon_year_mirrors(year) year = fix_kryon_year_title(year) mirrors = { 'original' => "https://www.kryon.com/freeAudio_folder/#{year}_freeAudio.html" } return mirrors end |
.get_kryon_year_url(year, url_version = 2) ⇒ Object
402 403 404 405 406 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 402 def self.get_kryon_year_url(year,url_version=2) year = fix_kryon_year_title(year) return "https://www.kryon.com/freeAudio_folder/mobile_pages/#{year}_freeAudio_m.html" end |
.parse_kryon_date(date, year = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 51 def self.parse_kryon_date(date,year=nil) # Don't modify args and clean them up so can use /\s/ instead of /[[:space:]]/ date = Util.clean_data(date.clone) year = Util.clean_data(year.clone) # Fix misspellings and/or weird shortenings date.gsub!(/Feburary/i,'February') # "Feburary 2-13, 2017" date.gsub!(/SEPT(\s+|\-)/i,'Sep\1') # "SEPT 29 - OCT 9, 2017", "Sept-Oct 2015" date.gsub!(/Septembe\s+/i,'September ') # "Septembe 4, 2016" date.gsub!(/Ocotber/i,'October') # "Ocotber 10, 2015" comma = date.include?(',') ? ',' : '' # "May 6 2017" r = Array.new(2) begin if date.include?('-') case date # "Sept-Oct 2015" when /\A[[:alpha:]]+\s*\-\s*[[:alpha:]]+\s+[[:digit:]]+\z/ r[1] = Date.strptime(date,'%b-%b %Y') r[0] = Date.strptime(date,'%b') r[0] = Date.new(r[1].year,r[0].month,r[0].day) # "4/28/12 - 4/29/12" when %r{\A[[:digit:]]+\s*/\s*[[:digit:]]+\s*/\s*[[:digit:]]+\s*\-} date = date.split(/\s*-\s*/) r[0] = Date.strptime(date[0],'%m/%d/%y') r[1] = Date.strptime(date[1],'%m/%d/%y') # "10-17 to 11-18, 2012" when /\A[[:digit:]]+\s*\-\s*[[:digit:]]+\s+to\s+ [[:digit:]]+\s*\-\s*[[:digit:]]+\s*,\s* [[:digit:]]+\z/xi date = date.split(/\s*to\s*/i) r[1] = Date.strptime(date[1],'%m-%d, %Y') r[0] = Date.strptime(date[0],'%m-%d') r[0] = Date.new(r[1].year,r[0].month,r[0].day) else case date # "SEPT 29 - OCT 9, 2017", "May 31-June 1, 2014" when /\A[[:alpha:]]+\s+[[:digit:]]+\s*\-\s*[[:alpha:]]+\s+[[:digit:]]+[\,\s]+[[:digit:]]+\z/ date = date.gsub(/\s*\-\s*/,'-') r1f = "%B %d-%B %d#{comma} %Y" # "OCT 25 - NOV 3" (2014) when /\A[[:alpha:]]+\s+[[:digit:]]+\s*\-\s*[[:alpha:]]+\s+[[:digit:]]+\z/ date = date.gsub(/\s*\-\s*/,'-') r1f = '%B %d-%B %d' if !year.nil? date << ", #{year}" r1f << ', %Y' end # "December 12-13" when /\A[[:alpha:]]+\s+[[:digit:]]+\s*\-\s*[[:digit:]]+\z/ date = date.gsub(/\s*\-\s*/,'-') # "September 16 - 2018" if date =~ /-[[:digit:]]{4}\z/ r1f = '%B %d-%Y' else r1f = '%B %d-%d'.dup if !year.nil? date << ", #{year}" r1f << ', %Y' end end # "June 30-July 1-2018" when /\A[[:alpha:]]+\s+[[:digit:]]+\s*\-\s* [[:alpha:]]+\s+[[:digit:]]+\s*\-\s* [[:digit:]]+\z/x date = date.gsub(/\s*\-\s*/,'-') r1f = '%B %d-%B %d-%Y' # "September 7 & 9-2018" when /\A[[:alpha:]]+\s+[[:digit:]]+\s+\&\s+[[:digit:]]+\s*\-\s*[[:digit:]]+\z/ date = date.gsub(/\s*\-\s*/,'-') r1f = '%B %d & %d-%Y' else # "OCT 27 - 28 - 29, 2017"; remove spaces around dashes date.gsub!(/\s+\-\s+/,'-') # "June 7-9-16-17" & "June 9-10-11-12" if date =~ /\A[[:alpha:]]+\s*[[:digit:]]+\-[[:digit:]]+\-[[:digit:]]+\-[[:digit:]]+\z/ r1f = '%B %d-%d-%d-%d' if !year.nil? date << ", #{year}" r1f << ', %Y' end else # "MAY 15-16-17, 2017" and "January 7-8, 2017" r1f = (date =~ /\-.*\-/) ? "%B %d-%d-%d#{comma} %Y" : "%B %d-%d#{comma} %Y" end end r[1] = Date.strptime(date,r1f) r[0] = Date.strptime(date,'%B %d') r[0] = Date.new(r[1].year,r[0].month,r[0].day) end elsif date.include?('/') # "1/7/2012" if date =~ %r{\A[[:digit:]]+\s*/\s*[[:digit:]]+\s*/\s*[[:digit:]]+\z} date = date.gsub(/\s+/,'') r[0] = Date.strptime(date,'%m/%d/%Y') r[1] = nil else # "JULY/AUG 2017" r[1] = Date.strptime(date,'%b/%b %Y') r[0] = Date.strptime(date,'%b') r[0] = Date.new(r[1].year,r[0].month,r[0].day) end else case date # "April 11, 12, 2015" when /\A[[:alpha:]]+\s*[[:digit:]]+\s*,\s*[[:digit:]]+\s*,\s*[[:digit:]]+\z/ r[1] = Date.strptime(date,'%B %d, %d, %Y') r[0] = Date.strptime(date,'%B %d') r[0] = Date.new(r[1].year,r[0].month,r[0].day) # "March, 2014" when /\A[[:alpha:]]+\s*,\s*[[:digit:]]+\z/ r[0] = Date.strptime(date,'%B, %Y') r[1] = nil else r[0] = Date.strptime(date,"%B %d#{comma} %Y") r[1] = nil end end rescue ArgumentError => e Log.instance.fatal("Invalid Date: '#{date}'",error: e) raise end r[0] = (!r[0].nil?) ? Util.format_date(r[0]) : '' r[1] = (!r[1].nil?) ? Util.format_date(r[1]) : '' return r end |
Instance Method Details
#parse_date_cell(cells, album) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 267 def parse_date_cell(cells,album) # Get url from date because sometimes there is not a topic return false if cells.length <= 1 return false if (cell = cells[1]).nil? return false if (cell = cell.css('a')).nil? return false if cell.length < 1 # For 2014 albums cells = cell cell = nil cells.each do |c| if !c.nil? && !Util.empty_s?(c.content) && !c['href'].nil? cell = c break end end return false if cell.nil? r_date = self.class.parse_kryon_date(Util.clean_data(cell.content),@title) album.date_begin = r_date[0] album.date_end = r_date[1] album.url = Util.clean_link(@release.url,cell['href']) return false if album.date_begin.empty? || album.url.empty? return true end |
#parse_language_cell(cells, album) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 297 def parse_language_cell(cells,album) return false if cells.length <= 4 return false if (cell = cells[4]).nil? return false if (cell = cell.content).nil? cell = Util.clean_data(cell) # For the official site, they always have English, so add it if not present album.languages = Iso.languages.find_by_kryon(cell,add_english: true) return false if album.languages.nil? || album.languages.empty? return true end |
#parse_location_cell(cells, album) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 310 def parse_location_cell(cells,album) return false if cells.length <= 3 return false if (cell = cells[3]).nil? return false if (cell = cell.content).nil? return false if cell =~ /[[:space:]]*RADIO[[:space:]]+SHOW[[:space:]]*/ # 2014 return false if (cell = Util.clean_data(cell)).empty? album.locations = Iso.find_kryon_locations(cell) return false if album.locations.nil? || album.locations.empty? return true end |
#parse_site(title = nil, url = nil, artist = nil) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 190 def parse_site(title=nil,url=nil,artist=nil) @artist = artist unless artist.nil? @title = title unless title.nil? @url = Util.empty_s?(url) ? self.class.get_kryon_year_url(@title) : url raise ArgumentError,'Artist cannot be nil' if @artist.nil? raise ArgumentError,'Title cannot be empty' if @title.nil? || (@title = @title.strip).empty? raise ArgumentError,'URL cannot be empty' if @url.nil? || (@url = @url.strip).empty? @release = @artist.releases[@title] @trainers.load_file if @release.nil? @release = ReleaseData.new @release.mirrors = self.class.get_kryon_year_mirrors(@title) @release.title = @title @release.updated_on = @updated_on @release.url = @url @artist.releases[@title] = @release end doc = Nokogiri::HTML(URI(@release.url).open,nil,'utf-8') # Force utf-8 encoding row_pos = 1 rows = doc.css('table tr tr') rows.each do |row| next if row.nil? next if (cells = row.css('td')).nil? album = AlbumData.new album.updated_on = @updated_on @exclude_album = false # There is always a date cell has_date_cell = parse_date_cell(cells,album) # Sometimes there is not a topic, location, or language cell, but not all 3! # - Put || last because of short-circuit ||! # - For some reason, "or" does not work (even though it is supposed to be non-short-circuit) has_other_cell = parse_topic_cell(cells,album) has_other_cell = parse_location_cell(cells,album) || has_other_cell has_other_cell = parse_language_cell(cells,album) || has_other_cell if !has_date_cell || !has_other_cell || @exclude_album # - If it doesn't have any cells, it is probably javascript or something else, so don't log it # - If @exclude_album, then it has already been logged, so don't log it if (!has_date_cell && has_other_cell) || (has_date_cell && !@exclude_album) log.warn("Excluding album: #{row_pos},#{album.date_begin},#{album.date_end},#{album.title}," \ "#{album.locations},#{album.languages}") row_pos += 1 end next end # Is it actually old or new? if @artist.albums.key?(album.url) && album == @artist.albums[album.url] album.updated_on = @artist.albums[album.url].updated_on end album.url = Util.fix_link(album.url) @artist.albums[album.url] = album if !@release.albums.include?(album.url) @release.albums.push(album.url) @release.updated_on = @updated_on end row_pos += 1 end return @release end |
#parse_topic_cell(cells, album) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/unclekryon/parsers/kryon_aum_year_parser.rb', line 324 def parse_topic_cell(cells,album) return false if cells.length <= 2 return false if (cell = cells[2]).nil? return false if (cell = cell.css('a')).nil? return false if cell.length < 1 # For 2017 "San Jose, California (3)" cells = cell cell = nil cells.each do |c| if !c.nil? && !Util.empty_s?(c.content) cell = c break end end return false if cell.nil? album.title = Util.fix_shortwith_text(Util.clean_data(cell.content)) exclude_topics = / GROUP[[:space:]]+PHOTO| PLEASE[[:space:]]+READ /ix if album.title =~ exclude_topics log.warn("Excluding album: Topic[#{album.title}]") @exclude_album = true return false end # Sometimes, the date cell's href is an image (See 2016 'Las Vegas, NV - "Numerology" - (3)') good_urls = / \.html?[[:space:]]*\z /ix date_url = album.url topic_url = Util.clean_link(@release.url,cell['href']) # Sometimes, the date cell's href is wrong (See 2016 '"Five Concepts for the New Human" (2)') if album.url !~ good_urls || (!Util.empty_s?(topic_url) && date_url != topic_url) album.url = topic_url log.warn("Using topic cell's href for URL: #{File.basename(date_url)}=>#{File.basename(album.url)}") if Util.empty_s?(album.url) msg = "Date and topic cells' hrefs are empty: Topic[#{album.title}]" if DevOpts.instance.dev? raise msg else log.warn(msg) end return false end end return false if album.title.empty? return true end |