diff --git a/DownloadHelper/.gitignore b/DownloadHelper/.gitignore new file mode 100644 index 0000000..54b9694 --- /dev/null +++ b/DownloadHelper/.gitignore @@ -0,0 +1,2 @@ +config.json +*.pyc diff --git a/DownloadHelper/README.md b/DownloadHelper/README.md new file mode 100644 index 0000000..3d334a5 --- /dev/null +++ b/DownloadHelper/README.md @@ -0,0 +1,7 @@ +###DownloadHelper### + +SNI problem: + +`pip install pyOpenSSL` +`pip install ndg-httpsclient` +`pip install pyasn1` \ No newline at end of file diff --git a/DownloadHelper/config.json.example b/DownloadHelper/config.json.example new file mode 100644 index 0000000..cbc7573 --- /dev/null +++ b/DownloadHelper/config.json.example @@ -0,0 +1,22 @@ +{ + "url": "https://your.domain.name/your_downloads_dir_name/", + "http_user": "YOUR_USERNAME", + "http_password": "YOUR_PASSWORD", + "file_type": [ + ".mp4", + ".wmv", + ".mkv", + ".avi", + ".zip", + ".rar", + ".7z", + ".tar", + ".ANY_OTHER" + ], + "mirror": [ + "https://mirror1.aaa.com/any/", + "https://mirror2.bbb.org/proxy/", + "https://mirror3.ccc.net/directory/", + "https://mirror4.ddd.me/name/" + ] +} \ No newline at end of file diff --git a/DownloadHelper/index2link.py b/DownloadHelper/index2link.py new file mode 100755 index 0000000..c256f9f --- /dev/null +++ b/DownloadHelper/index2link.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +import os +import requests +import json +import base64 + +from bs4 import BeautifulSoup + +__author__ = 'ty' + +config = json.load(open('config.json')) + +authorization = base64.b64encode(config["http_user"] + ":" + + config["http_password"]) + +url = config["url"] + +file_type = config["file_type"] +mirror = config["mirror"] + +headers = {"Authorization": "Basic " + authorization} + +link_list = [] + + +def list_dir(target_url): + r = requests.get(target_url, headers=headers, verify=True) + + soup = BeautifulSoup(r.text) + + links = soup.find_all("a") + + for link in links: + href = link.get('href') + + if href == "../": + continue + + if href.endswith('/'): + list_dir(target_url + href) + else: + link_list.append(target_url + href) + + +list_dir(url) + +link_list.sort(key=os.path.splitext) +link_list.sort(key=lambda f: os.path.splitext(f)[1]) + +for l in link_list: + + if any(os.path.splitext(l)[1].lower() in s for s in file_type): + + download_link = l + + for m in mirror: + download_link += " " + l.replace(url, m) + print download_link + "\n" diff --git a/DownloadHelper/mirror.py b/DownloadHelper/mirror.py new file mode 100755 index 0000000..5cfb277 --- /dev/null +++ b/DownloadHelper/mirror.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +import json +import sys + +__author__ = 'ty' + +config = json.load(open('config.json')) +mirror = config["mirror"] +url = config["url"] + +l = sys.argv[1] + +download_link = l + +for m in mirror: + download_link += " " + l.replace(url, m) +print download_link + "\n"