Created
December 6, 2015 00:09
-
-
Save korayal/ac4fdef363487deabe99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import sys | |
import requests | |
from bs4 import BeautifulSoup | |
from random import randint | |
# USAGE: ./dpdl.py 'http://altyazi.org/sub/s/380146/Doctor-Who.html' | |
def dl_divxplanet(dl_url): | |
s = requests.Session() | |
req1 = s.get(dl_url) | |
page = BeautifulSoup(req1.text, 'html5lib') | |
# find the dl button and set keys for the file request | |
form = page.find('form', id='dlform') | |
indir_keys = form.find_all('input', attrs={'type': 'hidden'}) | |
form_data = {} | |
for k in indir_keys: | |
form_data[k['name']] = k['value'] | |
form_data['x'] = randint(1,19) | |
form_data['y'] = randint(1,19) | |
f = s.post('http://altyazi.org/indir.php', data=form_data, stream=True) | |
if f.status_code == 200: | |
if 'Content-Disposition' in f.headers: | |
# use the provided file name if possible | |
fname = f.headers['Content-Disposition'].split('filename=')[1].strip('"\'') | |
else: | |
# use a generic name | |
fname = 'test.zip' | |
with open(fname, 'wb') as outfile: | |
for chunk in f.iter_content(1024): | |
outfile.write(chunk) | |
else: | |
raise ConnectionError("Couldn't Get The File") | |
s.close() | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
dl_divxplanet(sys.argv[1]) | |
else: | |
raise ValueError('You must enter a valid url') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment