Skip to content

Instantly share code, notes, and snippets.

@DarkKowalski
Last active April 27, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkKowalski/89e7742f1e2b98b65f611b922aa102d3 to your computer and use it in GitHub Desktop.
Save DarkKowalski/89e7742f1e2b98b65f611b922aa102d3 to your computer and use it in GitHub Desktop.
下载米游社表情包 Download HoYoLab(CN) Stickers
#!/usr/bin/env ruby
# 2022-04-28 it works
# gem install faraday
require 'faraday'
require 'json'
require 'fileutils'
root_dir = 'download'
res = Faraday.get 'https://api-static.mihoyo.com/takumi/misc/api/emoticon_set'
lists = JSON.parse(res.body)['data']['list']
lists.each do |list|
list_name = list['name']
list_id = list['id']
list_path = File.join(root_dir, list_name)
list_status = list['status']
stickers = list['list']
if list_status == 'draft'
puts "Skip list #{list_id} - #{list_name}"
next
else
puts "Fetch list #{list_id} - #{list_name}"
FileUtils.mkdir_p list_path
end
stickers = list['list']
stickers.each do |sticker|
id = sticker['id']
name = sticker['name']
url = sticker['icon']
ext = url.split('.').last
image_path = File.join(list_path, "#{name}.#{ext}")
puts "-- Fetch sticker #{id} - #{name}.#{ext}: #{url}"
image = Faraday.get(url).body
File.open(image_path, 'wb') { |f| f.write(image) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment