プロジェクト

全般

プロフィール

機能 #532 » openimg-tumblr fotolife.diff

hycon miyagi, 2012-11-09 17:59

差分を表示:

core/plugin/openimg/openimg.rb (作業コピー)
184 184
      nil
185 185
    end
186 186
  }
187

  
187
  
188
  # Tumblr image
189
  # http://tmblr.co/[-\w]+ http://tumblr.com/[[:36進数:]]+
190
  # http://{screen-name}.tumblr.com/post/\d+
191
  # 上記を展開し、記事タイプがphotoかphotosetなら /post/ を /image/ にすると
192
  # 単一画像ページが得られることを利用した画像展開
193
  addsupport(/^http:\/\/([-0-9a-z]+\.tumblr\.com\/post\/\d+|tmblr\.co\/[-\w]+$|tumblr\.com\/[0-9a-z]+$)/, nil) { |url, cancel|
194
    def fetch(t)
195
      req = URI.parse(t)
196
      res = Net::HTTP.new(req.host).request_head(req.path)
197
      case res
198
      when Net::HTTPSuccess
199
        t
200
      when Net::HTTPRedirection
201
        fetch(res['location'])
202
      else
203
        nil
204
      end
205
    end
206
    
207
    t = fetch(url)
208
    /^(http:\/\/[^\/]+\/)post(\/\d+)/ =~ t
209
    if $~
210
      imgurlresolver($1 + "image" + $2, 'id' => 'image')
211
    else
212
      warn "たんぶらの記事ページじゃないっぽい"
213
      nil
214
    end
215
  }
216
  
188 217
  ::Gtk::TimeLine.addopenway(/.*\.(?:jpg|png|gif|)$/) { |shrinked_url, cancel|
189 218
    url = MessageConverters.expand_url_one(shrinked_url)
190 219
    Delayer.new(Delayer::NORMAL) { display(url, cancel) }
core/plugin/openimg/pattern_file.json (作業コピー)
107 107
			},
108 108
			"class": "pict"
109 109
		}
110
	},
111
	"Tumblr image": {
112
		"url": "^http://[-0-9a-z]+\\.tumblr\\.com/image/\\d+",
113
		"attribute": {
114
			"id": "image"
115
		}
116
	},
117
	"はてなフォトライフ": {
118
		"url": "^http://f\\.hatena\\.ne\\.jp/[-\\w]+/\\d{9,}",
119
		"attribute": {
120
			"tag" : "img",
121
			"attribute": "src",
122
			"class": "foto"
123
		}
110 124
	}
111 125
}
    (1-1/1)