Skip to content

Commit

Permalink
Merge pull request #809 from dai-vdr/fix_amazon_wrong_stored_cache
Browse files Browse the repository at this point in the history
amazon plugin: support HTTP Found response and discard wrong stored cache
  • Loading branch information
tdtds authored Aug 15, 2019
2 parents 0f3bb76 + 422ce6e commit fdbbf1e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion misc/plugin/amazon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def amazon_fetch( url, limit = 10 )
case res
when Net::HTTPSuccess
res.body
when Net::HTTPRedirection
when Net::HTTPRedirection, Net::HTTPFound
amazon_fetch( res['location'], limit - 1 )
when Net::HTTPForbidden, Net::HTTPServiceUnavailable
raise AmazonRedirectError.new( limit.to_s )
Expand Down Expand Up @@ -281,6 +281,9 @@ def amazon_get( asin, with_image = true, label = nil, pos = 'amazon' )
Dir::mkdir( cache ) unless File::directory?( cache )
begin
xml = File::read( "#{cache}/#{country}#{asin}.xml" )
if xml.chomp == 'true'
raise Errno::ENOENT
end
rescue Errno::ENOENT
xml = amazon_call_ecs( asin, id_type, country )
File::open( "#{cache}/#{country}#{asin}.xml", 'wb' ) {|f| f.write( xml )}
Expand Down

0 comments on commit fdbbf1e

Please sign in to comment.