gamerom 0.3.0 → 0.4.0

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,29 +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")
39
- progress_bar = ProgressBar.new(platform, sections.count)
37
+ def self.sections
38
+ ('a'..'z').to_a.unshift('number')
39
+ end
40
+
41
+ def self.extract_games(platform)
40
42
  sections.each_with_index do |section, index|
41
- page = Nokogiri::HTML(RestClient.get("https://vimm.net/vault/?p=list&system=#{platform}&section=#{section}"))
42
- games.append *page.css('table.hovertable td:first-child a:first-child').map { |game|
43
- {
44
- id: game['href'].split('/').last.to_i,
45
- name: game.text,
46
- region: 'USA',
47
- }
48
- }
49
- progress_bar.set(index+1)
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
- progress_bar.finish
52
- 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
+ }
53
55
  end
54
56
 
55
57
  def self.install(game)
@@ -58,7 +60,7 @@ module Gamerom
58
60
  agent.pluggable_parser.default = Mechanize::Download
59
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'
60
62
  page = agent.get("https://vimm.net/vault/#{game.id}")
61
- form = page.form_with(:id => 'download_form')
63
+ form = page.form_with(id: 'download_form')
62
64
 
63
65
  filenames = []
64
66
  game_files = []
@@ -67,24 +69,25 @@ module Gamerom
67
69
  if multiple_disks.empty?
68
70
  game_files << { id: form['mediaId'], name: 'single file rom' }
69
71
  else
70
- puts "multiple discs detected"
71
- 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'] } })
72
74
  end
73
75
 
74
76
  game_files.each do |game_file|
75
77
  puts "downloading #{game_file[:name]}"
76
78
  form.method = 'GET'
77
- button = form.button_with(:type => "submit")
79
+ button = form.button_with(type: 'submit')
78
80
  response = nil
79
81
  form['mediaId'] = game_file[:id]
80
- agent.progressbar{
82
+ agent.progressbar do
81
83
  response = form.click_button(button)
82
- }
83
- if response.code.to_i == 200
84
- filename = response.filename
85
- response.save!("#{game.filepath}/#{filename}")
86
- filenames << filename
87
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
88
91
  end
89
92
  yield filenames
90
93
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamerom
4
- VERSION = "0.3.0"
4
+ VERSION = '0.4.0'
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.3.0
4
+ version: 0.4.0
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-14 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,6 +118,7 @@ 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
@@ -126,6 +127,7 @@ files:
126
127
  - lib/gamerom/game.rb
127
128
  - lib/gamerom/game_info.rb
128
129
  - lib/gamerom/repo.rb
130
+ - lib/gamerom/repo_adapter.rb
129
131
  - lib/gamerom/repo_adapters/coolrom.rb
130
132
  - lib/gamerom/repo_adapters/romnation.rb
131
133
  - lib/gamerom/repo_adapters/vimm.rb
@@ -147,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
149
  requirements:
148
150
  - - ">="
149
151
  - !ruby/object:Gem::Version
150
- version: 3.0.0
152
+ version: 3.0.1
151
153
  required_rubygems_version: !ruby/object:Gem::Requirement
152
154
  requirements:
153
155
  - - ">="
154
156
  - !ruby/object:Gem::Version
155
157
  version: '0'
156
158
  requirements: []
157
- rubygems_version: 3.2.3
159
+ rubygems_version: 3.2.15
158
160
  signing_key:
159
161
  specification_version: 4
160
162
  summary: The Video Game ROM downloader