Links are almost always base64 encoded now and the online url decoders always produce garbage. I was wondering if there is a project out there that would allow me to self-host this type of tool?
I’d probably network this container through gluetun because, yanno, privacy.
Edit to add: Doesn’t have to be specifically base64 focused. Any link decoder that I can use in a privacy respecting way, would be welcome.
Edit 2: See if your solution will decode this link (the one in the image): https://link.sfchronicle.com/external/41488169.38548/aHR0cHM6Ly93d3cuaG90ZG9nYmlsbHMuY29tL2hhbWJ1cmdlci1tb2xkcy9idXJnZXItZG9nLW1vbGQ_c2lkPTY4MTNkMTljYzM0ZWJjZTE4NDA1ZGVjYSZzcz1QJnN0X3JpZD1udWxsJnV0bV9zb3VyY2U9bmV3c2xldHRlciZ1dG1fbWVkaXVtPWVtYWlsJnV0bV90ZXJtPWJyaWVmaW5nJnV0bV9jYW1wYWlnbj1zZmNfYml0ZWN1cmlvdXM/6813d19cc34ebce18405decaB7ef84e41 (it should decode to this page: https://www.hotdogbills.com/hamburger-molds)
The
/
character isn’t a part of the base64 encoding. In fact, only one part of the URL looks like base64. No plain base64 tool (whether via CLI, self-hosted, or otherwise) will be able to decode an entire URL like that. You’ll first need to parse the URL to isolate the base64 part. This is literally solved with a single line of bash:echo "https://link.sfchronicle.com/external/41488169.38548/aHR0cHM6Ly93d3cuaG90ZG9nYmlsbHMuY29tL2hhbWJ1cmdlci1tb2xkcy9idXJnZXItZG9nLW1vbGQ_c2lkPTY4MTNkMTljYzM0ZWJjZTE4NDA1ZGVjYSZzcz1QJnN0X3JpZD1udWxsJnV0bV9zb3VyY2U9bmV3c2xldHRlciZ1dG1fbWVkaXVtPWVtYWlsJnV0bV90ZXJtPWJyaWVmaW5nJnV0bV9jYW1wYWlnbj1zZmNfYml0ZWN1cmlvdXM/6813d19cc34ebce18405decaB7ef84e41" | cut -d/ -f6 | base64 -d
See TIO for example.
edit: add TIO link
| cut -d/ -f6 |
means? I assume thecut
is the parsing? But maybe that is wrong? Would love to learn how to learn this.Try explainshell.com - you can paste in any oneliner and the site will parse it and explain each part.
Here’s the link
cut --help
andman cut
can teach you more than anyone here.But: “|” takes the output of the former command, and uses it as input for the latter. So it’s like copying the output of “echo […]”, executing “cut -d ‘/’ -f 6”, and pasting it into that. Then copy the output of “cut”, execute “base64 -d” and paste it there. Except the pipe (“|”) automates that on one line.
And yes, cut takes a string (so a list of characters, for example the url), split’s it at what -d specifies (eg. cut -d ‘/’ splits at “/”), so it now internally has a list of strings, “https:”, “”, “link.sfchronicle.com”, “external”, 41488169.38548", “aHR0cHM6Ly93d3cuaG90ZG9nYmlsbHMuY29tL2hhbWJ1cmdlci1tb2xkcy9idXJnZXItZG9nLW1vbGQ_c2lkPTY4MTNkMTljYzM0ZWJjZTE4NDA1ZGVjYSZzcz1QJnN0X3JpZD1udWxsJnV0bV9zb3VyY2U9bmV3c2xldHRlciZ1dG1fbWVkaXVtPWVtYWlsJnV0bV90ZXJtPWJyaWVmaW5nJnV0bV9jYW1wYWlnbj1zZmNfYml0ZWN1cmlvdXM” and “6813d19cc34ebce18405decaB7ef84e41”, and from that list outputs whatever is specified by -f (so eg. -f 6 means the 6th of those strings. And -f 2-3 means the 2nd to 3rd string. And -5 means everything up to and including the fifth, and 3- means everything after and including the third).
But all of that is explained better in the manpage (man cut). And the best way to learn is to just fuck around. So
echo "t es t str i n g, 1" | cut ...
and try various arguments.You can use
man <command>
(in this caseman cut
) to read a program’s manual page. Appending--help
(without any other arguments will often produce at least a short description of the program and list the available options.Cut into fields based on the delimiter (/ in this case). The “-f6” selects which field you want.