19
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
21
21
# sudo apt install python3-urllib3
22
- import argparse , struct , sys , threading , logging , json , urllib , subprocess , tempfile
22
+ import struct , sys , threading , logging , json , urllib , subprocess , tempfile
23
23
from urllib .parse import urlparse
24
24
from urllib .request import urlopen
25
25
from os .path import splitext , basename , join , expanduser
26
26
from mimetypes import guess_extension
27
27
28
28
cookie_filepath = join (tempfile .gettempdir (), 'uget_cookie' )
29
29
UGET_COMMAND = "uget-gtk"
30
- UGET_CATEGORY_DIR = join (expanduser ('~' ), '.config/uGet/category' )
31
30
VERSION = "2.0.4"
32
31
33
32
logger = logging .getLogger ()
34
- # log_file_path = join(expanduser('~'), 'uget-chrome-wrapper.log')
35
- # logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', filename=log_file_path, filemode='a', level=logging.DEBUG)
33
+ log_file_path = join (expanduser ('~' ), 'uget-chrome-wrapper.log' )
34
+ logging .basicConfig (format = '%(asctime)s [%(levelname)s]: %(message)s' , filename = log_file_path , filemode = 'a' , level = logging .DEBUG )
36
35
logger .propagate = False
37
36
38
37
# Platform specific configuration
@@ -42,7 +41,6 @@ if sys.platform == 'win32':
42
41
msvcrt .setmode (sys .stdin .fileno (), os .O_BINARY )
43
42
msvcrt .setmode (sys .stdout .fileno (), os .O_BINARY )
44
43
UGET_COMMAND = 'uget'
45
- UGET_CATEGORY_DIR = join (expanduser ('~' ), 'AppData\\ Local\\ uGet\\ category' )
46
44
47
45
def extract_file_name (url ):
48
46
fileName = ''
@@ -127,7 +125,7 @@ def read_message():
127
125
pass
128
126
if not filename :
129
127
filename = extract_file_name (url )
130
-
128
+
131
129
# Add the referer url
132
130
if referer :
133
131
command .append ("--http-referer=" + referer )
@@ -155,42 +153,5 @@ def read_message():
155
153
sys .exit (0 )
156
154
157
155
158
- def download_category (fileName ):
159
- """
160
- Download the category from the repository and store in the config folder.
161
- """
162
- downloads_directory = join (expanduser ('~' ), 'Downloads' )
163
- url = 'https://raw.githubusercontent.com/slgobinath/uget-chrome-wrapper/master/config/category/' + fileName
164
- with urlopen (url ) as response :
165
- data = json .loads (response .read ().decode ('utf-8' ))
166
- data ['info' ]['common' ]['folder' ] = join (downloads_directory , data ['info' ]['common' ]['folder' ])
167
-
168
- category_file = join (UGET_CATEGORY_DIR , fileName )
169
- logger .debug ('Writing to ' + str (category_file ))
170
- with open (category_file , 'w' ) as outfile :
171
- json .dump (data , outfile , indent = 4 )
172
-
173
- def add_categories ():
174
- """
175
- Download and add the categories to the uGet config directory.
176
- """
177
- for index in range (1 , 7 ):
178
- print ('000{}.json' .format (index ))
179
- download_category ('000{}.json' .format (index ))
180
-
181
- def Main ():
182
- read_message ()
183
-
184
-
185
156
if __name__ == '__main__' :
186
- parser = argparse .ArgumentParser ()
187
- parser .add_argument ("-c" , "--categorize" , help = "create new categories based on the file types" , action = "store_true" )
188
- parser .add_argument ("-v" , "--version" , help = "display the version of uget-chrome-wrapper and exit" , action = "store_true" )
189
- args = parser .parse_args ()
190
-
191
- if args .version :
192
- print ('uget-chrome-wrapper {}' .format (VERSION ))
193
- elif args .categorize :
194
- add_categories ()
195
- else :
196
- Main ()
157
+ read_message ()
0 commit comments