Class: Gamerom::RepoAdapters::Romnation

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

Overview

Romnation - An adapter for the ROMNation repository website

Constant Summary collapse

PLATFORM =
{
  'amstrad' => 'Amstrad',
  'atari2600' => 'Atari 2600',
  'atari5200' => 'Atari 5200',
  'atari7800' => 'Atari 7800',
  'atarijaguar' => 'Atari Jaguar',
  'atarilynx' => 'Atari Lynx',
  'colecovision' => 'ColecoVision',
  'commodore64' => 'Commodore 64',
  'gamegear' => 'Game Gear',
  'gb' => 'Game Boy',
  'gbc' => 'Game Boy Color',
  'gcdvectrex' => 'Vectrex',
  'genesis' => 'Genesis',
  'intellivision' => 'Intellivision',
  'mame' => 'MAME',
  'msx1' => 'MSX',
  'msx2' => 'MSX2',
  'mtx' => 'MTX',
  'n64' => 'N64',
  'neogeocd' => 'Neo Geo CD',
  'neogeopocket' => 'Neo Geo Pocket',
  'nes' => 'NES',
  'oric' => 'Oric',
  'pce' => 'PC Engine',
  'radioshackcolorcomputer' => 'TRS-80',
  'samcoupe' => 'SAM Coupé',
  'segacd' => 'Sega CD',
  'segamastersystem' => 'Master System',
  'snes' => 'SNES',
  'thompsonmo5' => 'Thomson MO5',
  'virtualboy' => 'Virtual Boy',
  'watara' => 'Watara Supervision',
  'wonderswan' => 'WonderSwan',
}.freeze

Class Method Summary collapse

Methods included from Gamerom::RepoAdapter

games, nokogiri_get

Class Method Details

.extract_games(platform) ⇒ Object



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

def self.extract_games(platform)
  sections.each_with_index do |section, index|
    pages = extract_pages(platform, section)
    yield extract_games_from_section_pages(platform, section, pages), index
  end
end

.extract_games_from_section_pages(platform, section, pages) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/gamerom/repo_adapters/romnation.rb', line 72

def self.extract_games_from_section_pages(platform, section, pages)
  pages.reduce([]) do |section_games, p|
    page = nokogiri_get("https://www.romnation.net/srv/roms/#{platform}/#{section}/page-#{p}_sort-title.html")
    games_links = page.css('table.listings td.title a')
    section_games.append(*games_links.map { |game_link| game(game_link) })
  end
end

.extract_pages(platform, section) ⇒ Object



65
66
67
68
69
70
# File 'lib/gamerom/repo_adapters/romnation.rb', line 65

def self.extract_pages(platform, section)
  page = nokogiri_get("https://www.romnation.net/srv/roms/#{platform}/#{section}/sort-title.html")
  pages = ['1']
  pages = page.css('.pagination').first.css('a').map(&:text).map(&:strip).reject(&:empty?) unless page.css('.pagination').empty?
  pages
end

.game(game_link) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/gamerom/repo_adapters/romnation.rb', line 80

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

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

Yields:

  • ([filename])


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/gamerom/repo_adapters/romnation.rb', line 90

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'
  page = agent.get("https://www.romnation.net/download/rom/#{game.id}")

  response = nil
  agent.progressbar do
    response = page.link_with(text: 'Download This Rom').click
  end

  return unless response.code.to_i == 200

  filename = CGI.unescape(response.filename.split('_host=').first)
  FileUtils.mkdir_p(game.filepath)
  response.save!("#{game.filepath}/#{filename}")
  yield [filename]
end

.platformsObject



50
51
52
# File 'lib/gamerom/repo_adapters/romnation.rb', line 50

def self.platforms
  PLATFORM
end

.sectionsObject



54
55
56
# File 'lib/gamerom/repo_adapters/romnation.rb', line 54

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