I mostly view porn on my mobile and would like to download videos I like for offline viewing. So I wrote a script for SL4A to grab videos from one of my favorite sites, xhamster.com without having to be a member of the site.
This could be adapted to be used on other sites though, if they provide a location to the video somewhere in the source of the page. You would need to fiddle around with the regex, but completely doable. You could also make it work for regular computers by removing the android stuff.
Furthermore, this can be an example on how to save stream or binary data from the web using python and some examples on using the limited UI sl4a has.
# getvid.py: Used to download porn vids
# from xhamster.com without being a member.
# Made for Android's SL4A, root is not required.
# Writen by: techb
# Date: May 25 2015
# License: None, script is public domain, but at
# least credit me if you share this.
# This script is presented 'as is' and the author
# is not responsible for misuse or errors you may get.
import android
import urllib2
import re
import sys
import os
droid = android.Android()
def findInPage(page):
for line in page:
if '.mp4' in line and 'file=' in line:
found = re.search('file=".*"',line)
if found:
url = found.group()[6:-1]
name = re.search(r'\w+\.mp4', url).group()
return (name, url)
else:
droid.makeToast('Video not found in page.\nExiting.')
sys.exit()
def getPage():
site = droid.dialogGetInput('', 'Webpage:', None).result
resp = urllib2.urlopen(site)
page = resp.readlines()
resp.close()
return page
def saveVid(file_name, url):
BUFF_SIZE = 1024*14 #play with this number to help download speeds
progress = 0
p = urllib2.urlopen(url)
size = p.headers["Content-Length"]
droid.dialogCreateHorizontalProgress("Downloading", "Progress", int(size))
droid.dialogShow()
# os.chdir("/choose/another/dir/if/you/want")
with open(file_name, "wb") as f:
while True:
buff = p.read(BUFF_SIZE)
if not buff:
break
progress += len(buff)
droid.dialogSetCurrentProgress(progress)
f.write(buff)
f.close()
droid.dialogDismiss()
droid.makeToast("%s saved to %s" % (file_name, os.getcwd()))
if __name__ == '__main__':
page = getPage()
video = findInPage(page)
saveVid(video[0], video[1])
droid.notify(video[0], 'Download complete')