# frozen_string_literal: true # @see Source::URL::Weibo module Source class Extractor class Weibo < Source::Extractor def match? Source::URL::Weibo === parsed_url end def image_urls if parsed_url.image_url? [parsed_url.full_image_url] elsif api_response.present? if api_response["pics"].present? api_response["pics"].pluck("url").map { |url| Source::URL.parse(url).full_image_url } elsif api_response.dig("page_info", "type") == "video" variants = api_response["page_info"]["media_info"].to_h.values + api_response["page_info"]["urls"].to_h.values largest_video = variants.max_by do |variant| if /template=(?\d+)x(?\d+)/ =~ variant.to_s width.to_i * height.to_i else 0 end end [largest_video] end else [url] end end def page_url return nil unless api_response.present? artist_id = api_response["user"]["id"] illust_base62_id = api_response["bid"] "https://www.weibo.com/#{artist_id}/#{illust_base62_id}" end def tags return [] if api_response.blank? matches = api_response["text"]&.scan(/surl-text">#(.*?)#