picfisher 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/TODO.md +1 -0
- data/lib/picfisher/downloader.rb +13 -1
- data/lib/picfisher/fishing_boat.rb +6 -1
- data/lib/picfisher/log.rb +7 -3
- data/lib/picfisher/sanitizer.rb +1 -1
- data/lib/picfisher/version.rb +1 -1
- data/lib/picfisher.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6b49dc4c4a306ff17087d90b81c875043f63062b1760eb0f481e2968b44dd66
|
4
|
+
data.tar.gz: 4caafb009411921cef9a4c3c60a8e231072de6a369f6b4e7a5386d636534d241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cb50f69831f0421ec7cda95a942730ebdec12ceadc664a7c65fbba5322ee0c6315b5eefa06440041106756c3ba54c1fcad876c180abf551047b299da09fa2d7
|
7
|
+
data.tar.gz: 56739738de69a7e0f314815c0665018d516af93cc39451884ae8abe2ac1ba56db02a45cc4e272cab14a9bb32653fbd66e569bc0482999444702bb0ce9b2b8133
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.2.0] - 2024-05-30
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Debug Level is 'info' by default
|
13
|
+
- Error handling when image URL is not valid
|
14
|
+
|
15
|
+
|
8
16
|
## [0.1.0] - 2024-05-30
|
9
17
|
|
10
18
|
### Added
|
data/README.md
CHANGED
data/TODO.md
CHANGED
@@ -5,3 +5,4 @@
|
|
5
5
|
- Add a progress bar for the downloading phase.
|
6
6
|
- Allow multiple concurrent downloads. Add an extra param to decide the number, default `5`
|
7
7
|
- Add error handling to the Downloader. Many things can be wrong when connecting to the internet.
|
8
|
+
- Allow URLs without image extension. This requires the source urls file to have a predictable estructure. Or we request all the images and check the media type of the response.
|
data/lib/picfisher/downloader.rb
CHANGED
@@ -4,8 +4,20 @@ module PicFisher
|
|
4
4
|
module Downloader
|
5
5
|
# TODO: We need to add error handling here
|
6
6
|
def self.download(url, output_path)
|
7
|
-
PicFisher::Log.debug("
|
7
|
+
PicFisher::Log.debug("Fishing #{url} to #{output_path}")
|
8
8
|
|
9
|
+
begin
|
10
|
+
_dowload(url, output_path)
|
11
|
+
rescue OpenURI::HTTPError => e
|
12
|
+
message = "Failed to fish #{url}: #{e}"
|
13
|
+
PicFisher::Log.error(message)
|
14
|
+
raise PicFisher::Error.new(message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self._dowload(url, output_path)
|
9
21
|
io_stream = OpenURI::open_uri(url)
|
10
22
|
|
11
23
|
File.open(output_path, "wb") do |f|
|
@@ -8,7 +8,12 @@ module PicFisher
|
|
8
8
|
urls = PicFisher::URLExtractor.extract(file_to_string)
|
9
9
|
urls.each do |url|
|
10
10
|
sanitized_url = PicFisher::Sanitizer.sanitize_image_url(url)
|
11
|
-
|
11
|
+
|
12
|
+
begin
|
13
|
+
PicFisher::Downloader.download(url, "#{output_directory_path}/#{sanitized_url}")
|
14
|
+
rescue PicFisher::Error
|
15
|
+
PicFisher::Log.error("Failed to fish #{url}. Skipping...")
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/lib/picfisher/log.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module PicFisher
|
2
2
|
module Log
|
3
3
|
def self.debug(message)
|
4
|
-
if ["debug"].include?
|
4
|
+
if ["debug"].include? debug_level
|
5
5
|
output(:debug, message)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.info(message)
|
10
|
-
if ["debug", "info"].include?
|
10
|
+
if ["debug", "info"].include? debug_level
|
11
11
|
output(:info, message)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.error(message)
|
16
|
-
if ["debug", "info", "error"].include?
|
16
|
+
if ["debug", "info", "error"].include? debug_level
|
17
17
|
output(:error, message)
|
18
18
|
end
|
19
19
|
end
|
@@ -24,5 +24,9 @@ module PicFisher
|
|
24
24
|
final_message = "PicFisher [#{level.upcase}] #{message}"
|
25
25
|
Kernel.puts(final_message)
|
26
26
|
end
|
27
|
+
|
28
|
+
def self.debug_level
|
29
|
+
ENV["DEBUG_LEVEL"] || "info" # default is info
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
data/lib/picfisher/sanitizer.rb
CHANGED
data/lib/picfisher/version.rb
CHANGED
data/lib/picfisher.rb
CHANGED
@@ -27,7 +27,7 @@ module PicFisher
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if !Dir.exist?(output_directory_path)
|
30
|
-
message = "Directory not found: #{
|
30
|
+
message = "Directory not found: #{output_directory_path}"
|
31
31
|
PicFisher::Log.error(message)
|
32
32
|
raise PicFisher::Error.new(message)
|
33
33
|
end
|