Class: Gamerom::RepoAdapters::Vimm

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

Overview

Vimm - An adapter for the Vimm’s Lair repository website

Constant Summary collapse

PLATFORM =
{
  'Dreamcast' => 'Dreamcast',
  'DS' => 'Nintendo DS',
  'GameCube' => 'GameCube',
  'GB' => 'Game Boy',
  'GBA' => 'Game Boy Advance',
  'GBC' => 'Game Boy Color',
  'Genesis' => 'Genesis',
  'N64' => 'Nintendo 64',
  'NES' => 'Nintendo',
  'PS1' => 'PlayStation',
  'PS2' => 'PlayStation 2',
  'PS3' => 'PlayStation 3',
  'PSP' => 'PlayStation Portable',
  'Saturn' => 'Saturn',
  'SNES' => 'Super Nintendo',
  'Wii' => 'Wii',
  'WiiWare' => 'WiiWare',
}.freeze

Class Method Summary collapse

Methods included from Gamerom::RepoAdapter

games, nokogiri_get

Class Method Details

.extract_games(platform) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/gamerom/repo_adapters/vimm.rb', line 41

def self.extract_games(platform)
  sections.each_with_index do |section, index|
    page = nokogiri_get("https://vimm.net/vault/?p=list&system=#{platform}&section=#{section}")
    game_links = page.css('table.hovertable td:first-child a:first-child')
    yield game_links.map { |game_link| game(game_link) }, index
  end
end

.game(game_link) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/gamerom/repo_adapters/vimm.rb', line 49

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

.install(game) {|filenames| ... } ⇒ Object

Yields:

  • (filenames)


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
# File 'lib/gamerom/repo_adapters/vimm.rb', line 57

def self.install(game)
  FileUtils.mkdir_p(game.filepath)
  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://vimm.net/vault/#{game.id}")
  form = page.form_with(id: 'download_form')

  filenames = []
  game_files = []
  multiple_disks = page.css('#download_disc_number')

  if multiple_disks.empty?
    game_files << { id: form['mediaId'], name: 'single file rom' }
  else
    puts 'multiple discs detected'
    game_files.concat(multiple_disks.children[1..-2].map { |disk| { name: disk.text, id: disk['value'] } })
  end

  game_files.each do |game_file|
    puts "downloading #{game_file[:name]}"
    form.method = 'GET'
    button = form.button_with(type: 'submit')
    response = nil
    form['mediaId'] = game_file[:id]
    agent.progressbar do
      response = form.click_button(button)
    end

    break unless response.code.to_i == 200

    filename = response.filename
    response.save!("#{game.filepath}/#{filename}")
    filenames << filename
  end
  yield filenames
end

.platformsObject



33
34
35
# File 'lib/gamerom/repo_adapters/vimm.rb', line 33

def self.platforms
  PLATFORM
end

.sectionsObject



37
38
39
# File 'lib/gamerom/repo_adapters/vimm.rb', line 37

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