Upload 5 files
Browse files- data.json +0 -0
- get_posters.py +40 -0
- get_stylesubject.py +48 -0
- merge_language.py +40 -0
- requirements.txt +2 -0
data.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
get_posters.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import json
|
4 |
+
import requests
|
5 |
+
import time
|
6 |
+
|
7 |
+
from pathlib import Path
|
8 |
+
|
9 |
+
|
10 |
+
def main(json_path):
|
11 |
+
with open(json_path, 'r') as file:
|
12 |
+
data = json.load(file)
|
13 |
+
|
14 |
+
os.makedirs('./data', exist_ok=True)
|
15 |
+
|
16 |
+
for movie in data['movies']:
|
17 |
+
for movie_file, countries in movie.items():
|
18 |
+
base_filename = movie_file.split(".")[0]
|
19 |
+
|
20 |
+
for country, details in countries.items():
|
21 |
+
out_path = './data/' + 'US-' + country
|
22 |
+
os.makedirs(out_path, exist_ok=True)
|
23 |
+
country_code_download_dir = Path(out_path + '/' + country + '-poster')
|
24 |
+
country_code_download_dir.mkdir(exist_ok=True)
|
25 |
+
image_url = details['link']
|
26 |
+
response = requests.get(image_url)
|
27 |
+
|
28 |
+
if response.status_code == 200:
|
29 |
+
download_dir = country_code_download_dir
|
30 |
+
file_path = f"{download_dir}/{movie_file}"
|
31 |
+
|
32 |
+
with open(file_path, 'wb') as file:
|
33 |
+
file.write(response.content)
|
34 |
+
print(f"Downloaded {file_path}")
|
35 |
+
|
36 |
+
else:
|
37 |
+
print(f"Failed to download from {image_url}")
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
main(sys.argv[1])
|
get_stylesubject.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import sys
|
3 |
+
import os
|
4 |
+
import json
|
5 |
+
|
6 |
+
def crop_image(image_path, top_left, bottom_right):
|
7 |
+
image = Image.open(image_path)
|
8 |
+
image = image.convert('RGBA')
|
9 |
+
cropped_image = image.crop((*top_left, *bottom_right))
|
10 |
+
return cropped_image
|
11 |
+
|
12 |
+
def main(json_path, data_dir):
|
13 |
+
target_dir = './must-bench'
|
14 |
+
os.makedirs(target_dir, exist_ok=True)
|
15 |
+
with open(json_path, 'r') as file:
|
16 |
+
data = json.load(file)
|
17 |
+
|
18 |
+
for movie in data['movies']:
|
19 |
+
for movie_file, countries in movie.items():
|
20 |
+
for country, details in countries.items():
|
21 |
+
coords = details['coords']
|
22 |
+
available = details['available']
|
23 |
+
if available and coords:
|
24 |
+
base_dir = f"{data_dir}/US-{country}"
|
25 |
+
save_base_dir = f"{target_dir}/{country}"
|
26 |
+
src_dir = os.path.join(base_dir, f"{country}-poster")
|
27 |
+
img_path = os.path.join(src_dir, movie_file)
|
28 |
+
|
29 |
+
for i in range(0, len(coords), 4):
|
30 |
+
if i == len(coords) - 4:
|
31 |
+
break
|
32 |
+
if i+3 >= len(coords):
|
33 |
+
print(f"{movie_file} + {country} Invalid coordinates.")
|
34 |
+
break
|
35 |
+
top_left = (coords[i], coords[i+1])
|
36 |
+
bottom_right = (coords[i+2], coords[i+3])
|
37 |
+
cropped_image = crop_image(img_path, top_left, bottom_right)
|
38 |
+
base_name = movie_file.split(".")[0]
|
39 |
+
|
40 |
+
save_dir = os.path.join(save_base_dir, base_name)
|
41 |
+
os.makedirs(save_dir, exist_ok=True)
|
42 |
+
|
43 |
+
save_path = os.path.join(save_dir, f"{i//4}.png")
|
44 |
+
resized_image = cropped_image.resize((256, 256))
|
45 |
+
resized_image.save(save_path)
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
main(sys.argv[1], sys.argv[2])
|
merge_language.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import shutil
|
4 |
+
|
5 |
+
def get_subdirectories(dir_path):
|
6 |
+
return [d for d in os.listdir(dir_path) if os.path.isdir(os.path.join(dir_path, d))]
|
7 |
+
|
8 |
+
def main(dir1, dir2):
|
9 |
+
base_dir = "./must-bench"
|
10 |
+
dir1_path = os.path.join(base_dir, dir1)
|
11 |
+
dir2_path = os.path.join(base_dir, dir2)
|
12 |
+
|
13 |
+
subdirs1 = set(get_subdirectories(dir1_path))
|
14 |
+
subdirs2 = set(get_subdirectories(dir2_path))
|
15 |
+
common_subdirs = subdirs1.intersection(subdirs2)
|
16 |
+
|
17 |
+
new_dir = base_dir + '/' + dir1 + '-' + dir2
|
18 |
+
if not os.path.exists(new_dir):
|
19 |
+
os.makedirs(new_dir)
|
20 |
+
|
21 |
+
for subdir in common_subdirs:
|
22 |
+
dir1_sub_path = os.path.join(dir1_path, subdir)
|
23 |
+
dir2_sub_path = os.path.join(dir2_path, subdir)
|
24 |
+
dst_path = os.path.join(new_dir, subdir)
|
25 |
+
os.makedirs(dst_path, exist_ok=True)
|
26 |
+
|
27 |
+
total_files = os.listdir(dir1_sub_path) + os.listdir(dir2_sub_path)
|
28 |
+
|
29 |
+
for file in total_files:
|
30 |
+
file1 = os.path.join(dir1_sub_path, file)
|
31 |
+
file2 = os.path.join(dir2_sub_path, file)
|
32 |
+
|
33 |
+
if os.path.exists(file1):
|
34 |
+
|
35 |
+
shutil.copy(file1, os.path.join(dst_path, f"{dir1}_{file}"))
|
36 |
+
if os.path.exists(file2):
|
37 |
+
shutil.copy(file2, os.path.join(dst_path, f"{dir2}_{file}"))
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
main(sys.argv[1], sys.argv[2])
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
requests
|
2 |
+
pillow
|