Obscure filenames of mp4 files - away from being embarrassed by accidently opening family videos at work!
Project description
filenames-secure
Obscure filenames of mp4 files - away from being embarrassed by accidently opening family videos at work!
Install with: pip install filenames-secure
Obscure filenames of mp4 files - away from being embarrassed by accidently opening family videos at work!
Usage
Simply $ filenames-secure
to obscure and restore.
How it Works
Filenames will be CRC-32'd, with restore record kept in an JSON file in the same folder.
Collisions
If there are hash collisions, a different secure filename will be selected, then the collision check goes again, until there are no collisions - so there should be no risks of getting data lost - however, there are no warranties.
Functional / Stability
If filename A is encoded into B this time, it will be encoded into B again next time, and forever - if there are no collisions that force a change.
Does CRC-32 often collide?
No. It rarely happens. If it occurs, I suggest going out, buying a lottery.
Code
The code is simple:
import abbrs
RC_FILENAME = 'filenames-secure.json'
def make_dat(ls):
def is_mp4(x):
s = x.split('.')
return len(s) >= 2 and (s[-1] == 'mp4' or s[-2] == 'mp4')
def check_collision(d):
for i, v in enumerate(d):
for j in range(i + 1, len(d)):
if d[i][0] == d[j][0]:
return j
dat = [ [ abbrs.cool_hash(i), i ] for i in filter(is_mp4, ls) ]
while True:
i = check_collision(dat)
if i:
print(f'Repairing collision: {dat[i][0]} -> {dat[i][1]}')
dat[i][0] = abbrs.cool_hash(dat[i][0])
else:
break
return dat
if __name__ == '__main__':
import os
if os.path.exists(RC_FILENAME):
dat = abbrs.load_json(RC_FILENAME)
for hash, filename in dat:
os.rename(hash, filename)
else:
dat = make_dat(os.listdir())
abbrs.json_dump(RC_FILENAME, dat)
for hash, filename in dat:
print(f'{hash} = {filename}')
os.rename(filename, hash)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for filenames_secure-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b1dd85712cf2f9992a3b1d91e6fb4e0b1d531700aa1934735bbe2b19c27b592 |
|
MD5 | 1b6ec8dc140edae1789188f3829d416f |
|
BLAKE2b-256 | 1d39443df68e422d33e143fdd3b967faa4c9d4020ed3d83cafc7255e2491f1fd |