gamerom 0.2.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,13 @@
3
3
  require 'mechanize'
4
4
  require 'mechanize/progressbar'
5
5
  require 'mechanizeprogress'
6
- require 'nokogiri'
7
- require 'rest-client'
8
6
 
9
7
  module Gamerom
10
8
  module RepoAdapters
9
+ # Vimm - An adapter for the Vimm's Lair repository website
11
10
  class Vimm
11
+ extend Gamerom::RepoAdapter
12
+
12
13
  PLATFORM = {
13
14
  'Dreamcast' => 'Dreamcast',
14
15
  'DS' => 'Nintendo DS',
@@ -27,28 +28,30 @@ module Gamerom
27
28
  'SNES' => 'Super Nintendo',
28
29
  'Wii' => 'Wii',
29
30
  'WiiWare' => 'WiiWare',
30
- }
31
+ }.freeze
31
32
 
32
33
  def self.platforms
33
34
  PLATFORM
34
35
  end
35
36
 
36
- def self.games(platform)
37
- games = []
38
- sections = ('a'..'z').to_a.unshift("number")
37
+ def self.sections
38
+ ('a'..'z').to_a.unshift('number')
39
+ end
39
40
 
40
- sections.each do |section|
41
- print "#{section} "
42
- page = Nokogiri::HTML(RestClient.get("https://vimm.net/vault/?p=list&system=#{platform}&section=#{section}"))
43
- games.append *page.css('table.hovertable td:first-child a:first-child').map { |game|
44
- {
45
- id: game['href'].split('/').last.to_i,
46
- name: game.text,
47
- region: 'USA',
48
- }
49
- }
41
+ def self.extract_games(platform)
42
+ sections.each_with_index do |section, index|
43
+ page = nokogiri_get("https://vimm.net/vault/?p=list&system=#{platform}&section=#{section}")
44
+ game_links = page.css('table.hovertable td:first-child a:first-child')
45
+ yield game_links.map { |game_link| game(game_link) }, index
50
46
  end
51
- games
47
+ end
48
+
49
+ def self.game(game_link)
50
+ {
51
+ id: game_link['href'].split('/').last.to_i,
52
+ name: game_link.text,
53
+ region: 'USA',
54
+ }
52
55
  end
53
56
 
54
57
  def self.install(game)
@@ -57,33 +60,34 @@ module Gamerom
57
60
  agent.pluggable_parser.default = Mechanize::Download
58
61
  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'
59
62
  page = agent.get("https://vimm.net/vault/#{game.id}")
60
- form = page.form_with(:id => 'download_form')
63
+ form = page.form_with(id: 'download_form')
61
64
 
62
65
  filenames = []
63
66
  game_files = []
64
67
  multiple_disks = page.css('#download_disc_number')
65
68
 
66
69
  if multiple_disks.empty?
67
- game_files << { id: game.id, name: 'single file rom' }
70
+ game_files << { id: form['mediaId'], name: 'single file rom' }
68
71
  else
69
- puts "multiple discs detected"
70
- game_files.concat multiple_disks.children[1..-2].map { |disk| { name: disk.text, id: disk['value']} }
72
+ puts 'multiple discs detected'
73
+ game_files.concat(multiple_disks.children[1..-2].map { |disk| { name: disk.text, id: disk['value'] } })
71
74
  end
72
75
 
73
76
  game_files.each do |game_file|
74
77
  puts "downloading #{game_file[:name]}"
75
- form.action = "https://download4.vimm.net/download/?mediaId=#{game_file[:id]}"
76
78
  form.method = 'GET'
77
- button = form.button_with(:type => "submit")
79
+ button = form.button_with(type: 'submit')
78
80
  response = nil
79
- agent.progressbar{
81
+ form['mediaId'] = game_file[:id]
82
+ agent.progressbar do
80
83
  response = form.click_button(button)
81
- }
82
- if response.code.to_i == 200
83
- filename = response.filename
84
- response.save!("#{game.filepath}/#{filename}")
85
- filenames << filename
86
84
  end
85
+
86
+ break unless response.code.to_i == 200
87
+
88
+ filename = response.filename
89
+ response.save!("#{game.filepath}/#{filename}")
90
+ filenames << filename
87
91
  end
88
92
  yield filenames
89
93
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamerom
4
- VERSION = "0.2.0"
4
+ VERSION = '0.4.1'
5
5
  end
@@ -1,21 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Mechanize - A Monkeypatch for the mechanize progressbar
1
4
  class Mechanize
2
5
  include MechanizeProgressBarAPI # (1of7)a
3
6
  class HTTP
7
+ # Agent - A Monkeypatch for the mechanize progressbar
4
8
  class Agent
5
- def response_read response, request, uri = nil
9
+ def response_read(response, request, _uri = nil)
6
10
  body_io = StringIO.new
7
11
  body_io.set_encoding Encoding::BINARY if body_io.respond_to? :set_encoding
8
12
  total = 0
9
- mpbar = MechanizeProgressBar.new(self.context, request, response) # (2of7)a
13
+ mpbar = MechanizeProgressBar.new(context, request, response) # (2of7)a
10
14
 
11
15
  begin
12
- response.read_body { |part|
16
+ response.read_body do |part|
13
17
  total += part.length
14
18
  body_io.write(part)
15
- # log.debug("Read #{part.length} bytes (#{total} total)") if log
19
+ # log.debug("Read #{part.length} bytes (#{total} total)") if log
16
20
  log.debug("Read #{part.length} bytes (#{total} total)") if log && !mpbar.suppress_logger? # (3of7)m
17
21
  mpbar.inc(part.length) # (4of7)a
18
- }
22
+ end
19
23
  rescue Net::HTTP::Persistent::Error => e
20
24
  body_io.rewind
21
25
  raise Mechanize::ResponseReadError.new(e, response, body_io)
@@ -27,14 +31,14 @@ class Mechanize
27
31
  log.debug("Read #{total} bytes total") if log && !mpbar.suppress_logger? # (7of7)a
28
32
 
29
33
  raise Mechanize::ResponseCodeError, response if
30
- Net::HTTPUnknownResponse === response
34
+ Net::HTTPUnknownResponse == response
31
35
 
32
36
  content_length = response.content_length
33
37
 
34
- unless Net::HTTP::Head === request or Net::HTTPRedirection === response then
35
- raise EOFError, "Content-Length (#{content_length}) does not match " \
36
- "response body length (#{body_io.length})" if
37
- content_length and content_length != body_io.length
38
+ unless Net::HTTP::Head == request || Net::HTTPRedirection == response
39
+ if content_length && content_length != body_io.length
40
+ raise EOFError, "Content-Length (#{content_length}) does not match response body length (#{body_io.length})"
41
+ end
38
42
  end
39
43
 
40
44
  body_io
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamerom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Mundim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -118,14 +118,18 @@ files:
118
118
  - Rakefile
119
119
  - bin/console
120
120
  - bin/setup
121
+ - entrypoint.sh
121
122
  - exe/gamerom
122
123
  - gamerom.gemspec
123
124
  - lib/gamerom.rb
124
125
  - lib/gamerom/cli.rb
125
126
  - lib/gamerom/config.rb
126
127
  - lib/gamerom/game.rb
128
+ - lib/gamerom/game_info.rb
127
129
  - lib/gamerom/repo.rb
130
+ - lib/gamerom/repo_adapter.rb
128
131
  - lib/gamerom/repo_adapters/coolrom.rb
132
+ - lib/gamerom/repo_adapters/romnation.rb
129
133
  - lib/gamerom/repo_adapters/vimm.rb
130
134
  - lib/gamerom/version.rb
131
135
  - lib/mechanizeprogress.rb
@@ -145,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
149
  requirements:
146
150
  - - ">="
147
151
  - !ruby/object:Gem::Version
148
- version: 3.0.0
152
+ version: 3.0.1
149
153
  required_rubygems_version: !ruby/object:Gem::Requirement
150
154
  requirements:
151
155
  - - ">="
152
156
  - !ruby/object:Gem::Version
153
157
  version: '0'
154
158
  requirements: []
155
- rubygems_version: 3.2.3
159
+ rubygems_version: 3.2.15
156
160
  signing_key:
157
161
  specification_version: 4
158
162
  summary: The Video Game ROM downloader