Class: Gamerom::RepoAdapters::Coolrom

Inherits:
Object
  • Object
show all
Extended by:
Gamerom::RepoAdapter
Defined in:
lib/gamerom/repo_adapters/coolrom.rb

Overview

Coolrom - An adapter for the CoolROM repository website

Constant Summary collapse

PLATFORM =
{
  'atari2600' => 'Atari 2600',
  'atari5200' => 'Atari 5200',
  'atari7800' => 'Atari 7800',
  'atarijaguar' => 'Atari Jaguar',
  'atarilynx' => 'Atari Lynx',
  'c64' => 'Commodore 64',
  'cps1' => 'CPS1',
  'cps2' => 'CPS2',
  'mame' => 'MAME',
  'namcosystem22' => 'Namco System 22',
  'neogeo' => 'Neo Geo',
  'neogeocd' => 'Neo Geo CD',
  'neogeopocket' => 'Neo Geo Pocket',
  'segacd' => 'Sega CD',
  'dc' => 'Sega Dreamcast',
  'gamegear' => 'Sega Game Gear',
  'genesis' => 'Sega Genesis',
  'mastersystem' => 'Sega Master System',
  'model2' => 'Sega Model 2',
  'saturn' => 'Sega Saturn',
  'psx' => 'Sony Playstation',
  'ps2' => 'Sony Playstation 2',
  'psp' => 'Sony Playstation Portable',
}.freeze

Class Method Summary collapse

Methods included from Gamerom::RepoAdapter

games, nokogiri_get

Class Method Details

.extract_games(platform) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 47

def self.extract_games(platform)
  sections.each_with_index do |section, index|
    page = nokogiri_get("https://coolrom.com.au/roms/#{platform}/#{section}/")
    regions = page.css('input.region').map { |i| i['name'] }
    regions.each do |region|
      game_links = page.css("div.#{region} a")
      yield game_links.map { |game_link| game(game_link, region) }, index
    end
  end
end

.game(game_link, region) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 58

def self.game(game_link, region)
  {
    id: game_link['href'].split('/')[3].to_i,
    name: game_link.text,
    region: region,
  }
end

.install(game) {|[filename]| ... } ⇒ Object

Yields:

  • ([filename])


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 66

def self.install(game)
  agent = Mechanize.new
  agent.pluggable_parser.default = Mechanize::Download
  agent.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'

  response = nil
  agent.progressbar do
    response = agent.get("https://coolrom.com.au/downloader.php?id=#{game.id}")
  end

  return unless response.code.to_i == 200

  filename = response.filename
  FileUtils.mkdir_p(game.filepath)
  response.save!("#{game.filepath}/#{filename}")
  yield [filename]
end

.platformsObject



39
40
41
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 39

def self.platforms
  PLATFORM
end

.sectionsObject



43
44
45
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 43

def self.sections
  ('a'..'z').to_a.unshift('0')
end