iloveck101 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.
- checksums.yaml +7 -0
 - data/bin/iloveck101 +57 -0
 - metadata +45 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 66cf58a890c173c74ecb46bfd45a201109932340
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 70f7cddf8c973b33a737847f1ff2e1b9fb64fa3c
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2b57e9bb3d6ae5f2b135d8669aebdb2e65cd8f145b3855b2ebb452bf12396541b23b54384d20672b0ee7c252bd8e22027ac95ca923185e868229e68b95978a9d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 6bc17062805da87fb1018ee463665e7369d03ee5ea37156e12d6f9db72ce5de039c3196ee6b97c107496374a56199834a2eb21c597231ebc8047780f96db3e12
         
     | 
    
        data/bin/iloveck101
    ADDED
    
    | 
         @@ -0,0 +1,57 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'open-uri'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'set'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            def iloveck101(url)
         
     | 
| 
      
 8 
     | 
    
         
            +
              page_uri = URI.parse(url)
         
     | 
| 
      
 9 
     | 
    
         
            +
              if page_uri.hostname.nil? or not page_uri.hostname.end_with?('ck101.com')
         
     | 
| 
      
 10 
     | 
    
         
            +
                STDERR.print "Unrecognizeed URL: #{url}\n"
         
     | 
| 
      
 11 
     | 
    
         
            +
                return
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              case page_uri.path
         
     | 
| 
      
 15 
     | 
    
         
            +
              when %r{thread-(\d+)-.+\.html}
         
     | 
| 
      
 16 
     | 
    
         
            +
                thread_id = $1
         
     | 
| 
      
 17 
     | 
    
         
            +
              else
         
     | 
| 
      
 18 
     | 
    
         
            +
                STDERR.print "Unrecognizeed URL: #{url}\n"
         
     | 
| 
      
 19 
     | 
    
         
            +
                return
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              page_content = page_uri.read
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              title = page_content.match(%r{<title>(.+)</title>})[1]
         
     | 
| 
      
 25 
     | 
    
         
            +
                .split(' - ')[0]
         
     | 
| 
      
 26 
     | 
    
         
            +
                .gsub('/', '')
         
     | 
| 
      
 27 
     | 
    
         
            +
                .strip
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              image_url_set = Set.new(
         
     | 
| 
      
 30 
     | 
    
         
            +
                page_content
         
     | 
| 
      
 31 
     | 
    
         
            +
                  .scan(%r{file="([^"]+)"})
         
     | 
| 
      
 32 
     | 
    
         
            +
                  .map { |e| e[0] }
         
     | 
| 
      
 33 
     | 
    
         
            +
                  .find_all { |e| e.index('.thumb.').nil?}
         
     | 
| 
      
 34 
     | 
    
         
            +
              )
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              target_folder_path = File.expand_path("~/Pictures/iloveck101/#{thread_id} - #{title}")
         
     | 
| 
      
 37 
     | 
    
         
            +
              if not Dir.exists?(target_folder_path)
         
     | 
| 
      
 38 
     | 
    
         
            +
                FileUtils.mkdir_p(target_folder_path)
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              image_url_set.each { |image_url|
         
     | 
| 
      
 42 
     | 
    
         
            +
                image_uri = page_uri.merge(image_url)
         
     | 
| 
      
 43 
     | 
    
         
            +
                filename = File.expand_path(File.basename(image_uri.path), target_folder_path)
         
     | 
| 
      
 44 
     | 
    
         
            +
                File.open(filename, 'wb') { |f|
         
     | 
| 
      
 45 
     | 
    
         
            +
                  f.write(open(image_uri).read)
         
     | 
| 
      
 46 
     | 
    
         
            +
                }
         
     | 
| 
      
 47 
     | 
    
         
            +
              }
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            if __FILE__ == $0
         
     | 
| 
      
 52 
     | 
    
         
            +
              if ARGV.length > 1
         
     | 
| 
      
 53 
     | 
    
         
            +
                iloveck101(ARGV[0])
         
     | 
| 
      
 54 
     | 
    
         
            +
              else
         
     | 
| 
      
 55 
     | 
    
         
            +
                STDERR.print "Usage: #{File.basename($0)} URL\n"
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,45 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: iloveck101
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - WanCW
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-12-03 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: Download images from ck101 thread, inspired by tzangms.
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: wancw.wang@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 16 
     | 
    
         
            +
            - iloveck101
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - bin/iloveck101
         
     | 
| 
      
 21 
     | 
    
         
            +
            homepage: http://github.com/wancw/iloveck101
         
     | 
| 
      
 22 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 23 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 24 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 25 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 26 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 27 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 29 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 32 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 34 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 35 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 36 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 37 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 38 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 39 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 40 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 41 
     | 
    
         
            +
            rubygems_version: 2.0.3
         
     | 
| 
      
 42 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 43 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 44 
     | 
    
         
            +
            summary: Download images from ck101 thread
         
     | 
| 
      
 45 
     | 
    
         
            +
            test_files: []
         
     |