popflash_match_downloader 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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +7 -0
- data/bin/popflash_match_downloader +21 -0
- data/lib/popflash_match_downloader.rb +13 -0
- data/lib/popflash_match_downloader/downloader.rb +49 -0
- data/lib/popflash_match_downloader/match_file_name_extractor.rb +24 -0
- data/lib/popflash_match_downloader/recent_matches_extractor.rb +25 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8cd58dd4c0ed2752d1e935bf588c1fc67d292ff6
|
4
|
+
data.tar.gz: 8daca61a1959c87d8426ec1b0c2b3e1592759232
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38d50c94bf6701ba41a51b1beaaef622d7b497e42101dc187517336ed3208cafab3956175365ca1a48b797311f3bf72cf06d2064ae349a2b0b5b607f28eb3820
|
7
|
+
data.tar.gz: 415996f54f16727742faf0dc3149e4960d755c9529875e81d628649072f5cc472003da6ff1768415f5a84a886ccd45f8da4fe13bb77af9d716a2a7bf43931f32
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Lukas Stabe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# popflash_match_downloader
|
2
|
+
|
3
|
+
> This tool is a wip and does not have configuration files etc yet.
|
4
|
+
|
5
|
+
This gem contains a utility to download demos of your recent matches from [popflash.site](https://popflash.site).
|
6
|
+
|
7
|
+
It works by scraping your user page, which contains a list of your five most recent matches. It then finds the match download link on each matches page and downloads the demo, if it hasn't already been downloaded.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'thor'
|
3
|
+
require 'popflash_match_downloader'
|
4
|
+
|
5
|
+
class PopflashMatchDownloaderCli < Thor
|
6
|
+
desc 'download USER_ID', 'Downloads the most recent five matches for the given user id'
|
7
|
+
method_option :download_dir, aliases: '-d', desc: 'The download target directory', default: './'
|
8
|
+
def download(user_id)
|
9
|
+
e = PopflashMatchDownloader::RecentMatchesExtractor.new(user_id)
|
10
|
+
files = e.find_match_ids.map do |id|
|
11
|
+
PopflashMatchDownloader::MatchFileNameExtractor.new(id).extract_file_name
|
12
|
+
end
|
13
|
+
|
14
|
+
loader = PopflashMatchDownloader::Downloader.new options[:download_dir]
|
15
|
+
files.each do |f|
|
16
|
+
loader.download_file_if_needed f
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
PopflashMatchDownloaderCli.start
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module PopflashMatchDownloader
|
5
|
+
POPFLASH_SITE_URL = 'https://popflash.site/'
|
6
|
+
|
7
|
+
class UnexpectedContentError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'popflash_match_downloader/match_file_name_extractor'
|
12
|
+
require 'popflash_match_downloader/recent_matches_extractor'
|
13
|
+
require 'popflash_match_downloader/downloader'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module PopflashMatchDownloader
|
4
|
+
class Downloader
|
5
|
+
def initialize download_directory
|
6
|
+
@download_directory = File.expand_path(download_directory)
|
7
|
+
end
|
8
|
+
|
9
|
+
def file_path name
|
10
|
+
File.join @download_directory, name
|
11
|
+
end
|
12
|
+
|
13
|
+
def is_file_downloaded? name
|
14
|
+
File.exist? file_path(name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def download_file name
|
18
|
+
file_location = '/' + name
|
19
|
+
|
20
|
+
Net::HTTP.start('s3.popflash.site') do |http|
|
21
|
+
http.request_get file_location do |response|
|
22
|
+
while response.is_a? Net::HTTPRedirection
|
23
|
+
location = response['location']
|
24
|
+
puts "redirecting to #{location}"
|
25
|
+
response = http.request_get location
|
26
|
+
end
|
27
|
+
|
28
|
+
if response.is_a? Net::HTTPSuccess
|
29
|
+
File.open file_path(name), 'wb' do |f|
|
30
|
+
response.read_body { |seg| f.write seg }
|
31
|
+
end
|
32
|
+
else
|
33
|
+
puts "couldn't donwload demo. error: #{response.message}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def download_file_if_needed name
|
40
|
+
if is_file_downloaded? name
|
41
|
+
puts "already downloaded #{name}"
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "downloading #{name}"
|
46
|
+
download_file name
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PopflashMatchDownloader
|
2
|
+
class MatchFileNameExtractor
|
3
|
+
def initialize match_id
|
4
|
+
@match_id = match_id
|
5
|
+
end
|
6
|
+
|
7
|
+
DEMO_LINK_REGEX = %r{^http://s3.popflash.site/([[:graph:]]+.dem)$}
|
8
|
+
MATCH_URL_PREFIX = POPFLASH_SITE_URL + 'match/'
|
9
|
+
|
10
|
+
def extract_file_name
|
11
|
+
match_url = MATCH_URL_PREFIX + @match_id
|
12
|
+
|
13
|
+
doc = Nokogiri::HTML open(match_url)
|
14
|
+
|
15
|
+
link = doc.css('a.demo-download').first
|
16
|
+
raise UnexpectedContentError if link == nil
|
17
|
+
|
18
|
+
match_id_match = link['href'].match(DEMO_LINK_REGEX)
|
19
|
+
raise UnexpectedContentError if match_id_match == nil
|
20
|
+
|
21
|
+
match_id_match.captures.first
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PopflashMatchDownloader
|
2
|
+
class RecentMatchesExtractor
|
3
|
+
def initialize user_id
|
4
|
+
@user_id = user_id
|
5
|
+
end
|
6
|
+
|
7
|
+
MATCH_LINK_REGEX = %r{^/match/([[:graph:]&&[^/]]+)$}
|
8
|
+
USER_URL_PREFIX = POPFLASH_SITE_URL + 'user/'
|
9
|
+
|
10
|
+
class MatchLinkCssFilter
|
11
|
+
def isMatchLink node_set
|
12
|
+
node_set.find_all { |n| n['href'] =~ RecentMatchesExtractor::MATCH_LINK_REGEX }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_match_ids
|
17
|
+
profile_url = USER_URL_PREFIX + @user_id
|
18
|
+
|
19
|
+
doc = Nokogiri::HTML open(profile_url)
|
20
|
+
doc.css('a:isMatchLink', MatchLinkCssFilter.new).map do |l|
|
21
|
+
l['href'].match(MATCH_LINK_REGEX).captures.first
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: popflash_match_downloader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lukas Stabe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.19.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.19'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.19.1
|
33
|
+
description:
|
34
|
+
email: lukas@stabe.de
|
35
|
+
executables:
|
36
|
+
- popflash_match_downloader
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- bin/popflash_match_downloader
|
43
|
+
- lib/popflash_match_downloader.rb
|
44
|
+
- lib/popflash_match_downloader/downloader.rb
|
45
|
+
- lib/popflash_match_downloader/match_file_name_extractor.rb
|
46
|
+
- lib/popflash_match_downloader/recent_matches_extractor.rb
|
47
|
+
homepage: https://github.com/Ahti/popflash_match_downloader
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.2.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: A tool to download match demos from popflash.site
|
71
|
+
test_files: []
|