Small update to PyPKG-Gen/PKGBuild.
[PyMotherless.git] / pymotherless-dl.py
blob886e7d203370dd75d3faaa922bb90fcc7638660e
1 #!/usr/bin/env python
3 '''
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2016 Cool Dude 2k - http://idb.berlios.de/
13 Copyright 2016 Game Maker 2k - http://intdb.sourceforge.net/
14 Copyright 2016 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: pymotherless-dl.py - Last Update: 4/20/2016 Ver. 0.4.5 RC 1 - Author: cooldude2k $
17 '''
19 from __future__ import division, absolute_import, print_function;
20 import re, os, sys, pymotherless, argparse;
21 import logging as log;
23 __project__ = pymotherless.__project__;
24 __program_name__ = pymotherless.__program_name__;
25 __project_url__ = pymotherless.__project_url__;
26 __version_info__ = pymotherless.__version_info__;
27 __version_date_info__ = pymotherless.__version_date_info__;
28 __version_date__ = pymotherless.__version_date__;
29 __version_date_plusrc__ = pymotherless.__version_date_plusrc__
30 __version__ = pymotherless.__version__;
31 __version_date_plusrc__ = pymotherless.__version_date_plusrc__;
33 geturls_cj = pymotherless.geturls_cj;
34 geturls_ua = pymotherless.geturls_ua;
35 geturls_ua_firefox_windows7 = pymotherless.geturls_ua_firefox_windows7;
36 geturls_ua_seamonkey_windows7 = pymotherless.geturls_ua_seamonkey_windows7;
37 geturls_ua_chrome_windows7 = pymotherless.geturls_ua_chrome_windows7;
38 geturls_ua_chromium_windows7 = pymotherless.geturls_ua_chromium_windows7;
39 geturls_ua_internet_explorer_windows7 = pymotherless.geturls_ua_internet_explorer_windows7;
40 geturls_ua_pymotherless_python = pymotherless.geturls_ua_pymotherless_python;
41 geturls_ua_pymotherless_python_alt = pymotherless.geturls_ua_pymotherless_python_alt;
42 geturls_ua_googlebot_google = pymotherless.geturls_ua_googlebot_google;
43 geturls_ua_googlebot_google_old = pymotherless.geturls_ua_googlebot_google_old;
44 geturls_headers = pymotherless.geturls_headers;
45 geturls_headers_firefox_windows7 = pymotherless.geturls_headers_firefox_windows7;
46 geturls_headers_seamonkey_windows7 = pymotherless.geturls_headers_seamonkey_windows7;
47 geturls_headers_chrome_windows7 = pymotherless.geturls_headers_chrome_windows7;
48 geturls_headers_chromium_windows7 = pymotherless.geturls_headers_chromium_windows7;
49 geturls_headers_internet_explorer_windows7 = pymotherless.geturls_headers_internet_explorer_windows7;
50 geturls_headers_pymotherless_python = pymotherless.geturls_headers_pymotherless_python;
51 geturls_headers_pymotherless_python_alt = pymotherless.geturls_headers_pymotherless_python_alt;
52 geturls_headers_googlebot_google = pymotherless.geturls_headers_googlebot_google;
53 geturls_headers_googlebot_google_old = pymotherless.geturls_headers_googlebot_google_old;
54 geturls_download_sleep = pymotherless.geturls_download_sleep;
56 parser = argparse.ArgumentParser(description="get urls of images/videos from motherless.com", conflict_handler="resolve", add_help=True);
57 parser.add_argument("url", help="motherless url");
58 parser.add_argument("--version", action="version", version=__program_name__+" "+__version__);
59 parser.add_argument("-U", "--update", action="store_true", help="update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)");
60 parser.add_argument("--dump-user-agent", action="store_true", help="display the current browser identification");
61 parser.add_argument("--user-agent", default="Mozilla/5.0 (Windows NT 6.1; rv:44.0) Gecko/20100101 Firefox/44.0", help="specify a custom user agent");
62 parser.add_argument("--referer", default="http://motherless.com/", help="specify a custom referer, use if the video access");
63 parser.add_argument("-g", "--get-url", action="store_true", help="simulate, quiet but print URL");
64 parser.add_argument("--get-pageurl", action="store_true", help="simulate, quiet but print URL");
65 parser.add_argument("-e", "--get-title", action="store_true", help="simulate, quiet but print title");
66 parser.add_argument("--get-id", action="store_true", help="simulate, quiet but print id");
67 parser.add_argument("--get-thumbnail", action="store_true", help="simulate, quiet but print thumbnail URL");
68 parser.add_argument("--get-filename", action="store_true", help="simulate, quiet but print output filename");
69 parser.add_argument("--get-username", action="store_true", help="simulate, quiet but print uploaders username");
70 parser.add_argument("--get-views", action="store_true", help="simulate, quiet but print number of views");
71 parser.add_argument("--get-favorites", action="store_true", help="simulate, quiet but print number of favorites");
72 parser.add_argument("-v", "--verbose", action="store_true", help="print various debugging information");
73 getargs = parser.parse_args();
75 getargs_cj = geturls_cj;
76 getargs_headers = {'Referer': getargs.referer, 'User-Agent': getargs.user_agent, 'Accept-Encoding': "gzip, deflate", 'Accept-Language': "en-US,en;q=0.8,en-CA,en-GB;q=0.6", 'Accept-Charset': "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7", 'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 'Connection': "close"};
78 if(getargs.verbose==True):
79 log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG);
81 if(getargs.dump_user_agent==True):
82 print(getargs.user_agent);
83 exit();
85 motherless_linktype = pymotherless.get_motherless_link_type(getargs.url);
86 motherless_links = [];
87 if(motherless_linktype=="file"):
88 motherless_links.append(getargs.url);
89 if(motherless_linktype=="gallery"):
90 numpages = pymotherless.get_motherless_number_of_pages(getargs.url, getargs_headers, getargs_cj);
91 numcount = 1;
92 while(numcount <= numpages):
93 getlinks = pymotherless.get_motherless_galleries_links(getargs.url, getargs_headers, getargs_cj, page=numcount);
94 innumlinks = getlinks['numoflinks'];
95 innumcount = 0;
96 while(innumcount < innumlinks):
97 inmotherless_linktype = pymotherless.get_motherless_link_type(getlinks[innumcount]['url']);
98 if(inmotherless_linktype=="file"):
99 motherless_links.append(getlinks[innumcount]['url']);
100 innumcount = innumcount + 1;
101 numcount = numcount + 1;
103 if(getargs.get_url==True):
104 listsize = len(motherless_links);
105 listcount = 0;
106 while(listcount < listsize):
107 print(pymotherless.get_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj)['url']);
108 listcount = listcount + 1;
110 if(getargs.get_pageurl==True):
111 listsize = len(motherless_links);
112 listcount = 0;
113 while(listcount < listsize):
114 print(motherless_links[listcount]);
115 listcount = listcount + 1;
117 if(getargs.get_filename==True):
118 listsize = len(motherless_links);
119 listcount = 0;
120 while(listcount < listsize):
121 print(pymotherless.get_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj)['fullfilename']);
122 listcount = listcount + 1;
124 if(getargs.get_title==True):
125 listsize = len(motherless_links);
126 listcount = 0;
127 while(listcount < listsize):
128 print(pymotherless.get_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj)['title']);
129 listcount = listcount + 1;
131 if(getargs.get_username==True):
132 listsize = len(motherless_links);
133 listcount = 0;
134 while(listcount < listsize):
135 print(pymotherless.get_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj)['username']);
136 listcount = listcount + 1;
138 if(getargs.get_views==True):
139 listsize = len(motherless_links);
140 listcount = 0;
141 while(listcount < listsize):
142 print(pymotherless.get_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj)['numberofviews']);
143 listcount = listcount + 1;
145 if(getargs.get_favorites==True):
146 listsize = len(motherless_links);
147 listcount = 0;
148 while(listcount < listsize):
149 print(pymotherless.get_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj)['numberoffavorites']);
150 listcount = listcount + 1;
152 if(getargs.get_url==False and getargs.get_pageurl==False and getargs.get_thumbnail==False and getargs.get_filename==False and getargs.get_title==False and getargs.get_username==False and getargs.get_views==False and getargs.get_favorites==False):
153 listsize = len(motherless_links);
154 listcount = 0;
155 while(listcount < listsize):
156 if(motherless_linktype=="file"):
157 pymotherless.download_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj);
158 if(motherless_linktype=="gallery"):
159 pymotherless.download_motherless_links(motherless_links[listcount], getargs_headers, getargs_cj, outpath=os.getcwd()+os.path.sep+getargs.url.rsplit('/', 1)[-1]);
160 listcount = listcount + 1;