-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path(broken)_generate_switch_folder_images.py
More file actions
45 lines (34 loc) · 1.15 KB
/
(broken)_generate_switch_folder_images.py
File metadata and controls
45 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import re
import requests
# import webbrowser
from PIL import Image
from io import BytesIO
from mtlogger import logger
from _common import process_parent_folder, save_resized_image
IMAGE_URL = "https://tinfoil.media/ti/{game_id}/256/256/"
def main():
process_parent_folder(process_folder)
def process_folder(folder_path):
match = re.match(r'(^[0-9A-F]+$)', os.path.basename(os.path.normpath(folder_path)).upper())
if match:
game_id = match.group(1)
else:
logger.error(f'Could not extract a valid game ID from "{folder_path}"')
return
download_game_cover(game_id, folder_path)
def download_game_cover(game_id, folder_path):
image_url = IMAGE_URL.format(game_id = game_id)
# webbrowser.open(image_url)
response = requests.get(image_url)
if response.status_code != 200:
logger.error(f'Could not access the search results for {game_id}. Status code: {response.status_code}')
return
img = Image.open(BytesIO(response.content))
save_resized_image(img, folder_path)
if __name__ == '__main__':
try:
main()
except Exception as ex:
logger.error(f'An unexpected error occurred: {ex}')
input('Press Enter to exit...')