赞
踩
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # 真实、迅雷、QQ旋风下载地址之间的转换
- import base64
- import urllib
- import re
-
- __Author__ = "kingking"
-
- '''
- 原理:
- 迅雷下载地址:"thunder://"+Base64编码("AA"+"真实地址"+"ZZ")
- QQ旋风下载地址:"qqdl://"+Base64编码("真实地址")
- '''
- #############
- # 常量定义区 #
- #############
- THUNDER_HEADER = "thunder://"
- THUNDER_PREFIX = "AA"
- THUNDER_SUFFIX = "ZZ"
- QQ_HEADER = "qqdl://"
- ERROR = "传入的URL有误,请检查!"
-
- # 判断url是否有效
- def checkUrl(func):
- def wrapper(url):
- if re.match(r"(http|https|ftp|ed2k|thunder|qqdl)://", url):
- return func(url)
- else:
- return ERROR
- return wrapper
-
-
- def real2QQ(url):
- url = base64.b64encode(url.encode("utf-8"))
- url = QQ_HEADER + url.decode("utf-8")
- return url
-
-
- def qq2Real(url):
- url = url[len(QQ_HEADER):]
- url = base64.b64decode(url.encode("utf-8"))
- url = url.decode("utf-8")
- return url
-
-
- def real2Thunder(url):
- url = THUNDER_PREFIX + url + THUNDER_SUFFIX
- url = base64.b64encode(url.encode("utf-8"))
- url = THUNDER_HEADER + url.decode("utf-8")
- return url
-
-
- def thunder2Real(url):
- url = url[len(THUNDER_HEADER):]
- url = base64.b64decode(url.encode("utf-8"))
- url = url.decode("utf-8")
- url = url[len(THUNDER_PREFIX):-len(THUNDER_SUFFIX)]
- return url
-
-
- def qq2Thunder(url):
- return real2Thunder(qq2Real(url))
-
-
- def thunder2QQ(url):
- return real2QQ(thunder2Real(url))
-
-
- if __name__ == "__main__":
- # 测试用,SuperGirl第一季第2集下载地址:
- url_1 = r'ed2k://|file|Supergirl.S01E02.720p.HDTV.X264-DIMENSION.mkv|947617048|5D430BBD720C13598D867C3424B50B8D|h=2AG3ZXRLCWNGC4K5WFNC4QOMVDSXWBBM|/'
- url_2 = r'd2k://|file|Supergirl.S01E02.720p.HDTV.X264-DIMENSION.mkv|947617048|5D430BBD720C13598D867C3424B50B8D|h=2AG3ZXRLCWNGC4K5WFNC4QOMVDSXWBBM|/'
- url = 'thunder://QUFmdHA6Ly95Z2R5ODp5Z2R5OEB5ZzQ1LmR5ZHl0dC5uZXQ6NjAwNC9bJUU5JTk4JUIzJUU1JTg1JTg5JUU3JTk0JUI1JUU1JUJEJUIxd3d3LnlnZHk4LmNvbV0uJUU2JTgyJTlGJUU3JUE5JUJBJUU0JUJDJUEwLkhELjcyMHAuJUU1JTlCJUJEJUU4JUFGJUFEJUU0JUI4JUFEJUU1JUFEJTk3Lm1rdlpa'
- print(real2QQ(url_1))
- print(thunder2QQ(real2Thunder(url_1)))
- print(real2QQ(url_2))
- print(thunder2Real(url))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。