gamerom 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'mechanize'
4
- require 'nokogiri'
5
- require 'rest-client'
4
+ require 'mechanize/progressbar'
5
+ require 'mechanizeprogress'
6
6
 
7
7
  module Gamerom
8
8
  module RepoAdapters
9
+ # Vimm - An adapter for the Vimm's Lair repository website
9
10
  class Vimm
11
+ extend Gamerom::RepoAdapter
12
+
10
13
  PLATFORM = {
11
14
  'Dreamcast' => 'Dreamcast',
12
15
  'DS' => 'Nintendo DS',
@@ -25,46 +28,68 @@ module Gamerom
25
28
  'SNES' => 'Super Nintendo',
26
29
  'Wii' => 'Wii',
27
30
  'WiiWare' => 'WiiWare',
28
- }
31
+ }.freeze
29
32
 
30
33
  def self.platforms
31
34
  PLATFORM
32
35
  end
33
36
 
34
- def self.games(platform)
35
- games = []
36
- sections = ('a'..'z').to_a.unshift("number")
37
+ def self.sections
38
+ ('a'..'z').to_a.unshift('number')
39
+ end
37
40
 
38
- sections.each do |section|
39
- print "#{section} "
40
- page = Nokogiri::HTML(RestClient.get("https://vimm.net/vault/?p=list&system=#{platform}&section=#{section}"))
41
- games.append *page.css('table.hovertable td:first-child a:first-child').map { |game|
42
- {
43
- id: game['href'].split('/').last.to_i,
44
- name: game.text,
45
- region: 'USA',
46
- }
47
- }
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
48
46
  end
49
- 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
+ }
50
55
  end
51
56
 
52
57
  def self.install(game)
58
+ FileUtils.mkdir_p(game.filepath)
53
59
  agent = Mechanize.new
54
60
  agent.pluggable_parser.default = Mechanize::Download
55
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'
56
62
  page = agent.get("https://vimm.net/vault/#{game.id}")
57
- form = page.form_with(:id => 'download_form')
58
- form.action = "https://download4.vimm.net/download/?mediaId=#{game.id}"
59
- form.method = 'GET'
60
- button = form.button_with(:type => "submit")
61
- response = form.click_button(button)
62
- if response.code.to_i == 200
63
+ form = page.form_with(id: 'download_form')
64
+
65
+ filenames = []
66
+ game_files = []
67
+ multiple_disks = page.css('#download_disc_number')
68
+
69
+ if multiple_disks.empty?
70
+ game_files << { id: form['mediaId'], name: 'single file rom' }
71
+ else
72
+ puts 'multiple discs detected'
73
+ game_files.concat(multiple_disks.children[1..-2].map { |disk| { name: disk.text, id: disk['value'] } })
74
+ end
75
+
76
+ game_files.each do |game_file|
77
+ puts "downloading #{game_file[:name]}"
78
+ form.method = 'GET'
79
+ button = form.button_with(type: 'submit')
80
+ response = nil
81
+ form['mediaId'] = game_file[:id]
82
+ agent.progressbar do
83
+ response = form.click_button(button)
84
+ end
85
+
86
+ break unless response.code.to_i == 200
87
+
63
88
  filename = response.filename
64
- FileUtils.mkdir_p(game.filepath)
65
89
  response.save!("#{game.filepath}/#{filename}")
66
- yield filename
90
+ filenames << filename
67
91
  end
92
+ yield filenames
68
93
  end
69
94
  end
70
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamerom
4
- VERSION = "0.1.0"
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Mechanize - A Monkeypatch for the mechanize progressbar
4
+ class Mechanize
5
+ include MechanizeProgressBarAPI # (1of7)a
6
+ class HTTP
7
+ # Agent - A Monkeypatch for the mechanize progressbar
8
+ class Agent
9
+ def response_read(response, request, _uri = nil)
10
+ body_io = StringIO.new
11
+ body_io.set_encoding Encoding::BINARY if body_io.respond_to? :set_encoding
12
+ total = 0
13
+ mpbar = MechanizeProgressBar.new(context, request, response) # (2of7)a
14
+
15
+ begin
16
+ response.read_body do |part|
17
+ total += part.length
18
+ body_io.write(part)
19
+ # log.debug("Read #{part.length} bytes (#{total} total)") if log
20
+ log.debug("Read #{part.length} bytes (#{total} total)") if log && !mpbar.suppress_logger? # (3of7)m
21
+ mpbar.inc(part.length) # (4of7)a
22
+ end
23
+ rescue Net::HTTP::Persistent::Error => e
24
+ body_io.rewind
25
+ raise Mechanize::ResponseReadError.new(e, response, body_io)
26
+ ensure # (5of7)a
27
+ mpbar.finish # (6of7)a
28
+ end
29
+
30
+ body_io.rewind
31
+ log.debug("Read #{total} bytes total") if log && !mpbar.suppress_logger? # (7of7)a
32
+
33
+ raise Mechanize::ResponseCodeError, response if
34
+ Net::HTTPUnknownResponse == response
35
+
36
+ content_length = response.content_length
37
+
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
42
+ end
43
+
44
+ body_io
45
+ end
46
+ end
47
+ end
48
+ end
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.1.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-08 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
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mechanize-progressbar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: nokogiri
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: 1.11.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: progressbar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rest-client
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +107,7 @@ files:
79
107
  - ".rspec"
80
108
  - ".rubocop.yml"
81
109
  - ".ruby-version"
110
+ - CHANGELOG.md
82
111
  - CODE_OF_CONDUCT.md
83
112
  - Dockerfile
84
113
  - Gemfile
@@ -89,16 +118,21 @@ files:
89
118
  - Rakefile
90
119
  - bin/console
91
120
  - bin/setup
121
+ - entrypoint.sh
92
122
  - exe/gamerom
93
123
  - gamerom.gemspec
94
124
  - lib/gamerom.rb
95
125
  - lib/gamerom/cli.rb
96
126
  - lib/gamerom/config.rb
97
127
  - lib/gamerom/game.rb
128
+ - lib/gamerom/game_info.rb
98
129
  - lib/gamerom/repo.rb
130
+ - lib/gamerom/repo_adapter.rb
99
131
  - lib/gamerom/repo_adapters/coolrom.rb
132
+ - lib/gamerom/repo_adapters/romnation.rb
100
133
  - lib/gamerom/repo_adapters/vimm.rb
101
134
  - lib/gamerom/version.rb
135
+ - lib/mechanizeprogress.rb
102
136
  homepage: https://github.com/lucasmundim/gamerom
103
137
  licenses:
104
138
  - MIT
@@ -106,7 +140,7 @@ metadata:
106
140
  allowed_push_host: https://rubygems.org
107
141
  homepage_uri: https://github.com/lucasmundim/gamerom
108
142
  source_code_uri: https://github.com/lucasmundim/gamerom
109
- changelog_uri: https://github.com/lucasmundim/gamerom/CHANGELOG.md
143
+ changelog_uri: https://github.com/lucasmundim/gamerom/blob/master/CHANGELOG.md
110
144
  post_install_message:
111
145
  rdoc_options: []
112
146
  require_paths:
@@ -115,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
149
  requirements:
116
150
  - - ">="
117
151
  - !ruby/object:Gem::Version
118
- version: 3.0.0
152
+ version: 3.0.1
119
153
  required_rubygems_version: !ruby/object:Gem::Requirement
120
154
  requirements:
121
155
  - - ">="
122
156
  - !ruby/object:Gem::Version
123
157
  version: '0'
124
158
  requirements: []
125
- rubygems_version: 3.2.3
159
+ rubygems_version: 3.2.15
126
160
  signing_key:
127
161
  specification_version: 4
128
162
  summary: The Video Game ROM downloader