parker 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6de19b17c3640302aaade18a9d582f9f722932c
4
+ data.tar.gz: c48cf8251883eeee06758cf1ca2751668132e1a6
5
+ SHA512:
6
+ metadata.gz: bc6d256b2e12b1fbdb0cd9e0b66d5bc9f173a8c0c130c0333481ce75c9c246828fb9c93e1e027907227c7cf877f7a656f18d9a8f969a8b3ecc09c3fce65810b1
7
+ data.tar.gz: f4c8445a9b40b25f3499226303de72bb3e752e3fbdc82bc13d7e0ce8e5c3f9925d25f8e7121a2b8f604301cbde65b2287f7f83e3e732471a01929e8753286407
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
5
+
6
+ require 'parker'
7
+ require 'parker/version'
8
+ require 'json'
9
+ require 'trollop'
10
+
11
+ trap('SIGINT') do
12
+ puts 'Cancelled!'
13
+ exit!
14
+ end
15
+
16
+ source_directory = File.expand_path(File.join('~/', '.config', 'parker'))
17
+
18
+ options = Trollop.options do
19
+ version "parker v#{Parker::VERSION}"
20
+ banner <<-EOS
21
+ A ridiculous tool for organising game screenshots.
22
+
23
+ Usage:
24
+ parker
25
+ Options:
26
+ EOS
27
+ opt :config, 'Config file path', type: :string, default: File.join(source_directory, 'config.json')
28
+ opt :destination, 'Output directory for screenshots', type: :string, default: Dir.pwd
29
+ end
30
+
31
+ unless Dir.exist?(source_directory)
32
+ FileUtils.mkdir_p(source_directory)
33
+ puts "Created config directory: #{source_directory}"
34
+ exit
35
+ end
36
+
37
+ platforms = []
38
+
39
+ Dir.glob(File.join(source_directory, '*.json')).each do |path|
40
+ platform_name = File.basename(path, File.extname(path)).capitalize
41
+
42
+ if (platform_klass = Object.const_get("Parker::Platform::#{platform_name}"))
43
+ platform_data = JSON.parse(File.read(path))
44
+
45
+ platforms << platform_klass.new(
46
+ platform_data['name'] || platform_name,
47
+ platform_data['source_path'],
48
+ platform_data['games'] || {}
49
+ )
50
+ end
51
+ end
52
+
53
+ output_path = File.expand_path(options[:destination])
54
+ FileUtils.mkdir_p(output_path) unless Dir.exist?(output_path)
55
+
56
+ puts "Copying screenshots to #{output_path}..."
57
+
58
+ platforms.each do |platform|
59
+ platform.games.each_value do |game|
60
+ if game.screenshots.length > 0
61
+ puts "- Scanning #{game.name} (#{platform.name})"
62
+ game.copy_screenshots(File.join(output_path, platform.name))
63
+ end
64
+ end
65
+ end
66
+
67
+ puts "Done!"
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(__dir__)
4
+
5
+ require 'json'
6
+
7
+ require 'parker/game'
8
+ require 'parker/screenshot'
9
+
10
+ require 'parker/platform/base'
11
+ require 'parker/platform/playstation'
12
+ require 'parker/platform/steam'
13
+ require 'parker/platform/switch'
@@ -0,0 +1,22 @@
1
+ module Parker
2
+ class Game
3
+ attr_accessor :name, :screenshots
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @screenshots = []
8
+ end
9
+
10
+ def copy_screenshots(output_path)
11
+ screenshots.each do |screenshot|
12
+ platform_path = File.join(output_path, name)
13
+ new_file_path = File.join(platform_path, screenshot.filename)
14
+
15
+ next if File.exist?(new_file_path)
16
+
17
+ FileUtils.mkdir(platform_path) unless Dir.exist?(platform_path)
18
+ FileUtils.cp(screenshot.path, new_file_path)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module Parker
2
+ module Platform
3
+ class Base
4
+ attr_reader :name, :source_path
5
+ attr_accessor :games
6
+
7
+ def initialize(name, source_path, game_data)
8
+ @name = name
9
+ @source_path = source_path
10
+ @games = {}
11
+
12
+ game_data.map do |identifier, name|
13
+ @games[identifier] = Game.new(name)
14
+ end
15
+
16
+ scan_games
17
+ end
18
+
19
+ def scan_games
20
+ raise 'Must be implemented by a subclass'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'digest'
2
+
3
+ module Parker
4
+ module Platform
5
+ class Playstation < Base
6
+ def scan_games
7
+ screenshots_path = File.join(source_path, '*', File::SEPARATOR, '*.jpg')
8
+
9
+ Dir.glob(screenshots_path).each do |path|
10
+ next if (path =~ /\_\d.jpg$/)
11
+
12
+ (game_name, screenshot_date) = File.basename(path, File.extname(path)).split('_')
13
+ game_id = Digest::SHA1.hexdigest(game_name)[0..9]
14
+
15
+ games[game_id] ||= Game.new(game_name.sub('™', '').sub('_', ' -'))
16
+ games[game_id].screenshots << Screenshot.new(path)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Parker
2
+ module Platform
3
+ class Steam < Base
4
+ def scan_games
5
+ games.each do |identifier, game|
6
+ screenshot_path = File.join(source_path, identifier.to_s, 'screenshots', '*.jpg')
7
+
8
+ Dir.glob(screenshot_path).each do |path|
9
+ game.screenshots << Screenshot.new(path)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Parker
2
+ module Platform
3
+ class Switch < Base
4
+ def scan_games
5
+ screenshot_path = File.join(source_path, '**', '*.jpg')
6
+
7
+ Dir.glob(screenshot_path).each do |path|
8
+ game_id = File.basename(path, File.extname(path)).split('-')[-1]
9
+ games[game_id].screenshots << Screenshot.new(path) if games[game_id]
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Parker
2
+ class Screenshot
3
+ attr_reader :path
4
+ attr_accessor :filename
5
+
6
+ def initialize(path)
7
+ @path = path
8
+
9
+ parts = File.basename(@path).match(/(\d{4})(\d{2})(\d{2})(\d+).+(\.[a-z]{3})/)
10
+ @filename = parts.to_a[1..-2].join('-') << parts[-1]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Parker
4
+ VERSION = '0.0.1'
5
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Bogan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trollop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ description: A ridiculous tool for organising game screenshots.
28
+ email:
29
+ - d+parker@waferbaby.com
30
+ executables:
31
+ - parker
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/parker
36
+ - lib/parker.rb
37
+ - lib/parker/game.rb
38
+ - lib/parker/platform/base.rb
39
+ - lib/parker/platform/playstation.rb
40
+ - lib/parker/platform/steam.rb
41
+ - lib/parker/platform/switch.rb
42
+ - lib/parker/screenshot.rb
43
+ - lib/parker/version.rb
44
+ homepage: http://github.com/waferbaby/parker
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.6.13
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: A tool for organising game screenshots
68
+ test_files: []