Initial import.
This commit is contained in:
commit
3401c755cc
9 changed files with 388 additions and 0 deletions
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
/.bundle/
|
||||
/.yardoc
|
||||
/Gemfile.lock
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
*.bundle
|
||||
*.so
|
||||
*.o
|
||||
*.a
|
||||
mkmf.log
|
4
Gemfile
Normal file
4
Gemfile
Normal file
|
@ -0,0 +1,4 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
# Specify your gem's dependencies in ../imgur-albumkeeper.gemspec
|
||||
gemspec
|
165
LICENSE.txt
Normal file
165
LICENSE.txt
Normal file
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
31
README.md
Normal file
31
README.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
# ../imgur::Albumkeeper
|
||||
|
||||
TODO: Write a gem description
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem '../imgur-albumkeeper'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
|
||||
$ bundle
|
||||
|
||||
Or install it yourself as:
|
||||
|
||||
$ gem install ../imgur-albumkeeper
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Write usage instructions here
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it ( https://github.com/[my-github-username]/../imgur-albumkeeper/fork )
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create a new Pull Request
|
2
Rakefile
Normal file
2
Rakefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
require "bundler/gem_tasks"
|
||||
|
130
bin/imgur-albumkeeper
Executable file
130
bin/imgur-albumkeeper
Executable file
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# Download imgur.com galleries easily
|
||||
#
|
||||
# Requirements:
|
||||
# gem install nokogiri
|
||||
#
|
||||
# Usage:
|
||||
# ruby imgur.rb [url of gallery] [directory to download into] [namespace for files]
|
||||
#
|
||||
# Example:
|
||||
# ruby imgur.rb http://imgur.com/a/npV94 battlefield3 scenery
|
||||
# All files will be downloaded into battlefield3 with filenames in the pattern of
|
||||
# scenery-[number].jpg
|
||||
|
||||
|
||||
require 'nokogiri'
|
||||
require 'open-uri'
|
||||
require 'date'
|
||||
require 'fileutils'
|
||||
require 'optparse'
|
||||
require 'pp'
|
||||
require "shellwords"
|
||||
|
||||
|
||||
def album_url origin_url
|
||||
url = URI.parse origin_url
|
||||
|
||||
url.hostname = case url.hostname
|
||||
when /(.*\.)?imgur.com/ then "imgur.com"
|
||||
else raise "ERROR: unknown url hostname !"
|
||||
end
|
||||
|
||||
url.path = case url.path
|
||||
when /^\/a\/(\S+).*?/ then
|
||||
'/a/' + $1 + '/layout/blog'
|
||||
else raise "ERROR: unknown url path !"
|
||||
end
|
||||
|
||||
puts "Fixed url #{url}"
|
||||
return url
|
||||
end
|
||||
|
||||
def parse_cmdline args
|
||||
options = {}
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: #{File.basename $0} [options]"
|
||||
|
||||
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
||||
options[:verbose] = v
|
||||
end
|
||||
|
||||
opts.on("-z", "--[no-]zip", "Compress album to cbz (zip)") do |v|
|
||||
options[:zip] = v
|
||||
end
|
||||
|
||||
opts.on("-f", "--[no-]force", "Force overwrite in case file(s) exists") do |v|
|
||||
options[:force] = v
|
||||
end
|
||||
end.parse! args
|
||||
return options
|
||||
end
|
||||
|
||||
options = parse_cmdline ARGV
|
||||
|
||||
#pp options
|
||||
#pp ARGV
|
||||
#exit 0
|
||||
|
||||
images = []
|
||||
now = Time.now
|
||||
url = album_url(ARGV[0])
|
||||
directory = ( defined?(ARGV[1]) ? ARGV[1] : nil )
|
||||
#namespace = ( defined?(ARGV[2]) ? ARGV[2] : "image" )
|
||||
namespace = "image"
|
||||
|
||||
# filter url
|
||||
|
||||
page = Nokogiri::HTML(open url)
|
||||
if directory.nil? then
|
||||
directory = page.title.strip.gsub(/\//,'-')
|
||||
directory = "#{directory} (#{url.path.split('/')[2]})"
|
||||
end
|
||||
directory = "#{now.year}#{sprintf("%02d", now.month)}/#{directory}"
|
||||
|
||||
page.search('.thumb-title').each do |image|
|
||||
uri = URI.parse(image.attributes['data-src'].value.gsub(/s.jpg/, '.jpg'))
|
||||
uri.scheme ||= "http"
|
||||
images << uri.to_s
|
||||
end
|
||||
|
||||
destination_exist = false
|
||||
if options[:zip] and File.exist?(directory + ".cbz")
|
||||
destination_exist = true
|
||||
elsif (
|
||||
not options[:zip] and
|
||||
FileTest.directory? directory and
|
||||
FileTest.file? "#{directory}/.imguralbum"
|
||||
) then
|
||||
destination_exist = true
|
||||
end
|
||||
|
||||
if destination_exist and not options[:force] then
|
||||
STDERR.puts "Destination already exists (use --force to overwrite)"
|
||||
exit 1
|
||||
end
|
||||
|
||||
unless FileTest.directory? directory then
|
||||
puts "Creating #{directory}"
|
||||
FileUtils.mkdir_p directory
|
||||
end
|
||||
|
||||
puts "Downloading images into #{directory}...\n\n"
|
||||
|
||||
images.each_with_index do |image, i|
|
||||
indexstr = sprintf("%04d", i)
|
||||
puts "Downloading #{image} as #{namespace}-#{indexstr}.jpg..."
|
||||
file = open(image)
|
||||
File.open("#{directory}/#{namespace}-#{indexstr}.jpg", 'w') do |f|
|
||||
f.write file.read
|
||||
end
|
||||
end
|
||||
FileUtils.touch "#{directory}/.imguralbum"
|
||||
|
||||
if options[:zip] then
|
||||
%x{zip -r #{directory.shellescape}.cbz #{directory.shellescape}}
|
||||
FileUtils.rm_rf directory
|
||||
end
|
||||
|
||||
puts "\nDone."
|
30
imgur-albumkeeper.gemspec
Normal file
30
imgur-albumkeeper.gemspec
Normal file
|
@ -0,0 +1,30 @@
|
|||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'imgur-albumkeeper/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "imgur-albumkeeper"
|
||||
spec.version = Gsfe::VERSION
|
||||
spec.authors = ["Glenn Y. Rolland"]
|
||||
spec.email = ["glenn.rolland@netcat.io"]
|
||||
spec.summary = %q{Archive imgur albums.}
|
||||
spec.description = %q{Archive imgur albums.}
|
||||
spec.homepage = ""
|
||||
spec.license = "MIT"
|
||||
|
||||
spec.files = `git ls-files -z`.split("\x0")
|
||||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
spec.add_runtime_dependency "nokogiri"
|
||||
spec.add_runtime_dependency "thor"
|
||||
#spec.add_runtime_dependency "html2haml"
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.6"
|
||||
spec.add_development_dependency "rake"
|
||||
spec.add_development_dependency "pry"
|
||||
spec.add_development_dependency "minitest"
|
||||
spec.add_development_dependency "rb-readline"
|
||||
end
|
7
lib/imgur-albumkeeper.rb
Normal file
7
lib/imgur-albumkeeper.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "../imgur/albumkeeper/version"
|
||||
|
||||
module ../imgur
|
||||
module Albumkeeper
|
||||
# Your code goes here...
|
||||
end
|
||||
end
|
5
lib/imgur-albumkeeper/version.rb
Normal file
5
lib/imgur-albumkeeper/version.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module ../imgur
|
||||
module Albumkeeper
|
||||
VERSION = "0.0.1"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue