Class: Gamerom::RepoAdapters::Coolrom
- Inherits:
-
Object
- Object
- Gamerom::RepoAdapters::Coolrom
- 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', 'ps3' => 'Sony Playstation 3', 'psp' => 'Sony Playstation Portable', }.freeze
Class Method Summary collapse
- .extract_games(platform) ⇒ Object
- .game(game_link, region) ⇒ Object
- .install(game) {|[filename]| ... } ⇒ Object
- .platforms ⇒ Object
- .sections ⇒ Object
Methods included from Gamerom::RepoAdapter
Class Method Details
.extract_games(platform) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 48 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'] } game_links = [] regions.each do |region| region_game_links = page.css("div.#{region} a") game_links.append(*region_game_links.map { |game_link| game(game_link, region) }) end yield game_links, index end end |
.game(game_link, region) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 61 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 69 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. 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 |
.platforms ⇒ Object
40 41 42 |
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 40 def self.platforms PLATFORM end |
.sections ⇒ Object
44 45 46 |
# File 'lib/gamerom/repo_adapters/coolrom.rb', line 44 def self.sections ('a'..'z').to_a.unshift('0') end |