-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam-screenshot-sort.py
42 lines (34 loc) · 1.46 KB
/
steam-screenshot-sort.py
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
#!/usr/bin/env python
import urllib2
import os
import json
import sys
import shutil
import re
def get_steam_name(steamID):
try:
steamID = int(steamID)
if steamID > 0 and steamID < 9223372036854775807:
r = urllib2.urlopen('https://store.steampowered.com/api/appdetails/?appids='+str(steamID))
data = json.load(r)
if (data[unicode(steamID)]['success']):
return unicode(data[unicode(steamID)]['data']['name'])
except:
pass
def main():
root = os.getcwd()
for dir_name in os.listdir(root):
dir_path = os.path.join(root, dir_name)
sreens_path = os.path.join(dir_path, 'screenshots')
game_name = get_steam_name(dir_name)
if (game_name):
game_name = re.sub(ur'[^a-zA-Z0-9-_]', ' ', game_name).strip()
new_folder = os.path.join(root, game_name)
if not os.path.isdir(new_folder):
os.mkdir(new_folder)
for img in os.listdir(sreens_path):
if (not os.path.isdir(os.path.join(sreens_path, img))):
shutil.copy2(os.path.join(sreens_path, img), new_folder)
shutil.rmtree(dir_path, True)
if __name__ == '__main__':
main()