comparison app/lib/legit_client.rb @ 253:d726e8b92dd1

Support animated gif (same as video)
author nanaya <me@nanaya.net>
date Mon, 25 Mar 2024 02:49:50 +0900
parents 151bc6d97d39
children
comparison
equal deleted inserted replaced
252:151bc6d97d39 253:d726e8b92dd1
54 ret = {} 54 ret = {}
55 55
56 json.each do |entity_media| 56 json.each do |entity_media|
57 val = {} 57 val = {}
58 58
59 if entity_media['type'] == 'photo' 59 case entity_media['type']
60 val[:image_url] = entity_media['media_url_https'] 60 when 'animated_gif', 'video'
61 elsif entity_media['type'] == 'video' 61 val[:variants] = entity_media['video_info']['variants']
62 val[:variants] = entity_media['video_info']['variants'] 62 .filter { |variant| variant['bitrate'].present? }
63 .filter { |variant| variant['bitrate'].present? } 63 .map do |variant|
64 .map do |variant| 64 {
65 { 65 bitrate: variant['bitrate'],
66 bitrate: variant['bitrate'], 66 url: variant['url'],
67 url: variant['url'], 67 }
68 } 68 end
69 end 69 when 'photo'
70 val[:image_url] = entity_media['media_url_https'].sub(/\.([^.]+)$/, '?format=\1')
70 end 71 end
71 72
72 if !val.empty? 73 if !val.empty?
73 val[:url] = entity_media['expanded_url'] 74 val[:url] = entity_media['expanded_url']
74 val[:type] = entity_media['type'] 75 val[:type] = entity_media['type']