-
Notifications
You must be signed in to change notification settings - Fork 1
/
ah-dl
executable file
·60 lines (51 loc) · 2.17 KB
/
ah-dl
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
#!/usr/bin/env python3
__author__ = 'auroux_l'
import mechanicalsoup
import re
from time import sleep
import subprocess
base_url = "http://www.anime-ultime.net/"
prx = None
#prx = {'http': 'http://127.0.0.1:8080'}
def json_head(ref):
return {'X-Requested-With': "XMLHttpRequest", 'Referer': ref,
'Accept': 'application/json, text/javascript, */*; q=0.01', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
def post_page(browser, url, data, ref):
global prx
return browser.post(url, data=data, proxies=prx, headers=json_head(ref))
if __name__ == "__main__":
import argparse
aparse = argparse.ArgumentParser(description='AnimeUltime main script')
aparse.add_argument(dest='page_adr', metavar='PAGE_ADR', type=str, help='page address that containt ALL the download link')
args = aparse.parse_args()
page_adr = args.page_adr
print("LOAD %s" % page_adr)
# get a browser
browser = mechanicalsoup.Browser()
# hit first page (get cookies and stuff)
current_page = browser.get(page_adr)
# collect all dl link
all_dl_links = []
for link in current_page.soup.select('td[class^=td] a[href^=info]'):
if link.contents[0] == 'Télécharger':
all_dl_links.append(link.attrs['href'])
###
for link in all_dl_links:
id_to_dl = -1
current_page = browser.get(base_url + link)
for dlp in current_page.soup.select('a[href^=javascript:open_ddlbox]'):
m = re.search('javascript:open_ddlbox\(\'dl_hq\', \'(\d+)\', \'hq\'\)', dlp.attrs['href'])
if m is not None:
id_to_dl = int(m.group(1).strip())
# download this ID
print(id_to_dl)
dlpage = post_page(browser, base_url + 'ddl/authorized_download.php', "idfile=%d&type=hq" % id_to_dl, base_url + link)
data = dlpage.json()
# first sleep
print(data)
print("WAIT...")
sleep(data['wait'] + 4)
dlpage = post_page(browser, base_url + 'ddl/authorized_download.php', "idfile=%d&type=hq" % id_to_dl, base_url + link)
data = dlpage.json()
print(data)
subprocess.check_call(['wget', base_url + data['link']])