forked from dryruner/imagecrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_objurl.py
86 lines (80 loc) · 1.82 KB
/
decode_objurl.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
import sys
encoded_str1 = "_z2C$q"
encoded_str2 = "_z&e3B"
encoded_str3 = "AzdH3F"
HASHTABLE = {
encoded_str1 : ":",
encoded_str2 : ".",
encoded_str3 : "/",
"w" : "a",
"k" : "b",
"v" : "c",
"1" : "d",
"j" : "e",
"u" : "f",
"2" : "g",
"i" : "h",
"t" : "i",
"3" : "j",
"h" : "k",
"s" : "l",
"4" : "m",
"g" : "n",
"5" : "o",
"r" : "p",
"q" : "q",
"6" : "r",
"f" : "s",
"p" : "t",
"7" : "u",
"e" : "v",
"o" : "w",
"8" : "1",
"d" : "2",
"n" : "3",
"9" : "4",
"c" : "5",
"m" : "6",
"0" : "7",
"b" : "8",
"l" : "9",
"a" : "0",
}
def DecodeObjUrl(objURL):
i = 0;
decoded_url = "";
while i < len(objURL):
if (objURL[i] == "_" and
objURL.find(encoded_str1, i, i + len(encoded_str1)) != -1):
decoded_url += HASHTABLE[encoded_str1]
i += len(encoded_str1)
elif (objURL[i] == "_" and
objURL.find(encoded_str2, i, i + len(encoded_str2)) != -1):
decoded_url += HASHTABLE[encoded_str2]
i += len(encoded_str2)
elif (objURL[i] == "A" and
objURL.find(encoded_str3, i, i + len(encoded_str3)) != -1):
decoded_url += HASHTABLE[encoded_str3]
i += len(encoded_str3)
elif objURL[i] in HASHTABLE:
decoded_url += HASHTABLE[objURL[i]]
i += 1
else:
decoded_url += objURL[i]
i += 1
# print "decoded_url = ", decoded_url
return decoded_url
def ProcessRawObjUrlFile(in_f, out_f):
with open(in_f, 'r') as infile:
with open(out_f, 'w') as outfile:
for objURL in infile:
decoded_url = DecodeObjUrl(objURL)
outfile.write(decoded_url);
if __name__ == '__main__':
if len(sys.argv) != 3:
print "Usage: ./decode.py <raw_objURL_file> <decoded_objURL_file>"
sys.exit(1)
infile = sys.argv[1]
outfile = sys.argv[2]
ProcessRawObjUrlFile(infile, outfile)