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: 6/16/2016 Ver. 0.4.7 RC 1 - Author: cooldude2k $
19 from __future__
import division
, absolute_import
, print_function
;
20 import re
, os
, sys
, hashlib
, shutil
, platform
, tempfile
, urllib
, gzip
, time
, argparse
, cgi
, subprocess
, imp
;
21 import logging
as log
;
24 imp
.find_module('requests');
29 havemechanize
= False;
31 imp
.find_module('mechanize');
35 havemechanize
= False;
36 if(sys
.version
[0]=="2"):
38 from cStringIO
import StringIO
;
40 from StringIO
import StringIO
;
41 # From http://python-future.org/compatible_idioms.html
42 from urlparse
import urlparse
, urlunparse
, urlsplit
, urlunsplit
, urljoin
;
43 from urllib
import urlencode
;
44 from urllib2
import urlopen
, Request
, HTTPError
;
45 import urllib2
, urlparse
, cookielib
;
46 if(sys
.version
[0]>="3"):
47 from io
import StringIO
, BytesIO
;
48 # From http://python-future.org/compatible_idioms.html
49 from urllib
.parse
import urlparse
, urlunparse
, urlsplit
, urlunsplit
, urljoin
, urlencode
;
50 from urllib
.request
import urlopen
, Request
;
51 from urllib
.error
import HTTPError
;
52 import urllib
.request
as urllib2
;
53 import urllib
.parse
as urlparse
;
54 import http
.cookiejar
as cookielib
;
56 __program_name__
= "PyMotherless";
57 __project__
= __program_name__
;
58 __project_url__
= "https://github.com/GameMaker2k/PyMotherless";
59 __version_info__
= (0, 4, 7, "RC 1", 1);
60 __version_date_info__
= (2016, 6, 16, "RC 1", 1);
61 __version_date__
= str(__version_date_info__
[0])+"."+str(__version_date_info__
[1]).zfill(2)+"."+str(__version_date_info__
[2]).zfill(2);
62 if(__version_info__
[4]!=None):
63 __version_date_plusrc__
= __version_date__
+"-"+str(__version_date_info__
[4]);
64 if(__version_info__
[4]==None):
65 __version_date_plusrc__
= __version_date__
;
66 if(__version_info__
[3]!=None):
67 __version__
= str(__version_info__
[0])+"."+str(__version_info__
[1])+"."+str(__version_info__
[2])+" "+str(__version_info__
[3]);
68 if(__version_info__
[3]==None):
69 __version__
= str(__version_info__
[0])+"."+str(__version_info__
[1])+"."+str(__version_info__
[2]);
71 geturls_cj
= cookielib
.CookieJar();
72 geturls_ua_firefox_windows7
= "Mozilla/5.0 (Windows NT 6.1; rv:44.0) Gecko/20100101 Firefox/44.0";
73 geturls_ua_seamonkey_windows7
= "Mozilla/5.0 (Windows NT 6.1; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39";
74 geturls_ua_chrome_windows7
= "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
75 geturls_ua_chromium_windows7
= "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chromium/48.0.2564.116 Chrome/48.0.2564.116 Safari/537.36";
76 geturls_ua_midori_windows7
= "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/538.15 (KHTML, like Gecko) Chrome/18.0.1025.133 Safari/538.15 Midori/0.5";
77 geturls_ua_internet_explorer_windows7
= "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko";
78 geturls_ua_pymotherless_python
= "Mozilla/5.0 (compatible; {proname}/{prover}; +{prourl})".format(proname
=__project__
, prover
=__version__
, prourl
=__project_url__
);
79 if(platform
.python_implementation()!=""):
80 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__
);
81 if(platform
.python_implementation()==""):
82 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__
);
83 geturls_ua_googlebot_google
= "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
84 geturls_ua_googlebot_google_old
= "Googlebot/2.1 (+http://www.google.com/bot.html)";
85 geturls_ua
= geturls_ua_firefox_windows7
;
86 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"};
87 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"};
88 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"};
89 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"};
90 geturls_headers_midori_windows7
= {'Referer': "http://motherless.com/", 'User-Agent': geturls_ua_midori_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"};
91 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"};
92 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"};
93 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"};
94 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"};
95 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"};
96 geturls_headers
= geturls_headers_firefox_windows7
;
97 geturls_download_sleep
= 0;
99 def add_url_param(url
, **params
):
101 parts
= list(urlparse
.urlsplit(url
));
102 d
= dict(cgi
.parse_qsl(parts
[n
])); # use cgi.parse_qs for list values
104 parts
[n
]=urlencode(d
);
105 return urlparse
.urlunsplit(parts
);
107 os
.environ
["PATH"] = os
.environ
["PATH"] + os
.pathsep
+ os
.path
.dirname(os
.path
.realpath(__file__
)) + os
.pathsep
+ os
.getcwd();
108 def which_exec(execfile):
109 for path
in os
.environ
["PATH"].split(":"):
110 if os
.path
.exists(path
+ "/" + execfile):
111 return path
+ "/" + execfile;
113 def listize(varlist
):
121 newlistreg
.update({ilx
: varlist
[il
]});
122 newlistrev
.update({varlist
[il
]: ilx
});
125 newlistfull
= {1: newlistreg
, 2: newlistrev
, 'reg': newlistreg
, 'rev': newlistrev
};
128 def twolistize(varlist
):
138 newlistnamereg
.update({ilx
: varlist
[il
][0].strip()});
139 newlistnamerev
.update({varlist
[il
][0].strip(): ilx
});
140 newlistdescreg
.update({ilx
: varlist
[il
][1].strip()});
141 newlistdescrev
.update({varlist
[il
][1].strip(): ilx
});
144 newlistnametmp
= {1: newlistnamereg
, 2: newlistnamerev
, 'reg': newlistnamereg
, 'rev': newlistnamerev
};
145 newlistdesctmp
= {1: newlistdescreg
, 2: newlistdescrev
, 'reg': newlistdescreg
, 'rev': newlistdescrev
};
146 newlistfull
= {1: newlistnametmp
, 2: newlistdesctmp
, 'name': newlistnametmp
, 'desc': newlistdesctmp
}
149 def arglistize(proexec
, *varlist
):
153 newarglist
= [proexec
];
155 if varlist
[il
][0] is not None:
156 newarglist
.append(varlist
[il
][0]);
157 if varlist
[il
][1] is not None:
158 newarglist
.append(varlist
[il
][1]);
162 # hms_string by ArcGIS Python Recipes
163 # https://arcpy.wordpress.com/2012/04/20/146/
164 def hms_string(sec_elapsed
):
165 h
= int(sec_elapsed
/ (60 * 60));
166 m
= int((sec_elapsed
% (60 * 60)) / 60);
167 s
= sec_elapsed
% 60.0;
168 return "{}:{:>02}:{:>05.2f}".format(h
, m
, s
);
170 # get_readable_size by Lipis
171 # http://stackoverflow.com/posts/14998888/revisions
172 def get_readable_size(bytes
, precision
=1, unit
="IEC"):
174 if(unit
!="IEC" and unit
!="SI"):
177 units
= [" B"," KiB"," MiB"," GiB"," TiB"," PiB"," EiB"," ZiB"];
178 unitswos
= ["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB"];
181 units
= [" B"," kB"," MB"," GB"," TB"," PB"," EB"," ZB"];
182 unitswos
= ["B","kB","MB","GB","TB","PB","EB","ZB"];
187 if abs(bytes
) < unitsize
:
188 strformat
= "%3."+str(precision
)+"f%s";
189 pre_return_val
= (strformat
% (bytes
, unit
));
190 pre_return_val
= re
.sub(r
"([0]+) ([A-Za-z]+)", r
" \2", pre_return_val
);
191 pre_return_val
= re
.sub(r
"\. ([A-Za-z]+)", r
" \1", pre_return_val
);
192 alt_return_val
= pre_return_val
.split();
193 return_val
= {'Bytes': orgbytes
, 'ReadableWithSuffix': pre_return_val
, 'ReadableWithoutSuffix': alt_return_val
[0], 'ReadableSuffix': alt_return_val
[1]}
196 strformat
= "%."+str(precision
)+"f%s";
197 pre_return_val
= (strformat
% (bytes
, "YiB"));
198 pre_return_val
= re
.sub(r
"([0]+) ([A-Za-z]+)", r
" \2", pre_return_val
);
199 pre_return_val
= re
.sub(r
"\. ([A-Za-z]+)", r
" \1", pre_return_val
);
200 alt_return_val
= pre_return_val
.split();
201 return_val
= {'Bytes': orgbytes
, 'ReadableWithSuffix': pre_return_val
, 'ReadableWithoutSuffix': alt_return_val
[0], 'ReadableSuffix': alt_return_val
[1]}
204 def get_readable_size_from_file(infile
, precision
=1, unit
="IEC", usehashes
=False, usehashtypes
="md5,sha1"):
206 usehashtypes
= usehashtypes
.lower();
207 getfilesize
= os
.path
.getsize(infile
);
208 return_val
= get_readable_size(getfilesize
, precision
, unit
);
210 hashtypelist
= usehashtypes
.split(",");
211 openfile
= open(infile
, "rb");
212 filecontents
= openfile
.read();
215 listnumend
= len(hashtypelist
);
216 while(listnumcount
< listnumend
):
217 hashtypelistlow
= hashtypelist
[listnumcount
].strip();
218 hashtypelistup
= hashtypelistlow
.upper();
219 filehash
= hashlib
.new(hashtypelistup
);
220 filehash
.update(filecontents
);
221 filegethash
= filehash
.hexdigest();
222 return_val
.update({hashtypelistup
: filegethash
});
226 def get_readable_size_from_string(instring
, precision
=1, unit
="IEC", usehashes
=False, usehashtypes
="md5,sha1"):
228 usehashtypes
= usehashtypes
.lower();
229 getfilesize
= len(instring
);
230 return_val
= get_readable_size(getfilesize
, precision
, unit
);
232 hashtypelist
= usehashtypes
.split(",");
234 listnumend
= len(hashtypelist
);
235 while(listnumcount
< listnumend
):
236 hashtypelistlow
= hashtypelist
[listnumcount
].strip();
237 hashtypelistup
= hashtypelistlow
.upper();
238 filehash
= hashlib
.new(hashtypelistup
);
239 if(sys
.version
[0]=="2"):
240 filehash
.update(instring
);
241 if(sys
.version
[0]>="3"):
242 filehash
.update(instring
.encode('utf-8'));
243 filegethash
= filehash
.hexdigest();
244 return_val
.update({hashtypelistup
: filegethash
});
248 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"}):
249 if isinstance(headers
, dict):
251 if(sys
.version
[0]=="2"):
252 for headkey
, headvalue
in headers
.iteritems():
253 returnval
.append((headkey
, headvalue
));
254 if(sys
.version
[0]>="3"):
255 for headkey
, headvalue
in headers
.items():
256 returnval
.append((headkey
, headvalue
));
257 elif isinstance(headers
, list):
263 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"}):
264 if isinstance(headers
, dict):
266 if(sys
.version
[0]=="2"):
267 for headkey
, headvalue
in headers
.iteritems():
268 returnval
.append(headkey
+": "+headvalue
);
269 if(sys
.version
[0]>="3"):
270 for headkey
, headvalue
in headers
.items():
271 returnval
.append(headkey
+": "+headvalue
);
272 elif isinstance(headers
, list):
278 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")]):
279 if isinstance(headers
, list):
284 returnval
.update({headers
[mli
][0]: headers
[mli
][1]});
286 elif isinstance(headers
, dict):
292 def get_httplib_support(checkvalue
=None):
293 global haverequests
, havemechanize
;
295 returnval
.append("urllib");
296 if(haverequests
==True):
297 returnval
.append("requests");
298 if(havemechanize
==True):
299 returnval
.append("mechanize");
300 if(not checkvalue
==None):
301 if(checkvalue
=="urllib1" or checkvalue
=="urllib2"):
302 checkvalue
= "urllib";
303 if(checkvalue
in returnval
):
309 def check_httplib_support(checkvalue
="urllib"):
310 if(checkvalue
=="urllib1" or checkvalue
=="urllib2"):
311 checkvalue
= "urllib";
312 returnval
= get_httplib_support(checkvalue
);
315 def download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", sleep
=-1):
316 global geturls_download_sleep
, haverequests
, havemechanize
;
318 sleep
= geturls_download_sleep
;
319 if(httplibuse
=="urllib1" or httplibuse
=="urllib2"):
320 httplibuse
= "urllib";
321 if(haverequests
==False and httplibuse
=="requests"):
322 httplibuse
= "urllib";
323 if(havemechanize
==False and httplibuse
=="mechanize"):
324 httplibuse
= "urllib";
325 if(httplibuse
=="urllib"):
326 returnval
= download_from_url_with_urllib(httpurl
, httpheaders
, httpcookie
, sleep
);
327 elif(httplibuse
=="requests"):
328 returnval
= download_from_url_with_requests(httpurl
, httpheaders
, httpcookie
, sleep
);
329 elif(httplibuse
=="mechanize"):
330 returnval
= download_from_url_with_mechanize(httpurl
, httpheaders
, httpcookie
, sleep
);
335 def download_from_url_file(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", buffersize
=524288, sleep
=-1):
336 global geturls_download_sleep
, haverequests
, havemechanize
;
338 sleep
= geturls_download_sleep
;
339 if(httplibuse
=="urllib1" or httplibuse
=="urllib2"):
340 httplibuse
= "urllib";
341 if(haverequests
==False and httplibuse
=="requests"):
342 httplibuse
= "urllib";
343 if(havemechanize
==False and httplibuse
=="mechanize"):
344 httplibuse
= "urllib";
345 if(httplibuse
=="urllib"):
346 returnval
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
, sleep
);
347 elif(httplibuse
=="requests"):
348 returnval
= download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
, sleep
);
349 elif(httplibuse
=="mechanize"):
350 returnval
= download_from_url_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, buffersize
, sleep
);
355 def download_from_url_to_file(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", outfile
="-", outpath
=os
.getcwd(), buffersize
=[524288, 524288], sleep
=-1):
356 global geturls_download_sleep
, haverequests
, havemechanize
;
358 sleep
= geturls_download_sleep
;
359 if(httplibuse
=="urllib1" or httplibuse
=="urllib2"):
360 httplibuse
= "urllib";
361 if(haverequests
==False and httplibuse
=="requests"):
362 httplibuse
= "urllib";
363 if(havemechanize
==False and httplibuse
=="mechanize"):
364 httplibuse
= "urllib";
365 if(httplibuse
=="urllib"):
366 returnval
= download_from_url_to_file_with_urllib(httpurl
, httpheaders
, httpcookie
, outfile
, outpath
, buffersize
, sleep
);
367 elif(httplibuse
=="requests"):
368 returnval
= download_from_url_to_file_with_requests(httpurl
, httpheaders
, httpcookie
, outfile
, outpath
, buffersize
, sleep
);
369 elif(httplibuse
=="mechanize"):
370 returnval
= download_from_url_to_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, outfile
, outpath
, buffersize
, sleep
);
375 def download_from_url_with_urllib(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
376 global geturls_download_sleep
;
378 sleep
= geturls_download_sleep
;
379 geturls_opener
= urllib2
.build_opener(urllib2
.HTTPCookieProcessor(httpcookie
));
380 if(isinstance(httpheaders
, dict)):
381 httpheaders
= make_http_headers_from_dict_to_list(httpheaders
);
382 geturls_opener
.addheaders
= httpheaders
;
384 geturls_text
= geturls_opener
.open(httpurl
);
385 log
.info("Downloading URL "+httpurl
);
386 if(geturls_text
.info().get("Content-Encoding")=="gzip" or geturls_text
.info().get("Content-Encoding")=="deflate"):
387 if(sys
.version
[0]=="2"):
388 strbuf
= StringIO(geturls_text
.read());
389 if(sys
.version
[0]>="3"):
390 strbuf
= BytesIO(geturls_text
.read());
391 gzstrbuf
= gzip
.GzipFile(fileobj
=strbuf
);
392 returnval_content
= gzstrbuf
.read()[:];
393 if(geturls_text
.info().get("Content-Encoding")!="gzip" and geturls_text
.info().get("Content-Encoding")!="deflate"):
394 returnval_content
= geturls_text
.read()[:];
395 returnval
= {'Type': "Content", 'Content': returnval_content
, 'Headers': dict(geturls_text
.info()), 'URL': geturls_text
.geturl(), 'Code': geturls_text
.getcode()};
396 geturls_text
.close();
399 def download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
=524288, sleep
=-1):
400 global geturls_download_sleep
;
401 exec_time_start
= time
.time();
403 sleep
= geturls_download_sleep
;
404 geturls_opener
= urllib2
.build_opener(urllib2
.HTTPCookieProcessor(httpcookie
));
405 if(isinstance(httpheaders
, dict)):
406 httpheaders
= make_http_headers_from_dict_to_list(httpheaders
);
407 geturls_opener
.addheaders
= httpheaders
;
409 geturls_text
= geturls_opener
.open(httpurl
);
410 downloadsize
= geturls_text
.info().get('Content-Length');
411 if(downloadsize
is not None):
412 downloadsize
= int(downloadsize
);
413 if downloadsize
is None: downloadsize
= 0;
416 log
.info("Downloading URL "+httpurl
);
417 with tempfile
.NamedTemporaryFile('wb+', prefix
="pywwwget-", delete
=False) as f
:
418 tmpfilename
= f
.name
;
419 returnval
= {'Type': "File", 'Filename': tmpfilename
, 'Filesize': downloadsize
, 'FilesizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'Headers': dict(geturls_text
.info()), 'URL': geturls_text
.geturl(), 'Code': geturls_text
.getcode()};
421 databytes
= geturls_text
.read(buffersize
);
422 if not databytes
: break;
423 datasize
= len(databytes
);
424 fulldatasize
= datasize
+ fulldatasize
;
427 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
428 downloaddiff
= fulldatasize
- prevdownsize
;
429 log
.info("Downloading "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Downloaded "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
430 prevdownsize
= fulldatasize
;
433 geturls_text
.close();
434 exec_time_end
= time
.time();
435 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to download file.");
436 returnval
.update({'Filesize': os
.path
.getsize(tmpfilename
), 'DownloadTime': float(exec_time_start
- exec_time_end
), 'DownloadTimeReadable': hms_string(exec_time_start
- exec_time_end
)});
439 def download_from_url_to_file_with_urllib(httpurl
, httpheaders
, httpcookie
, outfile
="-", outpath
=os
.getcwd(), buffersize
=[524288, 524288], sleep
=-1):
440 global geturls_download_sleep
;
442 sleep
= geturls_download_sleep
;
443 if(not outfile
=="-"):
444 outpath
= outpath
.rstrip(os
.path
.sep
);
445 filepath
= os
.path
.realpath(outpath
+os
.path
.sep
+outfile
);
446 if(not os
.path
.exists(outpath
)):
447 os
.makedirs(outpath
);
448 if(os
.path
.exists(outpath
) and os
.path
.isfile(outpath
)):
450 if(os
.path
.exists(filepath
) and os
.path
.isdir(filepath
)):
452 pretmpfilename
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
453 tmpfilename
= pretmpfilename
['Filename'];
454 downloadsize
= os
.path
.getsize(tmpfilename
);
456 log
.info("Moving file "+tmpfilename
+" to "+filepath
);
457 exec_time_start
= time
.time();
458 shutil
.move(tmpfilename
, filepath
);
459 exec_time_end
= time
.time();
460 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to move file.");
461 if(os
.path
.exists(tmpfilename
)==True):
462 os
.remove(tmpfilename
);
463 returnval
= {'Type': "File", 'Filename': filepath
, 'Filesize': downloadsize
, 'FilesizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
464 if(outfile
=="-" and sys
.version
[0]=="2"):
465 pretmpfilename
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
466 tmpfilename
= pretmpfilename
['Filename'];
467 downloadsize
= os
.path
.getsize(tmpfilename
);
470 exec_time_start
= time
.time();
471 with
open(tmpfilename
, 'rb') as ft
:
474 databytes
= ft
.read(buffersize
[1]);
475 if not databytes
: break;
476 datasize
= len(databytes
);
477 fulldatasize
= datasize
+ fulldatasize
;
480 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
481 downloaddiff
= fulldatasize
- prevdownsize
;
482 log
.info("Copying "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Copied "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
483 prevdownsize
= fulldatasize
;
486 fdata
= f
.getvalue();
489 os
.remove(tmpfilename
);
490 exec_time_end
= time
.time();
491 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to copy file.");
492 returnval
= {'Type': "Content", 'Content': fdata
, 'Contentsize': downloadsize
, 'ContentsizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
493 if(outfile
=="-" and sys
.version
[0]>="3"):
494 pretmpfilename
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
495 tmpfilename
= pretmpfilename
['Filename'];
496 downloadsize
= os
.path
.getsize(tmpfilename
);
499 exec_time_start
= time
.time();
500 with
open(tmpfilename
, 'rb') as ft
:
503 databytes
= ft
.read(buffersize
[1]);
504 if not databytes
: break;
505 datasize
= len(databytes
);
506 fulldatasize
= datasize
+ fulldatasize
;
509 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
510 downloaddiff
= fulldatasize
- prevdownsize
;
511 log
.info("Copying "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Copied "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
512 prevdownsize
= fulldatasize
;
515 fdata
= f
.getvalue();
518 os
.remove(tmpfilename
);
519 exec_time_end
= time
.time();
520 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to copy file.");
521 returnval
= {'Type': "Content", 'Content': fdata
, 'Contentsize': downloadsize
, 'ContentsizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
524 if(haverequests
==True):
525 def download_from_url_with_requests(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
526 global geturls_download_sleep
;
528 sleep
= geturls_download_sleep
;
529 if(isinstance(httpheaders
, list)):
530 httpheaders
= make_http_headers_from_list_to_dict(httpheaders
);
532 geturls_text
= requests
.get(httpurl
, headers
=httpheaders
, cookies
=httpcookie
);
533 log
.info("Downloading URL "+httpurl
);
534 if(geturls_text
.headers
.get('Content-Type')=="gzip" or geturls_text
.headers
.get('Content-Type')=="deflate"):
535 if(sys
.version
[0]=="2"):
536 strbuf
= StringIO(geturls_text
.content
);
537 if(sys
.version
[0]>="3"):
538 strbuf
= BytesIO(geturls_text
.content
);
539 gzstrbuf
= gzip
.GzipFile(fileobj
=strbuf
);
540 returnval_content
= gzstrbuf
.content
[:];
541 if(geturls_text
.headers
.get('Content-Type')!="gzip" and geturls_text
.headers
.get('Content-Type')!="deflate"):
542 returnval_content
= geturls_text
.content
[:];
543 returnval
= {'Type': "Content", 'Content': returnval_content
, 'Headers': dict(geturls_text
.headers
), 'URL': geturls_text
.url
, 'Code': geturls_text
.status_code
};
544 geturls_text
.close();
547 if(haverequests
==False):
548 def download_from_url_with_requests(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
549 returnval
= download_from_url_with_urllib(httpurl
, httpheaders
, httpcookie
, sleep
)
552 if(haverequests
==True):
553 def download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
=524288, sleep
=-1):
554 global geturls_download_sleep
;
555 exec_time_start
= time
.time();
557 sleep
= geturls_download_sleep
;
558 if(isinstance(httpheaders
, list)):
559 httpheaders
= make_http_headers_from_list_to_dict(httpheaders
);
561 geturls_text
= requests
.get(httpurl
, headers
=httpheaders
, cookies
=httpcookie
, stream
=True);
562 downloadsize
= int(geturls_text
.headers
.get('Content-Length'));
563 if(downloadsize
is not None):
564 downloadsize
= int(downloadsize
);
565 if downloadsize
is None: downloadsize
= 0;
568 log
.info("Downloading URL "+httpurl
);
569 with tempfile
.NamedTemporaryFile('wb+', prefix
="pywwwget-", delete
=False) as f
:
570 tmpfilename
= f
.name
;
571 returnval
= {'Type': "File", 'Filename': tmpfilename
, 'Filesize': downloadsize
, 'FilesizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'Headers': dict(geturls_text
.headers
), 'URL': geturls_text
.url
, 'Code': geturls_text
.status_code
};
572 for databytes
in geturls_text
.iter_content(chunk_size
=buffersize
):
573 datasize
= len(databytes
);
574 fulldatasize
= datasize
+ fulldatasize
;
577 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
578 downloaddiff
= fulldatasize
- prevdownsize
;
579 log
.info("Downloading "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Downloaded "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
580 prevdownsize
= fulldatasize
;
583 geturls_text
.close();
584 exec_time_end
= time
.time();
585 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to download file.");
586 returnval
.update({'Filesize': os
.path
.getsize(tmpfilename
), 'DownloadTime': float(exec_time_start
- exec_time_end
), 'DownloadTimeReadable': hms_string(exec_time_start
- exec_time_end
)});
589 if(haverequests
==False):
590 def download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
=524288, sleep
=-1):
591 returnval
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
, sleep
)
594 if(haverequests
==True):
595 def download_from_url_to_file_with_requests(httpurl
, httpheaders
, httpcookie
, outfile
="-", outpath
=os
.getcwd(), buffersize
=[524288, 524288], sleep
=-1):
596 global geturls_download_sleep
;
598 sleep
= geturls_download_sleep
;
599 if(not outfile
=="-"):
600 outpath
= outpath
.rstrip(os
.path
.sep
);
601 filepath
= os
.path
.realpath(outpath
+os
.path
.sep
+outfile
);
602 if(not os
.path
.exists(outpath
)):
603 os
.makedirs(outpath
);
604 if(os
.path
.exists(outpath
) and os
.path
.isfile(outpath
)):
606 if(os
.path
.exists(filepath
) and os
.path
.isdir(filepath
)):
608 pretmpfilename
= download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
609 tmpfilename
= pretmpfilename
['Filename'];
610 downloadsize
= os
.path
.getsize(tmpfilename
);
612 log
.info("Moving file "+tmpfilename
+" to "+filepath
);
613 exec_time_start
= time
.time();
614 shutil
.move(tmpfilename
, filepath
);
615 exec_time_end
= time
.time();
616 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to move file.");
617 if(os
.path
.exists(tmpfilename
)==True):
618 os
.remove(tmpfilename
);
619 returnval
= {'Type': "File", 'Filename': filepath
, 'Filesize': downloadsize
, 'FilesizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
620 if(outfile
=="-" and sys
.version
[0]=="2"):
621 pretmpfilename
= download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
622 tmpfilename
= pretmpfilename
['Filename'];
623 downloadsize
= os
.path
.getsize(tmpfilename
);
626 exec_time_start
= time
.time();
627 with
open(tmpfilename
, 'rb') as ft
:
630 databytes
= ft
.read(buffersize
[1]);
631 if not databytes
: break;
632 datasize
= len(databytes
);
633 fulldatasize
= datasize
+ fulldatasize
;
636 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
637 downloaddiff
= fulldatasize
- prevdownsize
;
638 log
.info("Copying "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Copied "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
639 prevdownsize
= fulldatasize
;
642 fdata
= f
.getvalue();
645 os
.remove(tmpfilename
);
646 exec_time_end
= time
.time();
647 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to copy file.");
648 returnval
= {'Type': "Content", 'Content': fdata
, 'Contentsize': downloadsize
, 'ContentsizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
649 if(outfile
=="-" and sys
.version
[0]>="3"):
650 pretmpfilename
= download_from_url_file_with_requests(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
651 tmpfilename
= pretmpfilename
['Filename'];
652 downloadsize
= os
.path
.getsize(tmpfilename
);
655 exec_time_start
= time
.time();
656 with
open(tmpfilename
, 'rb') as ft
:
659 databytes
= ft
.read(buffersize
[1]);
660 if not databytes
: break;
661 datasize
= len(databytes
);
662 fulldatasize
= datasize
+ fulldatasize
;
665 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
666 downloaddiff
= fulldatasize
- prevdownsize
;
667 log
.info("Copying "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Copied "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
668 prevdownsize
= fulldatasize
;
671 fdata
= f
.getvalue();
674 os
.remove(tmpfilename
);
675 exec_time_end
= time
.time();
676 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to copy file.");
677 returnval
= {'Type': "Content", 'Content': fdata
, 'Contentsize': downloadsize
, 'ContentsizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
680 if(haverequests
==False):
681 def download_from_url_to_file_with_requests(httpurl
, httpheaders
, httpcookie
, outfile
="-", outpath
=os
.getcwd(), buffersize
=[524288, 524288], sleep
=-1):
682 returnval
= download_from_url_to_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
, outfile
, outpath
, sleep
)
685 if(havemechanize
==True):
686 def download_from_url_with_mechanize(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
687 global geturls_download_sleep
;
689 sleep
= geturls_download_sleep
;
690 geturls_opener
= mechanize
.Browser();
691 if(isinstance(httpheaders
, dict)):
692 httpheaders
= make_http_headers_from_dict_to_list(httpheaders
);
694 geturls_opener
.addheaders
= httpheaders
;
695 geturls_opener
.set_cookiejar(httpcookie
);
696 geturls_opener
.set_handle_robots(False);
697 geturls_text
= geturls_opener
.open(httpurl
);
698 log
.info("Downloading URL "+httpurl
);
699 if(geturls_text
.info().get("Content-Encoding")=="gzip" or geturls_text
.info().get("Content-Encoding")=="deflate"):
700 if(sys
.version
[0]=="2"):
701 strbuf
= StringIO(geturls_text
.read());
702 if(sys
.version
[0]>="3"):
703 strbuf
= BytesIO(geturls_text
.read());
704 gzstrbuf
= gzip
.GzipFile(fileobj
=strbuf
);
705 returnval_content
= gzstrbuf
.read()[:];
706 if(geturls_text
.info().get("Content-Encoding")!="gzip" and geturls_text
.info().get("Content-Encoding")!="deflate"):
707 returnval_content
= geturls_text
.read()[:];
708 returnval
= {'Type': "Content", 'Content': returnval_content
, 'Headers': dict(geturls_text
.info()), 'URL': geturls_text
.geturl(), 'Code': geturls_text
.code
};
709 geturls_text
.close();
712 if(havemechanize
==False):
713 def download_from_url_with_mechanize(httpurl
, httpheaders
, httpcookie
, sleep
=-1):
714 returnval
= download_from_url_with_urllib(httpurl
, httpheaders
, httpcookie
, sleep
)
717 if(havemechanize
==True):
718 def download_from_url_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, buffersize
=524288, sleep
=-1):
719 global geturls_download_sleep
;
720 exec_time_start
= time
.time();
722 sleep
= geturls_download_sleep
;
723 geturls_opener
= mechanize
.Browser();
724 if(isinstance(httpheaders
, dict)):
725 httpheaders
= make_http_headers_from_dict_to_list(httpheaders
);
727 geturls_opener
.addheaders
= httpheaders
;
728 geturls_opener
.set_cookiejar(httpcookie
);
729 geturls_opener
.set_handle_robots(False);
730 geturls_text
= geturls_opener
.open(httpurl
);
731 downloadsize
= int(geturls_text
.info().get('Content-Length'));
732 if(downloadsize
is not None):
733 downloadsize
= int(downloadsize
);
734 if downloadsize
is None: downloadsize
= 0;
737 log
.info("Downloading URL "+httpurl
);
738 with tempfile
.NamedTemporaryFile('wb+', prefix
="pywwwget-", delete
=False) as f
:
739 tmpfilename
= f
.name
;
740 returnval
= {'Type': "File", 'Filename': tmpfilename
, 'Filesize': downloadsize
, 'FilesizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'Headers': dict(geturls_text
.info()), 'URL': geturls_text
.geturl(), 'Code': geturls_text
.code
};
742 databytes
= geturls_text
.read(buffersize
);
743 if not databytes
: break;
744 datasize
= len(databytes
);
745 fulldatasize
= datasize
+ fulldatasize
;
748 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
749 downloaddiff
= fulldatasize
- prevdownsize
;
750 log
.info("Downloading "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Downloaded "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
751 prevdownsize
= fulldatasize
;
754 geturls_text
.close();
755 exec_time_end
= time
.time();
756 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to download file.");
757 returnval
.update({'Filesize': os
.path
.getsize(tmpfilename
), 'DownloadTime': float(exec_time_start
- exec_time_end
), 'DownloadTimeReadable': hms_string(exec_time_start
- exec_time_end
)});
760 if(havemechanize
==False):
761 def download_from_url_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, buffersize
=524288, sleep
=-1):
762 returnval
= download_from_url_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
, sleep
)
765 if(havemechanize
==True):
766 def download_from_url_to_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, outfile
="-", outpath
=os
.getcwd(), buffersize
=[524288, 524288], sleep
=-1):
767 global geturls_download_sleep
;
769 sleep
= geturls_download_sleep
;
770 if(not outfile
=="-"):
771 outpath
= outpath
.rstrip(os
.path
.sep
);
772 filepath
= os
.path
.realpath(outpath
+os
.path
.sep
+outfile
);
773 if(not os
.path
.exists(outpath
)):
774 os
.makedirs(outpath
);
775 if(os
.path
.exists(outpath
) and os
.path
.isfile(outpath
)):
777 if(os
.path
.exists(filepath
) and os
.path
.isdir(filepath
)):
779 pretmpfilename
= download_from_url_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
780 tmpfilename
= pretmpfilename
['Filename'];
781 downloadsize
= os
.path
.getsize(tmpfilename
);
783 log
.info("Moving file "+tmpfilename
+" to "+filepath
);
784 exec_time_start
= time
.time();
785 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to move file.");
786 shutil
.move(tmpfilename
, filepath
);
787 if(os
.path
.exists(tmpfilename
)==True):
788 os
.remove(tmpfilename
);
789 returnval
= {'Type': "File", 'Filename': filepath
, 'Filesize': downloadsize
, 'FilesizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
790 if(outfile
=="-" and sys
.version
[0]=="2"):
791 pretmpfilename
= download_from_url_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
792 tmpfilename
= pretmpfilename
['Filename'];
793 downloadsize
= os
.path
.getsize(tmpfilename
);
796 exec_time_start
= time
.time();
797 with
open(tmpfilename
, 'rb') as ft
:
800 databytes
= ft
.read(buffersize
[1]);
801 if not databytes
: break;
802 datasize
= len(databytes
);
803 fulldatasize
= datasize
+ fulldatasize
;
806 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
807 downloaddiff
= fulldatasize
- prevdownsize
;
808 log
.info("Copying "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Copied "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
809 prevdownsize
= fulldatasize
;
812 fdata
= f
.getvalue();
815 os
.remove(tmpfilename
);
816 exec_time_end
= time
.time();
817 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to copy file.");
818 returnval
= {'Type': "Content", 'Content': fdata
, 'Contentsize': downloadsize
, 'ContentsizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
819 if(outfile
=="-" and sys
.version
[0]>="3"):
820 pretmpfilename
= download_from_url_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, buffersize
[0], sleep
);
821 tmpfilename
= pretmpfilename
['Filename'];
822 downloadsize
= os
.path
.getsize(tmpfilename
);
825 exec_time_start
= time
.time();
826 with
open(tmpfilename
, 'rb') as ft
:
829 databytes
= ft
.read(buffersize
[1]);
830 if not databytes
: break;
831 datasize
= len(databytes
);
832 fulldatasize
= datasize
+ fulldatasize
;
835 percentage
= str("{0:.2f}".format(float(float(fulldatasize
/ downloadsize
) * 100))).rstrip('0').rstrip('.')+"%";
836 downloaddiff
= fulldatasize
- prevdownsize
;
837 log
.info("Copying "+get_readable_size(fulldatasize
, 2, "SI")['ReadableWithSuffix']+" / "+get_readable_size(downloadsize
, 2, "SI")['ReadableWithSuffix']+" "+str(percentage
)+" / Copied "+get_readable_size(downloaddiff
, 2, "IEC")['ReadableWithSuffix']);
838 prevdownsize
= fulldatasize
;
841 fdata
= f
.getvalue();
844 os
.remove(tmpfilename
);
845 exec_time_end
= time
.time();
846 log
.info("It took "+hms_string(exec_time_start
- exec_time_end
)+" to copy file.");
847 returnval
= {'Type': "Content", 'Content': fdata
, 'Contentsize': downloadsize
, 'ContentsizeAlt': {'IEC': get_readable_size(downloadsize
, 2, "IEC"), 'SI': get_readable_size(downloadsize
, 2, "SI")}, 'DownloadTime': pretmpfilename
['DownloadTime'], 'DownloadTimeReadable': pretmpfilename
['DownloadTimeReadable'], 'MoveFileTime': float(exec_time_start
- exec_time_end
), 'MoveFileTimeReadable': hms_string(exec_time_start
- exec_time_end
), 'Headers': pretmpfilename
['Headers'], 'URL': pretmpfilename
['URL'], 'Code': pretmpfilename
['Code']};
850 if(havemechanize
==False):
851 def download_from_url_to_file_with_mechanize(httpurl
, httpheaders
, httpcookie
, outfile
="-", outpath
=os
.getcwd(), buffersize
=[524288, 524288], sleep
=-1):
852 returnval
= download_from_url_to_file_with_urllib(httpurl
, httpheaders
, httpcookie
, buffersize
, outfile
, outpath
, sleep
)
855 def check_motherless_url(httpurl
):
857 httpurl
.replace("https://", "http://");
858 if(not httpurl
.startswith("http")):
859 httpurl
= "http://"+httpurl
;
860 urlparts
= urlsplit(httpurl
);
863 if(urlparts
.netloc
=="motherless.com" or urlparts
.netloc
=="www.motherless.com"):
864 urltype
= "motherless-link";
865 domaintype
= "motherless";
866 if(urlparts
.netloc
=="cdn.avatars.motherlessmedia.com" or urlparts
.netloc
=="cdn1.avatars.motherlessmedia.com" or urlparts
.netloc
=="cdn2.avatars.motherlessmedia.com" or urlparts
.netloc
=="cdn3.avatars.motherlessmedia.com" or urlparts
.netloc
=="cdn4.avatars.motherlessmedia.com"):
867 urltype
= "motherless-avatar";
868 domaintype
= "motherlessmedia";
869 if(urlparts
.netloc
=="cdn.images.motherlessmedia.com" or urlparts
.netloc
=="cdn1.images.motherlessmedia.com" or urlparts
.netloc
=="cdn2.images.motherlessmedia.com" or urlparts
.netloc
=="cdn3.images.motherlessmedia.com" or urlparts
.netloc
=="cdn4.images.motherlessmedia.com"):
870 urltype
= "motherless-image";
871 domaintype
= "motherlessmedia";
872 if(urlparts
.netloc
=="cdn.videos.motherlessmedia.com" or urlparts
.netloc
=="cdn1.videos.motherlessmedia.com" or urlparts
.netloc
=="cdn2.videos.motherlessmedia.com" or urlparts
.netloc
=="cdn3.videos.motherlessmedia.com" or urlparts
.netloc
=="cdn4.videos.motherlessmedia.com"):
873 urltype
= "motherless-video";
874 domaintype
= "motherlessmedia";
875 if(urlparts
.netloc
=="cdn.thumbs.motherlessmedia.com" or urlparts
.netloc
=="cdn1.thumbs.motherlessmedia.com" or urlparts
.netloc
=="cdn2.thumbs.motherlessmedia.com" or urlparts
.netloc
=="cdn3.thumbs.motherlessmedia.com" or urlparts
.netloc
=="cdn4.thumbs.motherlessmedia.com"):
876 urltype
= "motherless-thumbnail";
877 domaintype
= "motherlessmedia";
878 if(urltype
==None or domaintype
==None):
880 returnval
.update({'url': httpurl
, 'urltype': urltype
, 'domaintype': domaintype
, 'urlinfo': {'scheme': urlparts
.scheme
, 'netloc': urlparts
.netloc
, 'path': urlparts
.path
, 'query': urlparts
.query
, 'fragment': urlparts
.fragment
}});
883 def fix_motherless_url(httpurl
):
884 returnval
= check_motherless_url(httpurl
)['url'];
887 def get_motherless_link_type(httpurl
):
888 httpurl
= fix_motherless_url(httpurl
);
889 mregex_gettitle
= re
.escape("http://cdn")+"([1-4])"+re
.escape(".");
890 httpurl
= re
.sub(mregex_gettitle
, "http://cdn.", httpurl
);
891 mlessvidqstr
= urlparse
.parse_qs(urlparse
.urlparse(httpurl
).query
);
892 mlessvidid_parts
= urlparse
.urlparse(httpurl
);
893 mlessvidid
= mlessvidid_parts
.path
.split("/");
895 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")):
896 returnval
= "gallery";
897 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")):
898 returnval
= "gallery";
899 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")):
900 returnval
= "gallery";
901 if(mlessvidid
[1]=="videos" and len(mlessvidid
)==2):
902 returnval
= "sample-videos";
903 if(mlessvidid
[1]=="images" and len(mlessvidid
)==2):
904 returnval
= "sample-images";
905 if(mlessvidid
[1]=="galleries" and len(mlessvidid
)==2):
906 returnval
= "sample-galleries";
907 if(mlessvidid
[1]=="" and len(mlessvidid
)==2):
908 returnval
= "sample";
909 if(mlessvidid
[1]=="groups" and len(mlessvidid
)==2):
911 if(mlessvidid
[1]=="groups" and len(mlessvidid
)==3 and mlessvidid
[2]=="search"):
913 if(mlessvidid
[1]=="groups" and len(mlessvidid
)==4 and mlessvidid
[2]=="category"):
915 if(mlessvidid
[1]=="live" and len(mlessvidid
)==3 and (mlessvidid
[2]=="videos" or mlessvidid
[2]=="images")):
916 returnval
= "gallery";
917 if(mlessvidid
[1]=="u" and len(mlessvidid
)==3):
918 returnval
= "gallery";
919 if(mlessvidid
[1]=="f" and len(mlessvidid
)==4 and (mlessvidid
[2]=="videos" or mlessvidid
[2]=="images" or mlessvidid
[2]=="galleries")):
920 returnval
= "gallery";
921 if(mlessvidid
[1]=="galleries" and len(mlessvidid
)==4 and mlessvidid
[2]=="member"):
922 returnval
= "gallery";
923 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")):
924 returnval
= "gallery";
925 if(mlessvidid
[1]=="gv" and len(mlessvidid
)==3):
926 returnval
= "gallery";
927 if(mlessvidid
[1]=="gi" and len(mlessvidid
)==3):
928 returnval
= "gallery";
929 if(mlessvidid
[1]=="gm" and len(mlessvidid
)==3):
930 returnval
= "member";
931 if(mlessvidid
[1]=="term" and len(mlessvidid
)==3 and (mlessvidid
[2]=="videos" or mlessvidid
[2]=="images" or mlessvidid
[2]=="galleries")):
932 returnval
= "gallery";
933 if(mlessvidid
[1]=="g" and len(mlessvidid
)==4 and re
.match("^([0-9A-F]+)$", mlessvidid
[3])):
935 if(mlessvidid
[1]=="random" and len(mlessvidid
)==3 and (mlessvidid
[2]=="video" or mlessvidid
[2]=="image")):
937 if(re
.match("^V", mlessvidid
[1]) and len(mlessvidid
)==2):
939 if(re
.match("^H", mlessvidid
[1]) and len(mlessvidid
)==2):
940 returnval
= "gallery";
941 if(re
.match("^G", mlessvidid
[1]) and len(mlessvidid
)==2):
942 returnval
= "gallery";
943 if(re
.match("^G", mlessvidid
[1]) and len(mlessvidid
)==3):
945 if(re
.match("^g", mlessvidid
[1]) and len(mlessvidid
)==4 and re
.match("^([0-9A-F]+)$", mlessvidid
[3])):
947 if(mlessvidid
[1]=="members" and len(mlessvidid
)==2):
948 returnval
= "member";
949 if(mlessvidid
[1]=="members" and len(mlessvidid
)==3 and mlessvidid
[2]=="search"):
950 returnval
= "member";
951 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")):
952 returnval
= "member";
953 if(mlessvidid
[1]=="girls" and len(mlessvidid
)==2):
955 if(mlessvidid
[1]=="referers" and len(mlessvidid
)==2):
956 returnval
= "referers";
957 if(mlessvidid
[1]=="about" and len(mlessvidid
)==2):
959 if(mlessvidid_parts
.netloc
=="cdn.images.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn.videos.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn.thumbs.motherlessmedia.com"):
960 returnval
= "download";
961 if(mlessvidid_parts
.netloc
=="cdn1.images.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn1.videos.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn1.thumbs.motherlessmedia.com"):
962 returnval
= "download";
963 if(mlessvidid_parts
.netloc
=="cdn2.images.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn2.videos.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn2.thumbs.motherlessmedia.com"):
964 returnval
= "download";
965 if(mlessvidid_parts
.netloc
=="cdn3.images.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn3.videos.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn3.thumbs.motherlessmedia.com"):
966 returnval
= "download";
967 if(mlessvidid_parts
.netloc
=="cdn4.images.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn4.videos.motherlessmedia.com" or mlessvidid_parts
.netloc
=="cdn4.thumbs.motherlessmedia.com"):
968 returnval
= "download";
969 if(returnval
==False and len(mlessvidid
)==2 and re
.match("^([0-9A-F]+)$", mlessvidid
[1])):
973 def get_motherless_link_type_alt(httpurl
):
974 httpurl
= fix_motherless_url(httpurl
);
975 returnval
= {'urlinfo': check_motherless_url(httpurl
), 'motherlessinfo': get_motherless_link_type(httpurl
)};
978 def get_motherless_number_of_pages(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib"):
979 httpurl
= fix_motherless_url(httpurl
);
980 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
981 mrtext
= premrtext
['Content'];
982 if(sys
.version
[0]>="3"):
983 mrtext
= mrtext
.decode('ascii', 'replace');
984 mregex_getpagenum
= re
.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">")+"([0-9]+)"+re
.escape("</a>");
985 mlesspagenum
= re
.findall(mregex_getpagenum
, mrtext
);
987 returnval
= int(mlesspagenum
[-1][0]);
992 def get_motherless_user_info(username
, motherless_serv
=None):
993 motherless_subdomain
= "cdn.";
994 if(motherless_serv
<5 or motherless_serv
>0):
995 motherless_subdomain
= "cdn"+str(motherless_serv
)+".";
996 returnval
= {'username': username
};
997 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+username
+"-avatar.jpg", urlparse
.urlparse("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+username
+"-avatar.jpg").path
));
998 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
999 returnval
.update({'orginurl': "http://motherless.com/m/"+username
});
1000 returnval
.update({'orginurltype': "profile"});
1001 returnval
.update({'url': "http://motherless.com/m/"+username
});
1002 returnval
.update({'urltype': "profile"});
1003 returnval
.update({'avatarurl': "http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+username
+"-avatar.jpg"});
1004 returnval
.update({'avatarfullfilename': avatarfilenameext
});
1005 returnval
.update({'avatarfilename': avatarfilename
});
1006 returnval
.update({'avatarextension': avatarfileextension
});
1009 def get_motherless_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", motherless_serv
=None):
1010 httpurl
= fix_motherless_url(httpurl
);
1011 motherless_subdomain
= "cdn.";
1012 if(motherless_serv
<5 or motherless_serv
>0):
1013 motherless_subdomain
= "cdn"+str(motherless_serv
)+".";
1014 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1015 mrtext
= premrtext
['Content'];
1016 if(sys
.version
[0]>="3"):
1017 mrtext
= mrtext
.decode('ascii', 'replace');
1018 mregex_gettitle
= re
.escape("http://cdn")+"([1-4])"+re
.escape(".");
1019 mrtext
= re
.sub(mregex_gettitle
, "http://cdn.", mrtext
);
1020 mregex_gettitle
= re
.escape("<title>")+"(.*)"+re
.escape(" - MOTHERLESS.COM</title>");
1021 mlesstitle
= re
.findall(mregex_gettitle
, mrtext
);
1022 mregex_geturlone
= re
.escape("__fileurl = '")+'?\'?([^"\'>]*)'+re
.escape("';");
1023 mlesslinkone
= re
.findall(mregex_geturlone
, mrtext
);
1024 mregex_geturlonetype
= re
.escape("http://cdn.")+"(images|videos)"+re
.escape(".motherlessmedia.com/")+"(images|videos)"+re
.escape("/")+"([\w\/\?\&\=\.\-]+)";
1025 mlesslinkonetype
= re
.findall(mregex_geturlonetype
, mrtext
);
1026 mregex_geturltwo
= re
.escape("<meta property=\"og:image\" content=\"")+'?\'?([^"\'>]*)'+re
.escape("\">");
1027 mlesslinktwo
= re
.findall(mregex_geturltwo
, mrtext
);
1028 mregex_geturltwotype
= re
.escape("http://cdn.")+"(images|thumbs)"+re
.escape(".motherlessmedia.com/")+"(images|thumbs)"+re
.escape("/")+"([\w\/\?\&\=\.\-]+)";
1029 mlesslinktwotype
= re
.findall(mregex_geturltwotype
, mrtext
);
1030 filenameext
= os
.path
.basename(urlparse
.urljoin(mlesslinkone
[0], urlparse
.urlparse(mlesslinkone
[0]).path
));
1031 filename
, fileextension
= os
.path
.splitext(filenameext
);
1032 thumbfilenameext
= os
.path
.basename(urlparse
.urljoin(mlesslinktwo
[0], urlparse
.urlparse(mlesslinktwo
[0]).path
));
1033 thumbfilename
, thumbfileextension
= os
.path
.splitext(thumbfilenameext
);
1034 mregex_getuname
= re
.escape("<tr rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\"");
1035 mlessuname
= re
.findall(mregex_getuname
, mrtext
);
1036 mlessuname
= mlessuname
[0];
1037 mregex_geturlname
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" target=\"_blank\">\n <img");
1038 mlessurlname
= re
.findall(mregex_geturlname
, mrtext
);
1039 mlessurlname
= mlessurlname
[0].replace("/m/", "");
1040 mregex_getavatar
= re
.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re
.escape("\"\n class=\"avatar avatar-small\"");
1041 mlessavatar
= re
.findall(mregex_getavatar
, mrtext
);
1042 mlessavatar
= mlessavatar
[0];
1043 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin(mlessavatar
, urlparse
.urlparse(mlessavatar
).path
));
1044 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1045 mregex_getviews
= re
.escape("<strong>Views</strong>\n")+"(\s+|\t+)([0-9\,]+)(\s+\t+)"+re
.escape("</h2>");
1046 mlessviews
= re
.findall(mregex_getviews
, mrtext
);
1047 mregex_getfavorited
= re
.escape("<strong>Favorited</strong>\n")+"(\s+\t+)([0-9\,]+)(\s+\t+)"+re
.escape("</h2>");
1048 mlessfavorited
= re
.findall(mregex_getfavorited
, mrtext
);
1049 if(mlesslinkonetype
[0][1]=="images"):
1050 thumbnailaltpart
= thumbfilename
+"-zoom"+thumbfileextension
;
1051 thumbnailalt
= "http://"+motherless_subdomain
+"thumbs.motherlessmedia.com/thumbs/"+thumbnailaltpart
;
1052 thumbnailaltfilenameext
= os
.path
.basename(urlparse
.urljoin(thumbnailalt
, urlparse
.urlparse(thumbnailalt
).path
));
1053 thumbnailaltfilename
, thumbnailaltfileextension
= os
.path
.splitext(thumbnailaltfilenameext
);
1054 if(mlesslinkonetype
[0][1]=="videos"):
1055 thumbnailaltpart
= thumbfilename
+"-small"+thumbfileextension
;
1056 thumbnailalt
= "http://"+motherless_subdomain
+"thumbs.motherlessmedia.com/thumbs/"+thumbnailaltpart
;
1057 thumbnailaltfilenameext
= os
.path
.basename(urlparse
.urljoin(thumbnailalt
, urlparse
.urlparse(thumbnailalt
).path
));
1058 thumbnailaltfilename
, thumbnailaltfileextension
= os
.path
.splitext(thumbnailaltfilenameext
);
1060 mlessurltype
= get_motherless_link_type(mlesslinkone
[0]);
1061 if(mlesslinkonetype
[0][1]=="images"):
1062 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
, 'numberofviews': int(mlessviews
[0][1].replace(',', '')), 'numberoffavorites': int(mlessfavorited
[0][1].replace(',', ''))};
1063 if(mlesslinkonetype
[0][1]=="videos"):
1064 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
, 'numberofviews': int(mlessviews
[0][1].replace(',', '')), 'numberoffavorites': int(mlessfavorited
[0][1].replace(',', ''))};
1067 def get_motherless_links_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib"):
1068 httpurl
= fix_motherless_url(httpurl
);
1070 if(get_motherless_link_type(httpurl
)=="download"):
1071 urlparts
= urlparse
.urlparse(httpurl
);
1072 filewithext
= os
.path
.split(urlparts
.path
);
1073 if(filewithext
[0]=="/images"):
1074 filewithoutext
= os
.path
.splitext(filewithext
[1])[0];
1075 returnval
= get_motherless_links("http://motherless.com/"+filewithoutext
, httpheaders
, httpcookie
, httplibuse
="urllib");
1076 if(filewithext
[0]=="/thumbs"):
1077 filewithoutext
= os
.path
.splitext(filewithext
[1])[0];
1078 filewithoutext
= filewithoutext
.replace("-zoom", "");
1079 filewithoutext
= filewithoutext
.replace("-small", "");
1080 filewithoutext
= filewithoutext
.replace("-strip", "");
1081 returnval
= get_motherless_links("http://motherless.com/"+filewithoutext
, httpheaders
, httpcookie
, httplibuse
="urllib");
1084 def get_motherless_external_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib"):
1085 httpurl
= fix_motherless_url(httpurl
);
1086 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1087 mrtext
= premrtext
['Content'];
1088 if(sys
.version
[0]>="3"):
1089 mrtext
= mrtext
.decode('ascii', 'replace');
1090 mregex_geturlinternal
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" rev=\"outbound\" rel=\"nofollow\" class=\"pop\" target=\"_blank\" title=\"motherless link\">");
1091 mlesslinkinternal
= re
.findall(mregex_geturlinternal
, mrtext
);
1092 mregex_geturlexternal
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" rev=\"outbound\" rel=\"nofollow\" class=\"pop\" target=\"_blank\" title=\"external link\">");
1093 mlesslinkexternal
= re
.findall(mregex_geturlexternal
, mrtext
);
1094 returnvalone
= None;
1095 if(len(mlesslinkinternal
)>1):
1097 mlil
= len(mlesslinkinternal
);
1098 returnvalone
= {'numoflinks': mlil
};
1099 returnvalone
.update({'numofalllinks': len(mlesslinkinternal
)});
1100 returnvalone
.update({'orginurl': httpurl
});
1101 returnvalone
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1102 mlessrooturltype
= get_motherless_link_type(httpurl
);
1103 returnvalone
.update({'urltype': mlessrooturltype
});
1105 mlessurltype
= get_motherless_link_type(mlesslinkinternal
[mli
]);
1106 returnvalone
.update({mli
: {'urltype': mlessurltype
, 'url': mlesslinkinternal
[mli
]} });
1108 returnvaltwo
= None;
1109 if(len(mlesslinkexternal
)>1):
1111 mlil
= len(mlesslinkexternal
);
1112 returnvaltwo
= {'numoflinks': mlil
};
1113 returnvaltwo
.update({'numofalllinks': len(mlesslinkexternal
)});
1114 returnvaltwo
.update({'orginurl': httpurl
});
1115 returnvaltwo
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1116 mlessrooturltype
= get_motherless_link_type(httpurl
);
1117 returnvaltwo
.update({'urltype': mlessrooturltype
});
1119 returnvaltwo
.update({mli
: {'urltype': "external", 'url': mlesslinkexternal
[mli
]} });
1121 if(returnvalone
==None and returnvaltwo
==None):
1122 returnval
= {'internal': None, 'external': None};
1123 if(not returnvalone
==None and not returnvaltwo
==None):
1124 returnval
= {'internal': returnvalone
, 'external': returnvaltwo
};
1125 if(not returnvalone
==None and returnvaltwo
==None):
1126 returnval
= {'internal': returnvalone
, 'external': None};
1127 if(returnvalone
==None and not returnvaltwo
==None):
1128 returnval
= {'internal': None, 'external': returnvaltwo
};
1131 def get_motherless_galleries_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", page
=1, getlinks
=[0, -1], motherless_serv
=None):
1132 httpurl
= fix_motherless_url(httpurl
);
1133 motherless_subdomain
= "cdn.";
1134 if(motherless_serv
<5 or motherless_serv
>0):
1135 motherless_subdomain
= "cdn"+str(motherless_serv
)+".";
1136 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1137 mrtext
= premrtext
['Content'];
1138 if(sys
.version
[0]>="3"):
1139 mrtext
= mrtext
.decode('ascii', 'replace');
1140 mregex_getpagenum
= re
.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">")+"([0-9]+)"+re
.escape("</a>");
1141 mlesspagenum
= re
.findall(mregex_getpagenum
, mrtext
);
1143 lastpage
= int(mlesspagenum
[-1][0]);
1148 httpurl
= add_url_param(httpurl
, page
=str(page
));
1149 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1150 mrtext
= premrtext
['Content'];
1151 if(sys
.version
[0]>="3"):
1152 mrtext
= mrtext
.decode('ascii', 'replace');
1153 mregex_geturlone
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" class=\"img-container\" target=\"_self\">");
1154 mrtext_tmp
= re
.sub(re
.escape("http://motherless.com"), "", mrtext
);
1155 mrtext_tmp
= re
.sub(re
.escape("http://www.motherless.com"), "", mrtext_tmp
);
1156 mrtext_tmp
= re
.sub(re
.escape("http://motherless.com"), "", mrtext_tmp
);
1157 mrtext_tmp
= re
.sub(re
.escape("http://www.motherless.com"), "", mrtext_tmp
);
1158 mlesslinkone
= re
.findall(mregex_geturlone
, mrtext_tmp
);
1159 mregex_geturltwo
= re
.escape("<img class=\"static\" src=\"")+'?\'?([^"\'>]*)'+re
.escape("\" data-strip-src=\"")+'?\'?([^"\'>]*)'+re
.escape("\" alt=\"")+'?\'?([^">]*)'+re
.escape("\" />");
1160 mlesslinktwo
= re
.findall(mregex_geturltwo
, mrtext
);
1161 mregex_getcaption
= re
.escape("<h2 class=\"caption title\">")+"(.*)"+re
.escape("</h2>");
1162 mlesscaption
= re
.findall(mregex_getcaption
, mrtext
);
1163 mregex_gethits
= re
.escape("<div class=\"caption right\">")+"([0-9\,]+)"+re
.escape(" Hits</div>");
1164 mlesshits
= re
.findall(mregex_gethits
, mrtext
);
1165 mregex_getuserinfo
= re
.escape("<a class=\"caption left\" href=\"")+'?\'?([^"\'>]*)'+re
.escape("\">");
1166 mlessuname
= re
.findall(mregex_getuserinfo
, mrtext
);
1167 if(getlinks
[1]>len(mlesslinkone
) or getlinks
[1]==-1):
1168 getlinks
[1] = len(mlesslinkone
);
1169 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1170 tmpgetlinks0
= getlinks
[0];
1171 tmpgetlinks1
= getlinks
[1];
1172 getlinks
[0] = tmpgetlinks1
;
1173 getlinks
[1] = tmpgetlinks0
;
1178 returnval
= {'pages': lastpage
};
1179 returnval
.update({'curpage': page
});
1180 returnval
.update({'numoflinks': mlil
});
1181 returnval
.update({'numofalllinks': len(mlesslinkone
)});
1182 returnval
.update({'orginurl': httpurl
});
1183 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1184 mlessrooturltype
= get_motherless_link_type(httpurl
);
1185 returnval
.update({'urltype': mlessrooturltype
});
1187 mlessuname
[mli
] = mlessuname
[mli
].replace("/m/", "");
1188 stripfilenameext
= os
.path
.basename(urlparse
.urljoin(mlesslinktwo
[mli
][1], urlparse
.urlparse(mlesslinktwo
[mli
][1]).path
));
1189 stripfilename
, stripfileextension
= os
.path
.splitext(stripfilenameext
);
1190 thumbfilenameext
= os
.path
.basename(urlparse
.urljoin(mlesslinktwo
[mli
][0], urlparse
.urlparse(mlesslinktwo
[mli
][0]).path
));
1191 thumbfilename
, thumbfileextension
= os
.path
.splitext(thumbfilenameext
);
1192 mlessurltype
= get_motherless_link_type("http://motherless.com/"+mlesslinkone
[mli
]);
1193 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
]+"-avatar.jpg", urlparse
.urlparse("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
]+"-avatar.jpg").path
));
1194 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1195 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://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext
, 'avatarfilename': avatarfilename
, 'avatarextension': avatarfileextension
, 'numberofviews': int(mlesshits
[mli
].replace(',', ''))} });
1199 def get_motherless_random_links(httpheaders
, httpcookie
, httplibuse
="urllib", linktype
="video", getlinks
=[0, 80]):
1200 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1201 tmpgetlinks0
= getlinks
[0];
1202 tmpgetlinks1
= getlinks
[1];
1203 getlinks
[0] = tmpgetlinks1
;
1204 getlinks
[1] = tmpgetlinks0
;
1209 if(linktype
=="image"):
1210 returnval
= {'pages': 1};
1211 returnval
.update({'curpage': 1});
1212 returnval
.update({'numoflinks': 80});
1213 returnval
.update({'numofalllinks': mlil
});
1214 returnval
.update({'orginurl': "http://motherless.com/random/image"});
1215 returnval
.update({'orginurltype': "gallery"});
1216 returnval
.update({'urltype': "gallery"});
1218 get_links
= get_motherless_links("http://motherless.com/random/image", httpheaders
, httpcookie
, httplibuse
);
1219 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']} });
1221 if(linktype
=="video"):
1222 returnval
= {'pages': 1};
1223 returnval
.update({'curpage': 1});
1224 returnval
.update({'numoflinks': 80});
1225 returnval
.update({'numofalllinks': mlil
});
1226 returnval
.update({'orginurl': "http://motherless.com/random/video"});
1227 returnval
.update({'orginurltype': "gallery"});
1228 returnval
.update({'urltype': "gallery"});
1230 get_links
= get_motherless_links("http://motherless.com/random/video", httpheaders
, httpcookie
, httplibuse
);
1231 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']} });
1235 def get_motherless_random_links_alt(httpheaders
, httpcookie
, httplibuse
="urllib", linktype
="video", getlinks
=[0, 80]):
1236 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1237 tmpgetlinks0
= getlinks
[0];
1238 tmpgetlinks1
= getlinks
[1];
1239 getlinks
[0] = tmpgetlinks1
;
1240 getlinks
[1] = tmpgetlinks0
;
1245 if(linktype
=="image"):
1246 returnval
= {'pages': 1};
1247 returnval
.update({'curpage': 1});
1248 returnval
.update({'numoflinks': 80});
1249 returnval
.update({'numofalllinks': mlil
});
1250 returnval
.update({'orginurl': "http://motherless.com/random/image"});
1251 returnval
.update({'orginurltype': "gallery"});
1252 returnval
.update({'urltype': "gallery"});
1254 get_links
= get_motherless_links("http://motherless.com/random/image", httpheaders
, httpcookie
, httplibuse
);
1255 returnval
.update({mli
: get_links
});
1257 if(linktype
=="video"):
1258 returnval
= {'pages': 1};
1259 returnval
.update({'curpage': 1});
1260 returnval
.update({'numoflinks': 80});
1261 returnval
.update({'numofalllinks': mlil
});
1262 returnval
.update({'orginurl': "http://motherless.com/random/video"});
1263 returnval
.update({'orginurltype': "gallery"});
1264 returnval
.update({'urltype': "gallery"});
1266 get_links
= get_motherless_links("http://motherless.com/random/video", httpheaders
, httpcookie
, httplibuse
);
1267 returnval
.update({mli
: get_links
});
1271 def get_motherless_boards_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", getlinks
=[0, -1], motherless_serv
=None):
1272 httpurl
= fix_motherless_url(httpurl
);
1273 motherless_subdomain
= "cdn.";
1274 if(motherless_serv
<5 or motherless_serv
>0):
1275 motherless_subdomain
= "cdn"+str(motherless_serv
)+".";
1276 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1277 mrtext
= premrtext
['Content'];
1278 if(sys
.version
[0]>="3"):
1279 mrtext
= mrtext
.decode('ascii', 'replace');
1280 mrtext_tmp
= re
.sub(re
.escape("http://motherless.com"), "", mrtext
);
1281 mrtext_tmp
= re
.sub(re
.escape("http://www.motherless.com"), "", mrtext_tmp
);
1282 mrtext_tmp
= re
.sub(re
.escape("http://motherless.com"), "", mrtext_tmp
);
1283 mrtext_tmp
= re
.sub(re
.escape("http://www.motherless.com"), "", mrtext_tmp
);
1284 mregex_geturlone
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" title=\"motherless link\">");
1285 mlesslinkone
= re
.findall(mregex_geturlone
, mrtext_tmp
);
1286 mregex_geturlname
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" class=\"post-username special-member op-member\" title=\"op\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">");
1287 mlessurlname
= re
.findall(mregex_geturlname
, mrtext
);
1288 mlessavaturl
= "http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessurlname
[0][1]+"-avatar.jpg";
1289 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin(mlessavaturl
, urlparse
.urlparse(mlessavaturl
).path
));
1290 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1291 if(getlinks
[1]>len(mlesslinkone
) or getlinks
[1]==-1):
1292 getlinks
[1] = len(mlesslinkone
);
1293 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1294 tmpgetlinks0
= getlinks
[0];
1295 tmpgetlinks1
= getlinks
[1];
1296 getlinks
[0] = tmpgetlinks1
;
1297 getlinks
[1] = tmpgetlinks0
;
1302 returnval
= {'numoflinks': mlil
};
1303 returnval
.update({'numofalllinks': len(mlesslinkone
)});
1304 returnval
.update({'orginurl': httpurl
});
1305 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1306 mlessrooturltype
= get_motherless_link_type(httpurl
);
1307 returnval
.update({'urltype': mlessrooturltype
});
1308 returnval
.update({'userinfo': get_motherless_user_info(mlessurlname
[0][1])});
1309 returnval
.update({'username': mlessurlname
[0][1]});
1310 returnval
.update({'avatarurl': mlessavaturl
});
1311 returnval
.update({'avatarfullfilename': avatarfilenameext
});
1312 returnval
.update({'avatarfilename': avatarfilename
});
1313 returnval
.update({'avatarextension': avatarfileextension
});
1315 mlessurltype
= get_motherless_link_type("http://motherless.com"+mlesslinkone
[mli
]);
1316 returnval
.update({mli
: {'urltype': mlessurltype
, 'url': "http://motherless.com"+mlesslinkone
[mli
]} });
1320 def get_motherless_boards_posts(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", getposts
=[0, -1], motherless_serv
=None):
1321 httpurl
= fix_motherless_url(httpurl
);
1322 motherless_subdomain
= "cdn.";
1323 if(motherless_serv
<5 or motherless_serv
>0):
1324 motherless_subdomain
= "cdn"+str(motherless_serv
)+".";
1325 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1326 mrtext
= premrtext
['Content'];
1327 if(sys
.version
[0]>="3"):
1328 mrtext
= mrtext
.decode('ascii', 'replace');
1329 mregex_getposts
= "(\t+)"+re
.escape("<p>")+"(.+?)"+re
.escape("</p>")+"(\t+)";
1330 mlessposts
= re
.findall(mregex_getposts
, mrtext
);
1331 mregex_getuname
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\"");
1332 mlessuname
= re
.findall(mregex_getuname
, mrtext
);
1333 mregex_getopuname
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" class=\"post-username special-member op-member\" title=\"op\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">");
1334 mlessopuname
= re
.findall(mregex_getopuname
, mrtext
);
1335 if(getposts
[1]>len(mlessposts
) or getposts
[1]==-1):
1336 getposts
[1] = len(mlessposts
);
1337 if(getposts
[0]>getposts
[1] and not getposts
[1]==-1):
1338 tmpgetposts0
= getposts
[0];
1339 tmpgetposts1
= getposts
[1];
1340 getposts
[0] = tmpgetposts1
;
1341 getposts
[1] = tmpgetposts0
;
1346 returnval
= {'numofposts': mlil
};
1347 returnval
.update({'numofallposts': len(mlessposts
)});
1348 returnval
.update({'orginurl': httpurl
});
1349 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1350 mlessrooturltype
= get_motherless_link_type(httpurl
);
1351 returnval
.update({'urltype': mlessrooturltype
});
1352 returnval
.update({'userinfo': get_motherless_user_info(mlessopuname
[0][1])});
1353 returnval
.update({'username': mlessopuname
[0][1]});
1354 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessopuname
[0][1]+"-avatar.jpg", urlparse
.urlparse("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessopuname
[0][1]+"-avatar.jpg").path
));
1355 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1356 returnval
.update({'avatarurl': "http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessopuname
[0][1]+"-avatar.jpg"});
1357 returnval
.update({'avatarfullfilename': avatarfilenameext
});
1358 returnval
.update({'avatarfilename': avatarfilename
});
1359 returnval
.update({'avatarextension': avatarfileextension
});
1361 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
]+"-avatar.jpg", urlparse
.urlparse("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
]+"-avatar.jpg").path
));
1362 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1363 returnval
.update({mli
: {'post': mlessposts
[mli
][1], 'userinfo': get_motherless_user_info(mlessuname
[mli
]), 'username': mlessuname
[mli
], 'avatarurl': "http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext
, 'avatarfilename': avatarfilename
, 'avatarextension': avatarfileextension
} });
1367 def get_motherless_links_comments(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", getposts
=[0, -1], motherless_serv
=None):
1368 httpurl
= fix_motherless_url(httpurl
);
1369 motherless_subdomain
= "cdn.";
1370 if(motherless_serv
<5 or motherless_serv
>0):
1371 motherless_subdomain
= "cdn"+str(motherless_serv
)+".";
1372 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1373 mrtext
= premrtext
['Content'];
1374 if(sys
.version
[0]>="3"):
1375 mrtext
= mrtext
.decode('ascii', 'replace');
1376 mregex_getposts
= re
.escape("<div style=\"text-align: justify;\">\n")+"(\t+)(.+?)"+re
.escape("</div>");
1377 mlessposts
= re
.findall(mregex_getposts
, mrtext
);
1378 mregex_getuname
= re
.escape("<div class=\"media-comment\" id=\"")+'?\'?([^"\'>]*)'+re
.escape("\" rel=\"0\" rev=\"")+'?\'?([^"\'>]*)'+re
.escape("\">");
1379 mlessuname
= re
.findall(mregex_getuname
, mrtext
);
1380 mregex_getopuname
= re
.escape("<tr rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\"");
1381 mlessopuname
= re
.findall(mregex_getopuname
, mrtext
);
1382 if(getposts
[1]>len(mlessposts
) or getposts
[1]==-1):
1383 getposts
[1] = len(mlessposts
);
1384 if(getposts
[0]>getposts
[1] and not getposts
[1]==-1):
1385 tmpgetposts0
= getposts
[0];
1386 tmpgetposts1
= getposts
[1];
1387 getposts
[0] = tmpgetposts1
;
1388 getposts
[1] = tmpgetposts0
;
1393 returnval
= {'numofposts': mlil
};
1394 returnval
.update({'numofallposts': len(mlessposts
)});
1395 returnval
.update({'orginurl': httpurl
});
1396 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1397 mlessrooturltype
= get_motherless_link_type(httpurl
);
1398 returnval
.update({'urltype': mlessrooturltype
});
1399 returnval
.update({'userinfo': get_motherless_user_info(mlessopuname
[0])});
1400 returnval
.update({'username': mlessopuname
[0]});
1401 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessopuname
[0]+"-avatar.jpg", urlparse
.urlparse("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessopuname
[0]+"-avatar.jpg").path
));
1402 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1403 returnval
.update({'avatarurl': "http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessopuname
[0]+"-avatar.jpg"});
1404 returnval
.update({'avatarfullfilename': avatarfilenameext
});
1405 returnval
.update({'avatarfilename': avatarfilename
});
1406 returnval
.update({'avatarextension': avatarfileextension
});
1408 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
][1]+"-avatar.jpg", urlparse
.urlparse("http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
][1]+"-avatar.jpg").path
));
1409 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1410 returnval
.update({mli
: {'post': mlessposts
[mli
][1], 'userinfo': get_motherless_user_info(mlessuname
[mli
][1]), 'username': mlessuname
[mli
][1], 'avatarurl': "http://"+motherless_subdomain
+"avatars.motherlessmedia.com/thumbs/"+mlessuname
[mli
][1]+"-avatar.jpg", 'avatarfullfilename': avatarfilenameext
, 'avatarfilename': avatarfilename
, 'avatarextension': avatarfileextension
} });
1414 def get_motherless_search_members(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", page
=1, getlinks
=[0, -1]):
1415 httpurl
= fix_motherless_url(httpurl
);
1416 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1417 mrtext
= premrtext
['Content'];
1418 if(sys
.version
[0]>="3"):
1419 mrtext
= mrtext
.decode('ascii', 'replace');
1420 mregex_getpagenum
= re
.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">")+"([0-9]+)"+re
.escape("</a>");
1421 mlesspagenum
= re
.findall(mregex_getpagenum
, mrtext
);
1423 lastpage
= int(mlesspagenum
[-1][0]);
1428 httpurl
= add_url_param(httpurl
, page
=str(page
));
1429 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1430 mrtext
= premrtext
['Content'];
1431 if(sys
.version
[0]>="3"):
1432 mrtext
= mrtext
.decode('ascii', 'replace');
1433 mregex_getuname
= re
.escape("<tr rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\"");
1434 mlessuname
= re
.findall(mregex_getuname
, mrtext
);
1435 mregex_geturlname
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" target=\"_blank\">\n <img");
1436 mlessurlname
= re
.findall(mregex_geturlname
, mrtext
);
1437 mregex_getavatar
= re
.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re
.escape("\"\n class=\"avatar avatar-small\"");
1438 mlessavatar
= re
.findall(mregex_getavatar
, mrtext
);
1439 if(getlinks
[1]>len(mlessuname
) or getlinks
[1]==-1):
1440 getlinks
[1] = len(mlessuname
);
1441 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1442 tmpgetlinks0
= getlinks
[0];
1443 tmpgetlinks1
= getlinks
[1];
1444 getlinks
[0] = tmpgetlinks1
;
1445 getlinks
[1] = tmpgetlinks0
;
1450 returnval
= {'numoflinks': mlil
};
1451 returnval
.update({'numofalllinks': len(mlessuname
)});
1452 returnval
.update({'pages': lastpage
});
1453 returnval
.update({'curpage': page
});
1454 returnval
.update({'orginurl': httpurl
});
1455 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1456 mlessrooturltype
= get_motherless_link_type(httpurl
);
1457 returnval
.update({'urltype': mlessrooturltype
});
1459 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin(mlessavatar
[mli
], urlparse
.urlparse(mlessavatar
[mli
]).path
));
1460 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1461 mlessurlname
[mli
] = mlessurlname
[mli
].replace("/m/", "");
1462 mlessurltype
= get_motherless_link_type("http://motherless.com/"+mlessurlname
[mli
]);
1463 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
} });
1467 def get_motherless_girls(httpheaders
, httpcookie
, httplibuse
="urllib", getlinks
=[0, -1]):
1468 premrtext
= download_from_url("http://motherless.com/girls", httpheaders
, httpcookie
, httplibuse
);
1469 mrtext
= premrtext
['Content'];
1470 if(sys
.version
[0]>="3"):
1471 mrtext
= mrtext
.decode('ascii', 'replace');
1472 mregex_getuname
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" rev=\"")+'?\'?([^"\'>]*)'+re
.escape("\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">");
1473 mlessuname
= re
.findall(mregex_getuname
, mrtext
);
1474 mregex_geturlname
= re
.escape("\n\t\t\t\t\t\t<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" target=\"_blank\">");
1475 mlessurlname
= re
.findall(mregex_geturlname
, mrtext
);
1476 if(getlinks
[1]>len(mlessuname
) or getlinks
[1]==-1):
1477 getlinks
[1] = len(mlessuname
);
1478 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1479 tmpgetlinks0
= getlinks
[0];
1480 tmpgetlinks1
= getlinks
[1];
1481 getlinks
[0] = tmpgetlinks1
;
1482 getlinks
[1] = tmpgetlinks0
;
1487 returnval
= {'numoflinks': mlil
};
1488 returnval
.update({'numofalllinks': len(mlessuname
)});
1489 returnval
.update({'orginurl': "http://motherless.com/girls"});
1490 returnval
.update({'orginurltype': get_motherless_link_type("http://motherless.com/girls")});
1491 mlessrooturltype
= get_motherless_link_type("http://motherless.com/girls");
1492 returnval
.update({'urltype': mlessrooturltype
});
1494 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin(mlessuname
[mli
][0], urlparse
.urlparse(mlessuname
[mli
][0]).path
));
1495 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1496 mlessurltype
= get_motherless_link_type("http://motherless.com/"+mlessuname
[mli
][1]);
1497 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
} });
1501 def get_motherless_team(httpheaders
, httpcookie
, httplibuse
="urllib", getlinks
=[0, -1]):
1502 premrtext
= download_from_url("http://motherless.com/about", httpheaders
, httpcookie
, httplibuse
);
1503 mrtext
= premrtext
['Content'];
1504 if(sys
.version
[0]>="3"):
1505 mrtext
= mrtext
.decode('ascii', 'replace');
1506 mregex_getuname
= re
.escape("<div class=\"about-us-member\">\n <a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\"");
1507 mlessuname
= re
.findall(mregex_getuname
, mrtext
);
1508 mlessuname_odd
= mlessuname
[1::2];
1509 mlessuname_even
= mlessuname
[::2];
1510 mregex_getavatar
= re
.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re
.escape("\"\n class=\"avatar avatar-")+"(full|medium)"+re
.escape("\"");
1511 mlessavatar
= re
.findall(mregex_getavatar
, mrtext
);
1512 if(getlinks
[1]>len(mlessuname_odd
) or getlinks
[1]==-1):
1513 getlinks
[1] = len(mlessuname_odd
);
1514 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1515 tmpgetlinks0
= getlinks
[0];
1516 tmpgetlinks1
= getlinks
[1];
1517 getlinks
[0] = tmpgetlinks1
;
1518 getlinks
[1] = tmpgetlinks0
;
1523 returnval
= {'numoflinks': mlil
};
1524 returnval
.update({'numofalllinks': len(mlessuname
)});
1525 returnval
.update({'orginurl': "http://motherless.com/about"});
1526 returnval
.update({'orginurltype': get_motherless_link_type("http://motherless.com/about")});
1527 mlessrooturltype
= get_motherless_link_type("http://motherless.com/about");
1528 returnval
.update({'urltype': mlessrooturltype
});
1530 avatarfilenameext
= os
.path
.basename(urlparse
.urljoin(mlessavatar
[mli
][0], urlparse
.urlparse(mlessavatar
[mli
][0]).path
));
1531 avatarfilename
, avatarfileextension
= os
.path
.splitext(avatarfilenameext
);
1532 mlessuname_odd
[mli
] = mlessuname_odd
[mli
].replace("/m/", "");
1533 mlessuname_even
[mli
] = mlessuname_even
[mli
].replace("/m/", "");
1534 mlessurltype
= get_motherless_link_type("http://motherless.com/"+mlessuname_odd
[mli
]);
1535 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
} });
1539 def get_motherless_top_referrers(httpheaders
, httpcookie
, httplibuse
="urllib", getlinks
=[0, -1]):
1540 premrtext
= download_from_url("http://motherless.com/referers", httpheaders
, httpcookie
, httplibuse
);
1541 mrtext
= premrtext
['Content'];
1542 if(sys
.version
[0]>="3"):
1543 mrtext
= mrtext
.decode('ascii', 'replace');
1544 mregex_geturlname
= "([0-9]+)"+re
.escape(". <a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" class=\"pop\" target=\"_blank\" rel=\"nofollow\">\n ")+"(.*)"+re
.escape(" </a>");
1545 mlessurlname
= re
.findall(mregex_geturlname
, mrtext
);
1546 if(getlinks
[1]>len(mlessurlname
) or getlinks
[1]==-1):
1547 getlinks
[1] = len(mlessurlname
);
1548 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1549 tmpgetlinks0
= getlinks
[0];
1550 tmpgetlinks1
= getlinks
[1];
1551 getlinks
[0] = tmpgetlinks1
;
1552 getlinks
[1] = tmpgetlinks0
;
1557 returnval
= {'numoflinks': mlil
};
1558 returnval
.update({'numofalllinks': len(mlessurlname
)});
1559 returnval
.update({'orginurl': "http://motherless.com/referers"});
1560 returnval
.update({'orginurltype': get_motherless_link_type("http://motherless.com/referers")});
1561 mlessrooturltype
= get_motherless_link_type("http://motherless.com/referers");
1562 returnval
.update({'urltype': mlessrooturltype
});
1564 returnval
.update({mli
: {'urltype': "referer-links", 'url': mlessurlname
[mli
][1], 'title': mlessurlname
[mli
][2]} });
1568 def get_motherless_top_referers(httpheaders
, httpcookie
, httplibuse
="urllib", getlinks
=[0, -1]):
1569 return get_motherless_top_referrers(httpheaders
, httpcookie
, httplibuse
, getlinks
);
1571 def get_motherless_groups(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", page
=1, getlinks
=[0, -1]):
1572 httpurl
= fix_motherless_url(httpurl
);
1573 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1574 mrtext
= premrtext
['Content'];
1575 if(sys
.version
[0]>="3"):
1576 mrtext
= mrtext
.decode('ascii', 'replace');
1577 mregex_getpagenum
= re
.escape("\" class=\"pop\" rel=\"")+'?\'?([^"\'>]*)'+re
.escape("\">")+"([0-9]+)"+re
.escape("</a>");
1578 mlesspagenum
= re
.findall(mregex_getpagenum
, mrtext
);
1580 lastpage
= int(mlesspagenum
[-1][0]);
1585 httpurl
= add_url_param(httpurl
, page
=str(page
));
1586 premrtext
= download_from_url(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1587 mrtext
= premrtext
['Content'];
1588 if(sys
.version
[0]>="3"):
1589 mrtext
= mrtext
.decode('ascii', 'replace');
1590 mregex_getavatar
= re
.escape("<img\n src=\"")+'?\'?([^"\'>]*)'+re
.escape("\"\n class=\"avatar avatar-")+"(full|medium)"+re
.escape("\"");
1591 mlessavatar
= re
.findall(mregex_getavatar
, mrtext
);
1592 mregex_getgroups
= re
.escape("<a href=\"")+'?\'?([^"\'>]*)'+re
.escape("\" class=\"grunge motherless-red\">\n")+"(.*)"+re
.escape("</a>");
1593 mlessgroups
= re
.findall(mregex_getgroups
, mrtext
);
1594 if(getlinks
[1]>len(mlessgroups
) or getlinks
[1]==-1):
1595 getlinks
[1] = len(mlessgroups
);
1596 if(getlinks
[0]>getlinks
[1] and not getlinks
[1]==-1):
1597 tmpgetlinks0
= getlinks
[0];
1598 tmpgetlinks1
= getlinks
[1];
1599 getlinks
[0] = tmpgetlinks1
;
1600 getlinks
[1] = tmpgetlinks0
;
1605 returnval
= {'pages': lastpage
};
1606 returnval
.update({'curpage': page
});
1607 returnval
.update({'numoflinks': mlil
});
1608 returnval
.update({'numofalllinks': len(mlessgroups
)});
1609 returnval
.update({'orginurl': httpurl
});
1610 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1612 thumbfilenameext
= os
.path
.basename(urlparse
.urljoin(mlessavatar
[mli
][0], urlparse
.urlparse(mlessavatar
[mli
][0]).path
));
1613 thumbfilename
, thumbfileextension
= os
.path
.splitext(thumbfilenameext
);
1614 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
} });
1618 def get_motherless_sample_links(httpheaders
, httpcookie
, httplibuse
="urllib", numoflinks
=10, urltype
="video"):
1619 if(urltype
=="video"):
1620 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
]) } };
1621 if(urltype
=="image"):
1622 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
]) } };
1623 if(urltype
=="gallery"):
1624 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
]) } };
1626 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
]) } };
1629 def get_motherless_link_by_type(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", page
=1, getlinks
=[0, -1]):
1630 httpurl
= fix_motherless_url(httpurl
);
1632 if(get_motherless_link_type(httpurl
)=="link"):
1633 returnval
= get_motherless_links(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1634 if(get_motherless_link_type(httpurl
)=="gallery"):
1635 returnval
= get_motherless_galleries_links(httpurl
, httpheaders
, httpcookie
, httplibuse
, page
);
1636 if(get_motherless_link_type(httpurl
)=="sample-videos"):
1637 returnval
= get_motherless_sample_links(httpheaders
, httpcookie
, httplibuse
, 10, "video");
1638 if(get_motherless_link_type(httpurl
)=="sample-images"):
1639 returnval
= get_motherless_sample_links(httpheaders
, httpcookie
, httplibuse
, 10, "image");
1640 if(get_motherless_link_type(httpurl
)=="sample-galleries"):
1641 returnval
= get_motherless_sample_links(httpheaders
, httpcookie
, httplibuse
, 10, "gallery");
1642 if(get_motherless_link_type(httpurl
)=="sample" or get_motherless_link_type(httpurl
)=="sample-all"):
1643 returnval
= get_motherless_sample_links(httpheaders
, httpcookie
, httplibuse
, 10, "all");
1644 if(get_motherless_link_type(httpurl
)=="board"):
1645 returnval
= get_motherless_boards_links(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1646 if(get_motherless_link_type(httpurl
)=="member"):
1647 returnval
= get_motherless_search_members(httpurl
, httpheaders
, httpcookie
, httplibuse
, page
);
1648 if(get_motherless_link_type(httpurl
)=="girls"):
1649 returnval
= get_motherless_girls(httpheaders
, httpcookie
, httplibuse
);
1650 if(get_motherless_link_type(httpurl
)=="download"):
1651 returnval
= httpurl
;
1654 def view_motherless_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", viewerpro
="mpv", prearg
=[], proarg
=[]):
1655 httpurl
= fix_motherless_url(httpurl
);
1656 commandlist
= [viewerpro
] + prearg
;
1657 commandlist
= commandlist
+ [get_motherless_links(httpurl
, httpheaders
, httpcookie
, httplibuse
)['url']];
1658 commandlist
= commandlist
+ proarg
;
1659 mpvplaylistp
= subprocess
.Popen(commandlist
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
);
1660 mpvplayout
, mpvplayerr
= mpvplaylistp
.communicate();
1663 def download_motherless_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", sleep
=-1, buffersize
=[524288, 524288], outfile
="-", outpath
=os
.getcwd(), usetitlename
=False):
1664 global geturls_download_sleep
;
1665 httpurl
= fix_motherless_url(httpurl
);
1667 sleep
= geturls_download_sleep
;
1668 mlessurl
= get_motherless_links(httpurl
, httpheaders
, httpcookie
, httplibuse
);
1669 outputname
= mlessurl
['fullfilename'];
1670 outpath
= outpath
.rstrip(os
.path
.sep
);
1671 if(usetitlename
==True):
1672 outputname
= mlessurl
['title'];
1673 if(usetitlename
=="-" and outfile
=="-"):
1675 if(usetitlename
=="-" and not outfile
=="-"):
1676 outputname
= outfile
;
1677 returnval
= download_from_url_to_file(mlessurl
['url'], httpheaders
, httpcookie
, httplibuse
, outputname
, outpath
, buffersize
, sleep
);
1680 def download_motherless_links_by_type(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", sleep
=-1, buffersize
=[524288, 524288], outfile
="-", outpath
=os
.getcwd(), usetitlename
=False, page
=1, getlinks
=[0, -1]):
1681 global geturls_download_sleep
;
1682 httpurl
= fix_motherless_url(httpurl
);
1684 sleep
= geturls_download_sleep
;
1685 mlessurl
= get_motherless_link_by_type(httpurl
, httpheaders
, httpcookie
, httplibuse
, page
);
1686 if(mlessurl
['urltype']=="download"):
1687 outputname
= mlessurl
['fullfilename'];
1688 outpathname
= outpath
.rstrip(os
.path
.sep
);
1689 if(usetitlename
==True):
1690 outputname
= mlessurl
['title'];
1691 if(usetitlename
=="-" and outfile
[mli
]=="-"):
1693 if(usetitlename
=="-" and not outfile
[mli
]=="-"):
1694 outputname
= outfile
;
1695 returnval
= download_from_url_to_file(mlessurl
['url'], httpheaders
, httpcookie
, httplibuse
, outputname
, outpathname
, buffersize
, sleep
);
1696 if(not mlessurl
['urltype']=="download"):
1697 returnval
= mlessurl
;
1700 def download_motherless_galleries_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", sleep
=-1, buffersize
=[524288, 524288], outfile
="-", outpath
=os
.getcwd(), usetitlename
=False, page
=1, getlinks
=[0, -1]):
1701 global geturls_download_sleep
;
1702 httpurl
= fix_motherless_url(httpurl
);
1704 sleep
= geturls_download_sleep
;
1705 mlessgalleries
= get_motherless_galleries_links(httpurl
, httpheaders
, httpcookie
, httplibuse
, page
, getlinks
);
1707 mlil
= mlessgalleries
['numoflinks'];
1708 returnval
= {'pages': mlessgalleries
['pages']};
1709 returnval
.update({'numoflists': mlessgalleries
['numoflinks']});
1710 returnval
.update({'curpage': mlessgalleries
['curpage']});
1711 returnval
.update({'numoflinks': mlessgalleries
['numoflinks']});
1712 returnval
.update({'numofalllinks': mlessgalleries
['numofalllinks']});
1713 returnval
.update({'orginurl': httpurl
});
1714 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1716 mlesslink
= get_motherless_links(mlessgalleries
[mli
]['url'], httpheaders
, httpcookie
, httplibuse
);
1717 outputname
= mlesslink
['fullfilename'];
1718 outpath
= outpath
.rstrip(os
.path
.sep
);
1719 if(usetitlename
==True):
1720 outputname
= mlesslink
['title'];
1721 if(usetitlename
=="-" and outfile
=="-"):
1723 if(usetitlename
=="-" and not outfile
=="-"):
1724 outputname
= outfile
;
1725 returnval
.update({mli
: {'download': download_from_url_to_file(mlesslink
['url'], httpheaders
, httpcookie
, httplibuse
, outputname
, outpath
, buffersize
, sleep
), 'linkinfo': mlesslink
, 'outputfile': outputname
} });
1729 def download_motherless_boards_links(httpurl
, httpheaders
, httpcookie
, httplibuse
="urllib", sleep
=-1, buffersize
=[524288, 524288], outfile
="-", outpath
=os
.getcwd(), usetitlename
=False, getlinks
=[0, -1]):
1730 global geturls_download_sleep
;
1731 httpurl
= fix_motherless_url(httpurl
);
1733 sleep
= geturls_download_sleep
;
1734 mlessgalleries
= get_motherless_boards_links(httpurl
, httpheaders
, httpcookie
, httplibuse
, getlinks
);
1736 mlil
= mlessgalleries
['numoflinks'];
1737 returnval
= {'numoflists': mlessgalleries
['numoflinks']};
1738 returnval
.update({'numofalllinks': mlessgalleries
['numofalllinks']});
1739 returnval
.update({'orginurl': httpurl
});
1740 returnval
.update({'orginurltype': get_motherless_link_type(httpurl
)});
1742 mlesslink
= get_motherless_links(mlessgalleries
[mli
]['url'], httpheaders
, httpcookie
, httplibuse
);
1743 outputname
= mlesslink
['fullfilename'];
1744 outpath
= outpath
.rstrip(os
.path
.sep
);
1745 if(usetitlename
==True):
1746 outputname
= mlesslink
['title'];
1747 if(usetitlename
=="-" and outfile
=="-"):
1749 if(usetitlename
=="-" and not outfile
=="-"):
1750 outputname
= outfile
;
1751 returnval
.update({mli
: {'download': download_from_url_to_file(mlesslink
['url'], httpheaders
, httpcookie
, httplibuse
, outputname
, outpath
, buffersize
, sleep
), 'linkinfo': mlesslink
, 'outputfile': outputname
} });