mirror of
https://github.com/Xevion/truefile.git
synced 2025-12-06 21:16:54 -06:00
completed picture detection filtering via preservation of original filetype object
This commit is contained in:
@@ -11,12 +11,12 @@ def cli():
|
|||||||
def guess(*args, **kwargs):
|
def guess(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
g = filetype.guess(*args, **kwargs)
|
g = filetype.guess(*args, **kwargs)
|
||||||
return g.extension if g is not None else g
|
return g if g is not None else g
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def unequal(x, y):
|
def unequal(x, y):
|
||||||
return x != y
|
return x != '.' + y.extension
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option('-s', '--showall', is_flag=True, help='Show all files regardless of detected extension mishaps')
|
@click.option('-s', '--showall', is_flag=True, help='Show all files regardless of detected extension mishaps')
|
||||||
@@ -29,11 +29,14 @@ def detect(showall, picture):
|
|||||||
files = filter(os.path.isfile, files) # file not directory
|
files = filter(os.path.isfile, files) # file not directory
|
||||||
files = zip(files, map(guess, files)) # get scan of file type
|
files = zip(files, map(guess, files)) # get scan of file type
|
||||||
files = filter(lambda x : x[1] is not None, files) # filter for only images
|
files = filter(lambda x : x[1] is not None, files) # filter for only images
|
||||||
files = list(map(lambda x : (x[0], os.path.splitext(x[0])[1], '.' + x[1]), files)) # find just the file extension and put into tuple
|
files = list(map(lambda x : (x[0], os.path.splitext(x[0])[1], x[1]), files)) # find just the file extension and put into tuple
|
||||||
if not showall:
|
if not showall:
|
||||||
files = list(filter(lambda x : unequal(x[1], x[2]), files)) # filter for differing extensions
|
files = list(filter(lambda x : unequal(x[1], x[2]), files)) # filter for differing extensions
|
||||||
|
if picture:
|
||||||
|
files = list(filter(lambda x : x.mimetype == 'image', files))
|
||||||
|
print(f'Scanned {len(files)} files.')
|
||||||
largest = max(map(lambda x : len(x[0]), files)) # get length of the longest file name
|
largest = max(map(lambda x : len(x[0]), files)) # get length of the longest file name
|
||||||
print('\n'.join(map(lambda x : f'{x[0].ljust(largest)} | {colorama.Fore.RED if unequal(x[1], x[2]) else colorama.Fore.GREEN}{x[1]} -> {x[2]}{colorama.Fore.RESET}', files))) # print with proper spacing
|
print('\n'.join(map(lambda x : f'{x[0].ljust(largest)} | {colorama.Fore.RED if unequal(x[1], x[2]) else colorama.Fore.GREEN}{x[1]} -> {x[2].extension}{colorama.Fore.RESET}', files))) # print with proper spacing
|
||||||
print(colorama.Style.RESET_ALL, end='')
|
print(colorama.Style.RESET_ALL, end='')
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|||||||
Reference in New Issue
Block a user