Small update and added xv-dl.py.
[Python-Scripts.git] / MiniScripts / motherless-dl.py
blob4c70d86da8db3842f8d09a61d681f605d9fee512
1 #!/usr/bin/env python
3 '''
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2013 Cool Dude 2k - http://idb.berlios.de/
13 Copyright 2013 Game Maker 2k - http://intdb.sourceforge.net/
14 Copyright 2013 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: motherless-dl.py - Last Update: 10/11/2013 Ver. 1.6.4 RC 5 - Author: cooldude2k $
17 '''
19 from __future__ import division, absolute_import, print_function;
20 import re, os, sys, urllib, urllib2, cookielib, StringIO, gzip, time, datetime, argparse, urlparse;
21 if(__name__ == "__main__"):
22 sys.tracebacklimit = 0;
23 __version_info__ = (1, 6, 4, "RC 5");
24 if(__version_info__[3]!=None):
25 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2])+" "+str(__version_info__[3]);
26 if(__version_info__[3]==None):
27 __version__ = str(__version_info__[0])+"."+str(__version_info__[1])+"."+str(__version_info__[2]);
29 parser = argparse.ArgumentParser();
30 parser.add_argument("url", nargs="*", help="motherless url");
31 parser.add_argument("--version", action='store_true', help="print program version and exit");
32 parser.add_argument("--update", action='store_true', help="update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)");
33 parser.add_argument("--dump-user-agent", action='store_true', help="display the current browser identification");
34 parser.add_argument("--user-agent", nargs="?", default="Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0", help="specify a custom user agent");
35 parser.add_argument("--referer", nargs="?", default="http://motherless.com/", help="specify a custom referer, use if the video access");
36 parser.add_argument("--proxy", nargs="?", default=None, help="Use the specified HTTP/HTTPS proxy");
37 parser.add_argument("--id", action='store_true', help="use only video ID in file name");
38 parser.add_argument("--get-url", action='store_true', help="simulate, quiet but print URL");
39 parser.add_argument("--get-pageurl", action='store_true', help="simulate, quiet but print URL");
40 parser.add_argument("--get-title", action='store_true', help="simulate, quiet but print title");
41 parser.add_argument("--get-posts", action='store_true', help="simulate, quiet but print user posts");
42 parser.add_argument("--get-id", action='store_true', help="simulate, quiet but print id");
43 parser.add_argument("--get-thumbnail", action='store_true', help="simulate, quiet but print thumbnail URL");
44 parser.add_argument("--get-filename", action='store_true', help="simulate, quiet but print output filename");
45 parser.add_argument("--get-format", action='store_true', help="simulate, quiet but print file format");
46 parser.add_argument("--get-type", action='store_true', help="simulate, quiet but print file type");
47 parser.add_argument("--get-username", action='store_true', help="simulate, quiet but print uploaders username");
48 parser.add_argument("--get-bbcode", action='store_true', help="simulate, quiet but print bbcode");
49 parser.add_argument("--get-html", action='store_true', help="simulate, quiet but print html code");
50 parser.add_argument("--get-dimensions", action='store_true', help="simulate, quiet but print dimensions (width x height)");
51 parser.add_argument("--get-width", action='store_true', help="simulate, quiet but print width");
52 parser.add_argument("--get-height", action='store_true', help="simulate, quiet but print height");
53 parser.add_argument("--get-views", action='store_true', help="simulate, quiet but print number of views");
54 parser.add_argument("--get-favorites", action='store_true', help="simulate, quiet but print number of favorites");
55 parser.add_argument("--verbose", action='store_true', help="print various debugging information");
56 getargs = parser.parse_args();
57 if(getargs.version==True):
58 print(__version__);
59 sys.exit();
60 if(getargs.dump_user_agent==True):
61 print(getargs.user_agent);
62 sys.exit();
63 if(len(getargs.url)==0):
64 parser.print_help();
65 sys.exit();
66 def motherless_dl(mtlessgetargs=vars(getargs)):
67 fakeua = mtlessgetargs["user_agent"];
68 proxycfg = None;
69 if(mtlessgetargs["proxy"]!=None):
70 proxycfg = urllib2.ProxyHandler({"http": getargs.proxy});
71 geturls_cj = cookielib.CookieJar();
72 if(proxycfg==None):
73 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(geturls_cj));
74 if(proxycfg!=None):
75 geturls_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(geturls_cj), proxycfg);
76 geturls_opener.addheaders = [("Referer", mtlessgetargs["referer"]), ("User-Agent", fakeua), ("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")];
77 urllib2.install_opener(geturls_opener);
78 per_gal_sleep = 0;
79 per_url_sleep = 0;
80 numurlarg = len(mtlessgetargs["url"]);
81 cururlarg = 0;
82 while(cururlarg<numurlarg):
83 mlessvid = mtlessgetargs["url"][cururlarg];
84 if(re.match("^s([0-9]+)"+re.escape(".motherlessmedia.com"), urlparse.urlparse(mlessvid).hostname)):
85 geturls_text = geturls_opener.open("http://motherless.com/mogile_api.php?path="+urllib.quote_plus(mlessvid)+"&redirect=1");
86 mlessvid = geturls_text.geturl();
87 mregex_text = re.escape("http://motherless.com/")+"([\w\/\?\&\=]+)";
88 if(re.findall(mregex_text, mlessvid)):
89 mlessvid = re.findall(mregex_text, mlessvid);
90 mlessvid = "http://motherless.com/"+mlessvid[0];
91 if(mtlessgetargs["verbose"]==True):
92 print(mlessvid);
93 if(re.match("^"+re.escape("thumbs.motherlessmedia.com"), urlparse.urlparse(mlessvid).hostname)):
94 mlessvid = re.sub(re.escape("-zoom"), "", mlessvid);
95 mlessvid = re.sub(re.escape("-strip"), "", mlessvid);
96 mlessvidtmp = urlparse.urlparse(mlessvid).path.split("/");
97 mlessvid = "http://motherless.com/"+mlessvidtmp[2];
98 mregex_text = re.escape("http://motherless.com/")+"([\w\/\?\&\=]+)";
99 if(re.findall(mregex_text, mlessvid)):
100 mlessvid = re.findall(mregex_text, mlessvid);
101 mlessvid = "http://motherless.com/"+mlessvid[0];
102 mlessvid = re.sub(re.escape("http://motherless.com/"), "", mlessvid);
103 mlessvid = re.sub(re.escape("http://www.motherless.com/"), "", mlessvid);
104 mlessvid = re.sub(re.escape("https://motherless.com/"), "", mlessvid);
105 mlessvid = re.sub(re.escape("https://www.motherless.com/"), "", mlessvid);
106 mlessvid = re.sub(re.escape("motherless.com/"), "", mlessvid);
107 mlessvid = re.sub(re.escape("www.motherless.com/"), "", mlessvid);
108 mlessvid = re.sub("^"+re.escape("/"), "", mlessvid);
109 mlessvid = "http://motherless.com/"+mlessvid;
110 mregex_text = re.escape("http://motherless.com/")+"([\w\/\?\&\=]+)";
111 if(re.findall(mregex_text, mlessvid)):
112 mlessvid = re.findall(mregex_text, mlessvid);
113 mlessvid = "/"+mlessvid[0];
114 mlessvidqstr = urlparse.parse_qs(urlparse.urlparse(mlessvid).query);
115 mlessvidid = urlparse.urlparse(mlessvid).path.split("/");
116 mlessgallist = [];
117 if((re.match("^random", mlessvidid[1]) and len(mlessvidid)==2) or (re.match("^random", mlessvidid[1]) and len(mlessvidid)==3) and (re.match("^image", mlessvidid[2]) or re.match("^video", mlessvidid[2]))):
118 geturls_text = geturls_opener.open("http://motherless.com"+mlessvid);
119 mlessvid = geturls_text.geturl();
120 if(re.findall(mregex_text, mlessvid)):
121 mlessvid = re.findall(mregex_text, mlessvid);
122 mlessvid = mlessvid[0];
123 if(mtlessgetargs["verbose"]==True):
124 print(mlessvid);
125 if((re.match("^galleries", mlessvidid[1]) and len(mlessvidid)==4) or (re.match("^f", mlessvidid[1]) and re.match("^galleries", mlessvidid[2]) and len(mlessvidid)==4) or (re.match("^term", mlessvidid[1]) and re.match("^galleries", mlessvidid[2]) and len(mlessvidid)==4)):
126 geturls_text = geturls_opener.open("http://motherless.com"+mlessvid+"?page=1");
127 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
128 strbuf = StringIO.StringIO(geturls_text.read());
129 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
130 out_text = gzstrbuf.read()[:];
131 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
132 out_text = geturls_text.read()[:];
133 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
134 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
135 out_text = re.sub(re.escape("https://motherless.com"), "", out_text);
136 out_text = re.sub(re.escape("https://www.motherless.com"), "", out_text);
137 regex_ptext = re.escape("class=\"pop\" rel=\"")+"([0-9]+)"+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
138 page_text = re.findall(regex_ptext, out_text);
139 try:
140 numpages = int(page_text[-1][0]);
141 except IndexError:
142 numpages = 1;
143 curpage = 1;
144 while(curpage<=numpages):
145 if(curpage>1):
146 geturls_text = geturls_opener.open("http://motherless.com/"+mlessvid+"?page="+str(curpage));
147 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
148 strbuf = StringIO.StringIO(geturls_text.read());
149 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
150 out_text = gzstrbuf.read()[:];
151 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
152 out_text = geturls_text.read()[:];
153 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
154 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
155 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
156 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
157 regex_text = re.escape("")+"([\w\/]+)"+re.escape("\" class=\"img-container\" target=\"_self\">");
158 post_text = re.findall(regex_text, out_text);
159 numgal = len(post_text);
160 curgal = 0;
161 while(curgal<numgal):
162 mlessgallist.append(post_text[curgal]);
163 if(mtlessgetargs["verbose"]==True):
164 print(post_text[curgal]);
165 curgal = curgal + 1;
166 curpage = curpage + 1;
167 if(not re.match("^galleries", mlessvidid[1]) or (re.match("^galleries", mlessvidid[1]) and len(mlessvidid)<4) or (re.match("^galleries", mlessvidid[1]) and len(mlessvidid)>5)):
168 mlessgallist.append(mlessvid);
169 numusrgal = len(mlessgallist);
170 curusrgal = 0;
171 while(curusrgal<numusrgal):
172 mlessvid = mlessgallist[curusrgal];
173 if(not re.match("^\/", mlessvid)):
174 mlessvid = "/"+mlessvid;
175 mlessvidqstr = urlparse.parse_qs(urlparse.urlparse(mlessvid).query);
176 mlessvidid = urlparse.urlparse(mlessvid).path.split("/");
177 mlessurllist = [];
178 if((re.match("^G", mlessvidid[1]) and len(mlessvidid)==2) or (re.match("^H", mlessvidid[1]) and len(mlessvidid)==2) or (re.match("^V", mlessvidid[1]) and len(mlessvidid)==2) or (re.match("^live", mlessvidid[1]) and len(mlessvidid)==2) or (re.match("^g", mlessvidid[1]) and len(mlessvidid)==3) or (re.match("^u", mlessvidid[1]) and len(mlessvidid)==3) or (re.match("^term", mlessvidid[1]) and (re.match("^videos", mlessvidid[2]) or re.match("^images", mlessvidid[2])) and len(mlessvidid)==4) or (re.match("^f", mlessvidid[1]) and len(mlessvidid)==4 and (re.match("^videos", mlessvidid[3]) or re.match("^images", mlessvidid[3]))) or (re.match("^live", mlessvidid[1]) and len(mlessvidid)==3 and (re.match("^images", mlessvidid[2]) or re.match("^videos", mlessvidid[2]))) or (re.match("^images", mlessvidid[1]) and len(mlessvidid)==3 and (re.match("^favorited", mlessvidid[2]) or re.match("^viewed", mlessvidid[2]) or re.match("^commented", mlessvidid[2]) or re.match("^popular", mlessvidid[2]))) or (re.match("^videos", mlessvidid[1]) and len(mlessvidid)==3 and (re.match("^favorited", mlessvidid[2]) or re.match("^viewed", mlessvidid[2]) or re.match("^commented", mlessvidid[2]) or re.match("^popular", mlessvidid[2])))):
179 addtvar = False;
180 tvaradd = "";
181 if(re.match("^u", mlessvidid[1]) and len(mlessvidid)==3):
182 try:
183 if(mlessvidqstr["t"][0]=="i" or mlessvidqstr["t"][0]=="v"):
184 tvaradd = "&t="+mlessvidqstr["t"][0];
185 addtvar = True;
186 except KeyError:
187 addtvar = False;
188 except IndexError:
189 addtvar = False;
190 geturls_text = geturls_opener.open("http://motherless.com"+mlessvid+"?page=1"+tvaradd);
191 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
192 strbuf = StringIO.StringIO(geturls_text.read());
193 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
194 out_text = gzstrbuf.read()[:];
195 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
196 out_text = geturls_text.read()[:];
197 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
198 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
199 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
200 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
201 regex_ptext = re.escape("class=\"pop\" rel=\"")+"([0-9]+)"+re.escape("\">")+"([0-9]+)"+re.escape("</a>");
202 page_text = re.findall(regex_ptext, out_text);
203 try:
204 numpages = int(page_text[-1][0]);
205 except IndexError:
206 numpages = 1;
207 curpage = 1;
208 while(curpage<=numpages):
209 if(curpage>1):
210 geturls_text = geturls_opener.open("http://motherless.com"+mlessvid+"?page="+str(curpage)+tvaradd);
211 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
212 strbuf = StringIO.StringIO(geturls_text.read());
213 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
214 out_text = gzstrbuf.read()[:];
215 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
216 out_text = geturls_text.read()[:];
217 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
218 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
219 out_text = re.sub(re.escape("http://motherless.com"), "", out_text);
220 out_text = re.sub(re.escape("http://www.motherless.com"), "", out_text);
221 if(re.match("^V", mlessvidid[1])):
222 out_text = re.sub(re.escape("class=\"img-container\" target=\"_self\""), "title=\"motherless link\"", out_text);
223 out_text = re.sub(re.escape("class=\"pop plain\" target=\"_blank\""), "title=\"motherless link\"", out_text);
224 regex_text = re.escape("<a href=\"")+"([\w\/]+)"+re.escape("\" title=\"motherless link\">");
225 if(not re.match("^V", mlessvidid[1])):
226 regex_text = re.escape("")+"([\w\/]+)"+re.escape("\" class=\"img-container\" target=\"_self\">");
227 post_text = re.findall(regex_text, out_text);
228 numurls = len(post_text);
229 cururl = 0;
230 while(cururl<numurls):
231 mlessurllist.append(post_text[cururl]);
232 if(mtlessgetargs["verbose"]==True):
233 print(post_text[cururl]);
234 cururl = cururl + 1;
235 curpage = curpage + 1;
236 if((re.match("^G", mlessvidid[1]) and len(mlessvidid)==3 and re.match("([0-9A-F]+)", mlessvidid[2])) or (len(mlessvidid)==2 and re.match("([0-9A-F]+)", mlessvidid[1]))):
237 mlessurllist.append(mlessvid);
238 numlist = len(mlessurllist);
239 curlurl = 0;
240 mlessoutlist = [];
241 while(curlurl<numlist):
242 skiplnk = False;
243 try:
244 geturls_text = geturls_opener.open("http://motherless.com"+mlessurllist[curlurl]);
245 except urllib2.HTTPError:
246 skiplnk = True;
247 if(skiplnk==False):
248 if(geturls_text.info().get("Content-Encoding")=="gzip" or geturls_text.info().get("Content-Encoding")=="deflate"):
249 strbuf = StringIO.StringIO(geturls_text.read());
250 gzstrbuf = gzip.GzipFile(fileobj=strbuf);
251 subout_text = gzstrbuf.read()[:];
252 if(geturls_text.info().get("Content-Encoding")!="gzip" and geturls_text.info().get("Content-Encoding")!="deflate"):
253 subout_text = geturls_text.read()[:];
254 subout_text = re.sub(re.escape("http://motherless.com"), "", subout_text);
255 subout_text = re.sub(re.escape("http://www.motherless.com"), "", subout_text);
256 subout_text = re.sub(re.escape("http://motherless.com"), "", subout_text);
257 subout_text = re.sub(re.escape("http://www.motherless.com"), "", subout_text);
258 regex_title = re.escape("<title>")+"(.*)"+re.escape("</title>");
259 title_text = re.findall(regex_title, subout_text);
260 mlesstitle = re.sub(re.escape(" - MOTHERLESS.COM"), "", title_text[0]);
261 regex_thumb = re.escape("src=&quot;")+"(.*)"+re.escape("&quot;");
262 thumb_text = re.findall(regex_thumb, subout_text);
263 mlessthumb = thumb_text[0];
264 regex_text = re.escape("__fileurl = '")+"(.*)"+re.escape("';");
265 post_text = re.findall(regex_text, subout_text);
266 regex_img = re.escape("<meta property=\"og:image\" content=\"")+"(.*)"+re.escape("\">");
267 img_text = re.findall(regex_img, subout_text);
268 mlessimg = img_text[0];
269 regex_altimg = re.escape("<link rel=\"image_src\" type=\"image/")+"(.*)"+re.escape("\" href=\"")+"(.*)"+re.escape("\">");
270 altimg_text = re.findall(regex_altimg, subout_text);
271 mlessaltimg = altimg_text[0][1];
272 regex_usrname = re.escape("<a href=\"/u/")+"([\w]+)"+re.escape("\" class=\"pop plain thumb-member-link-uploads\">Uploads</a>");
273 usrname_text = re.findall(regex_usrname, subout_text);
274 mlessusrname = usrname_text[0];
275 mlessid = re.sub("^"+re.escape("/"), "", mlessurllist[curlurl]);
276 mlesspurl = "http://motherless.com"+mlessurllist[curlurl];
277 regex_numviews = re.escape("<strong>Views</strong>")+"\n+\t+([^\t]+)\t+"+re.escape("</h2>");
278 numviews_text = re.findall(regex_numviews, subout_text);
279 mlessnumviews = numviews_text[0];
280 mlessnumviews = re.sub(re.escape(","), "", mlessnumviews);
281 regex_numfavs = re.escape("<strong>Favorited</strong>")+"\n+\t+([^\t]+)\t+"+re.escape("</h2>");
282 numfavs_text = re.findall(regex_numfavs, subout_text);
283 mlessnumfavs = numfavs_text[0];
284 mlessnumfavs = re.sub(re.escape(","), "", mlessnumfavs);
285 ''' some good regex "!-%'-?A-~ " "!-%'-?A-~ \<\>\"\'\@\#" '''
286 regex_postdata = re.escape("<div class=\"media-comment-contents\">")+"\n\t+"+re.escape("<h4>")+"\n\t+"+re.escape("<a href=\"/m/")+"([\w]+)"+re.escape("\" class=\"pop plain\" target=\"_blank\">")+"\n\t+([^\t]+)\t+"+re.escape("</a>")+"\n\t+"+re.escape("</h4>")+"\n\t+"+re.escape("<div class=\"media-comment-meta\">")+"\n\t+([^\t]+)\t+"+re.escape("</div>")+"\n\t+"+re.escape("<div style=\"text-align: justify;\">")+"\n\t+([^\t]+)\t+"+re.escape("</div>");
287 postdata_text = re.findall(regex_postdata, subout_text);
288 numpost = len(postdata_text);
289 curpost = 0;
290 mlesspostlist = [];
291 ''' From Amber @ http://stackoverflow.com/a/9662362 '''
292 TAG_RE = re.compile(r'<[^>]+>');
293 while(numpost>0 and curpost<numpost):
294 newpostext = re.sub(re.escape("<br>"), "\n", postdata_text[curpost][3]);
295 newpostext = re.sub(re.escape("<br/>"), "\n", newpostext);
296 newpostext = re.sub(re.escape("<br />"), "\n", newpostext);
297 newpostext = TAG_RE.sub('', newpostext);
298 newpostext = re.sub(re.escape("/")+"([\w\/]+)", r"http://motherless.com/\1", newpostext);
299 mlesspostlist.append({"username": postdata_text[curpost][0], "avatar": "http://avatars.motherlessmedia.com/avatars/member/"+postdata_text[curpost][0]+".jpg", "smallavatar": "http://avatars.motherlessmedia.com/avatars/member/"+postdata_text[curpost][0]+"-small.jpg", "post": newpostext});
300 curpost = curpost + 1;
301 if(post_text>0):
302 mlesslink = post_text[0];
303 mlessext = os.path.splitext(urlparse.urlparse(mlesslink).path)[1];
304 mlessext = mlessext.replace(".", "");
305 mlessext = mlessext.lower();
306 if(mtlessgetargs["id"]==False):
307 mlessfname = urlparse.urlsplit(mlesslink).path.split("/")[-1];
308 if(mtlessgetargs["id"]==True):
309 mlessfname = re.sub(re.escape("/"), "_", mlessid)+"."+mlessext;
310 if(not mlessext=="mp4" and not mlessext=="flv"):
311 imginfo = {};
312 regex_ii_dimensions = re.escape("style=\"width: ")+"([0-9]+)"+re.escape("px; height: ")+"([0-9]+)"+re.escape("px; border: none;\"");
313 post_ii_dimensions = re.findall(regex_ii_dimensions, subout_text);
314 post_ii_width = post_ii_dimensions[0][0];
315 post_ii_height = post_ii_dimensions[0][1];
316 imginfo = {"width": int(post_ii_height), "height": int(post_ii_width), "views": int(mlessnumviews), "favorites": int(mlessnumfavs)};
317 if(mlessext=="mp4" or mlessext=="flv"):
318 vidinfo = {};
319 mlesslink = mlesslink+"?start=0";
320 regex_vi_file = re.escape("\"file\" : \"")+"(.*)"+re.escape("\",");
321 post_vi_file = re.findall(regex_vi_file, subout_text);
322 regex_vi_image = re.escape("\"image\" : \"")+"(.*)"+re.escape("\",");
323 post_vi_image = re.findall(regex_vi_image, subout_text);
324 regex_vi_height = re.escape("\"height\" : ")+"([0-9]+)"+re.escape(",");
325 post_vi_height = re.findall(regex_vi_height, subout_text);
326 regex_vi_width = re.escape("\"width\" : ")+"([0-9]+)"+re.escape(",");
327 post_vi_width = re.findall(regex_vi_width, subout_text);
328 regex_vi_filethumb = re.escape("\"file\": ")+"(.*)"+re.escape(",");
329 post_vi_filethumb = re.findall(regex_vi_filethumb, subout_text);
330 regex_vi_kind = re.escape("\"kind\": \"")+"(.*)"+re.escape("\"");
331 post_vi_kind = re.findall(regex_vi_kind, subout_text);
332 vidinfo = {"file": post_vi_file[0], "image": post_vi_image[0], "width": int(post_vi_width[0]), "height": int(post_vi_height[0]), "views": int(mlessnumviews), "favorites": int(mlessnumfavs), "filethumb": post_vi_filethumb[0], "thumbstrip": "http://thumbs.motherlessmedia.com/thumbs/"+mlessid+"-strip.jpg", "kind": post_vi_kind[0]};
333 if(mtlessgetargs["verbose"]==True):
334 print(mlesslink);
335 mlesslistitms = {};
336 mlesslistitms.update({"id": mlessid});
337 mlesslistitms.update({"title": mlesstitle});
338 mlesslistitms.update({"format": mlessext});
339 mlesslistitms.update({"filename": mlessfname});
340 mlesslistitms.update({"thumbnail": mlessthumb});
341 if(not mlessext=="mp4" and not mlessext=="flv"):
342 mlesslistitms.update({"vidpic": mlesslink});
343 mlesslistitms.update({"type": "image"});
344 mlesslistitms.update({"info": imginfo});
345 mlesslistitms.update({"dimensions": str(imginfo["width"])+"x"+str(imginfo["height"])});
346 mlesslistitms.update({"width": imginfo["width"]});
347 mlesslistitms.update({"height": imginfo["height"]});
348 mlesslistitms.update({"views": imginfo["views"]});
349 mlesslistitms.update({"favorites": imginfo["favorites"]});
350 if(mlessext=="mp4" or mlessext=="flv"):
351 mlesslistitms.update({"vidpic": mlessimg});
352 mlesslistitms.update({"type": "video"});
353 mlesslistitms.update({"info": vidinfo});
354 mlesslistitms.update({"dimensions": str(vidinfo["width"])+"x"+str(vidinfo["height"])});
355 mlesslistitms.update({"width": vidinfo["width"]});
356 mlesslistitms.update({"height": vidinfo["height"]});
357 mlesslistitms.update({"views": vidinfo["views"]});
358 mlesslistitms.update({"favorites": vidinfo["favorites"]});
359 mlesslistitms.update({"username": mlessusrname});
360 mlesslistitms.update({"avatar": "http://avatars.motherlessmedia.com/avatars/member/"+mlessusrname+".jpg"});
361 mlesslistitms.update({"smallavatar": "http://avatars.motherlessmedia.com/avatars/member/"+mlessusrname+"-small.jpg"});
362 mlesslistitms.update({"posts": mlesspostlist});
363 mlesslistitms.update({"pageurl": mlesspurl});
364 mlesslistitms.update({"url": mlesslink});
365 mlessoutlist.append(mlesslistitms);
366 if(curlurl<(numlist - 1)):
367 time.sleep(per_url_sleep);
368 curlurl = curlurl + 1;
369 if(curusrgal<(numusrgal - 1)):
370 time.sleep(per_gal_sleep);
371 curusrgal = curusrgal + 1;
372 cururlarg = cururlarg + 1;
373 return mlessoutlist;
374 if(__name__ == "__main__"):
375 mtlesslinks = motherless_dl();
376 mtlesslncount = len(mtlesslinks);
377 mtlesscurln = 0;
378 while(mtlesscurln<mtlesslncount):
379 if(getargs.get_id==True):
380 print(mtlesslinks[mtlesscurln]["id"]);
381 if(getargs.get_title==True):
382 print(mtlesslinks[mtlesscurln]["title"]);
383 if(getargs.get_posts==True):
384 numpost = len(mtlesslinks[mtlesscurln]["posts"]);
385 curpost = 0;
386 mlesspostlist = [];
387 while(numpost>0 and curpost<numpost):
388 print(mtlesslinks[mtlesscurln]["posts"][curpost]["username"]+": "+mtlesslinks[mtlesscurln]["posts"][curpost]["post"]);
389 curpost = curpost + 1;
390 if(getargs.get_format==True):
391 print(mtlesslinks[mtlesscurln]["format"]);
392 if(getargs.get_type==True):
393 print(mtlesslinks[mtlesscurln]["type"]);
394 if(getargs.get_filename==True):
395 print(mtlesslinks[mtlesscurln]["filename"]);
396 if(getargs.get_thumbnail==True):
397 print(mtlesslinks[mtlesscurln]["thumbnail"]);
398 if(mtlesslinks[mtlesscurln]["format"]=="mp4" or mtlesslinks[mtlesscurln]["format"]=="flv"):
399 print(mtlesslinks[mtlesscurln]["vidpic"]);
400 if(getargs.get_username==True):
401 print(mtlesslinks[mtlesscurln]["username"]);
402 if(getargs.get_pageurl==True):
403 print(mtlesslinks[mtlesscurln]["pageurl"]);
404 if(getargs.get_bbcode==True):
405 print("[URL="+mtlesslinks[mtlesscurln]["pageurl"]+"][IMG]"+mtlesslinks[mtlesscurln]["thumbnail"]+"[/IMG][/URL]");
406 if(getargs.get_html==True):
407 print("<a href=\""+mtlesslinks[mtlesscurln]["pageurl"]+"\"><img src=\""+mtlesslinks[mtlesscurln]["thumbnail"]+"\"></a>");
408 if(getargs.get_dimensions==True):
409 print(mtlesslinks[mtlesscurln]["dimensions"]);
410 if(getargs.get_width==True):
411 print(str(mtlesslinks[mtlesscurln]["width"]));
412 if(getargs.get_height==True):
413 print(str(mtlesslinks[mtlesscurln]["height"]));
414 if(getargs.get_views==True):
415 print(mtlesslinks[mtlesscurln]["views"]);
416 if(getargs.get_favorites==True):
417 print(mtlesslinks[mtlesscurln]["favorites"]);
418 if(getargs.get_url==True or (getargs.get_id==False and getargs.get_title==False and getargs.get_posts==False and getargs.get_format==False and getargs.get_filename==False and getargs.get_thumbnail==False and getargs.get_username==False and getargs.get_pageurl==False and getargs.get_bbcode==False and getargs.get_html==False and getargs.get_dimensions==False and getargs.get_width==False and getargs.get_height==False and getargs.get_views==False and getargs.get_favorites==False and getargs.get_type==False)):
419 print(mtlesslinks[mtlesscurln]["url"]);
420 mtlesscurln = mtlesscurln + 1;