File: test.py

package info (click to toggle)
persepolis-lib 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: python: 907; makefile: 2
file content (176 lines) | stat: -rwxr-xr-x 6,268 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import signal
import argparse
import sys
import os
import platform

# finding os platform
os_type = platform.system()

# Don't run persepolis as root!
if os_type == 'Linux' or os_type == 'FreeBSD' or os_type == 'OpenBSD' or os_type == 'Darwin':
    uid = os.getuid()
    if uid == 0:
        print('Do not run persepolis_lib as root.')
        sys.exit(1)


cwd = os.path.abspath(__file__)
run_dir = os.path.dirname(cwd)
# if persepolis run in test folder
print('persepolis_lib is running from test folder')
parent_dir = os.path.dirname(run_dir)

sys.path.insert(0, parent_dir)

from persepolis_lib.persepolis_lib import Download

# create  terminal arguments
parser = argparse.ArgumentParser(
    description='Persepolis command line download utility')
parser.add_argument('--version',
                    action='version', version='Persepolis lib: ' + Download.__Version__())
parser.add_argument('--link',
                    action='store', nargs=1,
                    help='Download link.(Use "" for links)')
parser.add_argument('--name',
                    action='store', nargs=1,
                    help='The  file  name  of  the downloaded file\
                            with extension.')
parser.add_argument('--number-of-threads',
                    action='store', nargs=1, help='Number of threads.')
parser.add_argument('--download-path', action='store', nargs=1,
                    help='Set download path.')
parser.add_argument('--proxy-ip', action='store', nargs=1, help='Proxy IP')
parser.add_argument('--proxy-port', action='store', nargs=1, help='proxy port')
parser.add_argument('--proxy-user',
                    action='store', nargs=1, help='Proxy user name')
parser.add_argument('--proxy-password', action='store', nargs=1,
                    help='Proxy pass word')
parser.add_argument('--proxy-type', action='store', nargs=1,
                    help='set type proxy. http or socks5')
parser.add_argument('--download-user', action='store', nargs=1,
                    help='Download user name')
parser.add_argument('--download-password', action='store', nargs=1,
                    help='Download pass word')
parser.add_argument('--header', action='store', nargs=1,
                    help='Append HEADER to HTTP request header.')
parser.add_argument('--user-agent', action='store', nargs=1,
                    help='Set user agent for HTTP(S) downloads.')
parser.add_argument('--cookie', action='store', nargs=1, help='Cookies file path')
parser.add_argument('--referrer', action='store', nargs=1,
                    help='Set an http referrer')
parser.add_argument('--chunk-size', action='store', nargs=1,
                    help='Chunk size in KiB, Default is 200 KiB')

parser.add_argument('--check-certificate', action='store', nargs=1,
                    help='Use certificate to verify the peers, Default is yes')

args, unknownargs = parser.parse_known_args()

add_link_dictionary = {'link': None,
                       'out': None,
                       'download_path': None,
                       'ip': None,
                       'port': None,
                       'proxy_user': None,
                       'proxy_passwd': None,
                       'proxy_type': None,
                       'download_user': None,
                       'download_passwd': None,
                       'header': None,
                       'user_agent': None,
                       'load_cookies': None,
                       'referer': None}


if args.link:
    add_link_dictionary['link'] = "".join(args.link)

if args.name:
    add_link_dictionary['out'] = "".join(args.name)

if args.download_path:
    add_link_dictionary['download_path'] = "".join(args.download_path)

if args.proxy_ip:
    add_link_dictionary['ip'] = "".join(args.proxy_ip)

if args.proxy_port:
    add_link_dictionary['port'] = "".join(args.proxy_port)

if args.proxy_user:
    add_link_dictionary['proxy_user'] = "".join(args.proxy_user)

if args.proxy_password:
    add_link_dictionary['proxy_passwd'] = "".join(args.proxy_password)

if args.proxy_type:
    add_link_dictionary['proxy_type'] = "".join(args.proxy_type)

if args.download_user:
    add_link_dictionary['download_user'] = "".join(args.download_user)

if args.download_password:
    add_link_dictionary['download_passwd'] = "".join(args.download_password)

if args.header:
    add_link_dictionary['header'] = "".join(args.header)


if args.user_agent:
    add_link_dictionary['user_agent'] = "".join(args.user_agent)

if args.cookie:
    add_link_dictionary['load_cookies'] = "".join(args.cookie)

if args.referrer:
    add_link_dictionary['referer'] = "".join(args.referrer)

if args.number_of_threads:
    number_of_threads = "".join(args.number_of_threads)
else:
    number_of_threads = 64

if args.check_certificate:
    check_certificate_out = "".join(args.check_certificate)
    if check_certificate_out in ['yes', 'true', 'True']:

        add_link_dictionary['check_certificate'] = True
    else:
        add_link_dictionary['check_certificate'] = False
else:
    add_link_dictionary['check_certificate'] = True

if args.chunk_size:
    chunk_size = "".join(args.chunk_size)
else:
    chunk_size = 200


if __name__ == '__main__':
    # create download object
    download_item = Download(add_link_dictionary, int(number_of_threads),
                             int(chunk_size), progress_bar=True, threads_progress_bar=False)

    # capture SIGINT signal
    signal.signal(signal.SIGINT, download_item.stop)

    # start download
    download_item.start()