Last active
April 27, 2022 19:22
-
-
Save DarkKowalski/89e7742f1e2b98b65f611b922aa102d3 to your computer and use it in GitHub Desktop.
下载米游社表情包 Download HoYoLab(CN) Stickers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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