A Python program for encoding urls using filename-valid (Win/Mac/Lin) characters in a human-readable way.
This program was written to allow saving images from the web with their source url in the filename.
It replaces unwanted characters (\/<>:*?"|.
) with filename-valid ones ({}[];+`'~,
). These replacement characters are encoded with an escape character (!
) before it. That is, the text Sharp and Curly: <> {} ;
becomes Sharp and Curly; [] !{!} !;
First, install python (python.org)
Next, run url_as_file_interactive.py
and follow the prompts to encode or decode text in your terminal.
Run python url_as_file_cmd.py -h
in your terminal for help.
Import url_as_file and codecs to start decoding and encoding strings in python:
import url_as_file
import codecs
my_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
result = codecs.encode(my_url, 'url-as-file')
print(result)
decode = codecs.decode(result, 'url-as-file')
print(decode)
Output:
https;}}www,youtube,com}watch`v=dQw4w9WgXcQ
https://www.youtube.com/watch?v=dQw4w9WgXcQ