gamerom 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed630a7050f3d5206302cdc93cd126be98bf854a6a89e076a807ae81703dc78d
4
- data.tar.gz: 24e25edcaebd1520d48c0ae7c0cc2d148d48ba1c002c16497d95579e372b51be
3
+ metadata.gz: 964cf92bf92c6fc0be0fb61f0fd6f9f216debb7231ccbfdc31da38b49b93463c
4
+ data.tar.gz: 2601482af6610a7b639a19f3b16fddf988fccb74a65732fa3b64c97e97cb2d4d
5
5
  SHA512:
6
- metadata.gz: 7dd4cc672d3bcbf177caf54d53add0070c703fa4cce022e3dca3beddcd6b07ab6793686aef6e0cf4518285b0887b272cf61e4d1063a6a72bb779f4f48633ec82
7
- data.tar.gz: b08221243a8b538b8343ffe84c7c2e011093bfeabb96208693f043c78bff396edfbee10ca779851a78bf1eed0db86dbb2bd81240cee56d5f5560ccda6be81642
6
+ metadata.gz: ce291c55b28cef9805292a5bd53f60a86bd51d5de665707f80cbfb1e38cb363843e9f3355303a625de3a706d07b5d52ea7cb6f565fa81ba96ea684fe067d35e3
7
+ data.tar.gz: 9b7d17f0ab5f1115f38d0364a05b6a2e9e3d0b57b4ad0965d882ea16f05b46138dfea43d46bbb1e61c3aca02b7e77a634dfbb1de9aafe9e9c8db24ed63c4ce7f
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2021-05-08
10
+ - Add support for downloading multiple disc ROMs on vimm repo
11
+ - Add progress bar to the install process
12
+
13
+ ## [0.1.0] - 2021-05-07
14
+ - Initial release
15
+
16
+ [Unreleased]: https://github.com/lucasmundim/gamerom/compare/v0.2.0...HEAD
17
+ [0.2.0]: https://github.com/lucasmundim/gamerom/compare/v0.1.0...v0.2.0
18
+ [0.1.0]: https://github.com/lucasmundim/gamerom/releases/tag/v0.1.0
data/Gemfile.lock CHANGED
@@ -1,9 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gamerom (0.1.0)
4
+ gamerom (0.2.0)
5
5
  mechanize (~> 2.8.0)
6
+ mechanize-progressbar (~> 0.2.0)
6
7
  nokogiri (~> 1.11.3)
8
+ progressbar (~> 0.9.0)
7
9
  rest-client (~> 2.1.0)
8
10
  thor (~> 1.1.0)
9
11
 
@@ -31,6 +33,9 @@ GEM
31
33
  rubyntlm (~> 0.6, >= 0.6.3)
32
34
  webrick (~> 1.7)
33
35
  webrobots (~> 0.1.2)
36
+ mechanize-progressbar (0.2.0)
37
+ mechanize (>= 1.0.0)
38
+ progressbar (>= 0.9.0)
34
39
  mime-types (3.3.1)
35
40
  mime-types-data (~> 3.2015)
36
41
  mime-types-data (3.2021.0225)
@@ -45,6 +50,7 @@ GEM
45
50
  parallel (1.20.1)
46
51
  parser (3.0.1.0)
47
52
  ast (~> 2.4.1)
53
+ progressbar (0.9.2)
48
54
  public_suffix (4.0.6)
49
55
  racc (1.5.2)
50
56
  rainbow (3.0.0)
data/README.md CHANGED
@@ -14,7 +14,7 @@ It currently supports the following repositories:
14
14
  Add this to your .bashrc, .bash_aliases, etc:
15
15
 
16
16
  ```
17
- alias gamerom='docker run --rm -it -v ~/.gamerom:/root/.gamerom docker.io/lucasmundim/gamerom:0.1.0'
17
+ alias gamerom='docker run --rm -it -v ~/.gamerom:/root/.gamerom docker.io/lucasmundim/gamerom:0.2.0'
18
18
  ```
19
19
 
20
20
  Use it as:
@@ -539,7 +539,7 @@ Print program version
539
539
 
540
540
  ```
541
541
  $ gamerom version
542
- 0.1.0
542
+ 0.2.0
543
543
  ```
544
544
 
545
545
  ## Development
data/gamerom.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.metadata["homepage_uri"] = spec.homepage
20
20
  spec.metadata["source_code_uri"] = spec.homepage
21
- spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
21
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -30,7 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_runtime_dependency "mechanize", "~> 2.8.0"
33
+ spec.add_runtime_dependency "mechanize-progressbar", "~> 0.2.0"
33
34
  spec.add_runtime_dependency "nokogiri", "~> 1.11.3"
35
+ spec.add_runtime_dependency "progressbar", "~> 0.9.0"
34
36
  spec.add_runtime_dependency "rest-client", "~> 2.1.0"
35
37
  spec.add_runtime_dependency "thor", "~> 1.1.0"
36
38
 
data/lib/gamerom/cli.rb CHANGED
@@ -33,7 +33,7 @@ module Gamerom
33
33
  shell.say "Game #{game_identifier} not found", :red
34
34
  end
35
35
  puts game
36
- puts game.filename if game.installed?
36
+ puts game.filenames if game.installed?
37
37
  rescue => e
38
38
  render_error e, options
39
39
  exit 1
data/lib/gamerom/game.rb CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  require 'fileutils'
4
4
  require 'ostruct'
5
+ require 'yaml'
5
6
 
6
7
  module Gamerom
7
8
  class Game < OpenStruct
8
- def filename
9
- "#{self.filepath}/#{File.read(self.state_filename)}"
9
+ def filenames
10
+ YAML.load_file(self.state_filename).map do |filename|
11
+ "#{self.filepath}/#{filename}"
12
+ end
10
13
  end
11
14
 
12
15
  def filepath
@@ -14,8 +17,8 @@ module Gamerom
14
17
  end
15
18
 
16
19
  def install
17
- self.repo.install self do |filename|
18
- self.update_state filename
20
+ self.repo.install self do |filenames|
21
+ self.update_state filenames
19
22
  end
20
23
  end
21
24
 
@@ -32,13 +35,13 @@ module Gamerom
32
35
  end
33
36
 
34
37
  def uninstall
35
- FileUtils.rm_rf self.filename
38
+ FileUtils.rm_rf self.filenames
36
39
  FileUtils.rm_rf self.state_filename
37
40
  end
38
41
 
39
- def update_state filename
42
+ def update_state filenames
40
43
  FileUtils.mkdir_p("#{Gamerom::STATE_DIR}/#{self.repo.name}/#{self.platform}/#{self.region}")
41
- File.write(self.state_filename, filename)
44
+ File.write(self.state_filename, filenames.to_yaml)
42
45
  end
43
46
 
44
47
  private
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mechanize'
4
+ require 'mechanize/progressbar'
5
+ require 'mechanizeprogress'
3
6
  require 'nokogiri'
4
7
  require 'rest-client'
5
8
 
@@ -58,19 +61,19 @@ module Gamerom
58
61
  end
59
62
 
60
63
  def self.install(game)
61
- response = RestClient::Request.execute(
62
- method: :get,
63
- url: "https://coolrom.com.au/downloader.php?id=#{game.id}",
64
- headers: {
65
- '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",
66
- },
67
- raw_response: true,
68
- )
69
- if response.code == 200
70
- filename = response.headers[:content_disposition].split('; ')[1].split('"')[1]
64
+ agent = Mechanize.new
65
+ agent.pluggable_parser.default = Mechanize::Download
66
+ 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'
67
+
68
+ response = nil
69
+ agent.progressbar{
70
+ response = agent.get("https://coolrom.com.au/downloader.php?id=#{game.id}")
71
+ }
72
+ if response.code.to_i == 200
73
+ filename = response.filename
71
74
  FileUtils.mkdir_p(game.filepath)
72
- FileUtils.cp(response.file.path, "#{game.filepath}/#{filename}")
73
- yield filename
75
+ response.save!("#{game.filepath}/#{filename}")
76
+ yield [filename]
74
77
  end
75
78
  end
76
79
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'mechanize'
4
+ require 'mechanize/progressbar'
5
+ require 'mechanizeprogress'
4
6
  require 'nokogiri'
5
7
  require 'rest-client'
6
8
 
@@ -50,21 +52,40 @@ module Gamerom
50
52
  end
51
53
 
52
54
  def self.install(game)
55
+ FileUtils.mkdir_p(game.filepath)
53
56
  agent = Mechanize.new
54
57
  agent.pluggable_parser.default = Mechanize::Download
55
58
  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
59
  page = agent.get("https://vimm.net/vault/#{game.id}")
57
60
  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
- filename = response.filename
64
- FileUtils.mkdir_p(game.filepath)
65
- response.save!("#{game.filepath}/#{filename}")
66
- yield filename
61
+
62
+ filenames = []
63
+ game_files = []
64
+ multiple_disks = page.css('#download_disc_number')
65
+
66
+ if multiple_disks.empty?
67
+ game_files << { id: game.id, name: 'single file rom' }
68
+ else
69
+ puts "multiple discs detected"
70
+ game_files.concat multiple_disks.children[1..-2].map { |disk| { name: disk.text, id: disk['value']} }
71
+ end
72
+
73
+ game_files.each do |game_file|
74
+ puts "downloading #{game_file[:name]}"
75
+ form.action = "https://download4.vimm.net/download/?mediaId=#{game_file[:id]}"
76
+ form.method = 'GET'
77
+ button = form.button_with(:type => "submit")
78
+ response = nil
79
+ agent.progressbar{
80
+ 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
+ end
67
87
  end
88
+ yield filenames
68
89
  end
69
90
  end
70
91
  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.2.0"
5
5
  end
@@ -0,0 +1,44 @@
1
+ class Mechanize
2
+ include MechanizeProgressBarAPI # (1of7)a
3
+ class HTTP
4
+ class Agent
5
+ def response_read response, request, uri = nil
6
+ body_io = StringIO.new
7
+ body_io.set_encoding Encoding::BINARY if body_io.respond_to? :set_encoding
8
+ total = 0
9
+ mpbar = MechanizeProgressBar.new(self.context, request, response) # (2of7)a
10
+
11
+ begin
12
+ response.read_body { |part|
13
+ total += part.length
14
+ body_io.write(part)
15
+ # log.debug("Read #{part.length} bytes (#{total} total)") if log
16
+ log.debug("Read #{part.length} bytes (#{total} total)") if log && !mpbar.suppress_logger? # (3of7)m
17
+ mpbar.inc(part.length) # (4of7)a
18
+ }
19
+ rescue Net::HTTP::Persistent::Error => e
20
+ body_io.rewind
21
+ raise Mechanize::ResponseReadError.new(e, response, body_io)
22
+ ensure # (5of7)a
23
+ mpbar.finish # (6of7)a
24
+ end
25
+
26
+ body_io.rewind
27
+ log.debug("Read #{total} bytes total") if log && !mpbar.suppress_logger? # (7of7)a
28
+
29
+ raise Mechanize::ResponseCodeError, response if
30
+ Net::HTTPUnknownResponse === response
31
+
32
+ content_length = response.content_length
33
+
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
+ end
39
+
40
+ body_io
41
+ end
42
+ end
43
+ end
44
+ 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.2.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-09 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
@@ -99,6 +128,7 @@ files:
99
128
  - lib/gamerom/repo_adapters/coolrom.rb
100
129
  - lib/gamerom/repo_adapters/vimm.rb
101
130
  - lib/gamerom/version.rb
131
+ - lib/mechanizeprogress.rb
102
132
  homepage: https://github.com/lucasmundim/gamerom
103
133
  licenses:
104
134
  - MIT
@@ -106,7 +136,7 @@ metadata:
106
136
  allowed_push_host: https://rubygems.org
107
137
  homepage_uri: https://github.com/lucasmundim/gamerom
108
138
  source_code_uri: https://github.com/lucasmundim/gamerom
109
- changelog_uri: https://github.com/lucasmundim/gamerom/CHANGELOG.md
139
+ changelog_uri: https://github.com/lucasmundim/gamerom/blob/master/CHANGELOG.md
110
140
  post_install_message:
111
141
  rdoc_options: []
112
142
  require_paths: