Created
January 17, 2022 05:27
-
-
Save Qman11010101/184a28369387565441af57e53cefd882 to your computer and use it in GitHub Desktop.
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
import os | |
import sys | |
import time | |
import traceback | |
import requests | |
req_url = "https://chunithm.sega.jp/storage/json/music.json" | |
img_baseurl = "https://new.chunithm-net.com/chuni-mobile/html/mobile/img/" | |
data = requests.get(req_url).json() | |
VERSION = "1.1.0" | |
print(f"CHUNITHMジャケット画像ダウンローダー Ver{VERSION}") | |
diff = input("難易度を半角で入力してください(例: 14+)>> ") | |
choiced = [] | |
for music in data: | |
if diff in [music["lev_bas"], music["lev_adv"], music["lev_exp"], music["lev_mas"], music["lev_ult"]]: | |
choiced.append(music) | |
if not len(choiced): | |
print("エラー: その難易度帯の楽曲は存在しません。") | |
print("Tips: 難易度は1~15の範囲で検索する必要があります。0以下および15+以上の楽曲は存在しません。") | |
sys.exit() | |
print(f"{len(choiced)}曲見つかりました。ダウンロードを開始します。") | |
os.makedirs(diff, exist_ok=True) | |
for music in choiced: | |
try: | |
url = img_baseurl + music["image"] | |
imageblob = requests.get(url) | |
if imageblob.status_code == 200: | |
title = music["title"] | |
print(f"「{title}」を {url} からダウンロードしています…") | |
table = str.maketrans('\\/:*?"<>|', "_________", "") | |
with open(f"./{diff}/" + f"{title}.png".translate(table), "wb") as i: | |
i.write(imageblob.content) | |
else: | |
print(f"Status: {imageblob.status_code} エラーが発生したため、ファイルのダウンロードができませんでした。") | |
except: | |
print("以下のエラーが発生したため、ファイルのダウンロードができませんでした。") | |
traceback.print_exc() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment