class UncleKryon::Hacker

Constants

HAX_DIRNAME
HAX_KRYON_FILENAME
TRAIN_DIRNAME
TRAIN_KRYON_FILENAME

Attributes

hax_dirname[RW]
hax_kryon_filename[RW]
no_clobber[RW]
no_clobber?[RW]
train_dirname[RW]
train_kryon_filename[RW]

Public Class Methods

new(hax_dirname: HAX_DIRNAME,hax_kryon_filename: HAX_KRYON_FILENAME,no_clobber: false, train_dirname: TRAIN_DIRNAME,train_kryon_filename: TRAIN_KRYON_FILENAME,**options) click to toggle source
# File lib/unclekryon/hacker.rb, line 40
def initialize(hax_dirname: HAX_DIRNAME,hax_kryon_filename: HAX_KRYON_FILENAME,no_clobber: false,
      train_dirname: TRAIN_DIRNAME,train_kryon_filename: TRAIN_KRYON_FILENAME,**options)
  @hax_dirname = hax_dirname
  @hax_kryon_filename = hax_kryon_filename
  @no_clobber = no_clobber
  @train_dirname = train_dirname
  @train_kryon_filename = train_kryon_filename
end

Public Instance Methods

build_hax_kryon_aums_filepath(release) click to toggle source
# File lib/unclekryon/hacker.rb, line 287
def build_hax_kryon_aums_filepath(release)
  return build_hax_kryon_filepath('aums',release)
end
build_hax_kryon_filepath(hax,release) click to toggle source
# File lib/unclekryon/hacker.rb, line 291
def build_hax_kryon_filepath(hax,release)
  raise 'Release (year) arg is nil' if release.nil?

  fn = @hax_kryon_filename.clone
  fn = fn.gsub('<hax>',hax)
  fn = fn.gsub('<release>',release.to_s)

  return File.join(@hax_dirname,fn)
end
build_train_kryon_filepath() click to toggle source
# File lib/unclekryon/hacker.rb, line 301
def build_train_kryon_filepath
  return File.join(@train_dirname,@train_kryon_filename)
end
create_kryon_aum_year_album_parser(date,year=nil,index=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 49
def create_kryon_aum_year_album_parser(date,year=nil,index=nil)
  pd = parse_date(date,year,index)
  date = pd[:date]
  index = pd[:index]
  year = pd[:year]

  # Try the yaml file
  artist = ArtistDataData.load_file(build_hax_kryon_aums_filepath(year))
  release = artist.releases[year]

  if release.nil?
    # Try manually from the site
    year_parser = create_kryon_aum_year_parser(year)
    artist = year_parser.artist
    release = year_parser.parse_site
    raise "Release[#{year}] does not exist" if release.nil?
  end

  album = find_kryon_aum_year_album(artist,date,year,index)[0]
  album_parser = KryonAumYearAlbumParser.new(artist,album.url)

  album_parser.album = album
  album_parser.trainers.filepath = build_train_kryon_filepath

  return album_parser
end
create_kryon_aum_year_parser(year) click to toggle source
# File lib/unclekryon/hacker.rb, line 76
def create_kryon_aum_year_parser(year)
  year_parser = KryonAumYearParser.new(year)

  year_parser.trainers.filepath = build_train_kryon_filepath

  return year_parser
end
find_kryon_aum_year_album(artist,date,year=nil,index=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 84
def find_kryon_aum_year_album(artist,date,year=nil,index=nil)
  album = nil
  albums = []

  artist.albums.values.each_with_index do |a,i|
    date_begin = Util.parse_date_s(a.date_begin)
    date_end = Util.parse_date_s(a.date_end)

    if (date_begin && ((date_end  && date >= date_begin && date <= date_end) ||
                       (!date_end && date == date_begin)))
      albums.push([a,i])
    end
  end

  if !albums.empty?
    if index >= 0 && index < albums.length
      album = albums[index]
    else
      raise "Invalid album ordinal number[#{index + 1}]"
    end
  end

  raise "Invalid album[#{date}]" if album.nil?

  return album
end
parse_date(date,year=nil,index=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 111
def parse_date(date,year=nil,index=nil)
  if !date.is_a?(Date)
    ds = date.split(':')
    date = ds[0]

    if index.nil?
      index = ds
      index = (index.length <= 1) ? 0 : (index[1].to_i - 1)
    end

    begin
      new_date = Date.strptime(date,'%Y.%m.%d')
    rescue ArgumentError
      new_date = Date.strptime(date,'%m.%d')

      if !year.nil?
        new_date = Date.new(year.to_i,new_date.month,new_date.day)
      end
    end

    date = new_date
  elsif index.nil?
    index = 0
  end

  if year.nil?
    # year is actually the release's title, so only override it if have to
    year = date.year.to_s
  end

  return {date: date,index: index,year: year}
end
parse_kryon_aum_year(year) click to toggle source
# File lib/unclekryon/hacker.rb, line 144
def parse_kryon_aum_year(year)
  year_parser = create_kryon_aum_year_parser(year)
  release = year_parser.parse_site

  if @no_clobber
    puts release.to_s
  else
    year_parser.artist.save_to_file(build_hax_kryon_aums_filepath(year))
  end
end
parse_kryon_aum_year_album(date,year=nil,index=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 155
def parse_kryon_aum_year_album(date,year=nil,index=nil)
  pd = parse_date(date,year,index)
  date = pd[:date]
  index = pd[:index]
  year = pd[:year]

  album_parser = create_kryon_aum_year_album_parser(date,year,index)
  album_parser.parse_site

  if @no_clobber
    puts album_parser.album.to_s
  else
    album_parser.artist.save_to_file(build_hax_kryon_aums_filepath(year))
  end
end
parse_kryon_aum_year_albums(year,begin_album=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 171
def parse_kryon_aum_year_albums(year,begin_album=nil)
  if !begin_album.nil?
    pd = parse_date(begin_album,year)
    begin_album = pd[:date]
    index = pd[:index]
    year = pd[:year]
  end

  # Try the yaml file
  artist = ArtistDataData.load_file(build_hax_kryon_aums_filepath(year))
  release = artist.releases[year]
  updated_on = nil

  if release.nil?
    # Try manually from the site
    year_parser = create_kryon_aum_year_parser(year)
    artist = year_parser.artist
    release = year_parser.parse_site
    raise "Release[#{year}] does not exist" if release.nil?
    updated_on = release.updated_on
  end

  album_parser = KryonAumYearAlbumParser.new
  album_parser.trainers.filepath = build_train_kryon_filepath
  album_parser.updated_on = updated_on unless updated_on.nil?

  albums = release.albums

  if !begin_album.nil?
    album_index = find_kryon_aum_year_album(artist,begin_album,year,index)[1]
    albums = albums[album_index..-1]
  end

  albums.each do |album_id|
    album = artist.albums[album_id]
    log.info("Hacking album[#{album.date_begin},#{album.date_end},#{album.title}]")
    #album = album_parser.parse_site(artist,album.url)
  end

  if @no_clobber
    puts release.to_s
  else
    artist.save_to_file(build_hax_kryon_aums_filepath(year))
  end
end
train_kryon_aum_year(year) click to toggle source
# File lib/unclekryon/hacker.rb, line 217
def train_kryon_aum_year(year)
  year_parser = create_kryon_aum_year_parser(year)
  year_parser.training = true
  year_parser.parse_site

  if @no_clobber
    puts year_parser.trainers.to_s
  else
    year_parser.trainers.save_to_file
  end
end
train_kryon_aum_year_album(date,year=nil,index=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 229
def train_kryon_aum_year_album(date,year=nil,index=nil)
  album_parser = create_kryon_aum_year_album_parser(date,year,index)
  album_parser.training = true
  album_parser.parse_site

  if @no_clobber
    puts album_parser.trainers.to_s
  else
    album_parser.trainers.save_to_file
  end
end
train_kryon_aum_year_albums(year,begin_album=nil) click to toggle source
# File lib/unclekryon/hacker.rb, line 241
def train_kryon_aum_year_albums(year,begin_album=nil)
  if !begin_album.nil?
    pd = parse_date(begin_album,year)
    begin_album = pd[:date]
    index = pd[:index]
    year = pd[:year]
  end

  # Try the yaml file
  artist = ArtistDataData.load_file(build_hax_kryon_aums_filepath(year))
  release = artist.releases[year]

  if release.nil?
    # Try manually from the site
    year_parser = create_kryon_aum_year_parser(year)
    artist = year_parser.artist
    release = year_parser.parse_site
    raise "Release[#{year}] does not exist" if release.nil?
  end

  albums = release.albums

  if !begin_album.nil?
    album_index = find_kryon_aum_year_album(artist,begin_album,year,index)[1]
    albums = albums[album_index..-1]
  end

  albums.each do |album_id|
    album = artist.albums[album_id]

    album_parser = KryonAumYearAlbumParser.new
    album_parser.album = album
    album_parser.trainers.filepath = build_train_kryon_filepath
    album_parser.training = true

    log.info("Training album[#{album.date_begin},#{album.date_end},#{album.title}]")
    #album = album_parser.parse_site(artist,album.url)

    if @no_clobber
      puts album_parser.trainers.to_s
    else
      album_parser.trainers.save_to_file
    end
  end
end