Skip to content

Instantly share code, notes, and snippets.

@jbanquo
Created October 22, 2017 13:02
Show Gist options
  • Save jbanquo/f80dd39458037c8e064ac6a137c6cdb9 to your computer and use it in GitHub Desktop.
Save jbanquo/f80dd39458037c8e064ac6a137c6cdb9 to your computer and use it in GitHub Desktop.
xvideos downloader, place the urls in a file called 'url.txt' and run it!
import re
import requests
import urllib3
def download_src(url, chunk_size=1024):
req = urllib3.PoolManager().request('GET', url, preload_content=False)
src = req.data.decode('utf-8')
req.release_conn()
return src
def download_vid(filename, url):
with open(filename, 'wb') as fout:
response = requests.get(url, stream=True)
response.raise_for_status()
# Write response data to file
for block in response.iter_content(8192):
fout.write(block)
def process(url):
# Download source
src = download_src(url)
# Parse details
title_regex = r'setVideoTitle\(\'(.*)\'\);'
vid_highq_regex = r'setVideoUrlHigh\(\'(.*)\'\);'
# vid_lowq_regex = r'setVideoUrlLow\(\'(.*)\'\);'
title = re.search(title_regex, src).group(1)
highq_url = re.search(vid_highq_regex, src).group(1)
# lowq_url = re.search(vid_lowq_regex, src).group(1)
# Download video
download_vid(parse_filename(title) + ".mp4", highq_url)
def parse_filename(name):
keepcharacters = (' ', '.', '_')
return ''.join(c for c in name if c.isalnum() or c in keepcharacters).rstrip()
# Download all videos in file
for line in open('urls.txt'):
line = line.rstrip()
print('Processing: {0}'.format(line))
process(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment