Sha256: 4d4168077b68969d3f9c5bf5672df5b2a71644c9d62dfc1d37d1db87e49bd9a7

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8
module Nokaya

  class TumblrAlbum < Basic

    def initialize args, options = {}
      super(args, options)
      @type = :tumblr
      parsed = parse(args[0])
      @urls = album(parsed)
      @filenames = name_files()
      @path = "#{@path}/tumblr-#{@workers.timed}"
    end

    private

    def album page
      return [] if page.nil?
      refs = []
      queries = ['img.photo', '.post .photo a img', '.entry img', 'article img', '.image img', '.item_content img', 'img.post-image', '.box img', '#allposts img', '.media img', '.wide img', '.big img', '.large img', '.gallery img', '.photos img', '.content img', 'img']
      queries.each do |query|
        refs = page.css query
        next if refs.empty?
        break
      end
      links = []
      refs.each do |l|
        target = l['src']
        unless (target == 'reblog.png' || target =~ /statcounter/ || target =~ /impixu/ || target =~ /quantserve/ || target == 'like.png')
          links << target
        end
      end
      links.compact
    end

    def name_files
      @urls.map do |url|
        "#{@type.to_s}-#{File.basename(url).gsub('tumblr_', '')}"
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nokaya-0.1.6 lib/nokaya/tumblr_album.rb
nokaya-0.1.5 lib/nokaya/tumblr_album.rb
nokaya-0.1.4 lib/nokaya/tumblr_album.rb
nokaya-0.1.3 lib/nokaya/tumblr_album.rb