-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_convert.py
More file actions
executable file
·106 lines (92 loc) · 3.56 KB
/
url_convert.py
File metadata and controls
executable file
·106 lines (92 loc) · 3.56 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# coding=utf8
import base64
import sys
class URL_Convert(object):
URL_TYPE_PLAIN = 0
URL_TYPE_THUNDER = 1
URL_TYPE_QQ = 2
URL_TYPE_FLASHGET = 3
URL_TYPE_UNKNOWN = 4
def __init__(self, url):
self.url = url
self.url_type = URL_Convert.URL_TYPE_UNKNOWN
self.url_plain = self.__convert_to_plain(self.url)
self.url_thunder = self.__url_thunder_encode(self.url_plain)
self.url_qq = self.__url_qq_encode(self.url_plain)
self.url_flashget = self.__url_flashget_encode(self.url_plain)
def print_result(self):
print "Plain url is {url_plain}\n" \
"Thunder url is {url_thunder}\n" \
"QQ url is {url_qq}\n" \
"Flashget url is {url_flashget}".format(
url_plain=self.url_plain,
url_thunder = self.url_thunder,
url_qq = self.url_qq,
url_flashget = self.url_flashget
)
def __check_url_type(self, url):
url_type = URL_Convert.URL_TYPE_UNKNOWN
if url.startswith("thunder://"):
url_type = URL_Convert.URL_TYPE_THUNDER
elif url.startswith("qqdl://"):
url_type = URL_Convert.URL_TYPE_QQ
elif url.startswith("Flashget://"):
url_type = URL_Convert.URL_TYPE_FLASHGET
else:
url_type = URL_Convert.URL_TYPE_PLAIN
return url_type
def __convert_to_plain(self, url):
url_plain = ""
self.url_type = self.__check_url_type(url)
if self.url_type == URL_Convert.URL_TYPE_PLAIN:
url_plain = url
elif self.url_type == URL_Convert.URL_TYPE_THUNDER:
url_plain = self.__url_thunder_decode(url)
elif self.url_type == URL_Convert.URL_TYPE_QQ:
url_plain = self.__url_qq_decode(url)
elif self.url_type == URL_Convert.URL_TYPE_FLASHGET:
url_plain = self.__url_flashget_decode(url)
return url_plain
def __url_thunder_decode(self, url):
url = url.replace("thunder://", "")
url = base64.b64decode(url)
url = url[2:-2]
return url
def __url_qq_decode(self, url):
url = url.replace("qqdl://", "")
url = base64.b64decode(url)
return url
def __url_flashget_decode(self, url):
url = url.replace("Flashget://", "")
url = url[:-5]
url = base64.b64decode(url)
url = url.replace("[FLASHGET]", "")
return url
def __url_thunder_encode(self, url):
thunder_prefix = "AA"
thunder_posix = "ZZ"
thunder_url_prefix = "thunder://"
thunder_url = thunder_url_prefix + base64.b64encode(thunder_prefix + url + thunder_posix)
return thunder_url
def __url_qq_encode(self, url):
qq_url_prefix = "qqdl://"
qq_url = qq_url_prefix + base64.b64encode(url)
return qq_url
def __url_flashget_encode(self, url):
flash_prefix = "[FLASHGET]"
flash_posix = "[FLASHGET]"
flash_url_prefix = "Flashget://"
flash_url_posix = "&1926"
flash_url = flash_url_prefix + base64.b64encode(flash_prefix + url + flash_posix) + flash_url_posix
return flash_url
if __name__ == "__main__":
# http://www.iqshw.com/url/xunlei/urlconvert.js
url = "http://www.baidu.com"
# url = "thunder://QUFodHRwOi8vd3d3LmJhaWR1LmNvbVpa"
# url = "qqdl://aHR0cDovL3d3dy5iYWlkdS5jb20="
# url = "Flashget://W0ZMQVNIR0VUXWh0dHA6Ly93d3cuYmFpZHUuY29tW0ZMQVNIR0VUXQ==&1926"
if len(sys.argv) >= 2:
url = str(sys.argv[1])
url_convert = URL_Convert(url)
url_convert.print_result()