1. ANSI clear 2. simplify url slice 3. empty slash list checking
This commit is contained in:
@@ -39,12 +39,19 @@ plat = platform.system().lower()
|
|||||||
if ('window' in plat) or plat.startswith('win'):
|
if ('window' in plat) or plat.startswith('win'):
|
||||||
# Darwin should treat as Linux
|
# Darwin should treat as Linux
|
||||||
IS_WIN = True
|
IS_WIN = True
|
||||||
|
# https://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences
|
||||||
|
# Even though ANSI escape sequence can be enable via `REG ADD HKCU\CONSOLE /f /v VirtualTerminalLevel /t REG_DWORD /d 1`
|
||||||
|
# But since this is not big deal to hide logo testing for this project, so no need.
|
||||||
|
ANSI_CLEAR = '\r' # Default cmd settings not support ANSI sequence
|
||||||
else:
|
else:
|
||||||
IS_WIN = False
|
IS_WIN = False
|
||||||
|
ANSI_CLEAR = '\r\x1b[0m\x1b[K'
|
||||||
try:
|
try:
|
||||||
import readline #to make input() edit-able by LEFT key
|
import readline #to make input() edit-able by LEFT key
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
pass
|
if not IS_WIN: #pyreadline for Windows? overkill
|
||||||
|
print('Please install readline module.')
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
x_tag = '✖'
|
x_tag = '✖'
|
||||||
@@ -52,8 +59,7 @@ try:
|
|||||||
plus_tag = '➕'
|
plus_tag = '➕'
|
||||||
pinterest_logo = '🅿️'
|
pinterest_logo = '🅿️'
|
||||||
# Test Windows unicode capability by printing logo, throws if not:
|
# Test Windows unicode capability by printing logo, throws if not:
|
||||||
print(pinterest_logo, end='\r')
|
print(pinterest_logo, end=ANSI_CLEAR, flush=True)
|
||||||
sys.stdout.flush()
|
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
x_tag = 'x'
|
x_tag = 'x'
|
||||||
done_tag = 'DONE'
|
done_tag = 'DONE'
|
||||||
@@ -859,7 +865,7 @@ def main():
|
|||||||
if url_path.endswith('/'):
|
if url_path.endswith('/'):
|
||||||
url_path = url_path[:-1]
|
url_path = url_path[:-1]
|
||||||
if '://' in url_path:
|
if '://' in url_path:
|
||||||
url_path = '/'.join(url_path.split('://')[1:][0].split('/')[1:])
|
url_path = '/'.join( url_path.split('/')[3:] )
|
||||||
if not url_path:
|
if not url_path:
|
||||||
return quit('{} {} {}'.format('\n[' + x_tag + '] Neither username/boardname nor valid link: ', args.path, '\n') )
|
return quit('{} {} {}'.format('\n[' + x_tag + '] Neither username/boardname nor valid link: ', args.path, '\n') )
|
||||||
if url_path.startswith('/'):
|
if url_path.startswith('/'):
|
||||||
@@ -868,7 +874,9 @@ def main():
|
|||||||
if '.' in slash_path[0]:
|
if '.' in slash_path[0]:
|
||||||
# Impossible dot in username, so it means host without https:// and nid remove
|
# Impossible dot in username, so it means host without https:// and nid remove
|
||||||
slash_path = slash_path[1:]
|
slash_path = slash_path[1:]
|
||||||
if len(slash_path) > 3:
|
if len(slash_path) == 0:
|
||||||
|
return quit('{} {} {}'.format('\n[' + x_tag + '] Neither username/boardname nor valid link: ', args.path, '\n') )
|
||||||
|
elif len(slash_path) > 3:
|
||||||
return quit('[!] Something wrong with Pinterest URL. Please report this issue at https://github.com/limkokhole/pinterest-downloader/issues , thanks.')
|
return quit('[!] Something wrong with Pinterest URL. Please report this issue at https://github.com/limkokhole/pinterest-downloader/issues , thanks.')
|
||||||
|
|
||||||
fs_f_max = None
|
fs_f_max = None
|
||||||
|
|||||||
Reference in New Issue
Block a user