Added more user agents.
[PyMotherless.git] / pymotherless.py
blobae90fde4add72b0816c85b87cf3ff909e11a1dc6
1 #!/usr/bin/env python
3 '''
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2016 Cool Dude 2k - http://idb.berlios.de/
13 Copyright 2016 Game Maker 2k - http://intdb.sourceforge.net/
14 Copyright 2016 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: pymotherless.py - Last Update: 02/08/2016 Ver. 0.3.7 RC 2 - Author: cooldude2k $
17 '''
19 from __future__ import division, absolute_import, print_function;
20 import re, os, sys, platform, urllib, gzip, time, datetime, argparse, cgi, subprocess, imp;
21 haverequests = False;
22 try:
23 imp.find_module('requests');
24 haverequests = True;
25 import requests;
26 except ImportError:
27 haverequests = False;
28 if(sys.version[0]=="2"):
29 try:
30 from cStringIO import StringIO;
31 except ImportError:
32 from StringIO import StringIO;
33 # From http://python-future.org/compatible_idioms.html
34 from urlparse import urlparse;
35 from urllib import urlencode;
36 from urllib2 import urlopen, Request, HTTPError;
37 import urllib2, urlparse, cookielib;
38 if(sys.version[0]>="3"):
39 from io import StringIO, BytesIO;
40 # From http://python-future.org/compatible_idioms.html
41 from urllib.parse import urlparse, urlencode
42 from urllib.request import urlopen, Request
43 from urllib.error import HTTPError
44 import urllib.request as urllib2;
45 import urllib.parse as urlparse;
46 import http.cookiejar as cookielib;
48 __program_name__ = "PyMotherless";
49 __project__ = __program_name__;
50 __project_url__ = "https://github.com/GameMaker2k/PyMotherless";
51 __version_info__ = (0, 3, 7, "RC 1", 1);
52 __version_date_info__ = (2016, 2, 8, "RC 1", 1);
53 __version_date__ = str(__version_date_info__[0])+"."+str(__version_date_info__[1]).zfill(2)+"."+str(__version_date_info__[2]).zfill(2);
54 if(__version_info__[4]!=None):
55 __version_date_plusrc__ = __version_date__+"-"+str(__version_date_info__[4]);
56 if(__version_info__[4]==None):
57 __version_date_plusrc__ = __version_date__;
58 if(__version_info__[3]!=None):
59 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])+" "+str(__version_info__[3]);
60 if(__version_info__[3]==None):
61 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2]);
63 geturls_cj = cookielib.CookieJar();
64 geturls_ua_firefox_windows7 = "Mozilla/5.0 (Windows NT 6.1; rv:44.0) Gecko/20100101 Firefox/44.0";
65 geturls_ua_seamonkey_windows7 = "Mozilla/5.0 (Windows NT 6.1; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39";
66 geturls_ua_chrome_windows7 = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36";
67 geturls_ua_chromium_windows7 = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.82 Chrome/48.0.2564.82 Safari/537.36";
68 geturls_ua_internet_explorer_windows7 = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko";
69 geturls_ua_pymotherless_python = "Mozilla/5.0 (compatible; {proname}/{prover}; +{prourl})".format(proname=__project__, prover=__version__, prourl=__project_url__);
70 if(platform.python_implementation()!=""):
71 geturls_ua_pymotherless_python_alt = "Mozilla/5.0 ({osver}; {archtype}; +{prourl}) {pyimp}/{pyver} (KHTML, like Gecko) {proname}/{prover}".format(osver=platform.system()+" "+platform.release(), archtype=platform.machine(), prourl=__project_url__, pyimp=platform.python_implementation(), pyver=platform.python_version(), proname=__project__, prover=__version__);
72 if(platform.python_implementation()==""):
73 geturls_ua_pymotherless_python_alt = "Mozilla/5.0 ({osver}; {archtype}; +{prourl}) {pyimp}/{pyver} (KHTML, like Gecko) {proname}/{prover}".format(osver=platform.system()+" "+platform.release(), archtype=platform.machine(), prourl=__project_url__, pyimp="Python", pyver=platform.python_version(), proname=__project__, prover=__version__);
74 geturls_ua_googlebot_google = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
75 geturls_ua_googlebot_google_old = "Googlebot/2.1 (+http://www.google.com/bot.html)";
76 geturls_ua = geturls_ua_firefox_windows7;
77 geturls_headers_firefox_windows7 = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_firefox_windows7, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
78 geturls_headers_seamonkey_windows7 = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_seamonkey_windows7, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
79 geturls_headers_chrome_windows7 = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_chrome_windows7, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
80 geturls_headers_chromium_windows7 = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_chromium_windows7, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
81 geturls_headers_internet_explorer_windows7 = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_internet_explorer_windows7, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
82 geturls_headers_pymotherless_python = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_pymotherless_python, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
83 geturls_headers_pymotherless_python_alt = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_pymotherless_python_alt, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
84 geturls_headers_googlebot_google = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_googlebot_google, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
85 geturls_headers_googlebot_google_old = {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_googlebot_google_old, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
87 geturls_headers = geturls_headers_firefox_windows7;
88 geturls_download_sleep = 0;
90 def add_url_param(url, **params):
91 n=3;
92 parts = list(urlparse.urlsplit(url));
93 d = dict(cgi.parse_qsl(parts[n])); # use cgi.parse_qs for list values
94 d.update(params);
95 parts[n]=urlencode(d);
96 return urlparse.urlunsplit(parts);
98 os.environ["PATH"] = os.environ["PATH"] + os.pathsep + os.path.dirname(os.path.realpath(__file__)) + os.pathsep + os.getcwd();
99 def which_exec(execfile):
100 for path in os.environ["PATH"].split(":"):
101 if os.path.exists(path + "/" + execfile):
102 return path + "/" + execfile;
104 def listize(varlist):
105 il = 0;
106 ix = len(varlist);
107 ilx = 1;
108 newlistreg = {};
109 newlistrev = {};
110 newlistfull = {};
111 while(il < ix):
112 newlistreg.update({ilx: varlist[il]});
113 newlistrev.update({varlist[il]: ilx});
114 ilx = ilx + 1;
115 il = il + 1;
116 newlistfull = {1: newlistreg, 2: newlistrev, 'reg': newlistreg, 'rev': newlistrev};
117 return newlistfull;
119 def twolistize(varlist):
120 il = 0;
121 ix = len(varlist);
122 ilx = 1;
123 newlistnamereg = {};
124 newlistnamerev = {};
125 newlistdescreg = {};
126 newlistdescrev = {};
127 newlistfull = {};
128 while(il < ix):
129 newlistnamereg.update({ilx: varlist[il][0].strip()});
130 newlistnamerev.update({varlist[il][0].strip(): ilx});
131 newlistdescreg.update({ilx: varlist[il][1].strip()});
132 newlistdescrev.update({varlist[il][1].strip(): ilx});
133 ilx = ilx + 1;
134 il = il + 1;
135 newlistnametmp = {1: newlistnamereg, 2: newlistnamerev, 'reg': newlistnamereg, 'rev': newlistnamerev};
136 newlistdesctmp = {1: newlistdescreg, 2: newlistdescrev, 'reg': newlistdescreg, 'rev': newlistdescrev};
137 newlistfull = {1: newlistnametmp, 2: newlistdesctmp, 'name': newlistnametmp, 'desc': newlistdesctmp}
138 return newlistfull;
140 def arglistize(proexec, *varlist):
141 il = 0;
142 ix = len(varlist);
143 ilx = 1;
144 newarglist = [proexec];
145 while(il < ix):
146 if varlist[il][0] is not None:
147 newarglist.append(varlist[il][0]);
148 if varlist[il][1] is not None:
149 newarglist.append(varlist[il][1]);
150 il = il + 1;
151 return newarglist;
153 def make_http_headers_from_dict_to_list(headers={'Referer': "http://motherless.com/", 'User-Agent': geturls_ua, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}):
154 if isinstance(headers, dict):
155 returnval = [];
156 if(sys.version[0]=="2"):
157 for headkey, headvalue in headers.iteritems():
158 returnval.append((headkey, headvalue));
159 if(sys.version[0]>="3"):
160 for headkey, headvalue in headers.items():
161 returnval.append((headkey, headvalue));
162 elif isinstance(headers, list):
163 returnval = headers;
164 else:
165 returnval = False;
166 return returnval;
168 def make_http_headers_from_dict_to_pycurl(headers={'Referer': "http://motherless.com/", 'User-Agent': geturls_ua, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"}):
169 if isinstance(headers, dict):
170 returnval = [];
171 if(sys.version[0]=="2"):
172 for headkey, headvalue in headers.iteritems():
173 returnval.append(headkey+": "+headvalue);
174 if(sys.version[0]>="3"):
175 for headkey, headvalue in headers.items():
176 returnval.append(headkey+": "+headvalue);
177 elif isinstance(headers, list):
178 returnval = headers;
179 else:
180 returnval = False;
181 return returnval;
183 def make_http_headers_from_list_to_dict(headers=[("Referer", "http://motherless.com/"), ("User-Agent", geturls_ua), ("Accept-Encoding", "gzip, deflate"), ("Accept-Language", "en-US,en;q=0.8,en-CA,en-GB;q=0.6"), ("Accept-Charset", "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7"), ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), ("Connection", "close")]):
184 if isinstance(headers, list):
185 returnval = {};
186 mli = 0;
187 mlil = len(headers);
188 while(mli<mlil):
189 returnval.update({headers[mli][0]: headers[mli][1]});
190 mli = mli + 1;
191 elif isinstance(headers, dict):
192 returnval = headers;
193 else:
194 returnval = False;
195 return returnval;
197 def download_from_url(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1):
198 global geturls_download_sleep, haverequests;
199 if(sleep<0):
200 sleep = geturls_download_sleep;
201 if(httplibuse=="urllib1" or httplibuse=="urllib2"):
202 httplibuse = "urllib";
203 if(httplibuse=="httplib1" or httplibuse=="httplib2"):
204 httplibuse = "httplib";
205 if(haverequests==False and httplibuse=="requests"):
206 httplibuse = "urllib";
207 if(httplibuse=="urllib"):
208 returnval = download_from_url_with_urllib(httpurl, httpheaders, httpcookie, sleep);
209 elif(httplibuse=="httplib"):
210 returnval = download_from_url_with_httplib(httpurl, httpheaders, httpcookie, sleep);
211 elif(httplibuse=="requests"):
212 returnval = download_from_url_with_requests(httpurl, httpheaders, httpcookie, sleep);
213 else:
214 returnval = False;
215 return returnval;
217 def download_from_url_file(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1):
218 global geturls_download_sleep, haverequests;
219 if(sleep<0):
220 sleep = geturls_download_sleep;
221 if(httplibuse=="urllib1" or httplibuse=="urllib2"):
222 httplibuse = "urllib";
223 if(httplibuse=="httplib1" or httplibuse=="httplib2"):
224 httplibuse = "httplib";
225 if(haverequests==False and httplibuse=="requests"):
226 httplibuse = "urllib";
227 if(httplibuse=="urllib"):
228 returnval = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, sleep);
229 elif(httplibuse=="requests"):
230 returnval = download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, sleep);
231 else:
232 returnval = False;
233 return returnval;
235 def download_from_url_to_file(httpurl, httpheaders, httpcookie, httplibuse="urllib", outfile="-", outpath=os.getcwd(), sleep=-1):
236 global geturls_download_sleep, haverequests;
237 if(sleep<0):
238 sleep = geturls_download_sleep;
239 if(httplibuse=="urllib1" or httplibuse=="urllib2"):
240 httplibuse = "urllib";
241 if(haverequests==False and httplibuse=="requests"):
242 httplibuse = "urllib";
243 if(httplibuse=="urllib"):
244 returnval = download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, outfile, outpath, sleep);
245 elif(httplibuse=="httplib"):
246 returnval = download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile, outpath, sleep);
247 elif(httplibuse=="requests"):
248 returnval = download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile, outpath, sleep);
249 else:
250 returnval = False;
251 return returnval;
253 def download_from_url_with_urllib(httpurl, httpheaders, httpcookie, sleep=-1):
254 global geturls_download_sleep;
255 if(sleep<0):
256 sleep = geturls_download_sleep;
257 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(httpcookie));
258 if isinstance(httpheaders, dict):
259 httpheaders = make_http_headers_from_dict_to_list(httpheaders);
260 geturls_opener.addheaders = httpheaders;
261 time.sleep(sleep);
262 geturls_text = geturls_opener.open(httpurl);
263 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
264 if(sys.version[0]=="2"):
265 strbuf = StringIO(geturls_text.read());
266 if(sys.version[0]>="3"):
267 strbuf = BytesIO(geturls_text.read());
268 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
269 returnval = gzstrbuf.read()[:];
270 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
271 returnval = geturls_text.read()[:];
272 return returnval;
274 def download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, sleep=-1):
275 global geturls_download_sleep;
276 if(sleep<0):
277 sleep = geturls_download_sleep;
278 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(httpcookie));
279 if isinstance(httpheaders, dict):
280 httpheaders = make_http_headers_from_dict_to_list(httpheaders);
281 geturls_opener.addheaders = httpheaders;
282 time.sleep(sleep);
283 geturls_text = geturls_opener.open(httpurl);
284 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
285 if(sys.version[0]=="2"):
286 strbuf = StringIO(geturls_text.read());
287 if(sys.version[0]>="3"):
288 strbuf = BytesIO(geturls_text.read());
289 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
290 returnval = gzstrbuf.read()[:];
291 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
292 returnval = geturls_text.read()[:];
293 return returnval;
295 def download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, outfile="-", outpath=os.getcwd(), sleep=-1):
296 global geturls_download_sleep;
297 if(sleep<0):
298 sleep = geturls_download_sleep;
299 if(not outfile=="-"):
300 outpath = outpath.rstrip(os.path.sep);
301 filepath = os.path.realpath(outpath+os.path.sep+outfile);
302 if(not os.path.exists(outpath)):
303 os.makedirs(outpath);
304 if(os.path.exists(outpath) and os.path.isfile(outpath)):
305 return False;
306 if(os.path.exists(filepath) and os.path.isdir(filepath)):
307 return False;
308 with open(filepath, 'wb+') as f:
309 f.write(download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, sleep));
310 f.closed;
311 returnval = True;
312 if(outfile=="-" and sys.version[0]=="2"):
313 f = StringIO();
314 f.write(download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, sleep));
315 returnval = f.getvalue();
316 f.closed;
317 if(outfile=="-" and sys.version[0]>="3"):
318 f = BytesIO();
319 f.write(download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, sleep));
320 returnval = f.getvalue();
321 f.closed;
322 return returnval;
324 if(haverequests==True):
325 def download_from_url_with_requests(httpurl, httpheaders, httpcookie, sleep=-1):
326 global geturls_download_sleep;
327 if(sleep<0):
328 sleep = geturls_download_sleep;
329 if isinstance(httpheaders, list):
330 httpheaders = make_http_headers_from_list_to_dict(httpheaders);
331 time.sleep(sleep);
332 geturls_text = requests.get(httpurl, headers=httpheaders, cookies=httpcookie);
333 if(geturls_text.headers['Content-Type']=="gzip" or geturls_text.headers['Content-Type']=="deflate"):
334 if(sys.version[0]=="2"):
335 strbuf = StringIO(geturls_text.content);
336 if(sys.version[0]>="3"):
337 strbuf = BytesIO(geturls_text.content);
338 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
339 returnval = gzstrbuf.content[:];
340 if(geturls_text.headers['Content-Type']!="gzip" and geturls_text.headers['Content-Type']!="deflate"):
341 returnval = geturls_text.content[:];
342 return returnval;
344 if(haverequests==True):
345 def download_from_url_with_requests(httpurl, httpheaders, httpcookie, sleep=-1):
346 returnval = download_from_url_with_urllib(httpurl, httpheaders, httpcookie, sleep)
347 return returnval;
349 if(haverequests==True):
350 def download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, sleep=-1):
351 global geturls_download_sleep;
352 if(sleep<0):
353 sleep = geturls_download_sleep;
354 if isinstance(httpheaders, list):
355 httpheaders = make_http_headers_from_list_to_dict(httpheaders);
356 time.sleep(sleep);
357 geturls_text = requests.get(httpurl, headers=httpheaders, cookies=httpcookie);
358 if(geturls_text.headers['Content-Type']=="gzip" or geturls_text.headers['Content-Type']=="deflate"):
359 if(sys.version[0]=="2"):
360 strbuf = StringIO(geturls_text.content);
361 if(sys.version[0]>="3"):
362 strbuf = BytesIO(geturls_text.content);
363 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
364 returnval = gzstrbuf.content[:];
365 if(geturls_text.headers['Content-Type']!="gzip" and geturls_text.headers['Content-Type']!="deflate"):
366 returnval = geturls_text.content[:];
367 return returnval;
369 if(haverequests==True):
370 def download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, sleep=-1):
371 returnval = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, sleep)
372 return returnval;
374 if(haverequests==True):
375 def download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile="-", outpath=os.getcwd(), sleep=-1):
376 global geturls_download_sleep;
377 if(sleep<0):
378 sleep = geturls_download_sleep;
379 if(not outfile=="-"):
380 outpath = outpath.rstrip(os.path.sep);
381 filepath = os.path.realpath(outpath+os.path.sep+outfile);
382 if(not os.path.exists(outpath)):
383 os.makedirs(outpath);
384 if(os.path.exists(outpath) and os.path.isfile(outpath)):
385 return False;
386 if(os.path.exists(filepath) and os.path.isdir(filepath)):
387 return False;
388 with open(filepath, 'wb+') as f:
389 f.write(download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, sleep));
390 f.closed;
391 returnval = True;
392 if(outfile=="-" and sys.version[0]=="2"):
393 f = StringIO();
394 f.write(download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, sleep));
395 returnval = f.getvalue();
396 f.closed;
397 if(outfile=="-" and sys.version[0]>="3"):
398 f = BytesIO();
399 f.write(download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, sleep));
400 returnval = f.getvalue();
401 f.closed;
402 return returnval;
404 if(haverequests==True):
405 def download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile="-", outpath=os.getcwd(), sleep=-1):
406 returnval = download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, outfile, outpath, sleep)
407 return returnval;
409 def get_motherless_get_number_pages(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
410 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
411 if(sys.version[0]>="3"):
412 mrtext = mrtext.decode('ascii', 'replace');
413 mregex_getpagenum = re.escape("page=")+"([0-9]+)"+re.escape("\" class=\"pop\" rel=\"")+"([0-9]+)"+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
414 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
415 try:
416 returnval = int(mlesspagenum[-1][0]);
417 except:
418 returnval = 1;
419 return returnval;
421 def get_motherless_get_link_type(httpurl):
422 mlessvidqstr = urlparse.parse_qs(urlparse.urlparse(httpurl).query);
423 mlessvidid_parts = urlparse.urlparse(httpurl);
424 mlessvidid = mlessvidid_parts.path.split("/");
425 returnval = False;
426 if(mlessvidid[1]=="videos" and len(mlessvidid)==3 and (mlessvidid[2]=="recent" or mlessvidid[2]=="favorited" or mlessvidid[2]=="viewed" or mlessvidid[2]=="commented" or mlessvidid[2]=="popular")):
427 returnval = "gallery";
428 if(mlessvidid[1]=="images" and len(mlessvidid)==3 and (mlessvidid[2]=="recent" or mlessvidid[2]=="favorited" or mlessvidid[2]=="viewed" or mlessvidid[2]=="commented" or mlessvidid[2]=="popular")):
429 returnval = "gallery";
430 if(mlessvidid[1]=="galleries" and len(mlessvidid)==3 and (mlessvidid[2]=="recent" or mlessvidid[2]=="favorited" or mlessvidid[2]=="viewed" or mlessvidid[2]=="commented" or mlessvidid[2]=="popular")):
431 returnval = "gallery";
432 if(mlessvidid[1]=="videos" and len(mlessvidid)==2):
433 returnval = "sample-videos";
434 if(mlessvidid[1]=="images" and len(mlessvidid)==2):
435 returnval = "sample-images";
436 if(mlessvidid[1]=="galleries" and len(mlessvidid)==2):
437 returnval = "sample-galleries";
438 if(mlessvidid[1]=="" and len(mlessvidid)==2):
439 returnval = "sample";
440 if(mlessvidid[1]=="live" and len(mlessvidid)==3 and (mlessvidid[2]=="videos" or mlessvidid[2]=="images")):
441 returnval = "gallery";
442 if(mlessvidid[1]=="u" and len(mlessvidid)==3):
443 returnval = "gallery";
444 if(mlessvidid[1]=="f" and len(mlessvidid)==4 and (mlessvidid[2]=="videos" or mlessvidid[2]=="images" or mlessvidid[2]=="galleries")):
445 returnval = "gallery";
446 if(mlessvidid[1]=="galleries" and len(mlessvidid)==4 and mlessvidid[2]=="member"):
447 returnval = "gallery";
448 if(mlessvidid[1]=="galleries" and len(mlessvidid)==5 and mlessvidid[2]=="member" and (mlessvidid[4]=="created" or mlessvidid[4]=="viewed" or mlessvidid[4]=="favorited" or mlessvidid[4]=="commented")):
449 returnval = "gallery";
450 if(mlessvidid[1]=="gv" and len(mlessvidid)==3):
451 returnval = "gallery";
452 if(mlessvidid[1]=="gi" and len(mlessvidid)==3):
453 returnval = "gallery";
454 if(mlessvidid[1]=="gm" and len(mlessvidid)==3):
455 returnval = "member";
456 if(mlessvidid[1]=="term" and len(mlessvidid)==3 and (mlessvidid[2]=="videos" or mlessvidid[2]=="images" or mlessvidid[2]=="galleries")):
457 returnval = "gallery";
458 if(mlessvidid[1]=="g" and len(mlessvidid)==4 and re.match("^([0-9A-F]+)$", mlessvidid[3])):
459 returnval = "file";
460 if(mlessvidid[1]=="random" and len(mlessvidid)==3 and (mlessvidid[2]=="video" or mlessvidid[2]=="image")):
461 returnval = "file";
462 if(re.match("^V", mlessvidid[1]) and len(mlessvidid)==2):
463 returnval = "board";
464 if(re.match("^H", mlessvidid[1]) and len(mlessvidid)==2):
465 returnval = "gallery";
466 if(re.match("^G", mlessvidid[1]) and len(mlessvidid)==2):
467 returnval = "gallery";
468 if(re.match("^G", mlessvidid[1]) and len(mlessvidid)==3):
469 returnval = "file";
470 if(re.match("^g", mlessvidid[1]) and len(mlessvidid)==4 and re.match("^([0-9A-F]+)$", mlessvidid[3])):
471 returnval = "file";
472 if(mlessvidid[1]=="members" and len(mlessvidid)==2):
473 returnval = "member";
474 if(mlessvidid[1]=="members" and len(mlessvidid)==3 and mlessvidid[2]=="search"):
475 returnval = "member";
476 if(mlessvidid[1]=="members" and len(mlessvidid)==4 and (mlessvidid[2]=="uploader" or mlessvidid[2]=="viewed" or mlessvidid[2]=="social" or mlessvidid[2]=="favorited" or mlessvidid[2]=="commented" or mlessvidid[2]=="mentioned" or mlessvidid[2]=="verified")):
477 returnval = "member";
478 if(mlessvidid[1]=="girls" and len(mlessvidid)==2):
479 returnval = "girls";
480 if(mlessvidid[1]=="referers" and len(mlessvidid)==2):
481 returnval = "referers";
482 if(mlessvidid[1]=="about" and len(mlessvidid)==2):
483 returnval = "team";
484 if(mlessvidid_parts.netloc=="cdn.images.motherlessmedia.com" or mlessvidid_parts.netloc=="cdn.videos.motherlessmedia.com" or mlessvidid_parts.netloc=="cdn.thumbs.motherlessmedia.com"):
485 returnval = "download";
486 if(returnval==False and len(mlessvidid)==2 and re.match("^([0-9A-F]+)$", mlessvidid[1])):
487 returnval = "file";
488 return returnval;
490 def get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
491 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
492 if(sys.version[0]>="3"):
493 mrtext = mrtext.decode('ascii', 'replace');
494 mregex_gettitle = re.escape("<title>")+"(.*)"+re.escape(" - MOTHERLESS.COM</title>");
495 mlesstitle = re.findall(mregex_gettitle, mrtext);
496 mregex_geturlone = re.escape("__fileurl = 'http://cdn.")+"(images|videos)"+re.escape(".motherlessmedia.com/")+"(images|videos)"+re.escape("/")+"([\w\/\?\&\=\.\-]+)"+re.escape("';");
497 mlesslinkone = re.findall(mregex_geturlone, mrtext);
498 mregex_geturltwo = re.escape("<meta property=\"og:image\" content=\"http://cdn.")+"(images|thumbs)"+re.escape(".motherlessmedia.com/")+"(images|thumbs)"+re.escape("/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\">");
499 mlesslinktwo = re.findall(mregex_geturltwo, mrtext);
500 filenameext = os.path.basename(urlparse.urljoin("http://cdn."+mlesslinkone[0][0]+".motherlessmedia.com/"+mlesslinkone[0][1]+"/"+mlesslinkone[0][2], urlparse.urlparse("http://cdn."+mlesslinkone[0][0]+".motherlessmedia.com/"+mlesslinkone[0][1]+"/"+mlesslinkone[0][2]).path));
501 filename, fileextension = os.path.splitext(filenameext);
502 thumbfilenameext = os.path.basename(urlparse.urljoin("http://cdn.images.motherlessmedia.com/"+mlesslinktwo[0][1]+"/"+mlesslinktwo[0][2], urlparse.urlparse("http://cdn.images.motherlessmedia.com/"+mlesslinktwo[0][1]+"/"+mlesslinktwo[0][2]).path));
503 thumbfilename, thumbfileextension = os.path.splitext(thumbfilenameext);
504 mregex_getuname = re.escape("<tr rel=\"")+"([\w\/\?\&\=\.\-]+)"+re.escape("\"");
505 mlessuname = re.findall(mregex_getuname, mrtext);
506 mlessuname = mlessuname[0];
507 mregex_geturlname = re.escape("<a href=\"/m/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" target=\"_blank\">\n <img");
508 mlessurlname = re.findall(mregex_geturlname, mrtext);
509 mlessurlname = mlessurlname[0];
510 mregex_getavatar = re.escape("<img\n src=\"")+"(.*)"+re.escape("\"\n class=\"avatar avatar-small\"");
511 mlessavatar = re.findall(mregex_getavatar, mrtext);
512 mlessavatar = mlessavatar[0];
513 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavatar, urlparse.urlparse(mlessavatar).path));
514 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
515 if(mlesslinkone[0][1]=="images"):
516 thumbnailaltpart = thumbfilename+"-zoom"+thumbfileextension;
517 thumbnailalt = "http://cdn.thumbs.motherlessmedia.com/thumbs/"+thumbnailaltpart;
518 thumbnailaltfilenameext = os.path.basename(urlparse.urljoin(thumbnailalt, urlparse.urlparse(thumbnailalt).path));
519 thumbnailaltfilename, thumbnailaltfileextension = os.path.splitext(thumbnailaltfilenameext);
520 if(mlesslinkone[0][1]=="videos"):
521 thumbnailaltpart = thumbfilename+"-small"+thumbfileextension;
522 thumbnailalt = "http://cdn.thumbs.motherlessmedia.com/thumbs/"+thumbnailaltpart;
523 thumbnailaltfilenameext = os.path.basename(urlparse.urljoin(thumbnailalt, urlparse.urlparse(thumbnailalt).path));
524 thumbnailaltfilename, thumbnailaltfileextension = os.path.splitext(thumbnailaltfilenameext);
525 returnval = False;
526 mlessurltype = get_motherless_get_link_type("http://cdn."+mlesslinkone[0][0]+".motherlessmedia.com/"+mlesslinkone[0][1]+"/"+mlesslinkone[0][2]);
527 if(mlesslinkone[0][1]=="images"):
528 returnval = {'type': mlesslinkone[0][1], 'urltype': mlessurltype, 'url': "http://cdn."+mlesslinkone[0][0]+".motherlessmedia.com/"+mlesslinkone[0][1]+"/"+mlesslinkone[0][2], 'orginurl': httpurl, 'orginurltype': get_motherless_get_link_type(httpurl), 'thumbnail': "http://cdn.thumbs.motherlessmedia.com/thumbs/"+mlesslinktwo[0][2], 'thumbnailalt': thumbnailalt+"?from_helper", 'title': mlesstitle[0], 'fullfilename': filenameext, 'filename': filename, 'extension': fileextension, 'thumbfullfilename': thumbfilenameext, 'thumbfilename': thumbfilename, 'thumbextension': thumbfileextension, 'thumbnailaltfullfilename': thumbnailaltpart, 'thumbnailaltfilename': thumbnailaltfilename, 'thumbnailaltextension': thumbnailaltfileextension, 'username': mlessuname, 'avatarurl': mlessavatar, 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension};
529 if(mlesslinkone[0][1]=="videos"):
530 returnval = {'type': mlesslinkone[0][1], 'url': "http://cdn."+mlesslinkone[0][0]+".motherlessmedia.com/"+mlesslinkone[0][1]+"/"+mlesslinkone[0][2], 'orginurl': httpurl, 'orginurltype': get_motherless_get_link_type(httpurl), 'thumbnail': "http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[0][1]+"/"+mlesslinktwo[0][2], 'thumbnailalt': thumbnailalt+"?from_helper", 'title': mlesstitle[0], 'fullfilename': filenameext, 'filename': filename, 'extension': fileextension, 'thumbfullfilename': thumbfilenameext, 'thumbfilename': thumbfilename, 'thumbextension': thumbfileextension, 'thumbnailaltfullfilename': thumbnailaltpart, 'thumbnailaltfilename': thumbnailaltfilename, 'thumbnailaltextension': thumbnailaltfileextension, 'username': mlessuname, 'avatarurl': mlessavatar, 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension};
531 return returnval;
533 def get_motherless_external_links(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
534 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
535 if(sys.version[0]>="3"):
536 mrtext = mrtext.decode('ascii', 'replace');
537 mregex_geturlinternal = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" rev=\"outbound\" rel=\"nofollow\" class=\"pop\" target=\"_blank\" title=\"motherless link\">");
538 mlesslinkinternal = re.findall(mregex_geturlinternal, mrtext);
539 mregex_geturlexternal = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" rev=\"outbound\" rel=\"nofollow\" class=\"pop\" target=\"_blank\" title=\"external link\">");
540 mlesslinkexternal = re.findall(mregex_geturlexternal, mrtext);
541 returnvalone = None;
542 if(len(mlesslinkinternal)>1):
543 mli = 0;
544 mlil = len(mlesslinkinternal);
545 returnvalone = {'numoflinks': mlil};
546 returnvalone.update({'numofalllinks': len(mlesslinkinternal)});
547 returnvalone.update({'orginurl': httpurl});
548 returnvalone.update({'orginurltype': get_motherless_get_link_type(httpurl)});
549 mlessrooturltype = get_motherless_get_link_type(httpurl);
550 returnvalone.update({'urltype': mlessrooturltype});
551 while(mli<mlil):
552 mlessurltype = get_motherless_get_link_type(mlesslinkinternal[mli]);
553 returnvalone.update({mli: {'urltype': mlessurltype, 'url': mlesslinkinternal[mli]} });
554 mli = mli + 1;
555 returnvaltwo = None;
556 if(len(mlesslinkexternal)>1):
557 mli = 0;
558 mlil = len(mlesslinkexternal);
559 returnvaltwo = {'numoflinks': mlil};
560 returnvaltwo.update({'numofalllinks': len(mlesslinkexternal)});
561 returnvaltwo.update({'orginurl': httpurl});
562 returnvaltwo.update({'orginurltype': get_motherless_get_link_type(httpurl)});
563 mlessrooturltype = get_motherless_get_link_type(httpurl);
564 returnvaltwo.update({'urltype': mlessrooturltype});
565 while(mli<mlil):
566 returnvaltwo.update({mli: {'urltype': "external", 'url': mlesslinkexternal[mli]} });
567 mli = mli + 1;
568 if(returnvalone==None and returnvaltwo==None):
569 returnval = {'internal': None, 'external': None};
570 if(not returnvalone==None and not returnvaltwo==None):
571 returnval = {'internal': returnvalone, 'external': returnvaltwo};
572 if(not returnvalone==None and returnvaltwo==None):
573 returnval = {'internal': returnvalone, 'external': None};
574 if(returnvalone==None and not returnvaltwo==None):
575 returnval = {'internal': None, 'external': returnvaltwo};
576 return returnval;
578 def get_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
579 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
580 if(sys.version[0]>="3"):
581 mrtext = mrtext.decode('ascii', 'replace');
582 mregex_getpagenum = re.escape("page=")+"([0-9]+)"+re.escape("\" class=\"pop\" rel=\"")+"([0-9]+)"+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
583 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
584 try:
585 lastpage = int(mlesspagenum[-1][0]);
586 except:
587 lastpage = 1;
588 if(page>lastpage):
589 page = lastpage;
590 httpurl = add_url_param(httpurl, page=str(page));
591 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
592 if(sys.version[0]>="3"):
593 mrtext = mrtext.decode('ascii', 'replace');
594 mregex_geturlone = re.escape("<a href=\"/")+"([\w\/]+)"+re.escape("\" class=\"img-container\" target=\"_self\">");
595 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext);
596 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
597 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext_tmp);
598 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
599 mlesslinkone = re.findall(mregex_geturlone, mrtext_tmp);
600 mregex_geturltwo = re.escape("<img class=\"static\" src=\"http://cdn.thumbs.motherlessmedia.com/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" data-strip-src=\"http://cdn.thumbs.motherlessmedia.com/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" alt=\"")+"(.*)"+re.escape("\" />");
601 mlesslinktwo = re.findall(mregex_geturltwo, mrtext);
602 mregex_getuserinfo = re.escape("<a class=\"caption left\" href=\"/m/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\">");
603 mlessuname = re.findall(mregex_getuserinfo, mrtext);
604 if(getlinks[1]>len(mlesslinkone) or getlinks[1]==-1):
605 getlinks[1] = len(mlesslinkone);
606 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
607 tmpgetlinks0 = getlinks[0];
608 tmpgetlinks1 = getlinks[1];
609 getlinks[0] = tmpgetlinks1;
610 getlinks[1] = tmpgetlinks0;
611 if(getlinks[0]<0):
612 getlinks[0] = 0;
613 mli = getlinks[0];
614 mlil = getlinks[1];
615 returnval = {'pages': lastpage};
616 returnval.update({'curpage': page});
617 returnval.update({'numoflinks': mlil});
618 returnval.update({'numofalllinks': len(mlesslinkone)});
619 returnval.update({'orginurl': httpurl});
620 returnval.update({'orginurltype': get_motherless_get_link_type(httpurl)});
621 mlessrooturltype = get_motherless_get_link_type(httpurl);
622 returnval.update({'urltype': mlessrooturltype});
623 while(mli<mlil):
624 stripfilenameext = os.path.basename(urlparse.urljoin("http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[mli][1], urlparse.urlparse("http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[mli][1]).path));
625 stripfilename, stripfileextension = os.path.splitext(stripfilenameext);
626 thumbfilenameext = os.path.basename(urlparse.urljoin("http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[mli][0], urlparse.urlparse("http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[mli][0]).path));
627 thumbfilename, thumbfileextension = os.path.splitext(thumbfilenameext);
628 mlessurltype = get_motherless_get_link_type("http://motherless.com/"+mlesslinkone[mli]);
629 avatarfilenameext = os.path.basename(urlparse.urljoin("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli]+"-avatar.jpg", urlparse.urlparse("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli]+"-avatar.jpg").path));
630 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
631 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlesslinkone[mli], 'thumbnail': "http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[mli][0], 'strip': "http://cdn.thumbs.motherlessmedia.com/"+mlesslinktwo[mli][1], 'title': mlesslinktwo[mli][2], 'thumbfullfilename': thumbfilenameext, 'thumbfilename': thumbfilename, 'thumbextension': thumbfileextension, 'stripfullfilename': stripfilenameext, 'stripfilename': stripfilename, 'stripextension': stripfileextension, 'username': mlessuname[mli], 'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
632 mli = mli + 1;
633 return returnval;
635 def get_motherless_random_links(httpheaders, httpcookie, httplibuse="urllib", linktype="video", getlinks=[0, 80]):
636 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
637 tmpgetlinks0 = getlinks[0];
638 tmpgetlinks1 = getlinks[1];
639 getlinks[0] = tmpgetlinks1;
640 getlinks[1] = tmpgetlinks0;
641 if(getlinks[0]<0):
642 getlinks[0] = 0;
643 mli = getlinks[0];
644 mlil = getlinks[1];
645 if(linktype=="image"):
646 returnval = {'pages': 1};
647 returnval.update({'curpage': 1});
648 returnval.update({'numoflinks': 80});
649 returnval.update({'numofalllinks': mlil});
650 returnval.update({'orginurl': "http://motherless.com/random/image"});
651 returnval.update({'orginurltype': "gallery"});
652 returnval.update({'urltype': "gallery"});
653 while(mli<mlil):
654 get_links = get_motherless_links("http://motherless.com/random/image", httpheaders, httpcookie, httplibuse);
655 returnval.update({mli: {'urltype': get_motherless_get_link_type("http://motherless.com/"+get_links['filename']), 'url': "http://motherless.com/"+get_links['filename'], 'thumbnail': get_links['thumbnail'], 'strip': get_links['thumbnailalt'], 'title': get_links['title'], 'thumbfullfilename': get_links['thumbfullfilename'], 'thumbfilename': get_links['thumbfilename'], 'thumbextension': get_links['thumbextension'], 'stripfullfilename': get_links['thumbnailaltfullfilename'], 'stripfilename': get_links['thumbnailaltextension'], 'stripextension': get_links['thumbnailaltfilename'], 'username': get_links['username'], 'avatarurl': get_links['avatarurl'], 'avatarfullfilename': get_links['avatarfullfilename'], 'avatarfilename': get_links['avatarfilename'], 'avatarextension': get_links['avatarextension']} });
656 mli = mli + 1;
657 if(linktype=="video"):
658 returnval = {'pages': 1};
659 returnval.update({'curpage': 1});
660 returnval.update({'numoflinks': 80});
661 returnval.update({'numofalllinks': mlil});
662 returnval.update({'orginurl': "http://motherless.com/random/video"});
663 returnval.update({'orginurltype': "gallery"});
664 returnval.update({'urltype': "gallery"});
665 while(mli<mlil):
666 get_links = get_motherless_links("http://motherless.com/random/video", httpheaders, httpcookie, httplibuse);
667 returnval.update({mli: {'urltype': get_motherless_get_link_type("http://motherless.com/"+get_links['filename']), 'url': "http://motherless.com/"+get_links['filename'], 'thumbnail': get_links['thumbnail'], 'strip': get_links['thumbnailalt'], 'title': get_links['title'], 'thumbfullfilename': get_links['thumbfullfilename'], 'thumbfilename': get_links['thumbfilename'], 'thumbextension': get_links['thumbextension'], 'stripfullfilename': get_links['thumbnailaltfullfilename'], 'stripfilename': get_links['thumbnailaltextension'], 'stripextension': get_links['thumbnailaltfilename'], 'username': get_links['username'], 'avatarurl': get_links['avatarurl'], 'avatarfullfilename': get_links['avatarfullfilename'], 'avatarfilename': get_links['avatarfilename'], 'avatarextension': get_links['avatarextension']} });
668 mli = mli + 1;
669 return returnval;
671 def get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
672 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
673 if(sys.version[0]>="3"):
674 mrtext = mrtext.decode('ascii', 'replace');
675 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext);
676 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
677 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext_tmp);
678 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
679 mregex_geturlone = re.escape("<a href=\"/")+"([\w\/]+)"+re.escape("\" title=\"motherless link\">");
680 mlesslinkone = re.findall(mregex_geturlone, mrtext_tmp);
681 mregex_geturlname = re.escape("<a href=\"/boards/member/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" class=\"post-username special-member op-member\" title=\"op\" rel=\"")+"([\w\/\?\&\=\.\-]+)"+re.escape("\">");
682 mlessurlname = re.findall(mregex_geturlname, mrtext);
683 mlessavaturl = "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessurlname[0][0]+"-avatar.jpg";
684 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavaturl, urlparse.urlparse(mlessavaturl).path));
685 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
686 if(getlinks[1]>len(mlesslinkone) or getlinks[1]==-1):
687 getlinks[1] = len(mlesslinkone);
688 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
689 tmpgetlinks0 = getlinks[0];
690 tmpgetlinks1 = getlinks[1];
691 getlinks[0] = tmpgetlinks1;
692 getlinks[1] = tmpgetlinks0;
693 if(getlinks[0]<0):
694 getlinks[0] = 0;
695 mli = getlinks[0];
696 mlil = getlinks[1];
697 returnval = {'numoflinks': mlil};
698 returnval.update({'numofalllinks': len(mlesslinkone)});
699 returnval.update({'orginurl': httpurl});
700 returnval.update({'orginurltype': get_motherless_get_link_type(httpurl)});
701 mlessrooturltype = get_motherless_get_link_type(httpurl);
702 returnval.update({'urltype': mlessrooturltype});
703 returnval.update({'username': mlessurlname[0][0]});
704 returnval.update({'avatarurl': mlessavaturl});
705 returnval.update({'avatarfullfilename': avatarfilenameext});
706 returnval.update({'avatarfilename': avatarfilename});
707 returnval.update({'avatarextension': avatarfileextension});
708 while(mli<mlil):
709 mlessurltype = get_motherless_get_link_type("http://motherless.com/"+mlesslinkone[mli]);
710 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlesslinkone[mli]} });
711 mli = mli + 1;
712 return returnval;
714 def get_motherless_search_members(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
715 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
716 if(sys.version[0]>="3"):
717 mrtext = mrtext.decode('ascii', 'replace');
718 mregex_getpagenum = re.escape("page=")+"([0-9]+)"+re.escape("\" class=\"pop\" rel=\"")+"([0-9]+)"+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
719 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
720 try:
721 lastpage = int(mlesspagenum[-1][0]);
722 except:
723 lastpage = 1;
724 if(page>lastpage):
725 page = lastpage;
726 httpurl = add_url_param(httpurl, page=str(page));
727 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse);
728 if(sys.version[0]>="3"):
729 mrtext = mrtext.decode('ascii', 'replace');
730 mregex_getuname = re.escape("<tr rel=\"")+"([\w\/\?\&\=\.\-]+)"+re.escape("\"");
731 mlessuname = re.findall(mregex_getuname, mrtext);
732 mregex_geturlname = re.escape("<a href=\"/m/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" target=\"_blank\">\n <img");
733 mlessurlname = re.findall(mregex_geturlname, mrtext);
734 mregex_getavatar = re.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re.escape("\"\n class=\"avatar avatar-small\"");
735 mlessavatar = re.findall(mregex_getavatar, mrtext);
736 if(getlinks[1]>len(mlessuname) or getlinks[1]==-1):
737 getlinks[1] = len(mlessuname);
738 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
739 tmpgetlinks0 = getlinks[0];
740 tmpgetlinks1 = getlinks[1];
741 getlinks[0] = tmpgetlinks1;
742 getlinks[1] = tmpgetlinks0;
743 if(getlinks[0]<0):
744 getlinks[0] = 0;
745 mli = getlinks[0];
746 mlil = getlinks[1];
747 returnval = {'numoflinks': mlil};
748 returnval.update({'numofalllinks': len(mlessuname)});
749 returnval.update({'pages': lastpage});
750 returnval.update({'curpage': page});
751 returnval.update({'orginurl': httpurl});
752 returnval.update({'orginurltype': get_motherless_get_link_type(httpurl)});
753 mlessrooturltype = get_motherless_get_link_type(httpurl);
754 returnval.update({'urltype': mlessrooturltype});
755 while(mli<mlil):
756 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavatar[mli], urlparse.urlparse(mlessavatar[mli]).path));
757 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
758 mlessurltype = get_motherless_get_link_type("http://motherless.com/"+mlessurlname[mli]);
759 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlessurlname[mli], 'username': mlessuname[mli], 'avatarurl': mlessavatar[mli], 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
760 mli = mli + 1;
761 return returnval;
763 def get_motherless_girls(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
764 mrtext = download_from_url("http://motherless.com/girls", httpheaders, httpcookie, httplibuse);
765 if(sys.version[0]>="3"):
766 mrtext = mrtext.decode('ascii', 'replace');
767 mregex_getuname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" rev=\"")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" rel=\"")+"(.*)"+re.escape("\">");
768 mlessuname = re.findall(mregex_getuname, mrtext);
769 mregex_geturlname = re.escape("\n\t\t\t\t\t\t<a href=\"/m/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\" target=\"_blank\">");
770 mlessurlname = re.findall(mregex_geturlname, mrtext);
771 if(getlinks[1]>len(mlessuname) or getlinks[1]==-1):
772 getlinks[1] = len(mlessuname);
773 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
774 tmpgetlinks0 = getlinks[0];
775 tmpgetlinks1 = getlinks[1];
776 getlinks[0] = tmpgetlinks1;
777 getlinks[1] = tmpgetlinks0;
778 if(getlinks[0]<0):
779 getlinks[0] = 0;
780 mli = getlinks[0];
781 mlil = getlinks[1];
782 returnval = {'numoflinks': mlil};
783 returnval.update({'numofalllinks': len(mlessuname)});
784 returnval.update({'orginurl': "http://motherless.com/girls"});
785 returnval.update({'orginurltype': get_motherless_get_link_type("http://motherless.com/girls")});
786 mlessrooturltype = get_motherless_get_link_type("http://motherless.com/girls");
787 returnval.update({'urltype': mlessrooturltype});
788 while(mli<mlil):
789 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessuname[mli][0], urlparse.urlparse(mlessuname[mli][0]).path));
790 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
791 mlessurltype = get_motherless_get_link_type("http://motherless.com/"+mlessuname[mli][1]);
792 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlessuname[mli][1], 'username': mlessuname[mli][1], 'avatarurl': mlessuname[mli][0], 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
793 mli = mli + 1;
794 return returnval;
796 def get_motherless_team(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
797 mrtext = download_from_url("http://motherless.com/about", httpheaders, httpcookie, httplibuse);
798 if(sys.version[0]>="3"):
799 mrtext = mrtext.decode('ascii', 'replace');
800 mregex_getuname = re.escape("<a href=\"/m/")+"([\w\/\?\&\=\.\-]+)"+re.escape("\"");
801 mlessuname = re.findall(mregex_getuname, mrtext);
802 mlessuname_odd = mlessuname[1::2];
803 mlessuname_even = mlessuname[::2];
804 mregex_getavatar = re.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re.escape("\"\n class=\"avatar avatar-")+"(full|medium)"+re.escape("\"");
805 mlessavatar = re.findall(mregex_getavatar, mrtext);
806 if(getlinks[1]>len(mlessuname_odd) or getlinks[1]==-1):
807 getlinks[1] = len(mlessuname_odd);
808 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
809 tmpgetlinks0 = getlinks[0];
810 tmpgetlinks1 = getlinks[1];
811 getlinks[0] = tmpgetlinks1;
812 getlinks[1] = tmpgetlinks0;
813 if(getlinks[0]<0):
814 getlinks[0] = 0;
815 mli = getlinks[0];
816 mlil = getlinks[1];
817 returnval = {'numoflinks': mlil};
818 returnval.update({'numofalllinks': len(mlessuname)});
819 returnval.update({'orginurl': "http://motherless.com/girls"});
820 returnval.update({'orginurltype': get_motherless_get_link_type("http://motherless.com/girls")});
821 mlessrooturltype = get_motherless_get_link_type("http://motherless.com/girls");
822 returnval.update({'urltype': mlessrooturltype});
823 while(mli<mlil):
824 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavatar[mli][0], urlparse.urlparse(mlessavatar[mli][0]).path));
825 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
826 mlessurltype = get_motherless_get_link_type("http://motherless.com/"+mlessuname_odd[mli]);
827 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlessuname_odd[mli], 'username': mlessuname_odd[mli], 'avatarurl': mlessavatar[mli][0], 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
828 mli = mli + 1;
829 return returnval;
831 def get_motherless_top_referrers(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
832 mrtext = download_from_url("http://motherless.com/referers", httpheaders, httpcookie, httplibuse);
833 if(sys.version[0]>="3"):
834 mrtext = mrtext.decode('ascii', 'replace');
835 mregex_geturlname = "([0-9]+)"+re.escape(". <a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" class=\"pop\" target=\"_blank\" rel=\"nofollow\">\n ")+"(.*)"+re.escape(" </a>");
836 mlessurlname = re.findall(mregex_geturlname, mrtext);
837 if(getlinks[1]>len(mlessurlname) or getlinks[1]==-1):
838 getlinks[1] = len(mlessurlname);
839 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
840 tmpgetlinks0 = getlinks[0];
841 tmpgetlinks1 = getlinks[1];
842 getlinks[0] = tmpgetlinks1;
843 getlinks[1] = tmpgetlinks0;
844 if(getlinks[0]<0):
845 getlinks[0] = 0;
846 mli = getlinks[0];
847 mlil = getlinks[1];
848 returnval = {'numoflinks': mlil};
849 returnval.update({'numofalllinks': len(mlessurlname)});
850 returnval.update({'orginurl': "http://motherless.com/referers"});
851 returnval.update({'orginurltype': get_motherless_get_link_type("http://motherless.com/referers")});
852 mlessrooturltype = get_motherless_get_link_type("http://motherless.com/referers");
853 returnval.update({'urltype': mlessrooturltype});
854 while(mli<mlil):
855 returnval.update({mli: {'urltype': "referer-links", 'url': mlessurlname[mli][1], 'title': mlessurlname[mli][2]} });
856 mli = mli + 1;
857 return returnval;
859 def get_motherless_top_referers(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
860 return get_motherless_top_referrers(httpheaders, httpcookie, httplibuse, getlinks);
862 def get_motherless_sample_links(httpheaders, httpcookie, httplibuse="urllib", numoflinks=10, urltype="video"):
863 if(urltype=="video"):
864 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/videos", 'orginurltype': get_motherless_get_link_type("http://motherless.com/videos"), 'videos': {'recent': get_motherless_galleries_links("http://motherless.com/videos/recent", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'favorited': get_motherless_galleries_links("http://motherless.com/videos/favorited", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'viewed': get_motherless_galleries_links("http://motherless.com/videos/viewed", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'commented': get_motherless_galleries_links("http://motherless.com/videos/commented", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'popular': get_motherless_galleries_links("http://motherless.com/videos/popular", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'live': get_motherless_galleries_links("http://motherless.com/live/videos", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'random': get_motherless_random_links(httpheaders, httpcookie, httplibuse, "video", [0, numoflinks]) } };
865 if(urltype=="image"):
866 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/images", 'orginurltype': get_motherless_get_link_type("http://motherless.com/images"), 'images': {'recent': get_motherless_galleries_links("http://motherless.com/images/recent", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'favorited': get_motherless_galleries_links("http://motherless.com/images/favorited", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'viewed': get_motherless_galleries_links("http://motherless.com/images/viewed", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'commented': get_motherless_galleries_links("http://motherless.com/images/commented", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'popular': get_motherless_galleries_links("http://motherless.com/images/popular", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'live': get_motherless_galleries_links("http://motherless.com/live/images", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'random': get_motherless_random_links(httpheaders, httpcookie, httplibuse, "image", [0, numoflinks]) } };
867 if(urltype=="gallery"):
868 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/galleries", 'orginurltype': get_motherless_get_link_type("http://motherless.com/galleries"), 'galleries': {'updated': get_motherless_galleries_links("http://motherless.com/galleries/updated", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'created': get_motherless_galleries_links("http://motherless.com/galleries/created", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'viewed': get_motherless_galleries_links("http://motherless.com/galleries/viewed", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'favorited': get_motherless_galleries_links("http://motherless.com/galleries/favorited", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'commented': get_motherless_galleries_links("http://motherless.com/galleries/commented", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]) } };
869 if(urltype=="all"):
870 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/", 'orginurltype': get_motherless_get_link_type("http://motherless.com/"), 'videos': {'recent': get_motherless_galleries_links("http://motherless.com/videos/recent", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'favorited': get_motherless_galleries_links("http://motherless.com/videos/favorited", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'viewed': get_motherless_galleries_links("http://motherless.com/videos/viewed", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'commented': get_motherless_galleries_links("http://motherless.com/videos/commented", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'popular': get_motherless_galleries_links("http://motherless.com/videos/popular", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'live': get_motherless_galleries_links("http://motherless.com/live/videos", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'random': get_motherless_random_links(httpheaders, httpcookie, httplibuse, "video", [0, numoflinks]) }, 'images': {'recent': get_motherless_galleries_links("http://motherless.com/images/recent", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'favorited': get_motherless_galleries_links("http://motherless.com/images/favorited", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'viewed': get_motherless_galleries_links("http://motherless.com/images/viewed", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'commented': get_motherless_galleries_links("http://motherless.com/images/commented", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'popular': get_motherless_galleries_links("http://motherless.com/images/popular", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'live': get_motherless_galleries_links("http://motherless.com/live/images", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'random': get_motherless_random_links(httpheaders, httpcookie, httplibuse, "image", [0, numoflinks]) }, 'galleries': {'updated': get_motherless_galleries_links("http://motherless.com/galleries/updated", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'created': get_motherless_galleries_links("http://motherless.com/galleries/created", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'viewed': get_motherless_galleries_links("http://motherless.com/galleries/viewed", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'favorited': get_motherless_galleries_links("http://motherless.com/galleries/favorited", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]), 'commented': get_motherless_galleries_links("http://motherless.com/galleries/commented", httpheaders, httpcookie, httplibuse, 1, [0, numoflinks]) } };
871 return returnval;
873 def get_motherless_get_link_by_type(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
874 returnval = False;
875 if(get_motherless_get_link_type(httpurl)=="file"):
876 returnval = get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse);
877 if(get_motherless_get_link_type(httpurl)=="gallery"):
878 returnval = get_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse, page);
879 if(get_motherless_get_link_type(httpurl)=="sample-videos"):
880 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "video");
881 if(get_motherless_get_link_type(httpurl)=="sample-images"):
882 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "image");
883 if(get_motherless_get_link_type(httpurl)=="sample-galleries"):
884 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "gallery");
885 if(get_motherless_get_link_type(httpurl)=="sample" or get_motherless_get_link_type(httpurl)=="sample-all"):
886 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "all");
887 if(get_motherless_get_link_type(httpurl)=="board"):
888 returnval = get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse);
889 if(get_motherless_get_link_type(httpurl)=="member"):
890 returnval = get_motherless_search_members(httpurl, httpheaders, httpcookie, httplibuse, page);
891 if(get_motherless_get_link_type(httpurl)=="girls"):
892 returnval = get_motherless_girls(httpheaders, httpcookie, httplibuse);
893 if(get_motherless_get_link_type(httpurl)=="download"):
894 returnval = httpurl;
895 return returnval;
897 def view_motherless_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", viewerpro="mpv", prearg=[], proarg=[]):
898 commandlist = [viewerpro] + prearg;
899 commandlist = commandlist + [get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse)['url']];
900 commandlist = commandlist + proarg;
901 mpvplaylistp = subprocess.Popen(commandlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE);
902 mpvplayout, mpvplayerr = mpvplaylistp.communicate();
903 return True;
905 def download_motherless_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, outfile="-", outpath=os.getcwd(), usetitlename=False):
906 global geturls_download_sleep;
907 if(sleep<0):
908 sleep = geturls_download_sleep;
909 mlessurl = get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse);
910 outputname = mlessurl['fullfilename'];
911 outpath = outpath.rstrip(os.path.sep);
912 if(usetitlename==True):
913 outputname = mlessurl['title'];
914 if(usetitlename=="-" and outfile=="-"):
915 outputname = "-";
916 if(usetitlename=="-" and not outfile=="-"):
917 outputname = outfile;
918 returnval = download_from_url_to_file(mlessurl['url'], httpheaders, httpcookie, httplibuse, outputname, outpath, sleep);
919 return returnval;
921 def download_motherless_links_by_type(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, outfile="-", outpath=os.getcwd(), usetitlename=False, page=1, getlinks=[0, -1]):
922 global geturls_download_sleep;
923 if(sleep<0):
924 sleep = geturls_download_sleep;
925 mlessurl = get_motherless_get_link_by_type(httpurl, httpheaders, httpcookie, httplibuse, page);
926 if(mlessurl['urltype']=="download"):
927 outputname = mlessurl['fullfilename'];
928 outpathname = outpath.rstrip(os.path.sep);
929 if(usetitlename==True):
930 outputname = mlessurl['title'];
931 if(usetitlename=="-" and outfile[mli]=="-"):
932 outputname = "-";
933 if(usetitlename=="-" and not outfile[mli]=="-"):
934 outputname = outfile;
935 returnval = download_from_url_to_file(mlessurl['url'], httpheaders, httpcookie, httplibuse, outputname, outpathname, sleep);
936 if(not mlessurl['urltype']=="download"):
937 returnval = mlessurl;
938 return returnval;
940 def download_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, outfile="-", outpath=os.getcwd(), usetitlename=False, page=1, getlinks=[0, -1]):
941 global geturls_download_sleep;
942 if(sleep<0):
943 sleep = geturls_download_sleep;
944 mlessgalleries = get_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse, page, getlinks);
945 mli = 0;
946 mlil = mlessgalleries['numoflinks'];
947 returnval = {'pages': mlessgalleries['pages']};
948 returnval.update({'numoflists': mlessgalleries['numoflinks']});
949 returnval.update({'curpage': mlessgalleries['curpage']});
950 returnval.update({'numoflinks': mlessgalleries['numoflinks']});
951 returnval.update({'numofalllinks': mlessgalleries['numofalllinks']});
952 returnval.update({'orginurl': httpurl});
953 returnval.update({'orginurltype': get_motherless_get_link_type(httpurl)});
954 while(mli<mlil):
955 mlesslink = get_motherless_links(mlessgalleries[mli]['url'], httpheaders, httpcookie, httplibuse);
956 outputname = mlesslink['fullfilename'];
957 outpath = outpath.rstrip(os.path.sep);
958 if(usetitlename==True):
959 outputname = mlesslink['title'];
960 if(usetitlename=="-" and outfile=="-"):
961 outputname = "-";
962 if(usetitlename=="-" and not outfile=="-"):
963 outputname = outfile;
964 returnval.update({mli: {'download': download_from_url_to_file(mlesslink['url'], httpheaders, httpcookie, httplibuse, outputname, outpath, sleep), 'linkinfo': mlesslink, 'outputfile': outputname} });
965 mli = mli + 1;
966 return returnval;
968 def download_get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, outfile="-", outpath=os.getcwd(), usetitlename=False, getlinks=[0, -1]):
969 global geturls_download_sleep;
970 if(sleep<0):
971 sleep = geturls_download_sleep;
972 mlessgalleries = get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse, getlinks);
973 mli = 0;
974 mlil = mlessgalleries['numoflinks'];
975 returnval = {'numoflists': mlessgalleries['numoflinks']};
976 returnval.update({'numofalllinks': mlessgalleries['numofalllinks']});
977 returnval.update({'orginurl': httpurl});
978 returnval.update({'orginurltype': get_motherless_get_link_type(httpurl)});
979 while(mli<mlil):
980 mlesslink = get_motherless_links(mlessgalleries[mli]['url'], httpheaders, httpcookie, httplibuse);
981 outputname = mlesslink['fullfilename'];
982 outpath = outpath.rstrip(os.path.sep);
983 if(usetitlename==True):
984 outputname = mlesslink['title'];
985 if(usetitlename=="-" and outfile=="-"):
986 outputname = "-";
987 if(usetitlename=="-" and not outfile=="-"):
988 outputname = outfile;
989 returnval.update({mli: {'download': download_from_url_to_file(mlesslink['url'], httpheaders, httpcookie, httplibuse, outputname, outpath, sleep), 'linkinfo': mlesslink, 'outputfile': outputname} });
990 mli = mli + 1;
991 return returnval;