naming, unused import

This commit is contained in:
limkokhole
2020-06-22 19:27:31 +08:00
parent a670311855
commit ebae776261
2 changed files with 17 additions and 17 deletions

View File

@@ -12,7 +12,7 @@ Download all images/videos from Pinterest user/board/section.
- [x] Multi-threads when download images. - [x] Multi-threads when download images.
- [x] Media Filename naming in PinID_Title_Description_[Date].Ext meaningful form. - [x] Media Filename naming in PinID_Title_Description_[Date].Ext meaningful form.
- [x] Media Filename truncate to ... fit maximum filename length automatically. -c to cut if you prefer. - [x] Media Filename truncate to ... fit maximum filename length automatically. -c to cut if you prefer.
- [x] Log PinID, Title, Description, Link, Metadata, [Date] to log.log file since media filename can't fit. - [x] Log PinID, Title, Description, Link, Metadata, [Date] to log-pinterest-downloader.log file since media filename can't fit.
- [x] Unique board/log name with timestamp options. - [x] Unique board/log name with timestamp options.
### Usage: ### Usage:

View File

@@ -51,7 +51,7 @@ import colorama
from colorama import Fore from colorama import Fore
colorama.init() # Windows need this colorama.init() # Windows need this
ANSI_CLEAR = '\x1b[0m\x1b[K' #ANSI_CLEAR = '\x1b[0m\x1b[K'
HIGHER_GREEN = Fore.LIGHTGREEN_EX HIGHER_GREEN = Fore.LIGHTGREEN_EX
HIGHER_RED = Fore.LIGHTRED_EX HIGHER_RED = Fore.LIGHTRED_EX
BOLD_ONLY = ['bold'] BOLD_ONLY = ['bold']
@@ -314,7 +314,7 @@ def fetch_boards(uname):
return boards return boards
# The filesystem limites is 255(normal) or 143((eCryptfs) bytes # The filesystem limits is 255(normal) or 143((eCryptfs) bytes
# So can't blindly [:] slice without encode first (which most downloaders do the wrong way) # So can't blindly [:] slice without encode first (which most downloaders do the wrong way)
# And need decode back after slice # And need decode back after slice
# And to ensure mix sequence byte in UTF-8 and work # And to ensure mix sequence byte in UTF-8 and work
@@ -326,24 +326,24 @@ def fetch_boards(uname):
# https://stackoverflow.com/questions/13132976 # https://stackoverflow.com/questions/13132976
# https://stackoverflow.com/questions/50385123 # https://stackoverflow.com/questions/50385123
# https://stackoverflow.com/questions/11820006 # https://stackoverflow.com/questions/11820006
def get_max_path(arg_cut, fs_f_max, fpart_excluded_ext, ext): def get_max_path(arg_cut, fs_f_max, fpart_excluded_immutable, immutable):
#print('before f: ' + fpart_excluded_ext) #print('before f: ' + fpart_excluded_immutable)
if arg_cut >= 0: if arg_cut >= 0:
fpart_excluded_ext = fpart_excluded_ext[:arg_cut] fpart_excluded_immutable = fpart_excluded_immutable[:arg_cut]
if ext: if immutable:
ext_len = len(ext.encode('utf-8')) # just in case immutable_len = len(immutable.encode('utf-8')) # just in case
else: else:
ext_len = 0 immutable_len = 0
space_remains = fs_f_max - ext_len space_remains = fs_f_max - immutable_len
# range([start], stop[, step]) # range([start], stop[, step])
# -1 step * 4 loop = -4, means looping 4 bytes(UTF-8 max) from right to left # -1 step * 4 loop = -4, means looping 4 bytes(UTF-8 max) from right to left
for gostan in range(space_remains, space_remains - 4, -1): for gostan in range(space_remains, space_remains - 4, -1):
try: try:
fpart_excluded_ext = fpart_excluded_ext.encode('utf-8')[: gostan ].decode('utf-8') fpart_excluded_immutable = fpart_excluded_immutable.encode('utf-8')[: gostan ].decode('utf-8')
except UnicodeDecodeError: except UnicodeDecodeError:
pass #print('Calm down, this is normal: ' + str(gostan) + ' f: ' + fpart_excluded_ext) pass #print('Calm down, this is normal: ' + str(gostan) + ' f: ' + fpart_excluded_immutable)
#print('after f: ' + fpart_excluded_ext) #print('after f: ' + fpart_excluded_immutable)
return fpart_excluded_ext return fpart_excluded_immutable
def get_output_file_path(url, arg_cut, fs_f_max, image_id, human_fname, save_dir): def get_output_file_path(url, arg_cut, fs_f_max, image_id, human_fname, save_dir):
@@ -351,13 +351,13 @@ def get_output_file_path(url, arg_cut, fs_f_max, image_id, human_fname, save_dir
pin_id_str = str(image_id) pin_id_str = str(image_id)
basename = os.path.basename(url) basename = os.path.basename(url)
_, ext = basename.split('.') _, ext = basename.split('.')
non_cut_and_non_gotstan_field = pin_id_str + '.' + ext immutable = pin_id_str + '.' + ext
fpart_excluded_ext_before = sanitize( human_fname ) fpart_excluded_ext_before = sanitize( human_fname )
#print( 'get output f:' + fpart_excluded_ext_before ) #print( 'get output f:' + fpart_excluded_ext_before )
fpart_excluded_ext = get_max_path(arg_cut, fs_f_max, fpart_excluded_ext_before fpart_excluded_ext = get_max_path(arg_cut, fs_f_max, fpart_excluded_ext_before
, non_cut_and_non_gotstan_field) , immutable)
if fpart_excluded_ext: if fpart_excluded_ext:
if fpart_excluded_ext_before == fpart_excluded_ext: # means not truncat if fpart_excluded_ext_before == fpart_excluded_ext: # means not truncat
@@ -370,7 +370,7 @@ def get_output_file_path(url, arg_cut, fs_f_max, image_id, human_fname, save_dir
fpart_excluded_ext = fpart_excluded_ext[:-1] fpart_excluded_ext = fpart_excluded_ext[:-1]
fpart_excluded_ext = get_max_path(arg_cut, fs_f_max, fpart_excluded_ext fpart_excluded_ext = get_max_path(arg_cut, fs_f_max, fpart_excluded_ext
, '...' + non_cut_and_non_gotstan_field) , '...' + immutable)
fpart_excluded_ext = fpart_excluded_ext + '...' fpart_excluded_ext = fpart_excluded_ext + '...'