真實、迅雷、QQ旋風下載地址轉換
阿新 • • 發佈:2019-01-24
#!/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))