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 $
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
;
24 imp
.find_module('requests');
29 if(sys
.version
[0]=="2"):
31 from cStringIO
import StringIO
;
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
):
92 parts
= list(urlparse
.urlsplit(url
));
93 d
= dict(cgi
.parse_qsl(parts
[n
])); # use cgi.parse_qs for list values
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
):
112 newlistreg
.update({ilx
: varlist
[il
]});
113 newlistrev
.update({varlist
[il
]: ilx
});
116 newlistfull
= {1: newlistreg
, 2: newlistrev
, 'reg': newlistreg
, 'rev': newlistrev
};
119 def twolistize(varlist
):
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
});
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
}
140 def arglistize(proexec
, *varlist
):
144 newarglist
= [proexec
];
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]);
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):
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):
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):
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):
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):
189 returnval
.update({headers
[mli
][0]: headers
[mli
][1]});
191 elif isinstance(headers
, dict):
197 def download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", sleep
=-1):
198 global geturls_download_sleep
, haverequests
;
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
);
217 def download_from_url_file(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", buffersize
=262144, sleep
=-1):
218 global geturls_download_sleep
, haverequests
;
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
);
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
;
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
);
255 def download_from_url_with_urllib(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
256 global geturls_download_sleep
;
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
;
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();
278 def download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
=262144, sleep
=-1):
279 global geturls_download_sleep
;
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
;
287 geturls_text
= geturls_opener
.open(httpurl
);
288 downloadsize
= int(geturls_text
.info().get('Content-Length'));
289 if downloadsize
is None: downloadsize
= 0;
291 log
.info("Downloading URL "+httpurl
);
292 with tempfile
.NamedTemporaryFile('wb+', prefix
="pymotherless-", delete
=False) as f
:
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.");
303 geturls_text
.close();
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
;
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
)):
317 if(os
.path
.exists(filepath
) and os
.path
.isdir(filepath
)):
319 tmpfilename
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
320 downloadsize
= os
.path
.getsize(tmpfilename
);
322 log
.info("Moving file "+tmpfilename
+" to "+filepath
);
323 with
open(tmpfilename
, 'rb') as ft
:
324 with
open(filepath
, 'wb+') as f
:
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.");
335 os
.remove(tmpfilename
);
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
);
341 with
open(tmpfilename
, 'rb') as ft
:
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.");
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
);
359 with
open(tmpfilename
, 'rb') as ft
:
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.");
371 os
.remove(tmpfilename
);
372 returnval
= f
.getvalue();
375 if(haverequests
==True):
376 def download_from_url_with_requests(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
377 global geturls_download_sleep
;
379 sleep
= geturls_download_sleep
;
380 if isinstance(httpheaders
, list):
381 httpheaders
= make_http_headers_from_list_to_dict(httpheaders
);
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();
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
)
402 if(haverequests
==True):
403 def download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
=262144, sleep
=-1):
404 global geturls_download_sleep
;
406 sleep
= geturls_download_sleep
;
407 if isinstance(httpheaders
, list):
408 httpheaders
= make_http_headers_from_list_to_dict(httpheaders
);
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;
414 log
.info("Downloading URL "+httpurl
);
415 with tempfile
.NamedTemporaryFile('wb+', prefix
="pymotherless-", delete
=False) as f
:
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.");
424 geturls_text
.close();
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
)
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
;
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
)):
444 if(os
.path
.exists(filepath
) and os
.path
.isdir(filepath
)):
446 tmpfilename
= download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
447 downloadsize
= os
.path
.getsize(tmpfilename
);
449 log
.info("Moving file "+tmpfilename
+" to "+filepath
);
450 with
open(tmpfilename
, 'rb') as ft
:
451 with
open(filepath
, 'wb+') as f
:
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.");
462 os
.remove(tmpfilename
);
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
);
468 with
open(tmpfilename
, 'rb') as ft
:
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.");
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
);
486 with
open(tmpfilename
, 'rb') as ft
:
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.");
498 os
.remove(tmpfilename
);
499 returnval
= f
.getvalue();
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
)
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
);
514 returnval
= int(mlesspagenum
[-1][0]);
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("/");
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):
540 if(mlessvidid
[1]=="groups" and len(mlessvidid
)==3 and mlessvidid
[2]=="search"):
542 if(mlessvidid
[1]=="groups" and len(mlessvidid
)==4 and mlessvidid
[2]=="category"):
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])):
564 if(mlessvidid
[1]=="random" and len(mlessvidid
)==3 and (mlessvidid
[2]=="video" or mlessvidid
[2]=="image")):
566 if(re
.match("^V", mlessvidid
[1]) and len(mlessvidid
)==2):
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):
574 if(re
.match("^g", mlessvidid
[1]) and len(mlessvidid
)==4 and re
.match("^([0-9A-F]+)$", mlessvidid
[3])):
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):
584 if(mlessvidid
[1]=="referers" and len(mlessvidid
)==2):
585 returnval
= "referers";
586 if(mlessvidid
[1]=="about" and len(mlessvidid
)==2):
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])):
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
});
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
);
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
};
655 def get_motherless_links_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib"):
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");
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
);
680 if(len(mlesslinkinternal
)>1):
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
});
690 mlessurltype
= get_motherless_link_type(mlesslinkinternal
[mli
]);
691 returnvalone
.update({mli
: {'urltype': mlessurltype
, 'url': mlesslinkinternal
[mli
]} });
694 if(len(mlesslinkexternal
)>1):
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
});
704 returnvaltwo
.update({mli
: {'urltype': "external", 'url': mlesslinkexternal
[mli
]} });
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
};
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
);
723 lastpage
= int(mlesspagenum
[-1][0]);
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
;
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
});
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
} });
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
;
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"});
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']} });
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"});
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']} });
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
;
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"});
829 get_links
= get_motherless_links("http://motherless.com/random/image", httpheaders
, httpcookie
, httplibuse
);
830 returnval
.update({mli
: get_links
});
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"});
841 get_links
= get_motherless_links("http://motherless.com/random/video", httpheaders
, httpcookie
, httplibuse
);
842 returnval
.update({mli
: get_links
});
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
;
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
});
885 mlessurltype
= get_motherless_link_type("http://motherless.com"+mlesslinkone
[mli
]);
886 returnval
.update({mli
: {'urltype': mlessurltype
, 'url': "http://motherless.com"+mlesslinkone
[mli
]} });
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
;
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
});
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
} });
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
;
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
});
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
} });
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
);
981 lastpage
= int(mlesspagenum
[-1][0]);
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
;
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
});
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
} });
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
;
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
});
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
} });
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
;
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
});
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
} });
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
;
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
});
1118 returnval
.update({mli
: {'urltype': "referer-links", 'url': mlessurlname
[mli
][1], 'title': mlessurlname
[mli
][2]} });
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
);
1132 lastpage
= int(mlesspagenum
[-1][0]);
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
;
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
)});
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
} });
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
]) } };
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
]) } };
1180 def get_motherless_link_by_type(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", page
=1, getlinks
=[0, -1]):
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
;
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();
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
;
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
=="-"):
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
);
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
;
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
]=="-"):
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
;
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
;
1250 sleep
= geturls_download_sleep
;
1251 mlessgalleries
= get_motherless_galleries_links(httpurl
, httpheaders
, httpcookie
, httplibuse
, page
, getlinks
);
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
)});
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
=="-"):
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
} });
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
;
1278 sleep
= geturls_download_sleep
;
1279 mlessgalleries
= get_motherless_boards_links(httpurl
, httpheaders
, httpcookie
, httplibuse
, getlinks
);
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
)});
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
=="-"):
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
} });