Small update.
[PyMotherless.git] / pymotherless.py
blob7b22a2743e7b5d0284ef1dfb387c5ff84e873c2f
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/25/2016 Ver. 0.4.3 RC 1 - Author: cooldude2k $
17 '''
19 from __future__ import division, absolute_import, print_function;
20 import re, os, sys, platform, tempfile, urllib, gzip, time, datetime, argparse, cgi, subprocess, imp;
21 import logging as log;
22 haverequests = False;
23 try:
24 imp.find_module('requests');
25 haverequests = True;
26 import requests;
27 except ImportError:
28 haverequests = False;
29 if(sys.version[0]=="2"):
30 try:
31 from cStringIO import StringIO;
32 except ImportError:
33 from StringIO import StringIO;
34 # From http://python-future.org/compatible_idioms.html
35 from urlparse import urlparse;
36 from urllib import urlencode;
37 from urllib2 import urlopen, Request, HTTPError;
38 import urllib2, urlparse, cookielib;
39 if(sys.version[0]>="3"):
40 from io import StringIO, BytesIO;
41 # From http://python-future.org/compatible_idioms.html
42 from urllib.parse import urlparse, urlencode
43 from urllib.request import urlopen, Request
44 from urllib.error import HTTPError
45 import urllib.request as urllib2;
46 import urllib.parse as urlparse;
47 import http.cookiejar as cookielib;
49 __program_name__ = "PyMotherless";
50 __project__ = __program_name__;
51 __project_url__ = "https://github.com/GameMaker2k/PyMotherless";
52 __version_info__ = (0, 4, 3, "RC 1", 1);
53 __version_date_info__ = (2016, 2, 25, "RC 1", 1);
54 __version_date__ = str(__version_date_info__[0])+"."+str(__version_date_info__[1]).zfill(2)+"."+str(__version_date_info__[2]).zfill(2);
55 if(__version_info__[4]!=None):
56 __version_date_plusrc__ = __version_date__+"-"+str(__version_date_info__[4]);
57 if(__version_info__[4]==None):
58 __version_date_plusrc__ = __version_date__;
59 if(__version_info__[3]!=None):
60 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])+" "+str(__version_info__[3]);
61 if(__version_info__[3]==None):
62 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2]);
64 geturls_cj = cookielib.CookieJar();
65 geturls_ua_firefox_windows7 = "Mozilla/5.0 (Windows NT 6.1; rv:44.0) Gecko/20100101 Firefox/44.0";
66 geturls_ua_seamonkey_windows7 = "Mozilla/5.0 (Windows NT 6.1; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39";
67 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";
68 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";
69 geturls_ua_internet_explorer_windows7 = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko";
70 geturls_ua_pymotherless_python = "Mozilla/5.0 (compatible; {proname}/{prover}; +{prourl})".format(proname=__project__, prover=__version__, prourl=__project_url__);
71 if(platform.python_implementation()!=""):
72 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__);
73 if(platform.python_implementation()==""):
74 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__);
75 geturls_ua_googlebot_google = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
76 geturls_ua_googlebot_google_old = "Googlebot/2.1 (+http://www.google.com/bot.html)";
77 geturls_ua = geturls_ua_firefox_windows7;
78 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"};
79 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"};
80 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"};
81 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"};
82 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"};
83 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"};
84 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"};
85 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"};
86 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_urllib(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", buffersize=262144, 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, buffersize, sleep);
229 elif(httplibuse=="httplib"):
230 returnval = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize, sleep);
231 elif(httplibuse=="requests"):
232 returnval = download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, buffersize, sleep);
233 else:
234 returnval = False;
235 return returnval;
237 def download_from_url_to_file(httpurl, httpheaders, httpcookie, httplibuse="urllib", outfile="-", outpath=os.getcwd(), buffersize=[262144, 262144], sleep=-1):
238 global geturls_download_sleep, haverequests;
239 if(sleep<0):
240 sleep = geturls_download_sleep;
241 if(httplibuse=="urllib1" or httplibuse=="urllib2"):
242 httplibuse = "urllib";
243 if(haverequests==False and httplibuse=="requests"):
244 httplibuse = "urllib";
245 if(httplibuse=="urllib"):
246 returnval = download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, outfile, outpath, buffersize, sleep);
247 elif(httplibuse=="httplib"):
248 returnval = download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, outfile, outpath, buffersize, sleep);
249 elif(httplibuse=="requests"):
250 returnval = download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile, outpath, buffersize, sleep);
251 else:
252 returnval = False;
253 return returnval;
255 def download_from_url_with_urllib(httpurl, httpheaders, httpcookie, sleep=-1):
256 global geturls_download_sleep;
257 if(sleep<0):
258 sleep = geturls_download_sleep;
259 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(httpcookie));
260 if isinstance(httpheaders, dict):
261 httpheaders = make_http_headers_from_dict_to_list(httpheaders);
262 geturls_opener.addheaders = httpheaders;
263 time.sleep(sleep);
264 geturls_text = geturls_opener.open(httpurl);
265 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
266 if(sys.version[0]=="2"):
267 strbuf = StringIO(geturls_text.read());
268 if(sys.version[0]>="3"):
269 strbuf = BytesIO(geturls_text.read());
270 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
271 returnval_content = gzstrbuf.read()[:];
272 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
273 returnval_content = geturls_text.read()[:];
274 returnval = {'Content': returnval_content, 'Headers': dict(geturls_text.info())};
275 geturls_text.close();
276 return returnval;
278 def download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize=262144, sleep=-1):
279 global geturls_download_sleep;
280 if(sleep<0):
281 sleep = geturls_download_sleep;
282 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(httpcookie));
283 if isinstance(httpheaders, dict):
284 httpheaders = make_http_headers_from_dict_to_list(httpheaders);
285 geturls_opener.addheaders = httpheaders;
286 time.sleep(sleep);
287 geturls_text = geturls_opener.open(httpurl);
288 downloadsize = int(geturls_text.info().get('Content-Length'));
289 if downloadsize is None: downloadsize = 0;
290 fulldatasize = 0;
291 log.info("Downloading URL "+httpurl);
292 with tempfile.NamedTemporaryFile('wb+', prefix="pymotherless-", delete=False) as f:
293 returnval = f.name;
294 while True:
295 databytes = geturls_text.read(buffersize);
296 if not databytes: break;
297 datasize = len(databytes);
298 fulldatasize = datasize + fulldatasize;
299 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
300 log.info("Downloading "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
301 f.write(databytes);
302 f.close();
303 geturls_text.close();
304 return returnval;
306 def download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, outfile="-", outpath=os.getcwd(), buffersize=[262144, 262144], sleep=-1):
307 global geturls_download_sleep;
308 if(sleep<0):
309 sleep = geturls_download_sleep;
310 if(not outfile=="-"):
311 outpath = outpath.rstrip(os.path.sep);
312 filepath = os.path.realpath(outpath+os.path.sep+outfile);
313 if(not os.path.exists(outpath)):
314 os.makedirs(outpath);
315 if(os.path.exists(outpath) and os.path.isfile(outpath)):
316 return False;
317 if(os.path.exists(filepath) and os.path.isdir(filepath)):
318 return False;
319 tmpfilename = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize[0], sleep);
320 downloadsize = os.path.getsize(tmpfilename);
321 fulldatasize = 0;
322 log.info("Moving file "+tmpfilename+" to "+filepath);
323 with open(tmpfilename, 'rb') as ft:
324 with open(filepath, 'wb+') as f:
325 while True:
326 databytes = ft.read(buffersize[1]);
327 if not databytes: break;
328 datasize = len(databytes);
329 fulldatasize = datasize + fulldatasize;
330 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
331 log.info("Copying "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
332 f.write(databytes);
333 f.close();
334 ft.close();
335 os.remove(tmpfilename);
336 returnval = True;
337 if(outfile=="-" and sys.version[0]=="2"):
338 tmpfilename = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize[0], sleep);
339 downloadsize = os.path.getsize(tmpfilename);
340 fulldatasize = 0;
341 with open(tmpfilename, 'rb') as ft:
342 f = StringIO();
343 while True:
344 databytes = ft.read(buffersize[1]);
345 if not databytes: break;
346 datasize = len(databytes);
347 fulldatasize = datasize + fulldatasize;
348 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
349 log.info("Copying "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
350 f.write(databytes);
351 f.close();
352 ft.close();
353 os.remove(tmpfilename);
354 returnval = f.getvalue();
355 if(outfile=="-" and sys.version[0]>="3"):
356 tmpfilename = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize[0], sleep);
357 downloadsize = os.path.getsize(tmpfilename);
358 fulldatasize = 0;
359 with open(tmpfilename, 'rb') as ft:
360 f = BytesIO();
361 while True:
362 databytes = ft.read(buffersize[1]);
363 if not databytes: break;
364 datasize = len(databytes);
365 fulldatasize = datasize + fulldatasize;
366 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
367 log.info("Copying "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
368 f.write(databytes);
369 f.close();
370 ft.close();
371 os.remove(tmpfilename);
372 returnval = f.getvalue();
373 return returnval;
375 if(haverequests==True):
376 def download_from_url_with_requests(httpurl, httpheaders, httpcookie, sleep=-1):
377 global geturls_download_sleep;
378 if(sleep<0):
379 sleep = geturls_download_sleep;
380 if isinstance(httpheaders, list):
381 httpheaders = make_http_headers_from_list_to_dict(httpheaders);
382 time.sleep(sleep);
383 geturls_text = requests.get(httpurl, headers=httpheaders, cookies=httpcookie);
384 if(geturls_text.headers.get('Content-Type')=="gzip" or geturls_text.headers.get('Content-Type')=="deflate"):
385 if(sys.version[0]=="2"):
386 strbuf = StringIO(geturls_text.content);
387 if(sys.version[0]>="3"):
388 strbuf = BytesIO(geturls_text.content);
389 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
390 returnval_content = gzstrbuf.content[:];
391 if(geturls_text.headers.get('Content-Type')!="gzip" and geturls_text.headers.get('Content-Type')!="deflate"):
392 returnval_content = geturls_text.content[:];
393 returnval = {'Content': returnval_content, 'Headers': dict(geturls_text.headers)};
394 geturls_text.close();
395 return returnval;
397 if(haverequests==False):
398 def download_from_url_with_requests(httpurl, httpheaders, httpcookie, sleep=-1):
399 returnval = download_from_url_with_urllib(httpurl, httpheaders, httpcookie, sleep)
400 return returnval;
402 if(haverequests==True):
403 def download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, buffersize=262144, sleep=-1):
404 global geturls_download_sleep;
405 if(sleep<0):
406 sleep = geturls_download_sleep;
407 if isinstance(httpheaders, list):
408 httpheaders = make_http_headers_from_list_to_dict(httpheaders);
409 time.sleep(sleep);
410 geturls_text = requests.get(httpurl, headers=httpheaders, cookies=httpcookie, stream=True);
411 downloadsize = int(geturls_text.headers.get('Content-Length'));
412 if downloadsize is None: downloadsize = 0;
413 fulldatasize = 0;
414 log.info("Downloading URL "+httpurl);
415 with tempfile.NamedTemporaryFile('wb+', prefix="pymotherless-", delete=False) as f:
416 returnval = f.name;
417 for databytes in geturls_text.iter_content(chunk_size=buffersize):
418 datasize = len(databytes);
419 fulldatasize = datasize + fulldatasize;
420 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
421 log.info("Downloading "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
422 f.write(databytes);
423 f.close();
424 geturls_text.close();
425 return returnval;
427 if(haverequests==False):
428 def download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, buffersize=262144, sleep=-1):
429 returnval = download_from_url_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize, sleep)
430 return returnval;
432 if(haverequests==True):
433 def download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile="-", outpath=os.getcwd(), buffersize=[262144, 262144], sleep=-1):
434 global geturls_download_sleep;
435 if(sleep<0):
436 sleep = geturls_download_sleep;
437 if(not outfile=="-"):
438 outpath = outpath.rstrip(os.path.sep);
439 filepath = os.path.realpath(outpath+os.path.sep+outfile);
440 if(not os.path.exists(outpath)):
441 os.makedirs(outpath);
442 if(os.path.exists(outpath) and os.path.isfile(outpath)):
443 return False;
444 if(os.path.exists(filepath) and os.path.isdir(filepath)):
445 return False;
446 tmpfilename = download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, buffersize[0], sleep);
447 downloadsize = os.path.getsize(tmpfilename);
448 fulldatasize = 0;
449 log.info("Moving file "+tmpfilename+" to "+filepath);
450 with open(tmpfilename, 'rb') as ft:
451 with open(filepath, 'wb+') as f:
452 while True:
453 databytes = ft.read(buffersize[1]);
454 if not databytes: break;
455 datasize = len(databytes);
456 fulldatasize = datasize + fulldatasize;
457 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
458 log.info("Copying "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
459 f.write(databytes);
460 f.close();
461 ft.close();
462 os.remove(tmpfilename);
463 returnval = True;
464 if(outfile=="-" and sys.version[0]=="2"):
465 tmpfilename = download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, buffersize[0], sleep);
466 downloadsize = os.path.getsize(tmpfilename);
467 fulldatasize = 0;
468 with open(tmpfilename, 'rb') as ft:
469 f = StringIO();
470 while True:
471 databytes = ft.read(buffersize[1]);
472 if not databytes: break;
473 datasize = len(databytes);
474 fulldatasize = datasize + fulldatasize;
475 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
476 log.info("Copying "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
477 f.write(databytes);
478 f.close();
479 ft.close();
480 os.remove(tmpfilename);
481 returnval = f.getvalue();
482 if(outfile=="-" and sys.version[0]>="3"):
483 tmpfilename = download_from_url_file_with_requests(httpurl, httpheaders, httpcookie, buffersize[0], sleep);
484 downloadsize = os.path.getsize(tmpfilename);
485 fulldatasize = 0;
486 with open(tmpfilename, 'rb') as ft:
487 f = BytesIO();
488 while True:
489 databytes = ft.read(buffersize[1]);
490 if not databytes: break;
491 datasize = len(databytes);
492 fulldatasize = datasize + fulldatasize;
493 percentage = str("{0:.2f}".format(float(float(fulldatasize / downloadsize) * 100))).rstrip('0').rstrip('.')+"%";
494 log.info("Copying "+str(fulldatasize)+" / "+str(downloadsize)+" bytes. "+str(percentage)+" done.");
495 f.write(databytes);
496 f.close();
497 ft.close();
498 os.remove(tmpfilename);
499 returnval = f.getvalue();
500 return returnval;
502 if(haverequests==False):
503 def download_from_url_to_file_with_requests(httpurl, httpheaders, httpcookie, outfile="-", outpath=os.getcwd(), buffersize=[262144, 262144], sleep=-1):
504 returnval = download_from_url_to_file_with_urllib(httpurl, httpheaders, httpcookie, buffersize, outfile, outpath, sleep)
505 return returnval;
507 def get_motherless_number_of_pages(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
508 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
509 if(sys.version[0]>="3"):
510 mrtext = mrtext.decode('ascii', 'replace');
511 mregex_getpagenum = re.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
512 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
513 try:
514 returnval = int(mlesspagenum[-1][0]);
515 except:
516 returnval = 1;
517 return returnval;
519 def get_motherless_link_type(httpurl):
520 mlessvidqstr = urlparse.parse_qs(urlparse.urlparse(httpurl).query);
521 mlessvidid_parts = urlparse.urlparse(httpurl);
522 mlessvidid = mlessvidid_parts.path.split("/");
523 returnval = False;
524 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")):
525 returnval = "gallery";
526 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")):
527 returnval = "gallery";
528 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")):
529 returnval = "gallery";
530 if(mlessvidid[1]=="videos" and len(mlessvidid)==2):
531 returnval = "sample-videos";
532 if(mlessvidid[1]=="images" and len(mlessvidid)==2):
533 returnval = "sample-images";
534 if(mlessvidid[1]=="galleries" and len(mlessvidid)==2):
535 returnval = "sample-galleries";
536 if(mlessvidid[1]=="" and len(mlessvidid)==2):
537 returnval = "sample";
538 if(mlessvidid[1]=="groups" and len(mlessvidid)==2):
539 returnval = "group";
540 if(mlessvidid[1]=="groups" and len(mlessvidid)==3 and mlessvidid[2]=="search"):
541 returnval = "group";
542 if(mlessvidid[1]=="groups" and len(mlessvidid)==4 and mlessvidid[2]=="category"):
543 returnval = "group";
544 if(mlessvidid[1]=="live" and len(mlessvidid)==3 and (mlessvidid[2]=="videos" or mlessvidid[2]=="images")):
545 returnval = "gallery";
546 if(mlessvidid[1]=="u" and len(mlessvidid)==3):
547 returnval = "gallery";
548 if(mlessvidid[1]=="f" and len(mlessvidid)==4 and (mlessvidid[2]=="videos" or mlessvidid[2]=="images" or mlessvidid[2]=="galleries")):
549 returnval = "gallery";
550 if(mlessvidid[1]=="galleries" and len(mlessvidid)==4 and mlessvidid[2]=="member"):
551 returnval = "gallery";
552 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")):
553 returnval = "gallery";
554 if(mlessvidid[1]=="gv" and len(mlessvidid)==3):
555 returnval = "gallery";
556 if(mlessvidid[1]=="gi" and len(mlessvidid)==3):
557 returnval = "gallery";
558 if(mlessvidid[1]=="gm" and len(mlessvidid)==3):
559 returnval = "member";
560 if(mlessvidid[1]=="term" and len(mlessvidid)==3 and (mlessvidid[2]=="videos" or mlessvidid[2]=="images" or mlessvidid[2]=="galleries")):
561 returnval = "gallery";
562 if(mlessvidid[1]=="g" and len(mlessvidid)==4 and re.match("^([0-9A-F]+)$", mlessvidid[3])):
563 returnval = "file";
564 if(mlessvidid[1]=="random" and len(mlessvidid)==3 and (mlessvidid[2]=="video" or mlessvidid[2]=="image")):
565 returnval = "file";
566 if(re.match("^V", mlessvidid[1]) and len(mlessvidid)==2):
567 returnval = "board";
568 if(re.match("^H", mlessvidid[1]) and len(mlessvidid)==2):
569 returnval = "gallery";
570 if(re.match("^G", mlessvidid[1]) and len(mlessvidid)==2):
571 returnval = "gallery";
572 if(re.match("^G", mlessvidid[1]) and len(mlessvidid)==3):
573 returnval = "file";
574 if(re.match("^g", mlessvidid[1]) and len(mlessvidid)==4 and re.match("^([0-9A-F]+)$", mlessvidid[3])):
575 returnval = "file";
576 if(mlessvidid[1]=="members" and len(mlessvidid)==2):
577 returnval = "member";
578 if(mlessvidid[1]=="members" and len(mlessvidid)==3 and mlessvidid[2]=="search"):
579 returnval = "member";
580 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")):
581 returnval = "member";
582 if(mlessvidid[1]=="girls" and len(mlessvidid)==2):
583 returnval = "girls";
584 if(mlessvidid[1]=="referers" and len(mlessvidid)==2):
585 returnval = "referers";
586 if(mlessvidid[1]=="about" and len(mlessvidid)==2):
587 returnval = "team";
588 if(mlessvidid_parts.netloc=="cdn.images.motherlessmedia.com" or mlessvidid_parts.netloc=="cdn.videos.motherlessmedia.com" or mlessvidid_parts.netloc=="cdn.thumbs.motherlessmedia.com"):
589 returnval = "download";
590 if(returnval==False and len(mlessvidid)==2 and re.match("^([0-9A-F]+)$", mlessvidid[1])):
591 returnval = "file";
592 return returnval;
594 def get_motherless_user_info(username):
595 returnval = {'username': username};
596 avatarfilenameext = os.path.basename(urlparse.urljoin("http://cdn.avatars.motherlessmedia.com/thumbs/"+username+"-avatar.jpg", urlparse.urlparse("http://cdn.avatars.motherlessmedia.com/thumbs/"+username+"-avatar.jpg").path));
597 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
598 returnval.update({'orginurl': "http://motherless.com/m/"+username});
599 returnval.update({'orginurltype': "profile"});
600 returnval.update({'url': "http://motherless.com/m/"+username});
601 returnval.update({'urltype': "profile"});
602 returnval.update({'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+username+"-avatar.jpg"});
603 returnval.update({'avatarfullfilename': avatarfilenameext});
604 returnval.update({'avatarfilename': avatarfilename});
605 returnval.update({'avatarextension': avatarfileextension});
606 return returnval;
608 def get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
609 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
610 if(sys.version[0]>="3"):
611 mrtext = mrtext.decode('ascii', 'replace');
612 mregex_gettitle = re.escape("<title>")+"(.*)"+re.escape(" - MOTHERLESS.COM</title>");
613 mlesstitle = re.findall(mregex_gettitle, mrtext);
614 mregex_geturlone = re.escape("__fileurl = '")+'?\'?([^"\'>]*)'+re.escape("';");
615 mlesslinkone = re.findall(mregex_geturlone, mrtext);
616 mregex_geturlonetype = re.escape("http://cdn.")+"(images|videos)"+re.escape(".motherlessmedia.com/")+"(images|videos)"+re.escape("/")+"([\w\/\?\&\=\.\-]+)";
617 mlesslinkonetype = re.findall(mregex_geturlonetype, mrtext);
618 mregex_geturltwo = re.escape("<meta property=\"og:image\" content=\"")+'?\'?([^"\'>]*)'+re.escape("\">");
619 mlesslinktwo = re.findall(mregex_geturltwo, mrtext);
620 mregex_geturltwotype = re.escape("http://cdn.")+"(images|thumbs)"+re.escape(".motherlessmedia.com/")+"(images|thumbs)"+re.escape("/")+"([\w\/\?\&\=\.\-]+)";
621 mlesslinktwotype = re.findall(mregex_geturltwotype, mrtext);
622 filenameext = os.path.basename(urlparse.urljoin(mlesslinkone[0], urlparse.urlparse(mlesslinkone[0]).path));
623 filename, fileextension = os.path.splitext(filenameext);
624 thumbfilenameext = os.path.basename(urlparse.urljoin(mlesslinktwo[0], urlparse.urlparse(mlesslinktwo[0]).path));
625 thumbfilename, thumbfileextension = os.path.splitext(thumbfilenameext);
626 mregex_getuname = re.escape("<tr rel=\"")+'?\'?([^"\'>]*)'+re.escape("\"");
627 mlessuname = re.findall(mregex_getuname, mrtext);
628 mlessuname = mlessuname[0];
629 mregex_geturlname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" target=\"_blank\">\n <img");
630 mlessurlname = re.findall(mregex_geturlname, mrtext);
631 mlessurlname = mlessurlname[0].replace("/m/", "");
632 mregex_getavatar = re.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re.escape("\"\n class=\"avatar avatar-small\"");
633 mlessavatar = re.findall(mregex_getavatar, mrtext);
634 mlessavatar = mlessavatar[0];
635 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavatar, urlparse.urlparse(mlessavatar).path));
636 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
637 if(mlesslinkonetype[0][1]=="images"):
638 thumbnailaltpart = thumbfilename+"-zoom"+thumbfileextension;
639 thumbnailalt = "http://cdn.thumbs.motherlessmedia.com/thumbs/"+thumbnailaltpart;
640 thumbnailaltfilenameext = os.path.basename(urlparse.urljoin(thumbnailalt, urlparse.urlparse(thumbnailalt).path));
641 thumbnailaltfilename, thumbnailaltfileextension = os.path.splitext(thumbnailaltfilenameext);
642 if(mlesslinkonetype[0][1]=="videos"):
643 thumbnailaltpart = thumbfilename+"-small"+thumbfileextension;
644 thumbnailalt = "http://cdn.thumbs.motherlessmedia.com/thumbs/"+thumbnailaltpart;
645 thumbnailaltfilenameext = os.path.basename(urlparse.urljoin(thumbnailalt, urlparse.urlparse(thumbnailalt).path));
646 thumbnailaltfilename, thumbnailaltfileextension = os.path.splitext(thumbnailaltfilenameext);
647 returnval = False;
648 mlessurltype = get_motherless_link_type(mlesslinkone[0]);
649 if(mlesslinkonetype[0][1]=="images"):
650 returnval = {'type': mlesslinkonetype[0][1], 'urltype': mlessurltype, 'url': mlesslinkone[0], 'orginurl': httpurl, 'orginurltype': get_motherless_link_type(httpurl), 'thumbnail': mlesslinktwo[0].replace("images", "thumbs"), '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, 'userinfo': get_motherless_user_info(mlessuname), 'username': mlessuname, 'avatarurl': mlessavatar, 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension};
651 if(mlesslinkonetype[0][1]=="videos"):
652 returnval = {'type': mlesslinkonetype[0][1], 'url': mlesslinkone[0], 'orginurl': httpurl, 'orginurltype': get_motherless_link_type(httpurl), 'thumbnail': mlesslinktwo[0].replace("images", "thumbs"), '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, 'userinfo': get_motherless_user_info(mlessuname), 'username': mlessuname, 'avatarurl': mlessavatar, 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension};
653 return returnval;
655 def get_motherless_links_from_url(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
656 returnval = False;
657 if(get_motherless_link_type(httpurl)=="download"):
658 urlparts = urlparse.urlparse(httpurl);
659 filewithext = os.path.split(urlparts.path);
660 if(filewithext[0]=="/images"):
661 filewithoutext = os.path.splitext(filewithext[1])[0];
662 returnval = get_motherless_links("http://motherless.com/"+filewithoutext, httpheaders, httpcookie, httplibuse="urllib");
663 if(filewithext[0]=="/thumbs"):
664 filewithoutext = os.path.splitext(filewithext[1])[0];
665 filewithoutext = filewithoutext.replace("-zoom", "");
666 filewithoutext = filewithoutext.replace("-small", "");
667 filewithoutext = filewithoutext.replace("-strip", "");
668 returnval = get_motherless_links("http://motherless.com/"+filewithoutext, httpheaders, httpcookie, httplibuse="urllib");
669 return returnval;
671 def get_motherless_external_links(httpurl, httpheaders, httpcookie, httplibuse="urllib"):
672 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
673 if(sys.version[0]>="3"):
674 mrtext = mrtext.decode('ascii', 'replace');
675 mregex_geturlinternal = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" rev=\"outbound\" rel=\"nofollow\" class=\"pop\" target=\"_blank\" title=\"motherless link\">");
676 mlesslinkinternal = re.findall(mregex_geturlinternal, mrtext);
677 mregex_geturlexternal = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" rev=\"outbound\" rel=\"nofollow\" class=\"pop\" target=\"_blank\" title=\"external link\">");
678 mlesslinkexternal = re.findall(mregex_geturlexternal, mrtext);
679 returnvalone = None;
680 if(len(mlesslinkinternal)>1):
681 mli = 0;
682 mlil = len(mlesslinkinternal);
683 returnvalone = {'numoflinks': mlil};
684 returnvalone.update({'numofalllinks': len(mlesslinkinternal)});
685 returnvalone.update({'orginurl': httpurl});
686 returnvalone.update({'orginurltype': get_motherless_link_type(httpurl)});
687 mlessrooturltype = get_motherless_link_type(httpurl);
688 returnvalone.update({'urltype': mlessrooturltype});
689 while(mli<mlil):
690 mlessurltype = get_motherless_link_type(mlesslinkinternal[mli]);
691 returnvalone.update({mli: {'urltype': mlessurltype, 'url': mlesslinkinternal[mli]} });
692 mli = mli + 1;
693 returnvaltwo = None;
694 if(len(mlesslinkexternal)>1):
695 mli = 0;
696 mlil = len(mlesslinkexternal);
697 returnvaltwo = {'numoflinks': mlil};
698 returnvaltwo.update({'numofalllinks': len(mlesslinkexternal)});
699 returnvaltwo.update({'orginurl': httpurl});
700 returnvaltwo.update({'orginurltype': get_motherless_link_type(httpurl)});
701 mlessrooturltype = get_motherless_link_type(httpurl);
702 returnvaltwo.update({'urltype': mlessrooturltype});
703 while(mli<mlil):
704 returnvaltwo.update({mli: {'urltype': "external", 'url': mlesslinkexternal[mli]} });
705 mli = mli + 1;
706 if(returnvalone==None and returnvaltwo==None):
707 returnval = {'internal': None, 'external': None};
708 if(not returnvalone==None and not returnvaltwo==None):
709 returnval = {'internal': returnvalone, 'external': returnvaltwo};
710 if(not returnvalone==None and returnvaltwo==None):
711 returnval = {'internal': returnvalone, 'external': None};
712 if(returnvalone==None and not returnvaltwo==None):
713 returnval = {'internal': None, 'external': returnvaltwo};
714 return returnval;
716 def get_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
717 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
718 if(sys.version[0]>="3"):
719 mrtext = mrtext.decode('ascii', 'replace');
720 mregex_getpagenum = re.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
721 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
722 try:
723 lastpage = int(mlesspagenum[-1][0]);
724 except:
725 lastpage = 1;
726 if(page>lastpage):
727 page = lastpage;
728 httpurl = add_url_param(httpurl, page=str(page));
729 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
730 if(sys.version[0]>="3"):
731 mrtext = mrtext.decode('ascii', 'replace');
732 mregex_geturlone = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" class=\"img-container\" target=\"_self\">");
733 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext);
734 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
735 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext_tmp);
736 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
737 mlesslinkone = re.findall(mregex_geturlone, mrtext_tmp);
738 mregex_geturltwo = re.escape("<img class=\"static\" src=\"")+'?\'?([^"\'>]*)'+re.escape("\" data-strip-src=\"")+'?\'?([^"\'>]*)'+re.escape("\" alt=\"")+'?\'?([^">]*)'+re.escape("\" />");
739 mlesslinktwo = re.findall(mregex_geturltwo, mrtext);
740 mregex_getuserinfo = re.escape("<a class=\"caption left\" href=\"")+'?\'?([^"\'>]*)'+re.escape("\">");
741 mlessuname = re.findall(mregex_getuserinfo, mrtext);
742 if(getlinks[1]>len(mlesslinkone) or getlinks[1]==-1):
743 getlinks[1] = len(mlesslinkone);
744 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
745 tmpgetlinks0 = getlinks[0];
746 tmpgetlinks1 = getlinks[1];
747 getlinks[0] = tmpgetlinks1;
748 getlinks[1] = tmpgetlinks0;
749 if(getlinks[0]<0):
750 getlinks[0] = 0;
751 mli = getlinks[0];
752 mlil = getlinks[1];
753 returnval = {'pages': lastpage};
754 returnval.update({'curpage': page});
755 returnval.update({'numoflinks': mlil});
756 returnval.update({'numofalllinks': len(mlesslinkone)});
757 returnval.update({'orginurl': httpurl});
758 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
759 mlessrooturltype = get_motherless_link_type(httpurl);
760 returnval.update({'urltype': mlessrooturltype});
761 while(mli<mlil):
762 mlessuname[mli] = mlessuname[mli].replace("/m/", "");
763 stripfilenameext = os.path.basename(urlparse.urljoin(mlesslinktwo[mli][1], urlparse.urlparse(mlesslinktwo[mli][1]).path));
764 stripfilename, stripfileextension = os.path.splitext(stripfilenameext);
765 thumbfilenameext = os.path.basename(urlparse.urljoin(mlesslinktwo[mli][0], urlparse.urlparse(mlesslinktwo[mli][0]).path));
766 thumbfilename, thumbfileextension = os.path.splitext(thumbfilenameext);
767 mlessurltype = get_motherless_link_type("http://motherless.com/"+mlesslinkone[mli]);
768 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));
769 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
770 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com"+mlesslinkone[mli], 'thumbnail': mlesslinktwo[mli][0], 'strip': mlesslinktwo[mli][1], 'title': mlesslinktwo[mli][2], 'thumbfullfilename': thumbfilenameext, 'thumbfilename': thumbfilename, 'thumbextension': thumbfileextension, 'stripfullfilename': stripfilenameext, 'stripfilename': stripfilename, 'stripextension': stripfileextension, 'userinfo': get_motherless_user_info(mlessuname[mli]), 'username': mlessuname[mli], 'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
771 mli = mli + 1;
772 return returnval;
774 def get_motherless_random_links(httpheaders, httpcookie, httplibuse="urllib", linktype="video", getlinks=[0, 80]):
775 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
776 tmpgetlinks0 = getlinks[0];
777 tmpgetlinks1 = getlinks[1];
778 getlinks[0] = tmpgetlinks1;
779 getlinks[1] = tmpgetlinks0;
780 if(getlinks[0]<0):
781 getlinks[0] = 0;
782 mli = getlinks[0];
783 mlil = getlinks[1];
784 if(linktype=="image"):
785 returnval = {'pages': 1};
786 returnval.update({'curpage': 1});
787 returnval.update({'numoflinks': 80});
788 returnval.update({'numofalllinks': mlil});
789 returnval.update({'orginurl': "http://motherless.com/random/image"});
790 returnval.update({'orginurltype': "gallery"});
791 returnval.update({'urltype': "gallery"});
792 while(mli<mlil):
793 get_links = get_motherless_links("http://motherless.com/random/image", httpheaders, httpcookie, httplibuse);
794 returnval.update({mli: {'urltype': get_motherless_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'], 'userinfo': get_motherless_user_info(get_links['username']), 'username': get_links['username'], 'avatarurl': get_links['avatarurl'], 'avatarfullfilename': get_links['avatarfullfilename'], 'avatarfilename': get_links['avatarfilename'], 'avatarextension': get_links['avatarextension']} });
795 mli = mli + 1;
796 if(linktype=="video"):
797 returnval = {'pages': 1};
798 returnval.update({'curpage': 1});
799 returnval.update({'numoflinks': 80});
800 returnval.update({'numofalllinks': mlil});
801 returnval.update({'orginurl': "http://motherless.com/random/video"});
802 returnval.update({'orginurltype': "gallery"});
803 returnval.update({'urltype': "gallery"});
804 while(mli<mlil):
805 get_links = get_motherless_links("http://motherless.com/random/video", httpheaders, httpcookie, httplibuse);
806 returnval.update({mli: {'urltype': get_motherless_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'], 'userinfo': get_motherless_user_info(get_links['username']), 'username': get_links['username'], 'avatarurl': get_links['avatarurl'], 'avatarfullfilename': get_links['avatarfullfilename'], 'avatarfilename': get_links['avatarfilename'], 'avatarextension': get_links['avatarextension']} });
807 mli = mli + 1;
808 return returnval;
810 def get_motherless_random_links_alt(httpheaders, httpcookie, httplibuse="urllib", linktype="video", getlinks=[0, 80]):
811 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
812 tmpgetlinks0 = getlinks[0];
813 tmpgetlinks1 = getlinks[1];
814 getlinks[0] = tmpgetlinks1;
815 getlinks[1] = tmpgetlinks0;
816 if(getlinks[0]<0):
817 getlinks[0] = 0;
818 mli = getlinks[0];
819 mlil = getlinks[1];
820 if(linktype=="image"):
821 returnval = {'pages': 1};
822 returnval.update({'curpage': 1});
823 returnval.update({'numoflinks': 80});
824 returnval.update({'numofalllinks': mlil});
825 returnval.update({'orginurl': "http://motherless.com/random/image"});
826 returnval.update({'orginurltype': "gallery"});
827 returnval.update({'urltype': "gallery"});
828 while(mli<mlil):
829 get_links = get_motherless_links("http://motherless.com/random/image", httpheaders, httpcookie, httplibuse);
830 returnval.update({mli: get_links});
831 mli = mli + 1;
832 if(linktype=="video"):
833 returnval = {'pages': 1};
834 returnval.update({'curpage': 1});
835 returnval.update({'numoflinks': 80});
836 returnval.update({'numofalllinks': mlil});
837 returnval.update({'orginurl': "http://motherless.com/random/video"});
838 returnval.update({'orginurltype': "gallery"});
839 returnval.update({'urltype': "gallery"});
840 while(mli<mlil):
841 get_links = get_motherless_links("http://motherless.com/random/video", httpheaders, httpcookie, httplibuse);
842 returnval.update({mli: get_links});
843 mli = mli + 1;
844 return returnval;
846 def get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
847 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
848 if(sys.version[0]>="3"):
849 mrtext = mrtext.decode('ascii', 'replace');
850 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext);
851 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
852 mrtext_tmp = re.sub(re.escape("http://motherless.com"), "", mrtext_tmp);
853 mrtext_tmp = re.sub(re.escape("http://www.motherless.com"), "", mrtext_tmp);
854 mregex_geturlone = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" title=\"motherless link\">");
855 mlesslinkone = re.findall(mregex_geturlone, mrtext_tmp);
856 mregex_geturlname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" class=\"post-username special-member op-member\" title=\"op\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">");
857 mlessurlname = re.findall(mregex_geturlname, mrtext);
858 mlessavaturl = "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessurlname[0][1]+"-avatar.jpg";
859 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavaturl, urlparse.urlparse(mlessavaturl).path));
860 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
861 if(getlinks[1]>len(mlesslinkone) or getlinks[1]==-1):
862 getlinks[1] = len(mlesslinkone);
863 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
864 tmpgetlinks0 = getlinks[0];
865 tmpgetlinks1 = getlinks[1];
866 getlinks[0] = tmpgetlinks1;
867 getlinks[1] = tmpgetlinks0;
868 if(getlinks[0]<0):
869 getlinks[0] = 0;
870 mli = getlinks[0];
871 mlil = getlinks[1];
872 returnval = {'numoflinks': mlil};
873 returnval.update({'numofalllinks': len(mlesslinkone)});
874 returnval.update({'orginurl': httpurl});
875 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
876 mlessrooturltype = get_motherless_link_type(httpurl);
877 returnval.update({'urltype': mlessrooturltype});
878 returnval.update({'userinfo': get_motherless_user_info(mlessurlname[0][1])});
879 returnval.update({'username': mlessurlname[0][1]});
880 returnval.update({'avatarurl': mlessavaturl});
881 returnval.update({'avatarfullfilename': avatarfilenameext});
882 returnval.update({'avatarfilename': avatarfilename});
883 returnval.update({'avatarextension': avatarfileextension});
884 while(mli<mlil):
885 mlessurltype = get_motherless_link_type("http://motherless.com"+mlesslinkone[mli]);
886 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com"+mlesslinkone[mli]} });
887 mli = mli + 1;
888 return returnval;
890 def get_motherless_boards_posts(httpurl, httpheaders, httpcookie, httplibuse="urllib", getposts=[0, -1]):
891 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
892 if(sys.version[0]>="3"):
893 mrtext = mrtext.decode('ascii', 'replace');
894 mregex_getposts = "(\t+)"+re.escape("<p>")+"(.+?)"+re.escape("</p>")+"(\t+)";
895 mlessposts = re.findall(mregex_getposts, mrtext);
896 mregex_getuname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\"");
897 mlessuname = re.findall(mregex_getuname, mrtext);
898 mregex_getopuname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" class=\"post-username special-member op-member\" title=\"op\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">");
899 mlessopuname = re.findall(mregex_getopuname, mrtext);
900 if(getposts[1]>len(mlessposts) or getposts[1]==-1):
901 getposts[1] = len(mlessposts);
902 if(getposts[0]>getposts[1] and not getposts[1]==-1):
903 tmpgetposts0 = getposts[0];
904 tmpgetposts1 = getposts[1];
905 getposts[0] = tmpgetposts1;
906 getposts[1] = tmpgetposts0;
907 if(getposts[0]<0):
908 getposts[0] = 0;
909 mli = getposts[0];
910 mlil = getposts[1];
911 returnval = {'numofposts': mlil};
912 returnval.update({'numofallposts': len(mlessposts)});
913 returnval.update({'orginurl': httpurl});
914 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
915 mlessrooturltype = get_motherless_link_type(httpurl);
916 returnval.update({'urltype': mlessrooturltype});
917 returnval.update({'userinfo': get_motherless_user_info(mlessopuname[0][1])});
918 returnval.update({'username': mlessopuname[0][1]});
919 avatarfilenameext = os.path.basename(urlparse.urljoin("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessopuname[0][1]+"-avatar.jpg", urlparse.urlparse("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessopuname[0][1]+"-avatar.jpg").path));
920 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
921 returnval.update({'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessopuname[0][1]+"-avatar.jpg"});
922 returnval.update({'avatarfullfilename': avatarfilenameext});
923 returnval.update({'avatarfilename': avatarfilename});
924 returnval.update({'avatarextension': avatarfileextension});
925 while(mli<mlil):
926 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));
927 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
928 returnval.update({mli: {'post': mlessposts[mli][1], 'userinfo': get_motherless_user_info(mlessuname[mli]), 'username': mlessuname[mli], 'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
929 mli = mli + 1;
930 return returnval;
932 def get_motherless_links_comments(httpurl, httpheaders, httpcookie, httplibuse="urllib", getposts=[0, -1]):
933 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
934 if(sys.version[0]>="3"):
935 mrtext = mrtext.decode('ascii', 'replace');
936 mregex_getposts = re.escape("<div style=\"text-align: justify;\">\n")+"(\t+)(.+?)"+re.escape("</div>");
937 mlessposts = re.findall(mregex_getposts, mrtext);
938 mregex_getuname = re.escape("<div class=\"media-comment\" id=\"")+'?\'?([^"\'>]*)'+re.escape("\" rel=\"0\" rev=\"")+'?\'?([^"\'>]*)'+re.escape("\">");
939 mlessuname = re.findall(mregex_getuname, mrtext);
940 mregex_getopuname = re.escape("<tr rel=\"")+'?\'?([^"\'>]*)'+re.escape("\"");
941 mlessopuname = re.findall(mregex_getopuname, mrtext);
942 if(getposts[1]>len(mlessposts) or getposts[1]==-1):
943 getposts[1] = len(mlessposts);
944 if(getposts[0]>getposts[1] and not getposts[1]==-1):
945 tmpgetposts0 = getposts[0];
946 tmpgetposts1 = getposts[1];
947 getposts[0] = tmpgetposts1;
948 getposts[1] = tmpgetposts0;
949 if(getposts[0]<0):
950 getposts[0] = 0;
951 mli = getposts[0];
952 mlil = getposts[1];
953 returnval = {'numofposts': mlil};
954 returnval.update({'numofallposts': len(mlessposts)});
955 returnval.update({'orginurl': httpurl});
956 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
957 mlessrooturltype = get_motherless_link_type(httpurl);
958 returnval.update({'urltype': mlessrooturltype});
959 returnval.update({'userinfo': get_motherless_user_info(mlessopuname[0])});
960 returnval.update({'username': mlessopuname[0]});
961 avatarfilenameext = os.path.basename(urlparse.urljoin("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessopuname[0]+"-avatar.jpg", urlparse.urlparse("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessopuname[0]+"-avatar.jpg").path));
962 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
963 returnval.update({'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessopuname[0]+"-avatar.jpg"});
964 returnval.update({'avatarfullfilename': avatarfilenameext});
965 returnval.update({'avatarfilename': avatarfilename});
966 returnval.update({'avatarextension': avatarfileextension});
967 while(mli<mlil):
968 avatarfilenameext = os.path.basename(urlparse.urljoin("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli][1]+"-avatar.jpg", urlparse.urlparse("http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli][1]+"-avatar.jpg").path));
969 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
970 returnval.update({mli: {'post': mlessposts[mli][1], 'userinfo': get_motherless_user_info(mlessuname[mli][1]), 'username': mlessuname[mli][1], 'avatarurl': "http://cdn.avatars.motherlessmedia.com/thumbs/"+mlessuname[mli][1]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
971 mli = mli + 1;
972 return returnval;
974 def get_motherless_search_members(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
975 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
976 if(sys.version[0]>="3"):
977 mrtext = mrtext.decode('ascii', 'replace');
978 mregex_getpagenum = re.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
979 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
980 try:
981 lastpage = int(mlesspagenum[-1][0]);
982 except:
983 lastpage = 1;
984 if(page>lastpage):
985 page = lastpage;
986 httpurl = add_url_param(httpurl, page=str(page));
987 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
988 if(sys.version[0]>="3"):
989 mrtext = mrtext.decode('ascii', 'replace');
990 mregex_getuname = re.escape("<tr rel=\"")+'?\'?([^"\'>]*)'+re.escape("\"");
991 mlessuname = re.findall(mregex_getuname, mrtext);
992 mregex_geturlname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" target=\"_blank\">\n <img");
993 mlessurlname = re.findall(mregex_geturlname, mrtext);
994 mregex_getavatar = re.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re.escape("\"\n class=\"avatar avatar-small\"");
995 mlessavatar = re.findall(mregex_getavatar, mrtext);
996 if(getlinks[1]>len(mlessuname) or getlinks[1]==-1):
997 getlinks[1] = len(mlessuname);
998 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
999 tmpgetlinks0 = getlinks[0];
1000 tmpgetlinks1 = getlinks[1];
1001 getlinks[0] = tmpgetlinks1;
1002 getlinks[1] = tmpgetlinks0;
1003 if(getlinks[0]<0):
1004 getlinks[0] = 0;
1005 mli = getlinks[0];
1006 mlil = getlinks[1];
1007 returnval = {'numoflinks': mlil};
1008 returnval.update({'numofalllinks': len(mlessuname)});
1009 returnval.update({'pages': lastpage});
1010 returnval.update({'curpage': page});
1011 returnval.update({'orginurl': httpurl});
1012 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
1013 mlessrooturltype = get_motherless_link_type(httpurl);
1014 returnval.update({'urltype': mlessrooturltype});
1015 while(mli<mlil):
1016 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavatar[mli], urlparse.urlparse(mlessavatar[mli]).path));
1017 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
1018 mlessurlname[mli] = mlessurlname[mli].replace("/m/", "");
1019 mlessurltype = get_motherless_link_type("http://motherless.com/"+mlessurlname[mli]);
1020 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlessurlname[mli], 'userinfo': get_motherless_user_info(mlessurlname[mli]), 'username': mlessuname[mli], 'avatarurl': mlessavatar[mli], 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
1021 mli = mli + 1;
1022 return returnval;
1024 def get_motherless_girls(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
1025 mrtext = download_from_url("http://motherless.com/girls", httpheaders, httpcookie, httplibuse)['Content'];
1026 if(sys.version[0]>="3"):
1027 mrtext = mrtext.decode('ascii', 'replace');
1028 mregex_getuname = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" rev=\"")+'?\'?([^"\'>]*)'+re.escape("\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">");
1029 mlessuname = re.findall(mregex_getuname, mrtext);
1030 mregex_geturlname = re.escape("\n\t\t\t\t\t\t<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" target=\"_blank\">");
1031 mlessurlname = re.findall(mregex_geturlname, mrtext);
1032 if(getlinks[1]>len(mlessuname) or getlinks[1]==-1):
1033 getlinks[1] = len(mlessuname);
1034 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
1035 tmpgetlinks0 = getlinks[0];
1036 tmpgetlinks1 = getlinks[1];
1037 getlinks[0] = tmpgetlinks1;
1038 getlinks[1] = tmpgetlinks0;
1039 if(getlinks[0]<0):
1040 getlinks[0] = 0;
1041 mli = getlinks[0];
1042 mlil = getlinks[1];
1043 returnval = {'numoflinks': mlil};
1044 returnval.update({'numofalllinks': len(mlessuname)});
1045 returnval.update({'orginurl': "http://motherless.com/girls"});
1046 returnval.update({'orginurltype': get_motherless_link_type("http://motherless.com/girls")});
1047 mlessrooturltype = get_motherless_link_type("http://motherless.com/girls");
1048 returnval.update({'urltype': mlessrooturltype});
1049 while(mli<mlil):
1050 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessuname[mli][0], urlparse.urlparse(mlessuname[mli][0]).path));
1051 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
1052 mlessurltype = get_motherless_link_type("http://motherless.com/"+mlessuname[mli][1]);
1053 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlessuname[mli][1], 'userinfo': get_motherless_user_info(mlessuname[mli][1]), 'username': mlessuname[mli][1], 'avatarurl': mlessuname[mli][0], 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
1054 mli = mli + 1;
1055 return returnval;
1057 def get_motherless_team(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
1058 mrtext = download_from_url("http://motherless.com/about", httpheaders, httpcookie, httplibuse)['Content'];
1059 if(sys.version[0]>="3"):
1060 mrtext = mrtext.decode('ascii', 'replace');
1061 mregex_getuname = re.escape("<div class=\"about-us-member\">\n <a href=\"")+'?\'?([^"\'>]*)'+re.escape("\"");
1062 mlessuname = re.findall(mregex_getuname, mrtext);
1063 mlessuname_odd = mlessuname[1::2];
1064 mlessuname_even = mlessuname[::2];
1065 mregex_getavatar = re.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re.escape("\"\n class=\"avatar avatar-")+"(full|medium)"+re.escape("\"");
1066 mlessavatar = re.findall(mregex_getavatar, mrtext);
1067 if(getlinks[1]>len(mlessuname_odd) or getlinks[1]==-1):
1068 getlinks[1] = len(mlessuname_odd);
1069 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
1070 tmpgetlinks0 = getlinks[0];
1071 tmpgetlinks1 = getlinks[1];
1072 getlinks[0] = tmpgetlinks1;
1073 getlinks[1] = tmpgetlinks0;
1074 if(getlinks[0]<0):
1075 getlinks[0] = 0;
1076 mli = getlinks[0];
1077 mlil = getlinks[1];
1078 returnval = {'numoflinks': mlil};
1079 returnval.update({'numofalllinks': len(mlessuname)});
1080 returnval.update({'orginurl': "http://motherless.com/about"});
1081 returnval.update({'orginurltype': get_motherless_link_type("http://motherless.com/about")});
1082 mlessrooturltype = get_motherless_link_type("http://motherless.com/about");
1083 returnval.update({'urltype': mlessrooturltype});
1084 while(mli<mlil):
1085 avatarfilenameext = os.path.basename(urlparse.urljoin(mlessavatar[mli][0], urlparse.urlparse(mlessavatar[mli][0]).path));
1086 avatarfilename, avatarfileextension = os.path.splitext(avatarfilenameext);
1087 mlessuname_odd[mli] = mlessuname_odd[mli].replace("/m/", "");
1088 mlessuname_even[mli] = mlessuname_even[mli].replace("/m/", "");
1089 mlessurltype = get_motherless_link_type("http://motherless.com/"+mlessuname_odd[mli]);
1090 returnval.update({mli: {'urltype': mlessurltype, 'url': "http://motherless.com/"+mlessuname_odd[mli], 'userinfo': get_motherless_user_info(mlessuname_odd[mli]), 'username': mlessuname_odd[mli], 'avatarurl': mlessavatar[mli][0], 'avatarfullfilename': avatarfilenameext, 'avatarfilename': avatarfilename, 'avatarextension': avatarfileextension} });
1091 mli = mli + 1;
1092 return returnval;
1094 def get_motherless_top_referrers(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
1095 mrtext = download_from_url("http://motherless.com/referers", httpheaders, httpcookie, httplibuse)['Content'];
1096 if(sys.version[0]>="3"):
1097 mrtext = mrtext.decode('ascii', 'replace');
1098 mregex_geturlname = "([0-9]+)"+re.escape(". <a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" class=\"pop\" target=\"_blank\" rel=\"nofollow\">\n ")+"(.*)"+re.escape(" </a>");
1099 mlessurlname = re.findall(mregex_geturlname, mrtext);
1100 if(getlinks[1]>len(mlessurlname) or getlinks[1]==-1):
1101 getlinks[1] = len(mlessurlname);
1102 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
1103 tmpgetlinks0 = getlinks[0];
1104 tmpgetlinks1 = getlinks[1];
1105 getlinks[0] = tmpgetlinks1;
1106 getlinks[1] = tmpgetlinks0;
1107 if(getlinks[0]<0):
1108 getlinks[0] = 0;
1109 mli = getlinks[0];
1110 mlil = getlinks[1];
1111 returnval = {'numoflinks': mlil};
1112 returnval.update({'numofalllinks': len(mlessurlname)});
1113 returnval.update({'orginurl': "http://motherless.com/referers"});
1114 returnval.update({'orginurltype': get_motherless_link_type("http://motherless.com/referers")});
1115 mlessrooturltype = get_motherless_link_type("http://motherless.com/referers");
1116 returnval.update({'urltype': mlessrooturltype});
1117 while(mli<mlil):
1118 returnval.update({mli: {'urltype': "referer-links", 'url': mlessurlname[mli][1], 'title': mlessurlname[mli][2]} });
1119 mli = mli + 1;
1120 return returnval;
1122 def get_motherless_top_referers(httpheaders, httpcookie, httplibuse="urllib", getlinks=[0, -1]):
1123 return get_motherless_top_referrers(httpheaders, httpcookie, httplibuse, getlinks);
1125 def get_motherless_groups(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
1126 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
1127 if(sys.version[0]>="3"):
1128 mrtext = mrtext.decode('ascii', 'replace');
1129 mregex_getpagenum = re.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
1130 mlesspagenum = re.findall(mregex_getpagenum, mrtext);
1131 try:
1132 lastpage = int(mlesspagenum[-1][0]);
1133 except:
1134 lastpage = 1;
1135 if(page>lastpage):
1136 page = lastpage;
1137 httpurl = add_url_param(httpurl, page=str(page));
1138 mrtext = download_from_url(httpurl, httpheaders, httpcookie, httplibuse)['Content'];
1139 if(sys.version[0]>="3"):
1140 mrtext = mrtext.decode('ascii', 'replace');
1141 mregex_getavatar = re.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re.escape("\"\n class=\"avatar avatar-")+"(full|medium)"+re.escape("\"");
1142 mlessavatar = re.findall(mregex_getavatar, mrtext);
1143 mregex_getgroups = re.escape("<a href=\"")+'?\'?([^"\'>]*)'+re.escape("\" class=\"grunge motherless-red\">\n")+"(.*)"+re.escape("</a>");
1144 mlessgroups = re.findall(mregex_getgroups, mrtext);
1145 if(getlinks[1]>len(mlessgroups) or getlinks[1]==-1):
1146 getlinks[1] = len(mlessgroups);
1147 if(getlinks[0]>getlinks[1] and not getlinks[1]==-1):
1148 tmpgetlinks0 = getlinks[0];
1149 tmpgetlinks1 = getlinks[1];
1150 getlinks[0] = tmpgetlinks1;
1151 getlinks[1] = tmpgetlinks0;
1152 if(getlinks[0]<0):
1153 getlinks[0] = 0;
1154 mli = getlinks[0];
1155 mlil = getlinks[1];
1156 returnval = {'pages': lastpage};
1157 returnval.update({'curpage': page});
1158 returnval.update({'numoflinks': mlil});
1159 returnval.update({'numofalllinks': len(mlessgroups)});
1160 returnval.update({'orginurl': httpurl});
1161 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
1162 while(mli<mlil):
1163 thumbfilenameext = os.path.basename(urlparse.urljoin(mlessavatar[mli][0], urlparse.urlparse(mlessavatar[mli][0]).path));
1164 thumbfilename, thumbfileextension = os.path.splitext(thumbfilenameext);
1165 returnval.update({mli: {'urltype': get_motherless_link_type("http://motherless.com/"+mlessgroups[mli][0]), 'url': "http://motherless.com"+mlessgroups[mli][0], 'urltype-image': get_motherless_link_type("http://motherless.com/"+mlessgroups[mli][0].replace("/g/", "/gi/")), 'url-image': "http://motherless.com"+mlessgroups[mli][0].replace("/g/", "/gi/"), 'urltype-video': get_motherless_link_type("http://motherless.com/"+mlessgroups[mli][0].replace("/g/", "/gv/")), 'url-video': "http://motherless.com"+mlessgroups[mli][0].replace("/g/", "/gv/"), 'urltype-member': get_motherless_link_type("http://motherless.com/"+mlessgroups[mli][0].replace("/g/", "/gm/")), 'url-member': "http://motherless.com"+mlessgroups[mli][0].replace("/g/", "/gm/"), 'thumbnail': mlessavatar[mli][0], 'title': mlessgroups[mli][1].strip(), 'thumbfullfilename': thumbfilenameext, 'thumbfilename': thumbfilename, 'thumbextension': thumbfileextension} });
1166 mli = mli + 1;
1167 return returnval;
1169 def get_motherless_sample_links(httpheaders, httpcookie, httplibuse="urllib", numoflinks=10, urltype="video"):
1170 if(urltype=="video"):
1171 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/videos", 'orginurltype': get_motherless_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]) } };
1172 if(urltype=="image"):
1173 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/images", 'orginurltype': get_motherless_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]) } };
1174 if(urltype=="gallery"):
1175 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/galleries", 'orginurltype': get_motherless_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]) } };
1176 if(urltype=="all"):
1177 returnval = {'numoflinks': numoflinks, 'orginurl': "http://motherless.com/", 'orginurltype': get_motherless_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]) } };
1178 return returnval;
1180 def get_motherless_link_by_type(httpurl, httpheaders, httpcookie, httplibuse="urllib", page=1, getlinks=[0, -1]):
1181 returnval = False;
1182 if(get_motherless_link_type(httpurl)=="file"):
1183 returnval = get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse);
1184 if(get_motherless_link_type(httpurl)=="gallery"):
1185 returnval = get_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse, page);
1186 if(get_motherless_link_type(httpurl)=="sample-videos"):
1187 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "video");
1188 if(get_motherless_link_type(httpurl)=="sample-images"):
1189 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "image");
1190 if(get_motherless_link_type(httpurl)=="sample-galleries"):
1191 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "gallery");
1192 if(get_motherless_link_type(httpurl)=="sample" or get_motherless_link_type(httpurl)=="sample-all"):
1193 returnval = get_motherless_sample_links(httpheaders, httpcookie, httplibuse, 10, "all");
1194 if(get_motherless_link_type(httpurl)=="board"):
1195 returnval = get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse);
1196 if(get_motherless_link_type(httpurl)=="member"):
1197 returnval = get_motherless_search_members(httpurl, httpheaders, httpcookie, httplibuse, page);
1198 if(get_motherless_link_type(httpurl)=="girls"):
1199 returnval = get_motherless_girls(httpheaders, httpcookie, httplibuse);
1200 if(get_motherless_link_type(httpurl)=="download"):
1201 returnval = httpurl;
1202 return returnval;
1204 def view_motherless_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", viewerpro="mpv", prearg=[], proarg=[]):
1205 commandlist = [viewerpro] + prearg;
1206 commandlist = commandlist + [get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse)['url']];
1207 commandlist = commandlist + proarg;
1208 mpvplaylistp = subprocess.Popen(commandlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE);
1209 mpvplayout, mpvplayerr = mpvplaylistp.communicate();
1210 return True;
1212 def download_motherless_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, buffersize=[262144, 262144], outfile="-", outpath=os.getcwd(), usetitlename=False):
1213 global geturls_download_sleep;
1214 if(sleep<0):
1215 sleep = geturls_download_sleep;
1216 mlessurl = get_motherless_links(httpurl, httpheaders, httpcookie, httplibuse);
1217 outputname = mlessurl['fullfilename'];
1218 outpath = outpath.rstrip(os.path.sep);
1219 if(usetitlename==True):
1220 outputname = mlessurl['title'];
1221 if(usetitlename=="-" and outfile=="-"):
1222 outputname = "-";
1223 if(usetitlename=="-" and not outfile=="-"):
1224 outputname = outfile;
1225 returnval = download_from_url_to_file(mlessurl['url'], httpheaders, httpcookie, httplibuse, outputname, outpath, buffersize, sleep);
1226 return returnval;
1228 def download_motherless_links_by_type(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, buffersize=[262144, 262144], outfile="-", outpath=os.getcwd(), usetitlename=False, page=1, getlinks=[0, -1]):
1229 global geturls_download_sleep;
1230 if(sleep<0):
1231 sleep = geturls_download_sleep;
1232 mlessurl = get_motherless_link_by_type(httpurl, httpheaders, httpcookie, httplibuse, page);
1233 if(mlessurl['urltype']=="download"):
1234 outputname = mlessurl['fullfilename'];
1235 outpathname = outpath.rstrip(os.path.sep);
1236 if(usetitlename==True):
1237 outputname = mlessurl['title'];
1238 if(usetitlename=="-" and outfile[mli]=="-"):
1239 outputname = "-";
1240 if(usetitlename=="-" and not outfile[mli]=="-"):
1241 outputname = outfile;
1242 returnval = download_from_url_to_file(mlessurl['url'], httpheaders, httpcookie, httplibuse, outputname, outpathname, buffersize, sleep);
1243 if(not mlessurl['urltype']=="download"):
1244 returnval = mlessurl;
1245 return returnval;
1247 def download_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, buffersize=[262144, 262144], outfile="-", outpath=os.getcwd(), usetitlename=False, page=1, getlinks=[0, -1]):
1248 global geturls_download_sleep;
1249 if(sleep<0):
1250 sleep = geturls_download_sleep;
1251 mlessgalleries = get_motherless_galleries_links(httpurl, httpheaders, httpcookie, httplibuse, page, getlinks);
1252 mli = 0;
1253 mlil = mlessgalleries['numoflinks'];
1254 returnval = {'pages': mlessgalleries['pages']};
1255 returnval.update({'numoflists': mlessgalleries['numoflinks']});
1256 returnval.update({'curpage': mlessgalleries['curpage']});
1257 returnval.update({'numoflinks': mlessgalleries['numoflinks']});
1258 returnval.update({'numofalllinks': mlessgalleries['numofalllinks']});
1259 returnval.update({'orginurl': httpurl});
1260 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
1261 while(mli<mlil):
1262 mlesslink = get_motherless_links(mlessgalleries[mli]['url'], httpheaders, httpcookie, httplibuse);
1263 outputname = mlesslink['fullfilename'];
1264 outpath = outpath.rstrip(os.path.sep);
1265 if(usetitlename==True):
1266 outputname = mlesslink['title'];
1267 if(usetitlename=="-" and outfile=="-"):
1268 outputname = "-";
1269 if(usetitlename=="-" and not outfile=="-"):
1270 outputname = outfile;
1271 returnval.update({mli: {'download': download_from_url_to_file(mlesslink['url'], httpheaders, httpcookie, httplibuse, outputname, outpath, buffersize, sleep), 'linkinfo': mlesslink, 'outputfile': outputname} });
1272 mli = mli + 1;
1273 return returnval;
1275 def download_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse="urllib", sleep=-1, buffersize=[262144, 262144], outfile="-", outpath=os.getcwd(), usetitlename=False, getlinks=[0, -1]):
1276 global geturls_download_sleep;
1277 if(sleep<0):
1278 sleep = geturls_download_sleep;
1279 mlessgalleries = get_motherless_boards_links(httpurl, httpheaders, httpcookie, httplibuse, getlinks);
1280 mli = 0;
1281 mlil = mlessgalleries['numoflinks'];
1282 returnval = {'numoflists': mlessgalleries['numoflinks']};
1283 returnval.update({'numofalllinks': mlessgalleries['numofalllinks']});
1284 returnval.update({'orginurl': httpurl});
1285 returnval.update({'orginurltype': get_motherless_link_type(httpurl)});
1286 while(mli<mlil):
1287 mlesslink = get_motherless_links(mlessgalleries[mli]['url'], httpheaders, httpcookie, httplibuse);
1288 outputname = mlesslink['fullfilename'];
1289 outpath = outpath.rstrip(os.path.sep);
1290 if(usetitlename==True):
1291 outputname = mlesslink['title'];
1292 if(usetitlename=="-" and outfile=="-"):
1293 outputname = "-";
1294 if(usetitlename=="-" and not outfile=="-"):
1295 outputname = outfile;
1296 returnval.update({mli: {'download': download_from_url_to_file(mlesslink['url'], httpheaders, httpcookie, httplibuse, outputname, outpath, buffersize, sleep), 'linkinfo': mlesslink, 'outputfile': outputname} });
1297 mli = mli + 1;
1298 return returnval;