EvilZone
Programming and Scripting => Scripting Languages => : techb May 27, 2015, 12:56:38 PM
-
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')
-
Sorry for going kind of off topic here, but which android version are you using(kitkat?). I just wonder it because I flashed new lollipop based rom to my nexus5 while back and wasn't able to make sl4a+python to work. So couldn't use any apps/scripts I had made. I had basically same issues that people in here --> https://groups.google.com/forum/m/#!topic/android-scripting/pe_4hxIgO1k
(Also had some issues with .sh scripts...that PIE thing..)
Didn't had time to wrestle with issue then and I have used chrooted enviroment since to run python scripts and stuff but can't use sl4a api with it, so it's not obviously so useful.
So if you are using some lollipop rom did you have to do something to make sl4a+python to work?
But cool script anyways.:D +1
-
Finally a useful tool , I mean pron , yes pron.
lel coolstuff.
How do you use python on your mobile irl ? (actually using it)
-
How do you use python on your mobile irl ? (actually using it)
By installing sl4a on android device
"Scripting Layer for Android (SL4A) brings scripting languages to Android by allowing you
to edit and execute scripts and interactive interpreters directly on the Android device. Python, Perl,
JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported."
I haven't used it myself but looked into it after tech b mentioned about it the other day.
And nice script.! I still need to learn python to understand it though :D
-
By installing sl4a on android device
"Scripting Layer for Android (SL4A) brings scripting languages to Android by allowing you
to edit and execute scripts and interactive interpreters directly on the Android device. Python, Perl,
JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported."
I haven't used it myself but looked into it after tech b mentioned about it the other day.
And nice script.! I still need to learn python to understand it though :D
I must live under a rock , pretty cool stuff.
Also the script is very easy to read.
-
+1 for this love spreading
-
I can see scripting on Android is quite easy, nice script. Might need to extend it to provide a URL or something to specify which video to download or which genre to pull from.
I might need to learn some android scripting but time doesn't allow me.