gamerom 0.1.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.
@@ -0,0 +1,85 @@
1
+ # 'frozen_string_literal' => true
2
+
3
+ require 'yaml'
4
+
5
+ REPOSITORIES = Dir["#{File.dirname(__FILE__)}/repo_adapters/*"].map do |file|
6
+ File.basename(file, '.rb')
7
+ end
8
+
9
+ REPOSITORIES.each do |repo|
10
+ require_relative "repo_adapters/#{repo}"
11
+ end
12
+
13
+ module Gamerom
14
+ class Repo
15
+ def self.list
16
+ REPOSITORIES.map do |repo|
17
+ self.new repo
18
+ end
19
+ end
20
+
21
+ def initialize name
22
+ @name = name
23
+ @repo = Gamerom::RepoAdapters.const_get(name.capitalize)
24
+ end
25
+
26
+ def install game, &block
27
+ @repo.install game, &block
28
+ end
29
+
30
+ def find platform, game_identifier
31
+ games(platform).find do |game|
32
+ if Float(game_identifier, exception: false)
33
+ game.id == game_identifier.to_i
34
+ else
35
+ game.name.downcase == game_identifier.downcase
36
+ end
37
+ end
38
+ end
39
+
40
+ def games platform, options={}
41
+ platform_database = "#{Gamerom::CACHE_DIR}/#{@name}/#{platform}.yml"
42
+ update_database platform unless File.exists? platform_database
43
+ games = YAML.load_file(platform_database).map { |game|
44
+ Game.new(game.merge(platform: platform, repo: self))
45
+ }
46
+
47
+ if !options[:region].nil?
48
+ games = games.select { |game|
49
+ options[:region].nil? || game.region == options[:region]
50
+ }
51
+ end
52
+
53
+ if !options[:keyword].nil?
54
+ games = games.select { |game|
55
+ game.name =~ /#{options[:keyword]}/i
56
+ }
57
+ end
58
+
59
+ games
60
+ end
61
+
62
+ def name
63
+ @name
64
+ end
65
+
66
+ def platforms
67
+ @repo.platforms
68
+ end
69
+
70
+ def regions platform
71
+ games(platform).map { |game| game.region }.sort.uniq
72
+ end
73
+
74
+ def to_s
75
+ @name
76
+ end
77
+
78
+ def update_database platform
79
+ games = @repo.games platform
80
+ puts
81
+ FileUtils.mkdir_p("#{Gamerom::CACHE_DIR}/#{@name}")
82
+ File.write("#{Gamerom::CACHE_DIR}/#{@name}/#{platform}.yml", games.to_yaml)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require 'rest-client'
5
+
6
+ module Gamerom
7
+ module RepoAdapters
8
+ class Coolrom
9
+ PLATFORM = {
10
+ 'atari2600' => 'Atari 2600',
11
+ 'atari5200' => 'Atari 5200',
12
+ 'atari7800' => 'Atari 7800',
13
+ 'atarijaguar' => 'Atari Jaguar',
14
+ 'atarilynx' => 'Atari Lynx',
15
+ 'c64' => 'Commodore 64',
16
+ 'cps1' => 'CPS1',
17
+ 'cps2' => 'CPS2',
18
+ 'mame' => 'MAME',
19
+ 'namcosystem22' => 'Namco System 22',
20
+ 'neogeo' => 'Neo Geo',
21
+ 'neogeocd' => 'Neo Geo CD',
22
+ 'neogeopocket' => 'Neo Geo Pocket',
23
+ 'segacd' => 'Sega CD',
24
+ 'dc' => 'Sega Dreamcast',
25
+ 'gamegear' => 'Sega Game Gear',
26
+ 'genesis' => 'Sega Genesis',
27
+ 'mastersystem' => 'Sega Master System',
28
+ 'model2' => 'Sega Model 2',
29
+ 'saturn' => 'Sega Saturn',
30
+ 'psx' => 'Sony Playstation',
31
+ 'ps2' => 'Sony Playstation 2',
32
+ 'psp' => 'Sony Playstation Portable',
33
+ }
34
+
35
+ def self.platforms
36
+ PLATFORM
37
+ end
38
+
39
+ def self.games(platform)
40
+ games = []
41
+ sections = ('a'..'z').to_a.unshift("0")
42
+
43
+ sections.each do |section|
44
+ print "#{section} "
45
+ page = Nokogiri::HTML(RestClient.get("https://coolrom.com.au/roms/#{platform}/#{section}/"))
46
+ regions = page.css('input.region').map { |i| i["name"] }
47
+ regions.each do |region|
48
+ games.append *page.css("div.#{region} a").map { |game|
49
+ {
50
+ id: game['href'].split('/')[3].to_i,
51
+ name: game.text,
52
+ region: region,
53
+ }
54
+ }
55
+ end
56
+ end
57
+ games
58
+ end
59
+
60
+ 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]
71
+ FileUtils.mkdir_p(game.filepath)
72
+ FileUtils.cp(response.file.path, "#{game.filepath}/#{filename}")
73
+ yield filename
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mechanize'
4
+ require 'nokogiri'
5
+ require 'rest-client'
6
+
7
+ module Gamerom
8
+ module RepoAdapters
9
+ class Vimm
10
+ PLATFORM = {
11
+ 'Dreamcast' => 'Dreamcast',
12
+ 'DS' => 'Nintendo DS',
13
+ 'GameCube' => 'GameCube',
14
+ 'GB' => 'Game Boy',
15
+ 'GBA' => 'Game Boy Advance',
16
+ 'GBC' => 'Game Boy Color',
17
+ 'Genesis' => 'Genesis',
18
+ 'N64' => 'Nintendo 64',
19
+ 'NES' => 'Nintendo',
20
+ 'PS1' => 'PlayStation',
21
+ 'PS2' => 'PlayStation 2',
22
+ 'PS3' => 'PlayStation 3',
23
+ 'PSP' => 'PlayStation Portable',
24
+ 'Saturn' => 'Saturn',
25
+ 'SNES' => 'Super Nintendo',
26
+ 'Wii' => 'Wii',
27
+ 'WiiWare' => 'WiiWare',
28
+ }
29
+
30
+ def self.platforms
31
+ PLATFORM
32
+ end
33
+
34
+ def self.games(platform)
35
+ games = []
36
+ sections = ('a'..'z').to_a.unshift("number")
37
+
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
+ }
48
+ end
49
+ games
50
+ end
51
+
52
+ def self.install(game)
53
+ agent = Mechanize.new
54
+ agent.pluggable_parser.default = Mechanize::Download
55
+ 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
+ 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
+ filename = response.filename
64
+ FileUtils.mkdir_p(game.filepath)
65
+ response.save!("#{game.filepath}/#{filename}")
66
+ yield filename
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamerom
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gamerom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Mundim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.11.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.11.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
69
+ description: A command-line installer for game ROMs from many repositories.
70
+ email:
71
+ - lucas.mundim@gmail.com
72
+ executables:
73
+ - gamerom
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".github/workflows/main.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".ruby-version"
82
+ - CODE_OF_CONDUCT.md
83
+ - Dockerfile
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - Makefile
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/setup
92
+ - exe/gamerom
93
+ - gamerom.gemspec
94
+ - lib/gamerom.rb
95
+ - lib/gamerom/cli.rb
96
+ - lib/gamerom/config.rb
97
+ - lib/gamerom/game.rb
98
+ - lib/gamerom/repo.rb
99
+ - lib/gamerom/repo_adapters/coolrom.rb
100
+ - lib/gamerom/repo_adapters/vimm.rb
101
+ - lib/gamerom/version.rb
102
+ homepage: https://github.com/lucasmundim/gamerom
103
+ licenses:
104
+ - MIT
105
+ metadata:
106
+ allowed_push_host: https://rubygems.org
107
+ homepage_uri: https://github.com/lucasmundim/gamerom
108
+ source_code_uri: https://github.com/lucasmundim/gamerom
109
+ changelog_uri: https://github.com/lucasmundim/gamerom/CHANGELOG.md
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 3.0.0
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.2.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: The Video Game ROM downloader
129
+ test_files: []